{listings} is a package that extends LaTeX's {verbatim} features. A variety of syntax highlighting options are available. For general questions about {verbatim} or {highlighting} use the respective tag. For the unrelated concept of list structures, use {lists} instead.
3
votes
1answer
60 views
verbments (listings alternative) and UTF-8
This is a follow-up question to UTF8 for listings
With these MWE I will not see the german umlauts in the resulted pdf (XeLaTeX was used):
\documentclass{article}
\usepackage{verbments}
...
6
votes
0answers
128 views
UTF8 for listings
With German umlauts I have to define these characters (Typesetting UTF8 listings with German Umlaute) and the following MWE is working:
\documentclass{article}
\usepackage[utf8]{inputenc}
...
1
vote
1answer
46 views
listing package: colored numbers, but not colored in variable names
How to format all numbers in a different color has been discussed in this post.
However, this also colors numbers that are part of a variable name. Is there an option to avoid that?
...
2
votes
1answer
40 views
listings package: formating all numbers in language definition?
How to format all numbers in a code has been shown here. I have adapted it to include it in a language definition:
\documentclass[fleqn, a4paper]{article}
\usepackage{listings}
\usepackage{color}
...
3
votes
1answer
132 views
How to include Maple code in LaTeX?
At here Fanciest way to include Mathematica code in LaTeX we can include Mathematica in LaTeX.
I want to include the code
restart:
with(geom3d):
eqS:=Equation(sphere(S,(x-1)^2 + (y-1)^2 +(z-1)^2 ...
4
votes
1answer
44 views
How to refer to the count value of number of lines in a lstlisting
I need to refer to to the count value of the number of lines in a listing. Is there a way to do that ?
\lstinputlisting[caption={SPARQL query used...},label={lst:sqry}]{codes/sparql_query.sparql}
...
3
votes
1answer
34 views
Add key for new Listings environment
I'm trying to add a new key to a custom listings environment. I have tried to modify this example.
My problem is that the value I am attempting to pass through in the document for the key does not ...
4
votes
2answers
101 views
Listing with mixed english and russian symbols in comments
I'm using the listings package for formatting .cpp code in LaTeX. My code needs to have mixed English and Russian words in comments. The font must be monospaced (preffered Courier family).
/* Prints ...
8
votes
2answers
148 views
Combining `tikzpicture` and `lstlisting`
I'm working on a custom lstlisting environment, in which I use TikZ to add a frame and a title. Because of the widespread curly braces of node I cannot use newenvironment, so I have to resort to ...
3
votes
1answer
35 views
Wider caption for listing using multicol
I am using the multicol and listings packages. I would like to have the caption spread across the entire listing for multi-column listings.
Here is a MWE of what I am attempting, however the output ...
6
votes
1answer
124 views
Typesetting an interactive “screen session”
Suppose I want to typeset a screen session in some programming language (GAP in my case, but it could be Python, BASH, or something else with an interactive read prompt just as well). So on my screen, ...
3
votes
2answers
76 views
Overbrace in lstlisting of Scala code
I want to add an overbrace to some text in a Scala code listing (using lstlisting).
\begin{lstlisting}
object TypeClass extends FooParMain {
def newApp(args: Array[String]) = new FooParApp {
...
3
votes
1answer
69 views
lstlisting in a box?
My problem is that I am trying to write a document with coloured sections for examples. Examples can contain code listings. Somehow I can't seem to combine a background colouring with a listing, or ...
1
vote
0answers
22 views
How to do source code listings in ConTeXt? [duplicate]
I am new to LaTeX and ConTeXt, so I hope I am not asking something obvious. I have been able to create a LaTeX document using \usepackage{listings}. Now I have discovered ConTeXt. Is it possible to ...
7
votes
1answer
202 views
“Display math should end with $$” error
I'm trying to write math in a code listing, like so :
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin[mathescape]{lstlisting}
$\infty$
\end{lstlisting}
\end{document}
I get ...
2
votes
0answers
49 views
Regular expressions in listings
I'm looking for a possibility to use regular expression in listings. I'd like to highlight each N thats followed by 4 decimal numbers for example N1234. How can I achieve that?
Here is an example:
...
2
votes
1answer
52 views
Use pxfonts in listings only
I really like the pxfont package for displaying code in listings. I would usually just do this to load pxfont for the entire document;
\usepackage{pxfonts}.
However, this time I am required to use a ...
1
vote
0answers
14 views
Minted in listing: break code across pages? [duplicate]
I'm using minted to highlight code. And I put that into listings -- in order to get those numbered. By it self minted breaks code across pages. But when I put it into listings -- I get code on a ...
1
vote
1answer
46 views
Minted: customise listing name? [duplicate]
How do I customize listing name: Listing 1: thing -- when I use minted? Here's an MWE:
\documentclass{article}
\usepackage{minted}
% \renewcommand{\lstlistingname}{Something} % doens't work!
...
5
votes
2answers
53 views
How to combine listing and figure into a single figure?
I am using package listings, and I would like to combine a listing and a figure into a single float. As an example, I am using listings as follows:
...
2
votes
1answer
48 views
\lstlistoflistings doesn't have enough room between numbers and title
I'm using the \lstlistoflistings command from the listings package to generate my list of code samples. Unfortunately there isn't enough room between the number and the code listing title. See the ...
2
votes
0answers
76 views
LaTeX source code listing like in professional books for \lstinputlisting [closed]
Found this topic: http://stackoverflow.com/questions/741985/latex-source-code-listing-like-in-professional-books and I'm very satisfied with this soulution, it looks just great in a generated pdf ...
1
vote
1answer
45 views
lst include has first line indented [duplicate]
When I'm including a source file, by way of \lstinputlistings{file/path/to/file}
However, This results in the following below:
Why is the first line not being formatted correctly? And how do i fix ...
6
votes
1answer
73 views
Adding words to lstlisting for Python langaue
I wish to add a few keywords to some python code inserted into a latex document. I want to make 'True' & 'False' appear yellow and also some module calls such as 'ttk' appear red. I have tried ...
1
vote
1answer
66 views
lstlisting: how to align highlighted code
I want to define a couple of new commands in order to highlight parts of my code (this is actually for a trace dump, not for a programming language).
My problem is that I can't seem to make the ...
2
votes
1answer
105 views
Syntax highlighting for different programming languages [duplicate]
In my paper I want to include some source codes with colored sytax. For syntax highlighting I use the listings package:
\lstset{frame=tb,
language={[Visual]Basic},
aboveskip=3mm,
belowskip=3mm,
...
6
votes
1answer
208 views
+50
Strange error when combining Beamer, Animate, Tikz and Listings
I'm working on some slides where I show how code is actually executed in Java. Therefore I'm working with the animate package to generate animations.
Without going into details, I've written a macro ...
1
vote
1answer
119 views
How to change fontsize in lstlisting without losing bold syntax highlighting?
If I load the listing package to set nice code and change the font size (like suggested there: Shrinking monospace style for listings package), I lose the syntax highlighting, because the font does ...
1
vote
1answer
112 views
Highlighting a Chunk of Code within a lstlisting by specifying the line number
This question in somehow related to http://stackoverflow.com/questions/1304315/highlighting-a-chunk-of-code-within-a-lstlisting but not exactly the same.
I want to make some slides with animation ...
2
votes
1answer
68 views
How to suppress automatic conversion of “<=” inside lstlisting/lstinline?
I have the following LaTeX code:
some text \lstinline!u <= 1! some text
In my output, the two characters <= get automatically joined to form a single "less-than-or-equal" chararacter (i.e. ...
2
votes
0answers
61 views
Default value for basicstyle in lstlisting
I have most of the code in Python, which renders very nice with this simple configuration of lstlisting
At a certain point I have to include an XML file, so I switched to language=XML but it renders ...
4
votes
1answer
58 views
Ignore keyword in Listings
Consider the following minimal example:
\documentclass{standalone}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[keywordstyle = \textbf, language = SQL, deletekeywords = {time}]
create ...
2
votes
0answers
48 views
spacing before scope resolution operator
I'm new to LaTeX and I have encountered a problem with the listings package, I have a space before the :: operator of C++ .
after reading lstlisting with c++: spaces around scope resolution operator ...
2
votes
1answer
140 views
Removing small gaps between lines in LaTeX lstlisting output
Whenever I set a somewhat dark background color in a code listing it becomes obvious that there are small line separations, these of course stay white making the overall appearance not desirable. My ...
0
votes
1answer
67 views
wrap listings package - Problem with verbatim argument
I would like to define a command that wraps a lstlisting environment in some other environments (esp. a minipage). I understand that working with verbatim arguments is a difficult task. I tried the ...
2
votes
2answers
69 views
How to prevent a listing from straddling two pages
If I have a small listing that happens to be at the end of a page,
how can I force LaTeX to place it on a new page so that it does not straddle two pages, which looks ugly for a small listing.
4
votes
2answers
115 views
Spaces inside Cyrillic listings
I want to include source file using listing package. In that file there are some cyrillic symbols in comments.
I setup listings like:
\lstset{extendedchars=\true,basicstyle=\ttfamily}
And in ...
4
votes
1answer
69 views
Make lstlisting honour baselinestretch
I have to use lstlisting instead of Verbatim in a particular case, because math escape doesn't work properly with the latter. I managed to have both look the same, but lstlisting ignores my ...
3
votes
1answer
97 views
Using math mode escapes with listings enabled fancyvrb
I am trying to escape math mode within Verbatim, using this answer. This works fine, until I use the listings package with fancyvrb=true
\documentclass{article}
\usepackage{fancyvrb}
...
14
votes
2answers
288 views
minted vs. texments vs. verbments
Regarding the typesetting of syntax-colored source code, I know that listings is inferior because it doesn't utilize a full lexer. Instead the Python-based solution is recommended. It seems there are ...
2
votes
1answer
85 views
Subscript and superscript in lstlisting?
I need to use subscript and superscript in a lstlisting block. lstlisting can replace strings by Latex commands, but is it also possible to replace some kind of regular expression like
...
2
votes
2answers
275 views
\ttfamily is too bold for me
I use the following settings for my listings:
\lstset{
%basicstyle=\ttfamily\tiny, % small
basicstyle=\ttfamily\scriptsize, % middle
}
But the font in the listings is too bold for me. I tried a ...
4
votes
1answer
61 views
Why doesn't \lstinline work in table column?
\documentclass[14pt]{extarticle}
\usepackage{xcolor}
\definecolor{deepblue}{rgb}{0,0,0.5}
\definecolor{deepred}{rgb}{0.6,0,0}
\definecolor{deepgreen}{rgb}{0,0.5,0}
\usepackage{listings}
...
2
votes
0answers
42 views
Right-align the prebreak symbol in a listings environment
I’m using the breaklines and prebreak option with listings, but I find it visually not very pleasing that the prebreak-symbols are not vertically aligned. I’d prefer if they were all on the very right ...
4
votes
0answers
71 views
lstlisting and this symbol : █ [duplicate]
I want to know how to print this symbol "█" that I have in an external file loaded with listing.
Or at least how to print it with \something, cause it's not a blackbox.
...
1
vote
1answer
120 views
Displaying (source)Code in research article [duplicate]
I have this urgent need to display two pieces of code side by side for comparison in my article. Displaying a code, I've couple of requirement
Should indent properly
Output should be syntax ...
1
vote
0answers
59 views
Globally set the justification in a framed box
I want to show the text from a Python Interpreter in a Windows console. This should be plain text (like you see in a command line terminal). I also want to show Python code snippets with highlighting. ...
4
votes
1answer
67 views
Set font size in pt in a listing
How can I set the basicstyle option to force the use of 9pt fonts in listings regardless of the default size of the document?
Using 9pt fonts is a requirement of the guidelines that I am using, so I ...
0
votes
1answer
55 views
Listings package not working properly with Exam class
When I gave my code in the exam class like
\begin{parts}
\part \begin{lstlisting}
echo The date is $date
\end{lstlisting}
\part \begin{lstlisting}
echo The date is $(date)
\end{lstlisting}
...
5
votes
1answer
75 views
listings package and latex3 variable
I'm trying to change a custom environment from a lot of optional parameters to a ;-separated list (using this answer as a template and writing its main functionality as a latex3 macro).
The macro ...


