# Tag Info

2

The listings package has an internal macro called \lst@InstallKeywords for exactly that purpose: defining a custom class of keywords. In your case, invoking \lst@InstallKeywords k{attributes}{attributestyle}\slshape{attributestyle}{}ld creates four keys: attributes, moreattributes, deleteattributes, and attributestyle, which have the same usage as their ...

2

\FloatBarrier of package placeins could be put before \begin{lstlisting} to output the pending floats before the long listing that should not be interrupted by floats.

6

Frames with listings package are known to be problematic. I've created a new environment mylisting with tcolorbox that reproduces your \lstset but has not those problems. MWE \documentclass[UKenglish,a4paper,11pt]{report} \usepackage{babel} %% Adjustments \addtolength{\topmargin}{-1\baselineskip} \addtolength{\textheight}{4\baselineskip} \pretolerance = ...

3

You can use the very powerful tcolorbox package that supports listings. Here's an example, the frame can be customized in various ways. I used the optional argument to the danlisting environment just to show that you use it for passing options to lstlisting. The environment is breakable across pages. \documentclass[UKenglish,a4paper,11pt]{report} ...

2

If "your friend" (yeah right! :p) looks up how the Python language is defined by listings in the file lstdvrs.dtx, "s/he" will see that the " character is defined as a string delimiter for that language: morestring=[b]",% No wonder, then, that TeX gets confused if "your friend" tries to also define that character as a shorthand for inline Python code. A ...

4

