# Tag Info

2

You can try defining a new theorem style: \newtheoremstyle{algo}% <name> {\topsep}% <space above> {\topsep}% <space below> {\itshape}% <body font> {}% <indent amount> {\bfseries}% <theorem head font> {}% ...

1

for such paragraphs use \begin{sloppypar} ... your paragraph with \lstinline... \end{sloppypar}

1

Official answer from the package author and maintainer: In your question you pointed out the correct issue. I think the simplest way is to use the option usetwoside=false: \lstnewenvironment{insertcode}{\mdframed[usetwoside=false]}{\endmdframed} In this case no check is done.

2

You have to add the color specification also in the formula: $\color{lstgreen}$$\frac{cm}{s}$$$ Complete example (please, try to include complete examples in questions): \documentclass[11pt,a4paper]{article} \usepackage{xcolor} \usepackage{listings} % color definition \definecolor{lstgreen}{rgb}{0,0.5,0} \lstset{escapechar=$, %$ ...

2

listings delays outputting space characters until the next entity is typeset. In the case of moredelim, the preceding spaces are only typeset when the %% delimiter is encountered. Now, while the "style" (ie. the second argument in square brackets) will of course be applied before printing the delimiter, the actual test whether any spaces are still to be ...

2

listings has a setting backgroundcolor=\color{gray} for this purpose: \lstset{backgroundcolor=\color{gray}} \begin{lstlisting} if (a < b) { printf("A is smaller than B!\n"); } a = b; \end{lstlisting} See section 2.7 of the manual which you should get with texdoc listings.

1

I've burrowed a bit through listings.sty and came up with the following solution. Please be aware that I found this through the "bull-in-the-chinashop"-method, and would very much appreciate if someone who knows what he/she's doing could check/improve this. The only addition (aside from dealing with @) is the third-to-last line. \makeatletter ...

4

If you set columns=flexible then spaces are not stretched as much. Also you should allow breaking of lines, but only at whitespaces. Finally, it is best to tell listings that the language being set is Java: \documentclass{article} % source code listing \usepackage{listings} \usepackage{color} \usepackage{xcolor} \usepackage{caption} % citation style ...

3

You have to use breaklines=true so that the lines are broken in to two. \documentclass{article} % source code listing \usepackage{listings} \usepackage{color} \usepackage{xcolor} \usepackage{caption} % citation style \usepackage{apacite} \DeclareCaptionFont{white}{\color{white}} \DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}} ...

5

Use mathescape Code \documentclass{article} \usepackage{listings} \begin{document} \begin{lstlisting}[mathescape] $vl(i)= \sum\limits_{i=1}^N{Al(i,j)*xl(j)} ;\quad i = 1,3$ \end{lstlisting} \end{document} Output EDIT To avoid blank lines in the background, you can try something with mdframed: \documentclass{book} \usepackage{xcolor} ...

0

The \footnotemark command is a fragile so it needs to be protected with \protect when used as a "moving argument": \begin{lstlisting}[float=h,caption={Description\protect\footnotemark.}, label={listing2}, ...] text text \end{lstlisting} In essence, "moving arguments" are macros that are passed to some other macro that eventually write them to an ...

4

It seems that you should be able to smuggle in a new key along the lines of add to literate. I'm not very familiar with the key management system being using in listings, so I'll perhaps leave figuring out how to create such a key up to you. Meanwhile, here is a macro and key combo that seem to accomplish what you want. \documentclass{article} ...

4

After a lot of experimentation, I still couldn't figure out how to get the desired output using morecomment; I ended up using moredelim (with the il prefix) instead, and I defined a \processDelimiter macro to process each occurence of my %% delimiter in the listing. See below (I left a few comments in my code). This solution is mostly okay but suffers from ...

4

