Tag Info

New answers tagged

2

You can prevent the breaks after \ by making this a letter, via alsoletter={\\}. However, arbitrary breaks before \ are dangerous and can give the wrong syntax from tex TeX point of view. \def\a{\b} is not the same as \def\a{ \b} which is equivalent to \def\a{ \b} On the other hand \def\a{\b\c} \def\a{\b \c} \def\a{\b \c} are equivalent. I ...


2

\documentclass{article} \usepackage{xcolor,listings} \begin{document} \begin{lstlisting}[basicstyle=\ttfamily,breaklines,prebreak={\space\hbox{\textcolor{teal}{!}}},postbreak={\hbox{\textcolor{blue}{!}}\space}] This is a long line. This is a long line. This is a long line. This is a long line. This is a long line. This is another long line. This is another ...


1

Seems like you have local copy of textcomp in D:\Documentos\Tesis\Circuitos Eléctricos\Latex\Filtros\01. Capacitivo\graficos\scripts\primero\textcomp.sty that is out of date. You should use the Miktex package manager to install textcomp.


3

The macro for inputting inline code is \lstinline[option]{<code} Hence use \newcommand{\inlinecode}[1]{\lstinline{#1}}. \documentclass{article} \usepackage{listings,lstautogobble} \usepackage[usenames,dvipsnames]{color} \newcommand{\inlinecode}[1]{\lstinline{#1}} % Custom Python Syntax \lstset { basicstyle=\small\ttfamily, ...


2

\documentclass{article} \usepackage{listings,lstautogobble} \usepackage[usenames,dvipsnames]{color} \newcommand{\inlinecode}{\lstinline[basicstyle=\ttfamily\normalsize, prebreak=]} % Custom Python Syntax \lstset { basicstyle=\small\ttfamily, commentstyle=\color{Green}, keywordstyle=\color{Cerulean}, frame=L, language=python, ...


0

The problem with your second snippet isn't really the overfull box (which is a warning, not an error), but the fact that using a flushright environment in \lstnewenvironment{codebox} {\begin{flushright}} {\end{flushright}} causes LaTeX to raise a (job aborted, no legal \end found) error. You could remedy that error by using a \raggedleft instead of a ...


1

Solution is to include package chngcntr and to place \counterwithin{lstlisting}{section} after \begin{document}. The complete code is then \documentclass[a4paper]{article} \usepackage{listings,chngcntr} \lstset{frame=Trbl,numbers=left} \usepackage{amsmath} \begin{document} \counterwithin{lstlisting}{section} \section{Introduction} First listing is ...


2

Putting this here because had the same problem, found this question and used code from the accepted answer, but then expanded it; might be useful for somebody else Here's a variant using LaTeX3's experimental regular expressions. Of course that's overkill for the question, but by matching the token against a regex it's much more powerful. Here I'm using it ...


4

You shouldn't use listings inside arguments, but if you are asking for troubles, another experimental workaround (explained in the documentation) is add a line feed (^^J) at the end of each line, escape \{}% characters and spaces. Unfortunately, then you can’t escape to LaTeX inside such listings (according to package documentation) so you have little chance ...


1

The listings documentation describes the linerange option as follows: linerange={⟨first1⟩-⟨last1⟩,⟨first2⟩-⟨last2⟩, and so on} can be used on individual listings only. The given line ranges of the listing are displayed. The intervals must be sorted and must not intersect. The range you use, linerange={1-4,7-7,9-13} is valid on both counts: the ...


2

For your first example using wrong quotes, you can correct them by making all your quotes neutral (non-curly). See How can I get straight double quotes in listings? Alternatively, you can simply use typewriter font in your basic or even just your string style. I usually do this anyway for listings: basicstyle=\normalsize\ttfamily, When using the correct ...


4

You can use url package to allow breaking in file paths, or you can use LaTeX's filename parser to extract just the basename: \documentclass{article} \usepackage{listings,url} \makeatletter \protected\def\basename#1{\filename@parse{#1}\filename@base.\filename@ext} \makeatother \begin{document} ...


1

The problem is that breaklines doesn't take decisions. It has two simple rules for breaking: Don't break the initial indentation (i.e., leave at least something other than whitespace on the line) Break only at whitespace. Since your line doesn't contain any whitespace, there's no feasible breakpoint whence no break.


1

You have to add breaklines=true as the option. Further you may define \lstset{basicstyle=\small\ttfamily,columns=fullflexible} to add some difference. \documentclass{IEEEtran} \usepackage{listings} \usepackage{lipsum} \lstset{basicstyle=\small\ttfamily,columns=fullflexible} \begin{document} \lipsum[1-2] ...


3

You should have a \lstset instruction in your preamble: \documentclass [11pt] {article} \usepackage{graphicx} \usepackage{enumitem} \usepackage{url} \usepackage{epstopdf} \usepackage{listings} %\input std-defs %\input EECE2323-header \lstset{ basicstyle=\ttfamily, columns=fullflexible, } \begin{document} %\noindent %\lab{3}{LAB3 - Arithmetic and ...


4

listings is essentially a verbatim environment that turns off normal latex processing, in particular \end{hello} does not end the environment. The package has facilities for defining custom environments, see section 4.16 of the listings manual. \documentclass{article} \usepackage{listings} \lstnewenvironment{hello}{\lstset{language=sh}}{} ...


3

Here in short whats going on. The colon is defined as \active@prefix :\active@char:. This definition is so that under certain conditions (e.g. in a protected@write, or when \if@safe@actives is true (which is the case in \@newl@bel)) the : expands to something that it "safe" in a label. But in your example : no longer has this safe definition as listings ...


3

The test \ifdefequal is wrong. You're better using xparse that allows to better distinguish when an optional argument is present or not. \documentclass[a4paper,twoside,10pt]{report} \usepackage{xparse} \usepackage{listings} \lstset{ escapechar = §, } \NewDocumentCommand{\lstref}{om}{% \IfNoValueTF{#1} {Listing \ref{#2}} {Zeile \ref{#2} in ...


2

It turns out that the beamer manual is a good idea to read. This is easily done using \begin{uncoverenv}< > ... \end{uncoverenv}. Anyone interested in trying this can check out the following example code: I found that \begin{onlyenv}< > ... \end{onlyenv} suits my needs better. The reason is apparent when the example code is executed and the ...


6

Joseph has already told you how to make the change locally. However, here are some more hints. You need moredelim={[is][keywordstyle]{@@}{@@}} and not morecomment={[s][keywordstyle]{@@}{@@}} to achieve what you want. MWE: \documentclass{report} \usepackage{listings} \begin{document} \begin{lstlisting}[moredelim={[is][keywordstyle]{@@}{@@}}] Some ...


5

You need braces just around the argument part \documentclass{report} \usepackage{listings} \begin{document} \begin{lstlisting}[morecomment={[s][keywordstyle]{@@}{@@}}] Some test loru @@ hello world @@ lorem ipsum \end{lstlisting} \end{document} This works by 'hiding' the inner [...] pairs from the parser: needed as the LaTeX2e mechanisms do not do ...


0

The answer by egreg loads new fonts that seems to change fonts for the whole document -- not only in listings (in my document it changed the font used in paragraphs). The accepted answer uses pcr -- some may find it not very beautiful. You could use lmtt instead. Below is the version that uses lmtt and additionally wraps the font-change command into the ...


3

A rather hacky solution is to use tcolorbox for the border so that you can use listings frame for the rule. Tcolorbox provides a library for boxes that contain listings and minted codes. Below is a minimal setting but you have lots of room for improvement since tcolorboxes are highly customizable: \documentclass{report} \usepackage{xcolor} ...


1

In this case you only need the monospace (typewriter) font, not the other features of \lstinline, so you can just use \texttt. As @barbarabeeton points out, to get a proper backslash in the same font, use this: \char`\\ So the command you need is this: \subsection{\texttt{\char`\\dot}} If you do this a lot, because it's TeX you can devise macros: ...


10

This combination of packages is attempting to load the xeCJK package twice: once on line 11 of ctex-xecjk-engine.def from the ctex package, and then again on line 43 of xeCJK-listings.sty from the listings package. The clash you are getting is that the options are different in each case (the first one specifies [BoldFont,normalindentfirst] while the second ...


18

The listings package itself doesn't offer this feature; you need to hack at it a bit. I won't elaborate much here, as I've left comments in my code, but the basic idea is to use a counter to keep track of the nesting level, and typeset each parenthesis in a colour corresponding to the current value of that counter (modulo 5, in your case). I used a similar ...


4

listings is not able to recognize if a number is a part of your variables or not. What I suggest is to define a character with no meaning as an escape character (e.g. ¢) and add escapechar=\¢,escapebegin=\color{ipython_green} to your settings. Then use things like ¢7e-3¢ inside your listing. MWE: %Minimal \documentclass[a4paper, 11pt, twoside]{report} ...


5

You have to use a different literate for starred ones: literate= *{-}{{{\color{ipython_purple}-}}}1, If you add more literates after this one (without the star) they will behave as if they were starred. For example literate= *{-}{{{\color{ipython_purple}-}}}1 {?}{{{\color{ipython_purple}?}}}1, Also, the quotes at the beginning of the listing are due ...


1

It looks we cannot activate one-letter and two-letter sequences (literate) at the same time in the listings package. Therefore, I created a small patch in Lua. It takes input file written in Verilog language (let it be the verilog-input.v file starting with \begin{lstlisting} and ending with \end{lstlisting}), it finds critical spots and changes them. The ...


0

I am in the process of upgrading my verbatimbox package to provide some code (not syntax) highlighting tools (see draft package revision below). I was able to achieve somewhat your goal of added vertical buffer with one limitation. Because the yellow colorfield is drawn for each verbatim line, if it reaches vertically too far upward, it overwrites the ...


0

This is a total hack, involving adding a \beforerule and \afterrule around the environment. \documentclass[a4paper]{article} \pagestyle{empty} \usepackage{listings,xcolor,lipsum} \lstset{ backgroundcolor = \color{yellow}, basicstyle = \ttfamily, columns = fullflexible, tabsize = 4, frame = leftline, framesep = 0pt, ...


4

You can define two separate styles, or even two separate environments. \documentclass[]{article} \usepackage{xcolor} \usepackage{listings} \lstdefinestyle{Python} { language=python, basicstyle=\small, identifierstyle=\ttfamily, keywordstyle=\bfseries\ttfamily\color[rgb]{0,0,1}, stringstyle=\ttfamily\color[rgb]{0.627,0.126,0.941}, ...


4

To achieve what you want, instead of adding emph=, define an escapechar and use the formatting of your emphstyle to emphasize that part of the line. For example, let's suppose that you have emphstyle=\underline Then, defining escapechar=ä you can write ä\underline{add(8, 4);}ä to emphasize add(8, 4); and not the other occurrences of add. MWE: ...



Top 50 recent answers are included