Comparing "Ej" (which works) with "Er" (which doesn't) \tracingall shows it goes wrong here \lst@IfNextChars@@ #1#2\relax #3->\def \lst@tofind {#2}\lst@lAddTo \lst@eaten { #3}\ifx #1#3\ifx \lst@tofind \@empty \let \lst@next \@tempa \else \let \lst@nex t \lst@IfNextChars@ \fi \expandafter \lst@next \else \expandafter \@tempb \fi #1<-" #2<-"" ...

2

I have polished your code and you placed two columns, p-type and l-type, next to each other. The effect was that left column was lower than you expected when dealing with text. I set them both to p-type, then it was easy to manipulate with them. I enclose an example for your further experiments. %! latex mal-listings.tex \documentclass{article} ...

3

Make rulecolor black. \documentclass{article} \usepackage{tikz} \usepackage{listings} \begin{document} \lstset{language=C++, basicstyle=\ttfamily, keywordstyle=\color{blue}\ttfamily, commentstyle=\color{green}\ttfamily, frame=single, rulecolor=\color{black}, %%% <--- here breaklines=true, } ...

5

\documentclass{article} \usepackage{fontspec} \usepackage{libertine} \newfontfamily\cjk{Code2000} \usepackage{fancyvrb} \begin{document} Some nonsense text with the Libertine font. \begin{Verbatim}[codes=\cjk,numbers=left,frame=single,label=Chinese test] My source code and Good bye! in Japanese: さよなら。 A greeting in Chinese: 你怎么样? \end{Verbatim} ...

6

I enclose an example with a help of the listingsutf8 package and the CODE2000 font. I ran xelatex and lualatex, the result looks all the same. %! {xe|lua}latex mal-cjkv.tex \documentclass{article} \pagestyle{empty} \usepackage{listingsutf8} \usepackage{fontspec} \usepackage{filecontents} \begin{filecontents*}{mal-code.tex} My source code and Good bye! in ...

4

This can be resolved saving the contents of the listing in a box and then use that box inside your restatable environment. To save the listing box add the lines: \newsavebox{\listbox} \begin{lrbox}{\listbox} \begin{lstlisting} Button btn = GuiHelper.FindButton("Click Me!"); GuiHelper.WaitUntilEnabled(btn, Is.True); GuiHelper.Click(btn); ...

4

Inside the font-latex-set-syntactic-keywords function, defined in font-latex.el, change (add-to-list 'font-latex-syntactic-keywords (,(concat "^[ \t]*\\\\begin *{\$$?:" verb-envs "\$$}.*\$$\n\$$") to (add-to-list 'font-latex-syntactic-keywords (,(concat "^[ \t]*\\\\begin *{\\(?:" verb-envs ...

5

Section 5.6 Automatic formatting of the listings package documentation describes how to get automatic indention. The idea is to define a format using \lstdefineformat (listings must be loaded with the formats option): \documentclass[11pt,a4paper] {article} \usepackage[formats]{listings} \usepackage{xcolor} \lstdefineformat{C}{% ...

3

In case what you want to highlight is part of the code, my suggestion would be, not to define !* and *! as escape-to-LaTeX delimiters, but to simply define them as "invisible" delimiters that highlight their content in red, instead. That way, you don't get any discrepancy in column alignment between the normal code and the highlighted code. See my MWE below. ...

2

There are three problems with your code. You have a blank line in the argument of \lstset, which is not allowed. There is a typo (\s1shape instead of \slshape) in the value passed to the stringstyle key. You're misusing \color. Whether the optional argument is rgb or RGB, the mandatory argument should be a comma-separated or space-separated list of three ...

1

Getting rid of the blank line 19 allows this to compile for me!

1

You could just use a displaymath environment instead. Then there is no need for any adjustments: Notes: I also added basicstyle=\ttfamily for the listsings. Otherwise, the code, especially G= lined didn't look right. Code: \documentclass[12pt]{article} \usepackage{amsmath} %\usepackage{unicode-math} \usepackage{listings} \begin{document} ...

2

You are using \displaystyle for fractions that are in inline math mode. This results in big fractions that extrude below the baseline. Hence this clash. Without \displaystyle: They don't clash. Hence if you are using \displaystyle you need some more vertical space and we provide that through aboveskip from listings. Through aboveskip you can adjust the ...

5

It is possible with tcolorbox. \documentclass{article} \usepackage{tcolorbox,listings} \usepackage[textheight=2in]{geometry} \lstdefinestyle{mystyle}{ basicstyle=\ttfamily, numbers=left, numberstyle=\tiny, numbersep=5pt } \tcbuselibrary{listings,skins,breakable} \newtcblisting{mycode}{ arc=0mm, top=0mm, bottom=0mm, ...

9

The premise of your question is wrong. The listings package defines no fewer than three Lua "dialects" in the file lstdvrs.dtx: [5.0]Lua, [5.1]Lua, and [5.2]Lua. Pick whichever is appropriate. You may want to change the way things look, but you shouldn't have to redefine all the syntax from scratch. \documentclass{article} \usepackage[T1]{fontenc} ...

2

There is dialect 5.0 defined: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{listings,inconsolata} \begin{document} \begin{lstlisting}[language={[5.0]Lua},basicstyle=\ttfamily\footnotesize,keywordstyle=\bfseries] local words = io.open('hyphens-' .. tex.jobname .. '.txt', 'w'); local outchar = unicode.utf8.char local function dumphyphens ...

2

I put this together to demonstrate how you can do this. Since you did not give a full example, I can't guarantee that it will fit right into what you are doing. I used newfloat to create a new float type listing, as you seem to have. minipages are used to set the listings themselves into the sub-floats. Depending on what you have already, this may be ...

1

There were a few mistakes in your \AddNoteOver. The main one being (#1).north west should not have the (), so should be #1.north west: Notes: The AddNote is from How can I put a curly brace inside an algorithm to group code lines?. Code: \documentclass[english,a4paper,12pt]{report} \usepackage[T1]{fontenc} \usepackage[latin9]{inputenc} ...

3

Another option with tikz. The technique used is similar to that of Karl, but I used escapechar key. escapechar=|, And the numbers are put as a node with overlay option so as to not disturb other things. Code: \documentclass[english,a4paper,12pt]{report} \usepackage[T1]{fontenc} \usepackage[latin9]{inputenc} \usepackage{listings} \usepackage{changepage} ...

4

You can use the symbols defined in pifont package (see page 77, Table 254 of The Comprehensive LaTeX Symbol List). Adding the option mathescape=true to your listing environment you can write something like $\llap{\textrm{\ding{173}}}$ at the beginning of the line where you want that symbol. MWE: \documentclass[english,a4paper,12pt]{report} ...

2

Sorry I mislead you on the previous question, you need an extra set of {} to hide listings from the table mechanism: \documentclass{article} \usepackage[T1]{fontenc} \usepackage[latin9]{inputenc} \usepackage{listings} \usepackage{color} \begin{document} \clearpage \begin{tabular}{|p{.4\textwidth}|p{.4\textwidth}|} ...

4

I get same errors on TexLive 2013. Use \ltset{} in preamble for setting parameters of lstlisting environment: \documentclass{article} \usepackage[T1]{fontenc} \usepackage[latin9]{inputenc} \usepackage{listings,xcolor} \lstset{ basicstyle={\scriptsize\ttfamily}, identifierstyle={\color{black}}, ...

2

Your example generated errors because color was not loaded, but other than that it basically worked. You don't need the tabular just two minipages are sufficient. Some of your lines are too ong to fit side by side, but that's a separate issue. \documentclass[english,a4paper,12pt]{report} \usepackage{mathpazo} \usepackage{graphicx} ...

2

As David said to do. In this case, I placed the result in a tabular. I also made the listings in \tiny, so as to make two side-by-side listings fit in the margin width. In my case, I also placed them in boxes beforehand, so that my tabular code would look nice: \begin{tabular}{|c|c|} \hline \stackinset{l}{-5pt}{t}{13\llength}{$\bullet$}{\listingA} & ...

5

The left frame is drawn by pieces of rules as high as a strut, but with \baselinestretch set to 0.8 some characters are higher than a strut. You could solve by changing the way the rules are computed, for instance with \documentclass{article} \usepackage{listings} \usepackage{setspace} \lstset{basicstyle=\footnotesize\ttfamily\selectfont, ...

4

I can offer a solution based on tcolorbox version 2.80 (2014/03/31) released just this day where a \lstinline wrapping is provided with help of xparse. Instead of using the new macro \RenewTotalTCBox from version 2.80 you can also some variation of my answer to How do I create a verbatim box with \newtcbinputlisting? with version 2.72. To adapt your ...

5

The lstdoc package is primarily meant to be used in documents using the ltxdoc class. That class loads the doc class internally, which contains two macro definitions that are particularly relevant here: \def\MakePercentIgnore{\catcode\%9\relax} \def\MakePercentComment{\catcode\%14\relax} Because the lstsample environment needs those two macros, but the ...

3

Many things have likely changed since this question was asked. I'm not entirely sure why your usage is not working, since it matches what is listed in the documentation. Maybe some incompatibility cropped up in recent updates. Anyway, here is a workaround using listings' mathescape feature, but maybe someone will come along with a real answer, and I will ...

7

There are two issues: \- is the same as - in literate, if you want to have a backslash in front of the hyphen, then the backslash needs to be escaped by a backslash. The hyphen does not need to be escaped by a backslash: \\- catches the backslash and the hyphen. From the documentation: 4.1 How to read the reference ... 5. If you want to enter one ...

1

Looks like there needs to be a frame line on the top in order for framextopmargin to have any impact. With the exception of a thin black line between the caption and frame itself, this is exactly what you asked for: \documentclass{article} \usepackage[svgnames]{xcolor} \usepackage{caption} \usepackage{listings} \usepackage{calc} \lstdefinestyle{outline}{ ...

3

One possibility using the listings package; since apparently you only want to highlight some specific strings, you can escape to LaTeX and do the coloring there (in my example I used the bera package just to have a mono-spaced font allowing boldface) \documentclass{article} \usepackage{xcolor} \usepackage{listings} \usepackage{bera}% for boldfaced ...

1

\documentclass[12pt]{article} \usepackage[utf8]{inputenc} \usepackage{listings} \begin{document} \leavevmode\vfill \begin{lstlisting}[frame=single,title=1.1] Code goes here! \end{lstlisting} \vfill \end{document}

7

The listings package provides a key called inputpath for specifying a path where \lstinputlisting should search for source files. Note that inputpath is only documented in the listings developer's guide, not in the user manual; if you haven't compiled the developer's guide, searching for "inputpath" in listings.dtx will lead you to the definition of the ...

0

I can recommend the minted package which uses pygments. \documentclass{article} \usepackage{minted} \begin{document} \begin{minted}{bash} $git status # on branch "master" foo in bar is blah for short output$ for i in seq 2`; do for> echo "Test \"number\" \${i} {}"; done Test "number" 1 {} Test "number" 2 {} \end{minted} \end{document}

4

If you have to type everything, can use a tabular with typewriter (\ttfamily) font. In next code I've used tcolorbox to provided a colored boxed background. \documentclass[a4paper]{article} \usepackage[skins]{tcolorbox} \begin{document} \begin{tcolorbox}[fontupper=\small\ttfamily, colback=gray!10, arc=0pt] \begin{tabular}{llll} byte\# & hexadecimal ...

4

The listings package provides the upquote toggle option to determine how the left and right quote are printed. Setting it to true does what you want (works similarly to setting the literate as in egreg's answer). This requires loading the textcomp package before the option is set. \documentclass[article]{memoir} \usepackage{textcomp} % <--- for other ...

7

The blank line at the end of your code is caused by the newline character at the very end of your embedded listing, i.e. at the end of the line #include <iostream> Because \end{lstlisting} hasn't been detected yet, listings prints that newline character verbatim. The same phenomenon occurs with the verbatim environment; see the "side note" in this ...

1

If I understand your question correctly, you want to have the keywords proc and end proc automatically detected inside a mathematical environment; here, align*. I do not think that this is possible. You could mark the keywords by hand inside a mathematical environment or you could insert escape sequences with some math stuff into listings code. This is ...

3

You can use the literate feature of listings and the \textasciigrave macro of textcomp. I have reduced the example to the essential. \documentclass[article]{memoir} \usepackage{textcomp} % <--- for other glyphs \usepackage[final]{listings} % to be shown independently draft of final \lstdefinestyle{CommandLineStyle}{ basicstyle=\small\ttfamily, ...

2

Simply add \usepackage[T1]{fontenc} to your preamble. Note that you don't need the upquote package if you load textcomp and set listings' upquote key to true. \documentclass{article} \usepackage[T1]{fontenc} \usepackage{textcomp} \usepackage{listings} \lstset{upquote=true} \begin{document} \begin{lstlisting} echo "Hello, world!" \end{lstlisting} ...

14

The listings package provides that functionality; see subsection 5.6 of the manual. Make sure the formats aspect is loaded, which can be done either by passing formats as a package option to listings, \usepackage[formats]{listings} or by using the \lstloadaspects macro after loading the listings package, \usepackage{listings} ... \lstloadaspects{formats} ...

12

There are other invisible characters than the space character (ASCII code 32); one of them is the tabulator, a.k.a. tab character (ASCII code 9), which are used in some types of source files; most notably, perhaps, in makefiles. For more information about invisible characters in general, I refer you to the Wikipedia page on ASCII control characters. The ...

3

A good solution that also works for listings was provided here: How to iterate through the name of files in a folder. You just have to modify the code like this: \documentclass{article} \usepackage{listings} \makeatletter \def\app@exe{\immediate\write18} \def\listDir#1{% \app@exe{ls #1/* | xargs cat >> \jobname.tmp}% ...

7

Because showexpl is based on the listings package, most of the latter's features, including the literate key should, in theory, work out of the box. For some reason, though, defining the literal replacements globally, like so \lstset { literate= *{\{}{{\textcolor{blue}{\{}}}{1} {\}}{{\textcolor{blue}{\}}}}{1}, } seems to break showexpl, which ...

Top 50 recent answers are included