I don't think it's possible with the comment key, but you could (ab)use escapeinside: \documentclass{article} \usepackage{xcolor} \usepackage{listings} \lstset% {% basicstyle=\ttfamily, % commentstyle=\itshape\color{blue}, % morecomment=[s]{\%\%}{\^^M}, escapeinside={\%\%}{\^^M}, escapebegin={\%\%\itshape\color{blue}\obeyspaces} } ...

5

Geoffrey Poore develops minted further and answered in this similar tex.SE Question: This is not supported in the current release (minted 1.7). There is a \mintinline command in the development version at https://github.com/gpoore/minted. The development version is currently at 2.0-alpha2, but based on my own use and reports from others, it should be ...

8

This seems to work: \documentclass{article} \usepackage{listings} \newcounter{foo} \setcounter{foo}{0} \newcommand*{\ProcessNewline}{% \stepcounter{foo}% } \makeatletter \lst@AddToHook{EOL}{\ProcessNewline} \makeatother \begin{document} \begin{lstlisting} one two three \end{lstlisting} [\thefoo] \end{document}

3

You're halfway there. The listings manual (p.31 in v1.5b) tells you that multiple classes of identifiers and associated styles can be defined by using \emph=[<number>]{<identifier list>} \emphstyle=[<number>]{<identifier style>} where <number> is some integer of your choice that gets associated with the class of identifiers ...

6

When the caption is below the float contents, you can adjust the following caption parameters through \captionsetup: aboveskip (space between the float contents and the caption) belowskip (space after the caption) The default values are, for scrbook class, aboveskip=10pt and belowskip=0pt. Also, a \baselineskip is added by default before the floating ...

0

\begin{framed} \begin{lstlisting} or \lstinputlisting{...} \end{lstlisting} \end{framed}

3

