Some keywords defined with the otherkeywords key are not formatted as expected when breaklines is set to true. Here is my MWE:  \documentclass[12pt, a4paper]{article} \usepackage{listings} \lstset{   basicstyle=\itshape\ttfamily,    keywordstyle=\upshape, } \lstdefinestyle{syntax}{   language=[ANSI]C,   otherkeywords={(,)},   breaklines=true, }  \begin{document} \begin{lstlisting}[style=syntax]   const ( int | float ) text \end{lstlisting} \end{document}   The result looks something like this (but nicely monospaced...):  const ( int | float ) text  If I set breaklines=false, it looks as expected:  const ( int | float ) text  Am I missing something obvious? As for versions, "This is pdfTeX, Version 3.1415926-2.4-1.40.13 (MiKTeX 2.9)" on Windows (at work, they force me...).
90979
As the title says, the option breaklines=true seems to have an undesired interaction when using literate; in the following example the closing parenthesis doesn't get colorized   \documentclass{article} \usepackage{xcolor} \usepackage{listings}  \lstset{   literate=     {)}{{\textcolor{red}{)}}}{1}     {(}{{\textcolor{red}{(}}}{1},   breaklines=true, }  \begin{document}  \begin{lstlisting} () \end{lstlisting}  \end{document}     Commenting out the breaklines=true option produces the desired result. What is producing this odd behaviour and how can it be prevented?
32819
I want to typeset a piece of code containing line breaks.  New lines should indent to a specified point in the previous line.  Here is a monospaced example to illustrate what I mean.  Notice how 'case' and 'of' line up below, as well as 'let' and 'in':  swap : forall a, b. Tuple a b -&gt; Tuple b a swap a b x = case x              of tuple a b y z. let x' = tuple b a z y                                in x'   The code I want to typeset is not monospaced, so I can't just use a verbatim environment to get what I want.  The actual LaTeX of the first line, for instance, is  \mathsf{swap} : \forall\alpha,\beta.\;\mathsf{Tuple}\;\alpha\;\beta\to\mathsf{Tuple}\;\beta\;\alpha   How can I align some text to a specific point in the previous line?
4554
How do I post text so that it is formatted as code?  What do I need to do so that my code shows up properly &mdash; not escaped or removed &mdash; when posted? And how to get the correct syntax highlighting?     For more information, see "" in the .
39736
How can I apply different styles to keywords depending on their prefix?  Here is some sample code:  (-2,0,0) (2,1,1) op-registerbox !box1 ;box1 /Blue op-setproperties   I'd like to typeset   words starting with ! and ; in color red, words starting with / in color green, words starting with cp- in bold.   So far, this is what I've got:  \lstdefinelanguage{XX} { basicstyle=\small\sffamily\fontseries{c}, emphstyle=\underbar, keywordsprefix=[2]{/}, alsoletter={/}, keywordstyle=\textbf, keywordstyle=[2]\color{green}, morekeywords={op,registerbox, ...}, morestring=[b][\color{green}]", columns=flexible, escapechar=\%, numbersep=6pt, numberstyle=\scriptsize }   I'm aware that only one keywordsprefix can be defined at the moment: specifying more than one class of prefix (keywordsprefix=[2]{/}) is currently not supported. I'd like to avoid having to list all the words that match my description into morekeywords. Is that possible? How?
81104
All single quotes in code samples are displayed as backticks and the copy-pasted code can't be compiled without fixing the quotation. Is it possible to prevent this?  for example:  \documentclass{beamer} \usepackage{listings} \begin{document}  \lstset{language=Python} \begin{frame}[fragile]{Code} \begin{lstlisting} print 'hi'  \end{lstlisting} \end{frame} \end{document}   Compiled with latexmk -pdf file.tex, which creates a log starting like: This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013).  Output:
105567
I have a custom style in lstlisting with numbers on the left and the number step is set every line. I would want to know how the listings could appear without number in case the listing has only one line.  My configuration is the following:  \lstset{ breaklines=true, captionpos=b, % sets the caption-position to bottom basicstyle=\ttfamily\footnotesize, commentstyle=\color{verdeComentario},    numbers=left, % número de línea a la izquierda stepnumber=1, % salto de cada línea tabsize=3, numberstyle=\tiny, xleftmargin=15pt, xrightmargin=15pt, framesep=5pt, frame=tb, framerule=0.2pt, backgroundcolor=\color{grisDebil}, lineskip=-1pt, tabsize=3, escapeinside={@}{@}, aboveskip=20pt, belowskip=20pt, }  % ----------------------------- %     Maude % -----------------------------  \lstdefinelanguage{maude} {     alsoletter={\:},     morecomment=[l]{---},     morecomment=[l]{***},     keywords={in, load, pr, protecting, sort, sorts, subsort, subsorts, including, class, msg, msgs, endfm, fmod, is, mod, endm, omod, endom},     keywords=[2]{eq,  mb, ceq, if, rl, crl, else, then, fi},     keywords=[3]{ctor, assoc, comm, gather, id\:},     keywords=[4]{op, ops, var, vars} }  \lstdefinestyle{maude}{     language=maude,     keywordstyle=\bfseries\color{rojoReservado},     keywordstyle=[2]\bfseries\color{verdeReservado},     keywordstyle=[3]\bfseries\color{turquesaReservado},     keywordstyle=[4]\bfseries\color{moradoReservado}, }   I could set in every listing with only one line the option numbers=none but I have a large document just written and I'll be very gratefull if I know how to do it automatically.
38035
Does anyone know a package for ?    Failing that, is anyone interested in writing a command to create one? I'm thinking of something that would have optional and configurable separators above and below (e.g., lines or large quotation marks), and option to float left, right, or center. Ideally the command should print the argument and the pull quote so you do not have to duplicate the text that you want to quote.   To avoid duplicating existing questions, perhaps we should focus on single column documents, so that the pull quote has to be boxed?
58455
I have a problem with a lstlisting environment. I want to use it for displaying several very long lines that can not be reformatted. Independently of the option breakatwhitespace=true or false my lines are not broken down so that the end is far outside of the printable area.  How to specify that line breaks are allowed at any character? Or is it possible to specify the characters (besides whitespace) that can be used for a line break?  Alternative: inserting a special (not-printed) character that indicates "break line here" - doe something like this exists?  \begin{lstlisting}[] Test1: 33b7a2f7c4cc93c46dd4ee2ed81aa1eb-9409135542c79d1ed50c9fde07fa600a_cce5a2fe76bfbd0c48d79fb43a7106f0_263e9a8711c1400fb2a716a1b820ac9a Test2: 33b7a2f7c4cc93c46dd2423423423423-9409135542c79d1ed50c9fde07fa600a_cce5a2fe76bfbd0c48d79fb43a7106f0_263e9a8711c1400fb2a716a1b820ac9a \end{lstlisting}   Update:  The  works fine. Additionally I found a different approach which works directly with a lstlisting environment:  \begin{lstlisting}[breakatwhitespace=true, literate={\-}{}{0\discretionary{-}{\\}{}}]   ... \end{lstlisting}   It allows to break the lines also at hyphenations. It has some drawbacks especially that the line breaks are looking different from the others in the environment. But may be for others this code may be helpful...  Found here:
90301
Formatting breaks if code follows a list:   List item List item  This is in a code block  This does not work as expected   However, it works if between the list and the code   List item List item   There is a line of normal text.  This is in a code block # This does work as expected   Edit  To make this clear: This is not about nesting code in a list but about code following a (finished) list not working as expected (by me). To put it differently: Why is a list not considered finished despite of following empty lines? What do I have to do?
33623
I have a document where I quiet often refer to source code element, such as class names, I wanted to format these strings differently, but at the beginning I didn't want to fiddle with various options I had, rather I defined my custom command as follows:  \providecommand{\inlinecode}[1]{\texttt{#1}}   Now my question is, what do you think is the best way to define \inlinecode? Note: I often use text with unescaped &lt;, >, e.g., List&lt;T&gt;.   The \texttt looks fine to me, and works with &lt;, >, but sometimes the words overflow the line. Is there any way to tell latex not to overflow the line, but rather "underflow" or insert more spaces between words, which seems to me as (maybe still ugly but) more acceptable than overflow? And is it possible to achieve it by only changing definition of my command, so I won't have to change the whole source?
100769
I want to typeset some LaTeX source code by listings. I've tried this:  \documentclass{article} \usepackage{listings} \usepackage{xcolor} \lstset{     delim = [s][\ttfamily\color{orange}]{$}{$} } \begin{document} \begin{lstlisting} \documentclass{article} \usepackage{amsmath} \begin{document} $E = mc^2$ \end{document} \end{lstlisting} \end{document}     The equation turns orange. However, the two dollar signs are also highlighted as orange. If I just want contents in the two dollar signs turns orange, what should I do?
19012
I have a problem with the lstlisting package. I want to define an \newenvironment with one obligatory parameter, which will be the caption name for the lstlisting. I will also have other lstlisting environments, that is why I am trying to define them separately.  I am also having some difficulties with \lstinline command (I set up a \newcommand to gain easier coding), which typesets keywords in normal text. Why can't it be in captions and similar?  I suppose something could be wrong with the preamble, that's why all the packages used are listed.  \documentclass{book} \usepackage[a4paper, top=3cm, bottom=3cm, heightrounded, outer=3cm, inner=3cm, marginparwidth=1.5cm, marginparsep=0.5cm]{geometry}  \usepackage{tocloft} \usepackage{amsmath}  \usepackage{eurosym} \usepackage{url} \usepackage{array} \usepackage{tabularx} \usepackage{multirow}  \usepackage{multicol}  \usepackage{graphics} \usepackage[dvips]{graphicx}  \usepackage{epstopdf}  \usepackage[dvipsnames]{xcolor}  \usepackage{verbatim} \usepackage{fancyvrb}  \usepackage{fancyhdr} \usepackage{paralist}  \usepackage{listings}  \usepackage{pifont}  \usepackage{indentfirst}   \lstset{language=[Visual]Basic, % keywordstyle=\color{blue},commentstyle=\color{ForestGreen},stringstyle=\color{Maroon},% basicstyle=\ttfamily\normalsize, frame=lines, % showspaces=false, showstringspaces=false,% tabsize=4, aboveskip=10pt, belowskip=10pt, % lineskip=2pt, numbers=left, numberstyle=\tiny, stepnumber=1, numbersep=5pt,% numberblanklines=false, % breaklines, breakatwhitespace, prebreak=\_, breakindent=0pt % }  \lstset{morekeywords={Or, Loop, Until, To, As, Single, Module, Double, ByVal}}  \lstset{emph={Console}, emphstyle=\color{Aquamarine}}  \newenvironment{case}[1]{\renewcommand\lstlistingname{Case}% \begin{lstlisting}[caption={#1}]}% {\end{lstlisting}}  \newcommand{\code}[1]{\lstinline[basicstyle=\rmfamily\normalsize, prebreak=, keywordstyle=\ttfamily]{#1}}   \begin{document}  Example with inline, that works: \code{Console, Sub in Module}.  \begin{case}{Hello world} %doesn't work Module Module1     Sub Main()         Console.WriteLine("Hello World!")         Console.ReadKey() End Sub End Module \end{case}  \end{document}   Thank you in advance!
115313
I have some pseudo-code where I want to highlight some sections in a different color (this is why: in an assignment at university, I have some code given and have to adapt it. I want to highlight what I changed for enhanced readability).  \documentclass[english, a4paper, 11pt]{article} \usepackage{xcolor} \usepackage{listings} lstset(language=C)  //best for pseudo-code IMHO  \begin{document} \begin{lstlisting}[frame=single]    public class A&lt;T&gt; extends B&lt;T&gt; {       \textcolor{red} {Stack stack};  //how can I achive this? Nothing should change, except for the textcolor. This code just prints the \textcolor command though.         //ctor        public A() {};    } \end{lstlisting} \end{document}
653
Is there a way to input particular sections of source code using \lstinputlisting (from the listings package) in a flexible way?  It's possible to use the firstline and lastline options to input particular line ranges, but this isn't robust to changes to the source file.  For example, suppose that the input source file is:  int square(int x) {   return x * x; }  int cube(int x) {   return x * x * x; }   In my LaTeX document, I can include the cube procedure using the command \lstinputlisting[firstline=5,lastline=7]{source.c}.  But suppose I later decide to rewrite the cube procedure.  The input source file becomes:  int square(int x) {   return x * x; }  int cube(int x) {   int x2;   x2 = square(x);   return x * x2; }   Now my LaTeX document will not show the final two lines of cube because the listing uses only lines 5-7.  I could manually update the line range, but this is tedious and error-prone.  Is there a way to mark sections of source code with some kind of label so that the listing will be robust to these sorts of changes?  For instance, perhaps the input source file would be something like  int square(int x) {   return x * x; }  /**\beginlabel{lst:cube} **/ int cube(int x) {   int x2;   x2 = square(x);   return x * x2; } /**\endlabel{lst:cube} **/   so that I could use something like \lstinputlisting[lines=lst:cube]{source.c} to include the section that I want and remain robust to changes.  I am open to using other packages for source code listings (e.g., minted) if helpful.
1731
Consider this question:    Unfortunately, the question title is displayed on SO as:     is `x— > 0 &amp;&amp; array[x]` well defined behavior in c++?   There are two issues here:   Less severe, the backticks are displayed verbatim and don’t delimit a code span. Not very nice but bearable. On the other hand, MathOverflow has this really nice math mode even in titles – why not also introduce this on SO for code? The -- operator is transformed into an em-dash. This is slightly misleading and simply unnecessary. I am all in favour of using SmartyPants (or whatever SO uses) to glam up the question title typography. But this shouldn’t go at the cost of correctness.   So I suggest allowing limited Markdown in titles (e.g. as in comments?) or at least fixing the formatting bug.
43759
I am trying to define an enviroment for a specific programming language, F#. Here's my code:  \definecolor{bluekeywords}{rgb}{0.13,0.13,1} \definecolor{greencomments}{rgb}{0,0.5,0} \definecolor{turqusnumbers}{rgb}{0.17,0.57,0.69} \definecolor{redstrings}{rgb}{0.5,0,0}  \lstdefinelanguage{FSharp}     {morekeywords={let, new, match, with, rec, open, module, namespace, type, of, member, and, for, in, do, begin, end, fun, function, try, mutable, if, then, else},     keywordstyle=\color{bluekeywords},     sensitive=false,     morecomment=[l][\color{greencomments}]{///},     morecomment=[l][\color{greencomments}]{//},     morecomment=[s][\color{greencomments}]{{(*}{*)}},     morestring=[b]",     stringstyle=\color{redstrings}     }  \newenvironment{fslisting}   {     \lstset{         language=FSharp,         basicstyle=\ttfamily,         breaklines=true,         columns=fullflexible}     \begin{lstlisting}   }   {     \end{lstlisting}   }   Then I'm trying to use it as such:  \begin{fslisting} type 'a Process = 'a Signal IObservable \end{fslisting}   But it doesn't work. The output log says that the listing is not terminated - or is terminated by the document. So the rest of the document is also formatted as a listing, which is of course not the intention.  What am I doing wrong here?
100341
I wonder why the compiler shift the item that does not fit the rest of the page to the next pages ?! How to tell the compiler to break such item ?!   Here is a screenshot     and here is code regarding this part   \documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsthm} \usepackage[utf8]{inputenc} \usepackage{titlesec} \usepackage{titletoc} \usepackage{enumitem} \usepackage{mathtools} \setlength{\footskip}{15pt}  \begin{document}  XXX\\[17.5cm] YYY \begin{align*} [\textbf{a},\textbf{b}]_{\mathbb{R}^9}  = \phi\bigl([\phi^{-1}(\textbf{a}),\phi^{-1}(\textbf{b})]_{\mathfrak{u}(3)} \bigr) . \end{align*}  We check the verification of the conditions the bracket $[\,\, , \,\,]_{\mathbb{R}^9}$ must satisfy in the following three steps:  \begin{enumerate}[nolistsep] \item[(i)] (The $\mathbb{R}$-linearity of $[\,\, ,\,\,]_{\mathbb{R}^9}$) For arbitrary $\textbf{a},\textbf{b},\textbf{c} \in \mathbb{R}^9$ and $\alpha_1,\alpha_2 \in \mathbb{R}$, it follows by the $\mathbb{R}$-linearity of $[\,\, \,\,]_{\mathfrak{u}(3)},\phi$ and  $\phi^{-1}$ that \begin{equation*} \begin{split} \bigl[\alpha_1 \textbf{a} + \alpha_2 \textbf{b} , \textbf{c}    \bigr]_{\mathbb{R}^9}   &amp;= \phi\bigl( [\phi^{-1}(\alpha_1\textbf{a}+\alpha_2 \textbf{b}), \phi^{-1}(\textbf{c})]_{\mathfrak{u}(3)}  \bigr) \\&amp;= \phi\bigl( [\alpha_1 \phi^{-1}(\textbf{a}) + \alpha_2 \phi^{-1} (\textbf{b}), \phi^{-1}(\textbf{c}) ]_{\mathfrak{u}(3)}    \bigr) \\&amp;= \phi\bigl( \alpha_1 [\phi^{-1}(\textbf{a}), \phi^{-1}   (\textbf{c})]_{\mathfrak{u}(3)} + \alpha_2 [\phi^{-1}(\textbf{b}), \phi^{-1}  (\textbf{c})]_{\mathfrak{u}(3)}       \bigr) \end{split} \end{equation*}  \end{enumerate}  \end{document}   latex split the block of equations normally except that when I use enumerate environment latex shifts the item entirely to the next page.. This is the only exception and I unfortunately do not know why !