General ⇒ Code Listings that can be referenced
-
- Posts: 35
- Joined: Thu Oct 27, 2011 5:31 pm
Code Listings that can be referenced
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.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Code Listings that can be referenced
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
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
Here\s a min ex:
Code: Select all
\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
Code: Select all
\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}
- Attachments
-
- The obtained output.
- code-formatting.png (17.66 KiB) Viewed 6057 times
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 35
- Joined: Thu Oct 27, 2011 5:31 pm