This solution isn't perfect (hence the community wiki), but it might get you or someone else started (if anyone would like to improve this solution, please feel free). I've borrowed some code from Emphasize contents between two '$' with listings to help the grouping delimiters. It's a tricky problem because you essentially wish to change the ... 4 The following approach is directly adapted from David Carlisle's answer to Maintainable typesetting of placeholders in code snippets: \documentclass{article} \usepackage[usenames,dvipsnames]{xcolor} \usepackage{listings} \def\beginlstdelim#1#2#3% {% \def\endlstdelim{#2\egroup}% \ttfamily#1\bgroup\color{#3}\aftergroup\endlstdelim% } \lstset {% ... 4 As others have correctly mentioned in the comments, you are using default behavior. To customize it, you can do something like this \documentclass[12pt]{article} \usepackage{geometry} \usepackage{listings} \usepackage{color} \usepackage[usenames,dvipsnames,svgnames,table]{xcolor} \geometry{a4paper} \begin{document} This is a sample file: \lstset{ ... 9 You can use escapeinside to add a label to a line which can then be referenced using \ref (or even \cref if you load the cleveref package), as described in the listings documentation- here's a little example % arara: pdflatex \documentclass{article} \usepackage{listings} % nice verbatim environments \lstset{% ... 3 As floats are by definition and concept single-page (at most) entities, you're going to have to work around this - here are a few suggestions: Don't make it a float, put long bits of code in an appendix (often stylistically better but I don't know how the code relates to what you're writing) Don't make it a float, just put it inline (maybe as a ... 5 I follow the suggestion of karlkoeller and will add new options text above listing and listing above text to tcolorbox (upcoming version 2.52 or above). For the time being, this is likely to be the code for the additions: \documentclass{article} \usepackage{tikz} \usepackage[most]{tcolorbox} \makeatletter \def\tcb@inputlisting@out@textAboveListing{% ... 2 You can define floating parameter in \lstset with float=H, and further you can define label and caption with \begin{lstlisting}[label={lst:firstLst},caption={The first listing}] \end{lstlisting} Then your listing is floating and has caption and label. The use of your algorithm enviroment is then imho not necessary anymore. 7 Such an option seems not to exist in the documentation. So I've tried to create a new one called text above listing with the following code: \makeatletter \def\tcb@inputlisting@out@textAboveListing{% \tcb@inputlisting@out@prepare% \tcbdimto\tcb@w@outside{\tcb@width}% \tcbdimto\tcb@w@inside{\tcb@width}% ... 0 I am not sure why the 2nd level of itemized nesting is throwing the error, however, here are a couple of options that work, depending on your preference.... Option 1: If the impetus to using draft option is mainly to do with images, and saving compilation time when rendering images, then you can force the listings to display in final mode ALWAYS via the ... 0 Here is a simple example to get you started. \documentclass{article} \usepackage{listings} \lstset{language=R,literate={<-}{{$\gets$}}1} \begin{document} \begin{lstlisting} a <- c(1,2,3) b <- data.frame(this=a,that=c(3,4,5)) \end{lstlisting} \end{document} The "literate" part gives you nicer assignment arrows, which is useful if you use ... 7 Ok, here are two approaches, both of which not perfect, both of which not 100% what was requested. But maybe together we can optimise them :-) \documentclass{article} \usepackage{listings} \usepackage{attachfile} \usepackage{accsupp} \usepackage{verbatim} \usepackage{color} \usepackage[misc]{ifsym} \definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9} ... 6 Verbatim environments are very special, and generally resist being the arguments of macros, which is effectively what you are doing when you try to put a verbatim environment inside another environment definition. For more details on this problem, see the UK TeX FAQ entry on the topic. Instead, what you can do is hook into the beginning of the verbatim or ... 1 The following should be right up your allow. It's achieved with the aid of subcaption and some manual float management: \documentclass{article} \usepackage{verbatimbox} \usepackage[T1]{fontenc} \usepackage{fancyvrb,listings,caption} \usepackage[labelformat=simple]{subcaption} \usepackage[scaled=.73]{beramono} \fvset{baselinestretch=0.94} \parindent=0pt ... 3 LaTeX Error: File listings.sty' not found. This error message means the source file needs the package lstings but the system doesn't have it. MikTeX were designed to be a TeX distribution that can install missing packages automatically, but this feature doesn't work well. Fortunately, you can install packages manually by three steps: Press ... 1 My current best effort at this is based on the concept by @Gilles at Unix SE. It is not a pure *TeX implementation, and it is not perfect, but it is the one that has allowed me to compress my first 1.4MB of text onto 36 pages: around 40kB and 1400 lines per page. I use perl to pre-process the input text to escape LaTeX special characters, and also add ... 1 tcolorbox uses the pgfkeys engine and you may add your own options the same way you made myexample. For your question, an answer is the following: \documentclass{article} \usepackage{tcolorbox} \tcbuselibrary{listings,breakable,skins} % tcolorbox settings \tcbset{ above/.style={colback=lightgray,colbacklower=white,listing and text}, ... 5 As you have already used, verbatim package is easy to configure to get proper line breaking and escape all the special characters. For CJK text, xeCJK is your friend. And there are some options of xeCJK to control the behavior for verbatim CJK text. I hacked into xeCJK package to tune the linebreak. It seems better, but not perfect. % -*- coding: utf-8 ... 2 An alternative is to wrap the underlining frame into a newenvironment called slide. Code: \documentclass{beamer} \usepackage[listings]{tcolorbox} % define a new environment called slide with two parameters. \newenvironment{slide}[2]{% \begin{frame}[fragile,environment=slide]{Example} \begin{tcblisting}{listing only} \begin{frame}{#1} #2 \end{frame} ... 4 It's not you, it's beamer... :) The frame environment is really finicky since it has to read the entire content before actually setting the frame. Why? Because when you use overlay specifications (like \pause, or \only, or \onslide, or ...) then the frame has to be broken up into different slides, each of which may require the exact same layout. So, in this ... 5 You can tell xetex to linebreak Chinese and not to worry about characters that are normally special. (You probably need to make more characters catcode 12, this shows the basic idea) \documentclass{article} \usepackage{fontspec} \setmainfont{SimSun} \newcommand\showlog[1]{{% \catcode\#=12 \catcode\^=12 \catcode\$=12 \obeylines \raggedright ...

