I would like to colorize in a special color all my constant which are all in capital letters in my code and all my method variables which begin with an @.  Is it possible to use Regex to define keywords with listings package ? It will help me for a lot of things !  For example, I actually have in a \lstdefinestyle:  keywords=[3]{@someName,@anotherName,@aboutOneHundredMore} keywords=[4]{SOME_NAME,ANOTHER_NAME,ABOUT_ONE_HUNDRED_MORE}   --> If I could replace this by:  keywords=[3]{/@.+/} keywords=[4]{/[A-Z_]+/}   it will save me from a lot of work !  If not, is there another way to have all my constant in a special color without defining all of them one by one in a keywords list ?  I first think about using morecomment or moredelim for the @ part but the ending character is problematic: it can be a space, a dot or a lot of other characters...
120758
I'm trying to typeset SuperCollider code using the listings package.  Any "freestanding" identifiers that begin with a capital letter are class names, and should be highlighted; by "freestanding", I mean outside of strings or comments. I would be tickled pink if listings could let you define identifiers in terms of regexp, e.g. [A-Z][A-Za-z0-9_]* but the manual doesn't suggests that as a possibility.  SuperCollider has some 2300 classes... I really don't relish listing all of them literally in my preamble. I guess I could extract them by hand for each individual listing, but I'd rather not have to.  Is there a way to do this without a really massive morekeywords expression? (Perhaps using another package?)  Sample SuperCollider code:  p.clear;  ~grains.addSpec(\tfreq, [1, 40, \exp]); ~grains.addSpec(\overlap, [0.1, 10, \exp]); ~grains.addSpec(\pos, [0, b.duration]);  // 3.43 is nice! ~grains.addSpec(\rate, [0.5, 2, \exp]); ~grains = { |tfreq = 25, overlap = 6, pan = 0, amp = 0.2, pos = 3.43,    rate = 1|    var trig = Impulse.ar(tfreq);    TGrains.ar(2, trig, b, rate, pos, overlap / tfreq, pan, amp) }; ~grains.play;   Impulse and TGrains should be highlighted in blue. I have dozens of other listings using different capitalized keywords.
94212
Trying to get my css / C# functions to look like this:  body {     color:#222; }   instead of this:  body  {     color:#222; }   when I auto-format the code.
44576
Using asp.net MVC I'd like to do this inside a view:  &lt;%= Html.TextBox("textbox1", null, new { class="class1" }) %&gt;   This statement does not compile because class is keyword in C#. I'd like to know how I can escape the property names such that this compiles.  It is possible to get this to compile if I change the "class" property to "Class" (uppercase C). But this is not suitable because strict xhtml says that all attributes (and element) names must be lowercase.
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!
62677
I am writing a Java utility which helps me to generate loads of data for performance testing.  It would be really cool to be able to specify a regex for Strings so that my generator spits out things which match this.  Is there something out there already baked which I can use to do this?  Or is there a library which gets me most of the way there?  Thanks
110221
I've actually a problem with my document.  I redefined the listing for my ruby code:  \usepackage{listings} \renewcommand\lstlistingname{Quellcode} \lstloadlanguages{Ruby} \lstset{% basicstyle=\small\ttfamily\color{black}, commentstyle = \ttfamily\color{red}, keywordstyle=\ttfamily\color{blue}, stringstyle=\color{orange}, backgroundcolor=\color{grey}, columns=fullflexible}  \DeclareCaptionFont{white}{\color{white}} \DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}} \captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}   And redefined the lstlistoflistings.  \renewcommand\lstlistlistingname{Quellcodeverzeichnis}  \addcontentsline{toc}{section}{Quellcodeverzeichnis}  \lstlistoflistings  \newpage   But the lstlistoflistings isn't showing the name, only the number of the lst.  Here is the actually lstlistoflistings:    Can anyone help me and show me how I can get the lstlistingname (Quellcode)  in every line of lstlistoflistings?  Thanks  UPDATE:  Here a MWE:  \documentclass[12pt, a4paper, oneside]{scrartcl}  \usepackage[utf8]{inputenc} \usepackage{textcomp} \usepackage[ngerman]{babel} \usepackage[hidelinks=true]{hyperref} \usepackage[final]{pdfpages}  \definecolor{grey}{gray}{0.9}  \usepackage{listings} \renewcommand\lstlistingname{Quellcode-Ausschnitt} \lstloadlanguages{Ruby} \lstset{% basicstyle=\small\ttfamily\color{black}, commentstyle = \ttfamily\color{red}, keywordstyle=\ttfamily\color{blue}, stringstyle=\color{orange}, backgroundcolor=\color{grey}, columns=fullflexible}  \usepackage{color} \usepackage{xcolor}  \usepackage{caption} \DeclareCaptionFont{white}{\color{white}} \DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}} \captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}  \usepackage{geometry} \geometry{a4paper, top=25mm, left=25mm, right=25mm, bottom=20mm, headsep=10mm, footskip=12mm}  \begin{document}   \renewcommand\lstlistlistingname{Quellcodeverzeichnis}  \addcontentsline{toc}{section}{Quellcodeverzeichnis}  \lstlistoflistings  \newpage    \begin{lstlisting}[language=Ruby, caption=StatusCalculator Initialize, label=initialize]   def initialize(project_id)     @project = Project.find(project_id)   end   \end{lstlisting}  \end{document}
70608
I have a variable for color. I use it to set color to strings, by evaluating it inside the string. However, I need to include space after the name(so that the name doesn't contain part of the text). This sometimes looks bad.  How can I avoid using(printing) this space?  Example(Let's say that Red=1 and NC=2):  echo -e "$Red Note: blabla$NC".   Output:  1 Note: blabla2.   Expected output:  1Note: blabla2.
41219
I search for "nurple" in a file. I found it, great. But now, every occurrence of "nurple" is rendered in sick black on yellow. Forever.  Forever, that is, until I search for something I know won't be found, such as "asdhfalsdflajdflakjdf" simply so it clears the previous search highlighting.  Can't I just hit a magic key to kill the highlights when I'm done searching?
10097
Does Java have a built-in way to escape arbitrary text so that it can be included in a regular expression? For example, if my users enter "$5", I'd like to match that exactly rather than a "5" after the end of input.
28541
I am running some unit test code. The unit test code outputs regular text. There is a lot of the text so I want to highlight for the user important keywords.  In this case the keywords are "PASS" and "FAIL".  How do you colorize "PASS" to be green and "FAIL" to be red?
18896
I've heard that you should use \[ ... \] for displayed equations instead of  $$ ... $$, but why is that?  I'd assumed that it's so that you can more easily tell which are starting and which are ending delimiters, but if I always use a syntax-highlighting text editor, I can see that easily based on the color of the symbols.  Is there any reason for this suggestion?
36638
My editor requires me to have a non-white background in my code listings. In order to make my code listings look nicer, I use the literate setting of listings to change underscores (which are very wide in the T1 font encoding) into narrower rules. Since I want the reader to be able to copy code from the PDF into a text editor and get syntactically valid code out, I am currently inserting an "invisible" textual underscore in addition to the rule.  I make the underscore invisible by using \textcolor to make it the same color as the non-white code listing background. However, this doesn't work when I typeset code with \lstinline where the background is white.  Thus I want the color of the underscore to change: In the lstlisting environment it should be grey, and in \lstinline it should be white. How do I achieve this?  Minimal Working Example:  \documentclass{article} \usepackage[T1]{fontenc} \usepackage{color,listings} \lstset{backgroundcolor=\color[rgb]{0.85,0.85,0.86},         literate={_}{\niceunderscore}1} \newcommand{\niceunderscore}{%   % Invisible underscore that can be copied in the PDF:   \makebox[0pt][l]{\makebox[3pt][c]{%     \textcolor[rgb]{0.85,0.85,0.86}{\_}}}%   % Visible, noncopyable rule:   \rule[-0.4pt]{3pt}{0.4pt}} \begin{document} This is what \lstinline+foo_bar+ looks like: \begin{lstlisting} foo_bar \end{lstlisting} \end{document}     As you can see, the underscore is visible as a grey character below the black rule in the inline text, but in the lstlisting environment, it is invisible like I want it to be.
116235
Trying to write -regex for a find statement that shows only directories with dots and numbers, for example 1.2.3.4 oraz 1.2.3 or 1.3.4.5.6 was trying something like  "-regex '\.[0-9.]+'", but it also shows dirs with letters. And I only want directories with numbers and dots.
19106
I've got a question (it's in the title) about listings that I do not believe have been answered anywhere (either that or my Google-fu isn't that sufficient). Before I knew of texcsstyle's star option, I tried to highlight double backslash (\\) by using the literate option (how monstrous):   literate=*{\\\\}{{\textcolor{red}{\textbackslash{}\textbackslash{}}}}{1}   With this I used to be able to highlight double backslash but since I didn't use texcsstyle I could not highlight the backslash that comes before all LaTeX commands. But when I finally DO use texcsstyle, the literate option suddenly no longer works for double backslash, even though all the other literate replacements (for &amp;,[,],{,},...) still work. I guess texcsstyle is interfering with the literate option? How do I resolve this? Is it even possible to have both texcsstyle and double backslash highlighted?  Edit: added an example, sorry. Uncomment the line with texcsstyle and you will see the double backslash stop getting highlighted.  \documentclass{article} \usepackage[T1]{fontenc}   \usepackage[usenames,dvipsnames,svgnames,table]{xcolor} \usepackage{listings} \usepackage{charter} \definecolor{lightgrey}{rgb}{0.9,0.9,0.9} \definecolor{darkgreen}{rgb}{0,0.6,0} \definecolor{darkred}{rgb}{0.6,0,0} \definecolor{myblue}{RGB}{20,105,176} \definecolor{darkgreen}{rgb}{0,0.6,0} \lstdefinelanguage{mytex}[LaTeX]{TeX}{   moretexcs={includegraphics,multicolumn,multirow,newcolumntype,intertext,},   morekeywords=[2]{figure,tabular,tabulary,document,minipage,verbatim,table,     enumerate,tikzpicture,preview},     % texcsstyle=*\bfseries\color{darkred},   literate=             *{\{}{{\textcolor{myblue}{\{}}}{1}             {\}}{{\textcolor{myblue}{\}}}}{1}             {\&amp;}{{\textcolor{red}{\&amp;}}}{1}             {\\\\}{{\textcolor{red}{\textbackslash{}\textbackslash{}}}}{1}             {[}{{\textcolor{myblue}{[}}}{1}             {]}{{\textcolor{myblue}{]}}}{1}, } \lstset{language=mytex} \lstdefinestyle{mystyle1}{ basicstyle=\small\ttfamily, keywordstyle=\color{purple}\bfseries, keywordstyle=[2]{\color{magenta}}, commentstyle=\color{darkgreen},  stringstyle=\color{orange}, identifierstyle=\ttfamily, showstringspaces=true, breaklines=true, tabsize=4, columns=fullflexible, keepspaces=true, } \lstset{style=mystyle1} \begin{document}    \begin{lstlisting} \begin{alignat*}{4}    y &amp; = -4   &amp; + 3 &amp; +4     &amp; -7      \\    y &amp; =      &amp; + 3 &amp;        &amp; -7      \\    \intertext{therefore}    a &amp; = b    &amp; d   &amp; = cccc &amp; e &amp; = d \\    a &amp; = bbbb &amp; d   &amp; = c    &amp; e &amp; =   \\ \end{alignat*} \end{lstlisting}  \end{document}
459
I was wondering if there is a good way for JSON files to be listed with the listings package.  The only language definition I could come up with, is this:  \lstdefinelanguage{json} {     morestring=[b]",     morestring=[d]' }   Now, this highlights the strings used in JSON files, but the important syntactical things in JSON are the curly braces, the square brackets, commas, and colons. I have sadly no Idea how I could make them be highlighted in a different manner. I tried adding { and } as identifier or as keywords, but it didn't work.  I'd really like to make listed JSON files appear nicer, since on a project I need to document I'd really need it. Also, I couldn't find a JSON definition for that on the internet, anywhere else.  On a more general thought: can I highlight all numerals with listings?
5856
When using Perl variable names with sigils with listings, the $ and @ sigils somehow get coloured in identifierstyle, but the % sigil remains unstyled.  Therefore, this code:  \documentclass{article}  \usepackage{listings,xcolor}  \lstdefinestyle{perl}{    language=Perl,    basicstyle=\ttfamily,    keywordstyle=\bfseries\color{green!40!black},    commentstyle=\color{purple!40!black},    identifierstyle=\color{blue},    stringstyle=\color{orange}, }  \lstset{style=perl}  \begin{document}     \begin{lstlisting}         my ($a, $b, $c) = ('a'..'z');         my ($a, $b, @c) = ('a'..'z');         my ($a, $b, %c) = ('a'..'z');     \end{lstlisting} \end{document}   gives this result:    Is there a way I could make listings understand that % should have the same style as $ or @?  The manual is pretty clear about keywords and comments, but it didn't help me understand the difference between an identifier and an operator (?) that doesn't get styled. Looking at the Perl language definition in lstlang1.sty didn't help either since there is nothing there about either $ and @ or %.
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: