Hi,
I wanna insert some referenceable code excerpts in a .tex file. What's my best option?
Status quo: while struggling with listings, I realized I couldn't squeeze the space between the words in the code.. so ended up using alltt, wrapped in a predefined example environment. But 'Example' is not really what I'm looking for ..
Update: However, if anyone knows how to decrease inter-word spacing in listing, I'm all ears on that as well.
Thanks.
General ⇒ Code Listings that can be referenced
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Code Listings that can be referenced
Get used to showing problems always by a proper minimal example. Otherwise missing information prevents effective help.
I can't comprehend your problems with listings. The package allows to put code into a floating environment which can be referenced. Code is usually typeset in a mono-spaced font. Hence there is no room for squeezing. The same applies to alltt. Perhaps you can clarify the reason(s) for shrinking inter-word spaces.
Thorsten
I can't comprehend your problems with listings. The package allows to put code into a floating environment which can be referenced. Code is usually typeset in a mono-spaced font. Hence there is no room for squeezing. The same applies to alltt. Perhaps you can clarify the reason(s) for shrinking inter-word spaces.
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 35
- Joined: Thu Oct 27, 2011 5:31 pm
Code Listings that can be referenced
I'm replacing images containing source code with, well, intext source code. Apart from aspect issues, I need to save a lot of space in the paper.
Here\s a min ex:
Using listings, "purple LINQ" jumps on line 2. With alltt, I still have some place left after "LINQ" until the end of line 1. The font size is the same, but the inter-word spacing is considerably larger with listings. If I take a closer look, the letters in one word seem to be pushing each other harder with listings...
Here\s a min ex:
Code: Select all
Code, edit and compile here:
\documentclass[runningheads,a4paper]{llncs}\usepackage{alltt}\usepackage{listings}\lstset{basicstyle=\footnotesize\ttfamily,breaklines = true}\begin{document}\begin{lstlisting}A painting synesthetically fragranced with vibrations of purple LINQ.\end{lstlisting}\begin{alltt}\footnotesize\ttfamily\centering\parbox{1.0\linewidth}{A painting synesthetically fragranced with vibrations of purple LINQ.}\end{alltt}\end{document}}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Code Listings that can be referenced
Indeed with listings the text seems to be spaced out a bit more. It will work with minted (see attachment).
This requires Python (and perhaps SetupTools) with Pygments installed. Pay attention to the instructions in the manual.
Code: Select all
Code, edit and compile here:
\documentclass[a4paper]{article}\usepackage{alltt}\usepackage{listings}\lstset{basicstyle=\footnotesize\ttfamily,breaklines=true}\usepackage{minted}\begin{document}\begin{lstlisting}[gobble=4]A painting synesthetically fragranced with vibrations of purple LINQ.\end{lstlisting}\begin{alltt}\footnotesizeA painting synesthetically fragranced with vibrations of purple LINQ.\end{alltt}\begin{minted}[fontsize=\footnotesize,gobble=4]{latex}A painting synesthetically fragranced with vibrations of purple LINQ.\end{minted}\end{document}
- Attachments
-
- The obtained output.
- code-formatting.png (17.66 KiB) Viewed 5728 times
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 35
- Joined: Thu Oct 27, 2011 5:31 pm
Re: Code Listings that can be referenced
Yep, worked, thanks. I'll come back a bit later with details on how I installed Pygments on Windows.