Tag Info

New answers tagged

0

If I understand correct, yuo want to \laebl the listing and \ref it some where. If so add the label like: \begin{listingsbox}{myc,label=mint}{test} and use \ref{mint} elsewhere. \documentclass{article} \usepackage[many,minted]{tcolorbox} \newcommand{\mynewminted}[3]{% \newminted[#1]{#2}{#3}% \tcbset{myminted/#1/.style={minted language=#2,minted ...


1

The \lstinputlisting instruction replaces a lstlisting environment. With your input, you are asking not to interpret \lstinputlisting. \documentclass{report} \usepackage{listings} \lstset{basicstyle=\footnotesize\ttfamily,breaklines=true} \lstset{framextopmargin=50pt,frame=bottomline} \begin{document} \lstinputlisting{C:/Temp/test.txt} \end{document}


0

If you want to preserve column alignment, but want to reduce inter character spacing, set the basewidth option to a smaller value: \documentclass{article} \usepackage{listings} \usepackage{xcolor} % for setting colors % set the default code style \lstset{ language=C++, frame=tb, % draw a frame at the top and bottom of the code block tabsize=4, ...


1

Box the listing before using it in the argument for \node: \documentclass{beamer} \usepackage{tikz} \usepackage{listings} \newcommand{\rednode}[1]{ \node[draw=red]{#1}; } \newsavebox\mybox \begin{document} \begin{lrbox}{\mybox} \begin{lstlisting} int main() { printf("Hello World\n"); } \end{lstlisting} \end{lrbox} \begin{frame}[fragile] ...


2

The inline verbatim is small because you specify it that way! Change the line basicstyle=\ttfamily\footnotesize, to basicstyle=\ttfamily, or whatever and you'll be fine.


0

Patch \lst@MakeCaption to do \linespread{1}: \documentclass[a5paper]{article} \usepackage{listings} \usepackage{etoolbox} \makeatletter \patchcmd\lst@MakeCaption {\ignorespaces} {\linespread{1}\selectfont\ignorespaces} {}{} \makeatother \begin{document} \begin{lstlisting}[ float, basicstyle=\ttfamily\footnotesize, lineskip=-0.7ex, ...


3

You can use caption package with setspace. \documentclass[a5paper]{article} \usepackage{listings} \usepackage{caption} \usepackage{setspace} \captionsetup[lstlisting]{font={stretch=1}} \begin{document} \begin{lstlisting}[float, basicstyle=\ttfamily\footnotesize, lineskip=-0.7ex, columns=fixed,basewidth=0.5em, captionpos=b, caption={Long caption text that ...


8

The frame is put outside of the listings. Therefore xleftmargin and xrightmargin can be used to leave room for the frame. The default for framesep is 3pt and the default for framerule is 0.4pt. Result: \documentclass[]{article} \usepackage{listings} \lstset{ basicstyle=\ttfamily\footnotesize, frame=single, % adds a frame around the code ...


2

This is due to a shortcoming of listings, which prevents it from breaking long sequences of digits and other symbol characters (even when breaklines is set and breakatwhitespace is cleared). Here, an ad-hoc hack is to add literate=::1, in the list of key-value pairs passed to \lstset.


3

Think twice Are you suggesting inserting the filename at the top of your listing, on a line numbered by 0, as if it were a line of code? I think that's a bad idea: you run the risk of confusing your readers. Typeset the filename as the listing's title A better alternative, in my opinion, is to typeset the filename as the listing's title, by passing the ...


0

Use accsupp package. This way you can copy regarless of visual line breaks. \documentclass{article} \usepackage{accsupp} \usepackage{listings} \begin{document} \BeginAccSupp{method=plain,ActualText=long long long command long long long command long long long command long long long command} \begin{lstlisting}[breaklines=true] long long long command long long ...


0

I found a solution. Simply add it as a keyword by adding the line otherkeywords={@param,@pre,@post,@return} to lstset. See below \documentclass[paper=a4, fontsize=11pt]{scrartcl} \usepackage{color,soul} % For text coloring and highlighting \usepackage{listings} \definecolor{dkgreen}{rgb}{0,0.6,0} %for listings ...


6

Here's a LuaLaTeX-based solution. Note that the search is case-sensitive: while "TEST" is highlighted, "test", "Test", and "TeSt" are not. % !TEX TS-program = lualatex \documentclass{article} \usepackage{xcolor,luacode,luatexbase} %% Lua-side code \begin{luacode} function highlight_TEST ( line ) return string.gsub ( line, "TEST", ...


7

Must be compiled with XeTeX. % arara: xelatex \documentclass{article} \usepackage{xesearch} \SearchList{make-blue}{\textcolor{blue}{#1}}{test} \SearchList{make-red}{\textcolor{red}{#1}}{maybe,different} \SearchList{code}{\lstinline{#1}}{code} \usepackage{listings} \lstset{basicstyle=\ttfamily} \usepackage{xcolor} \begin{document} Hello, this is a test, ...


4

The unexpandable stuff (\lowercase, \textsc, \MakeLowercase) must not appear in any counter value, which is used in anchor names. Package hyperref already uses \theH<counter> instead of \the<counter>. But it fails for \theHstnumber, because it uses \thelstlisting instead of \theHlstlisting. Fix: \documentclass[english]{report} ...


3

The following example sets a label for the listings by option label. The anchor name of the label is extracted and analyzed to get the internal listings number. In this case the unnumbered listings has anchor lstlisting.-1 with the number -1 for the listings. The anchor names for the line numbers follow the pattern lstnumber.<listings number>.<line ...


3

Here is one option: A redefinition of \thelstlisting and \thetable (and others...) to {\scshape\alph{chapter}}.\arabic{<cntr>} when you reach \appendix: \documentclass{report} \usepackage[colorlinks=true]{hyperref} \usepackage{listings} \lstset{frame=single} \renewcommand{\thetable}{{\scshape\thechapter}.\arabic{table}} \AtBeginDocument{% ...


5

You can use the upquote package: \documentclass{article} \usepackage{listings} \usepackage{upquote} \begin{document} \begin{lstlisting} `if`(...) \end{lstlisting} \end{document} For using BeraMono: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{beramono} \usepackage{listings} \usepackage{upquote} ...


2

The listings package had an upgrade that fixed a problem related to tabular (see the change history). Unfortunately, the fix was released after TeX Live had been frozen for producing the DVD, so one has to update the distribution using tlmgr or, with MacTeX, TeX Live Utility. The updated version should solve the issue. About your code, I'd use ...


1

I think you are better off if you load minted.sty with option newfloat and use the interface to tocloft.sty as described in newfloat.pdf. Code: \documentclass{article} \usepackage[titles]{tocloft} \newlistof{listing}{lol}{List of Listings} \usepackage[newfloat]{minted} \usepackage{caption} \newenvironment{code}{\captionsetup{type=listing}}{} ...


5

There is a hint on page 38 of the manual for the caption package: Please note that the listings package has its very own options for controlling the position and the skips of the caption: captionpos=, abovecaptionskip=, and belowcaptionskip=. (See listings documentation for details.) Trial and error shows that if you add \lstdefinestyle{interfaces}{ ...


3

The \autoref command can't 'know' the ref name for each counter, this has to be provided as a separate macro: I used the listings example by Marco Daniel provided in the Link by the O.P. and found that listings uses lstnumber as counter, so \newcommand{\lstnumberautorefname}{Line} is the relevant macro name to be defined (i.e. counter name + autorefname ...


2

Here's an example using the listings package which supports Verilog language: \documentclass{article} \usepackage{listings} \begin{document} \begin{lstlisting}[language={Verilog},tabsize=12,caption={A simple paragraph of Verilog code is below in verbatim}] Always@(posedge LRCK) Begin Counter=Counter+1 If ( Counter == 40) Begin ...


1

So... it is much like TeX except that tokens start with : instead of \? \documentclass{article} \usepackage{listings,xcolor} \makeatletter \lst@SaveOutputDef{"3A}\lstum@backslash \makeatother \lstdefinelanguage{clojure}{ moretexcs={counter-actor,as,increment,log-actor,log}, alsoletter=0123456789-, morestring=[b]" }[keywords,tex,strings] ...


2

Use showstringspaces=false; either globally (for all your listings): \documentclass{article} \usepackage[dvipsnames]{xcolor} \usepackage{listings} \lstset{ showstringspaces=false, language=C++, keywordstyle=\color{RedViolet}, stringstyle=\color{blue}, commentstyle=\color{ForestGreen}, morecomment=[l][\color{Orange}]{\#}, } ...


4

The simplest solution is not to use lstlistings but instead put the code into a chunk with eval=FALSE: \begin{frame}[fragile] <<eval=FALSE>>= rnorm(3) @ <<eval=TRUE>>= rnorm(3) @ \end{frame} UPDATE In my previous answer I assumed you wanted listings output to look like knitr. Now I see you want knitr output to look like ...


3

Short captions for lstlisting environments can be given almost the same way, \caption={[short caption]long caption}, see section 4.9 of the listings manual. Please note the {} pair to protect for the [] argument stuff, which is fragile. It's perhaps better, to use {...} for the long caption as well. \documentclass{article} \usepackage{listings} ...


2

I don't understand why this works either. More precisely, I don't know why you need to put the \discretionary after the number instead of inside the replacement text. \documentclass{article} %\usepackage[utf8]{inputenc}% all it does for me is produce warnings \usepackage[left=6cm,right=7cm]{geometry} \usepackage{parskip} \usepackage{showframe} ...


1

What you need is \resetcounteronoverlays{lstlisting} to prevent the counter from incrementing when using overlays. The complete code: \documentclass{beamer} \usetheme{Goettingen} %\usecolortheme{whale} \setbeamertemplate{frametitle continuation}[from second] % (cont.) from second slide \setbeamertemplate{bibliography item}{[\theenumiv]} % numbers ...


0

I adapted the example form TEX \documentclass{article} \usepackage{listings} \usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white \definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue \definecolor{mylilas}{RGB}{170,55,241} \lstset{language=Matlab,% %basicstyle=\color{red}, breaklines=true,% ...


0

We got the above image with the assistance of array package, you can change the width of columns as you like % \usepackage{array} \begin{center} \begin{tabular}{p{3.9cm}|p{3.9cm}} \begin{lstlisting} while (x > 0) do x++; \end{lstlisting} & \begin{lstlisting} x = 0; \end{lstlisting} \end{tabular} \end{center}


1

Using a Unicode-aware engine If changing engine to either XeTeX or LuaTeX is an option, then you can remove the literate stuff from the \lstset, remove inputenc and add fontspec. With those modifications it just works. Note that in the code below I set belowskip and aboveskip to 0pt where necessary to remove the gap between the different listings, rather ...



Top 50 recent answers are included