# Tag Info

1

Using a separate listing environment for shell-scripts with a specific name is quite easy, see the \lstnewenvironment code. More difficult is the splitting of the .lol and .los settings: \lst@MakeCaption must be redefined and changed to use los instead of lol. Please note: The current version does not work well with hyperref due to the anchors! \...

0

Okay after your guys help I figured it must be a package that screwed up my list of listings behavior/styling. After some debugging I found the package: the package float screws it up! MWE: \documentclass[12pt]{report} \title{List of listings problem} \author{Gerjan} \date{June 2016} \usepackage[english]{babel} % \usepackage{float} % Including this ...

2

Here is a solution. Use \setlength{\cftbeforetoctitleskip}{<dimen>} because \lstlistoflistings use \tableofcontents \documentclass{article} \usepackage{tocloft} \usepackage{listings} \setlength{\cftbeforetoctitleskip}{5cm} \begin{document} A \lstlistoflistings \begin{lstlisting}[caption={bla bla},label=list] for i:=maxint to 0 do begin { do nothing } ...

2

breakable inside a tabular does not seem very healthy as the tcolorbox most likely can't break at all. The disrupted box breaks apparently in as much boxes as have been used before, which is either a bug or tcolorbox sums up some pagegoal.

3

Here is a solution. The counter lstlisting is defined using \AtBeginDocument so the change must be done after \begin{document} or using \AtBeginDocument \documentclass{book} \usepackage{lipsum} \usepackage{listings} \usepackage{chngcntr} \AtBeginDocument{\counterwithin{lstlisting}{chapter}} \begin{document} \chapter{Foo} \begin{lstlisting}[caption={bla ...

3

hbox don't break over page -- see the documentation. But you can store the box in an array and retrieve the width: \documentclass{article} \usepackage[T1]{fontenc} \usepackage[margin=1in]{geometry} \usepackage{listings} \usepackage[most]{tcolorbox} \begin{filecontents}{mylisting.txt} blbub blblb \end{filecontents} \begin{document} \newboxarray{mylisting} \...

3

Since tcblisting is a verbatim environment it has to see the correct \end{tcblisting},so use \scantokens{\begin{tcblisting}...\end{tcblisting}. The number can be shifted into the tabular with some left skip value. This compiles for me both with LuaLaTeX and pdfLaTeX (on TL 2015, not updated on my old notebok yet) \documentclass{article} \usepackage{...

4

The following employs moredelim and some boxing to have any (syntax-formatted) part of a listing as hyperlink: int main(){ @foo@(); // <-- identifier is hyperlink } The link target (URL) is specified with the macro \btSetUrl{ theurl }. You could setup it once or redefine it inside the listing using any of listings's escape-to-latex options. In the ...

5

The simplest method I can think of is to just use listings's escapechar key. This requires choosing a character that doesn't appear in the code. For example, I've used the pipe character | below, but this would need to be changed to something else if the code fragment contained, say, a logical or bitwise or operation. \documentclass{article} \usepackage{...

2

Shift the loading of float after listings, this will cure the problem. The reason is the float@listhead setting provided by float package. If the package is loaded after listings, listings uses a different setup for \lstlistoflistings, especially the spacings are quite standard then. \documentclass[a4paper, 11pt]{book} \usepackage{chngcntr} \usepackage{...

2

The log file contains a warning: Class scrreprt Warning: \float@listhead detected! (scrreprt) Implementation of \float@listhead became (scrreprt) deprecated in KOMA-Script v3.01 2008/11/14 and (scrreprt) has been replaced by several more flexible (scrreprt) features of package tocbasic. (scrreprt) ...

1


1

Add the lstlisting counter to the reset list of the section counter with \counterwithout*{lstlisting}{section} -- the * prevents redefinition of \thelstlisting then! Saying \makeatletter \g@addto@macro\appendix{% \counterwithin*{lstlisting}{section}% } \makeatother this will automatically enable this specific style of resetting if \appendix is ...

4

You cannot do it like this: a lstlisting environment cannot be nested inside an environment defined with \NewEnviron. Moreover, you can't nest an environment in one defined by \NewEnviron if you don't use the proper \begin tag. \documentclass{article} \usepackage{listings} \usepackage{comment} \lstnewenvironment{cpp}[1][] {\lstset{language=C++,#1}} {} ...

5

The syntax colored listings are solved by OPmac tricks 0124 (C syntax), 126 (html syntax) or 0152 (Python syntax). You can simply extend these macros for another language, if you need. Note that referred macros need not any special external processor. All is done in classical TeX.

3

I have found myself in a similar situation, previously, and I was able to solve the problem in this way: \documentclass{article} \usepackage{graphicx,color} \usepackage{booktabs} \usepackage{listings} \lstdefinelanguage{NeoIDL}{ sensitive = true, keywords={}, otherkeywords={% Operators >, <, == }, keywords = [2]{module, resource, ...

1

My recommendation would be to use the package matlab-prettifier, which is based on listings but provides enhanced features for MATLAB code above and beyond those provided by listings' Matlab language definition (including support for block comments): \documentclass{article} \usepackage{matlab-prettifier} \lstset{style=Matlab-editor} \begin{document} \begin{...

0

Thanks that works perfectly! I put it in a language define: \lstdefinelanguage{BL233} { basicstyle = \ttfamily, morestring=[b][\color{stringcol}]", showstringspaces=false, literate = *{0}{{\textcolor{numbercol}{\ttfamily 0}}}1 % numbers } Also lets me define a second language expansion that explains the single letter macro commands: eg ...

2

Please, don't use the minimal class for testing, see Why should the minimal class be avoided? You have two ways for avoiding the infinite loop: either doing \lstset in the preamble or using \sb instead of _. First way \documentclass{article} \usepackage{ fontspec, unicode-math, listings, syntax, } \lstset{ literate={N0}{{$ℕ$}{$_0$}}2 }...

6

Here's a LuaLaTeX-based solution. It defines a function that "gobbles" the contents of all figure, table, and lstlisting environments. The only input-related requirement is this: the environments' \begin and \end statements must not occur on one and the same line of input. Note that it's not necessary to modify or "prime" any of the existing figure, table, ...

8

You can use e.g. environ to collect the body and throw them away: \documentclass[]{article} \usepackage{environ,listings} \RenewEnviron{table}{} \RenewEnviron{lstlisting}{} \RenewEnviron{figure}{} \begin{document} abllbl \begin{figure} figure \end{figure} \begin{table} table \end{table} \begin{lstlisting} abc \end{lstlisting} \end{document} If you ...

2

In LaTeX # is a special character and you need to escape it: alsoletter = {\#}, keywords=[2]{\#if,\#endif,\#else}, should work as expected.

4

This can be solved by using booleans. You define a boolean variable which states whether you want to include figures and tables or not. Each figure and table statement has to be surrounded by an if statement testing for the boolean variable. The simplest way to do this is: \documentclass{article} \usepackage{graphicx} \newif\ifplotfig % you can also ...

2

Knuth has developed the list.tex macros to produce code listings. To produce a listing of the file test.c with the content #include <stdio.h> int main() { printf("Hello World!\n"); } we input on the terminal \$ pdftex list.tex test.c <<< "\\bye" and obtain the following output Drawbacks: No syntax highlighting Overly long lines ...

4

Add the fragile option to your frame (section 12.9 "Verbatim and Fragile Text", beamer user guide): \documentclass{beamer} \mode<presentation> { \usetheme{Madrid} } \usepackage{listings} \begin{document} \begin{frame}[fragile] \frametitle{Test Slide} \begin{enumerate} \item Item 1 \begin{lstlisting}[language=bash] echo "Item 1" \end{lstlisting} \...

2

What I usually have in my lstlisting setup is: \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{listings} \lstset{ inputencoding = utf8, % Input encoding extendedchars = true, % Extended ASCII texcl = true, % Activate LaTeX commands in comments mathescape = true % Mathematical ...

1

If you can accept to escape to LaTeX for accented characters. From page 15 in listings manual: Similarly, if you are using UTF-8 extended characters in a listing, they must be placed within an escape to LaTeX. Note: I've commented mcode because MikTeX didn't find it. \documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage[T1]...

3

tcolorbox normally issues \pagebreak (among other things) when starting; this is ignored in tabular, but not in longtable. \documentclass[11pt]{article} \usepackage[T1]{fontenc} \usepackage{color} \usepackage{listings} \usepackage{tcolorbox} \tcbuselibrary{many,listings} \usepackage{longtable} \definecolor{bg}{RGB}{240,240,240} \begin{document} \begin{...

2

You can use tcblisting environment from tcolorbox package. With hbox key it'll be sized according to the dimensions of the content. \documentclass[11pt]{article} \usepackage[T1]{fontenc} \usepackage{color} \usepackage{listings} \usepackage{tcolorbox} \tcbuselibrary{listings} \definecolor{bg}{RGB}{240,240,240} \begin{document} \begin{tabular}{|p{0.8\...

4

\begin{lstlisting}[caption={Algorithm \unexpanded{[1]} - example}] works on me. or as Manuel said: \begin{lstlisting}[caption={Algorithm {[1]} - example}]

2

Apparently, the numwidth for figures is too small (which seems the fault of the mwart class.) Either redefine \l@figure or use \usepackage{tocloft} \addtolength{\cftfignumwidth}{10pt} to add more space, say, 10pt, here. Choose another value at will. \documentclass[12pt]{mwart} % Kodowanie: \usepackage[utf8]{inputenc} \usepackage{tocloft} \...

Top 50 recent answers are included