GeneralCode Listings that can be referenced

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
laailalalaa
Posts: 35
Joined: Thu Oct 27, 2011 5:31 pm

Code Listings that can be referenced

Post by laailalalaa »

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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Code Listings that can be referenced

Post by localghost »

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
laailalalaa
Posts: 35
Joined: Thu Oct 27, 2011 5:31 pm

Code Listings that can be referenced

Post by laailalalaa »

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:

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}}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Code Listings that can be referenced

Post by localghost »

Indeed with listings the text seems to be spaced out a bit more. It will work with minted (see attachment).

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}\footnotesize
A 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}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
This requires Python (and perhaps SetupTools) with Pygments installed. Pay attention to the instructions in the manual.
Attachments
The obtained output.
The obtained output.
code-formatting.png (17.66 KiB) Viewed 5728 times
laailalalaa
Posts: 35
Joined: Thu Oct 27, 2011 5:31 pm

Re: Code Listings that can be referenced

Post by laailalalaa »

Yep, worked, thanks. I'll come back a bit later with details on how I installed Pygments on Windows.
Post Reply