2

you do not have any special character except the # then you can use a simple \input. My example uses xelatex which makes live easier with CJK languages. \documentclass{article} \usepackage[margin=1cm]{geometry} \usepackage{fontspec} \setmainfont{Code2000} \setmonofont{DejaVu Sans Mono}%% has no chines characters \usepackage{pdflscape} ...

3

After some tinkering, I've come up with an alternative. I replaced < and > by the sexier and more common \textlangle and \textrangle; The placeholder text is now typeset in italics in the normal (including italic correction \/ at the end), which, arguably, looks much better. Unfortunately, there were some weird spacing issues with David's approach, ...

1

\lstdefinestyle{VHDL}{ language = VHDL, basicstyle = \footnotesize \ttfamily, keywordstyle = [1]\color{keyword}\bfseries, keywordstyle = [2]\color{STD}\bfseries, commentstyle = \color{comment},%%%%%%%%%% breaklines=true, % sets automatic line breaking tabsize=3 % sets default tabsize to 2 ...

1

Maybe a clearer explanation. "Text after the dollar sign appears in green" means you are talking about the editor you use for editing the TeX source. This has nothing to do with TeX math mode. TeX is a completely separate piece of software from the editor. TeX has absolutely no graphical user interface, but a command line interface instead. Editors run TeX ...

1

If you're using TeXnicCenter, and it's only the coloring inside the editor: This is a listed bug. The issue also effects the verbatim environment: http://sourceforge.net/p/texniccenter/bugs/318/. A "not really nice workaround": if it is really annoying (pages of code colored in a wrong way) you can put this after a wrong verbatim or listing environment: ...

2

From karlkoeller's comment: Document --> Settings --> LaTeX preamble, add \renewcommand{\lstlistingname}{Snippet} Caption and label has to be set for each listing of course, but the general style can be defined in Document --> Settings --> Listings:

9

\documentclass{article} \usepackage[dvipsnames]{xcolor} \usepackage{listings} \def\zz{\color{RubineRed}\textless\bgroup\itshape\aftergroup\endzz} \def\endzz{\textgreater\egroup} \lstset { moredelim = **[is][\zz]{@<}{>@}, basicstyle = \ttfamily, } \begin{document} Now the chevrons don't get italicised: \begin{lstlisting} ...

3

(This doesn't really concern Xetex so I excluded that from my example.) Sorry, I've misunderstood your question at first. A minipage is unbreakable by default, but you can use the xleftmargin=3pt and xrightmargin=3pt option of lstlisting. 3pt comes from the default value of the framesep option. If you change it, change these too (it can be automatized, but ...

1

The »minted« package is your friend here. It uses Python Pygments as back-end for syntax highlighting. And one of the Pygments lexers is for YAML. An approach how to get a YAML script formatted could look like this. \documentclass[11pt]{article} \usepackage[T1]{fontenc} \usepackage{minted} \begin{document} \section{The YAML Language} \begin{minted}[ ...

6

This is a workaround \documentclass{article} \usepackage{listings} \begin{document} \begin{lstlisting}[numbers=left,firstnumber=4,stepnumber=5,escapeinside={\%}{\%}] A%\addtocounter{lstnumber}{-3}% B C D E F G H I J K L M N \end{lstlisting} \end{document} Output Use firstnumber=3 and \addtocounter{lstnumber}{-2} if you want the numbering to start ...

2

The listings package allows you to set both the starting number and the interval. In your specific example: \lstset{numbers=left,firstnumber=1,stepnumber=10} See §2.6 of the documentation for details.

Top 50 recent answers are included