New answers tagged

2

In case that tocloft.sty is not a must, I can offer a solution with titletoc.sty. I think the interface is cleaner. There is also a solution at the end how to get rid of the additional vertical space in LOF. \documentclass[12pt,a4paper,draft,openany]{book} % For french \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[french]{babel} % For ...


3

By default tocloft can't hook into ToCs that are made by other packages, however, it's possible to use \newlistof{...} to redefine the \lstoflistings -- unfortunately, this requires knowledge of the counter being used for listings (its name is lstlisting) and \newlistof... tries to define a new counter for this -- this must fail (and is a design flaw of ...


2

You can pass the float option to \lstinputlisting to make it float: \documentclass{article} \usepackage{listings} \lstset{basicstyle=\footnotesize\ttfamily} \usepackage{lipsum} \begin{document} \lipsum[1] \lstinputlisting[caption={Hello}, float]{main.c} \end{document} There's also this question and its answers which have solutions for avoiding page ...


1

You need the listings key label={....}, not \label. The \label command would refer to the section 2 (which was typeset before), since this was the last counter being using in \refstepcounter before the caption come into action (which applies the listings counter) \documentclass{scrreprt} \usepackage{regexpatch}% http://ctan.org/pkg/regexpatch ...


1

Place a % at the line break point, as in \begin{test}{caption very % long}{lst:label} class BreakMe: def __init__(): pass \end{test} Here is the MWE: \documentclass[10pt]{article} \usepackage[usenames,dvipsnames]{color} \usepackage{graphicx} \usepackage{listings} \lstnewenvironment{test}[2] { \lstset{ language=Python, ...


2

Well, perhaps would it be easier to expand line 8 to two lines 8 and 9, containing each of them .... Package listings offers some options you can use to change line numbers. With options firstline and lastline you can define the showed lines in the printed listing, with firstnumber and lastnumber you can define the showed line numbers ... MWE: ...


3

update I don't think it's possible to use a \caption without much redefinitions. Here's a version with blend into=listings, which must be done in \AtBeginDocument or after \begin{document}. The title= will then be used as the long caption text, the short one is given by list text=... -- See the example, please. To move the caption to the bottom, the ...


3

You may have noticed that even packages which sport key-value syntax in the options refrain from allowing control sequences in the values. This has to do with how LaTeX manages the list of options, in order to zap spaces and divide it into pieces at commas. Since \ttfamily is a command that's defined as robust with \DeclareRobustCommand, it is not allowed ...


0

I created a lstlang0.sty with the list of keywords from M2-symbols.el. When stored locally, listings will automatically import the file and then it is possible to highlight keywords using language = Macaulay2. The keywords are divided into four groups, as explained in Sean's answer. By default, these typeset in the same manner. However, you can distinguish ...


1

To make sure single line captions are not centered, which is the default with caption, you can set singlelinecheck=false inside the \captionsetup command or the options when loading the caption package: \captionsetup{singlelinecheck=false} or \usepackage[singlelinecheck=false]{caption} Including the singlelinecheck=false in either of the options ...


1

I can verify that the regular expressions in M2-symbols.el do not give Emacs any additional information other than what the words mean. There are four categories listed in M2-mode-font-lock-keywords: Types (ComplexField, ...) Function names (associatedPrimes, ...) Constants (CallLimit, ...) Generic keywords (and, break, catch, ...) That's the only ...


1

You can use the gobble option to remove leading whitespace from the output of a listing. As you use “hard” tabulators, you should also tell it which tab size you prefer (option tabsize), because tabulators are expanded to spaces first. The whitespace is displayed verbatim because it's in a string. The idea is that spaces matter there, but ...


2

If you have the code in an external file you can use something like \lstinputlisting[language=awk]{yourcode.awk} You can still modify the aspect of your listing preceding it with \lstset{% extendedchars=true,% basicstyle=\footnotesize\ttfamily,% keywordstyle=\color{Brown}\bfseries,% commentstyle=\color{Blue}\sffamily,% showstringspaces=false,% ...


1

Change the beginning of the frame to: \begin{frame}[fragile] \fontencoding{T1}\selectfont \begin{lstlisting} If you have to do this for many frames, you can alternatively add these lines to your preamble: \usepackage{etoolbox} \AtBeginEnvironment{lstlisting}{\fontencoding{T1}\selectfont} Alternatively, you can compile with xelatex, loading the fontspec ...


2

You can't embed a verbatim - like environment like lstlisting inside another environment, at least not without much tricks (like \scantokens etc.) listings provides the facility to generate own, customizable environments with lstnewenvironment. Use \lstset{style=Matlab-editor} to provide the relevant settings in the start-up-code section of the environment. ...


1

@Werner's solution is fine, but adding spaces to the replacement will have different results in both lstlisting and lstinline. For example, if you replace -> by, say, -> and you have the following snippet: a -> a -> a -> a it will show up normally in lstinline, but it will show up with two spaces after the arrows in lstlisting, like this: ...


4

As specified in the listings manual (§2.8, p. 19), the (optional) emph option of \lstset is to define what to (automatically) emphasis, when the emphstyle option is for defining how to (automatically or manually as you're doing) emphasis. So you just need to replace emph by emphstyle! (-: \documentclass{article} \usepackage{listings} ...


2

You can change the command listings use when processing the asterisk: \documentclass{scrbook} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{listings} \usepackage{color} \definecolor{stringColor}{RGB}{42,0.0,255} \definecolor{keyword1Color}{RGB}{63,127,95} \definecolor{keyword2Color}{RGB}{63,127,200} ...


1

Imho you can use the TextStyle-Hook: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{xcolor} \definecolor{mygray}{rgb}{0.85,0.85,0.86} \newcommand\mylstcolor{mygray} \usepackage{listings} \lstset{backgroundcolor=\color{mygray}, literate={_}{\niceunderscore}1} \newcommand{\niceunderscore}{% % Invisible underscore that can be ...


4

If you just provide captionpos={b} - as it is stated in the manual - it is working fine. \documentclass[border=2mm]{standalone} \usepackage{listings} \begin{document} \begin{lstlisting}[ label={lst:rws}, captionpos={b}, caption={Pseudo-code of RWS Selection} ] r = Random(); /* Uniformly distributed random number in [0,1] */ sum = 0; for (i = 1; ...


3

I would suggest inserting an appropriate line-break inbetween two manually-separated \lstinline statements. That is, ... \noindent\lstinline{template<class UIntType, UIntType a, UIntType c, UIntType m>} \par \lstinline{class linear_congruential_engine} ... You may want to add some spaces at the start of the second \lstinline, if needed.


1

In your case you can just add option float to the call of the second listing. Then the listing can float over pages. In your case the complete second listing is moved to page two. MWE (see changed line marked with <=======): \documentclass[a4paper, 12pt, oneside]{report} \usepackage[a4paper, left=3.5cm, right=2cm, bottom=2.5cm, top=3cm]{geometry} ...


2

This is a bug in listings: it's globally setting \lccode`\~=`\z which is not sensible. TeX is then lower casing ~ to z and not finding a definition for an active z (oddly enough). I'd suggest simply fixing this with \lccode`\~=0\relax immediately after \usepackage{listings} The bug itself is caused by the internal macro \lst@CCPut, which sets the ...


2

The code holds specified parameters, but they haven't been told the environments to be used. See comments in code: \documentclass{scrreprt} \usepackage{regexpatch}% http://ctan.org/pkg/regexpatch \usepackage{color} \definecolor{codecolor}{rgb}{0.8,0.9,0.9} \definecolor{chatcolor}{rgb}{0.9,0.9,0.8} \usepackage{listings}% http://ctan.org/pkg/listings ...


4

\pm is internally defined as "the character ±". In the listings code \pm is used in an \lccode assigment but its value is much too large. You can avoid the problem by converting \pm to a macro. This is handled differently by listings. E.g. \documentclass{article} \usepackage{unicode-math} \usepackage{listings} \usepackage{fancyvrb} \AtBeginDocument{% ...


1

Here's a xassoccnt version of sharing/coupling counters that does not require more setup than defining a group of coupled counters, here figure and lstlisting. (This requires xassoccnt v0.6) After that, the figure / listings counter step together. \documentclass{book} \usepackage[T1]{fontenc} \usepackage{textgreek} \usepackage[utf8]{inputenc} ...


1

You could achieve universal numbering by defining a new counter and use that for your captions in listings and figure environments. \documentclass{book} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[english]{babel} \usepackage[demo]{graphicx} \usepackage{listings} % Define new counter for listings and figures. \newcounter{eikona} ...



Top 50 recent answers are included