# Tag Info

3

Try this: \documentclass{article} \usepackage{listings} \usepackage{xcolor} \begin{document} \lstdefinelanguage{Test} { comment=[s][\color{blue}]{\#}{\#}, comment=[l][\color{red}]{\#} } \begin{lstlisting}[language=Test] #comment foo # comment # bar baz # comment #comment# qux \end{lstlisting} \end{document} It seems that you have to be ...

1

You definitely should install the latest version of MiKTeX.I suggestyou first make a list of the installed packages with your present version. Then go toMiKTeX's download page, wher you'll can choose between a basis installer (32bit) or a basic installer (64bit). Download the one you want and follow the instructions. When installation is finished, launch ...

5

You shouldn't modify a file in the main distribution tree: if there is an update to the package, your modification will be lost. In section 4.19 of the manual it is said that listings will load a file called lstlocal.cfg if it exists in a directory read by TeX. (Thanks to Paul Gessler for the hint.) Strategy 1: create a new lstlocal.cfg in the “local tree” ...

5

Another way to do this is to use the collcell package and define a new columntype for your Java code. As Jubobs points out in the comments, if a cell contains non-code the formatting will be incorrect. You will need to override its specification using \multicolumn. If you have a mix of code and non-code in the same column then a solution like his is ...

1

Suggestions: use inline code instead of lstlisting environments, and, for convenience, use a one-character shorthand. \documentclass{article} \usepackage{listings} \lstMakeShortInline[language=Java,basicstyle=\ttfamily] \begin{document} \begin{tabular}{l|p{7cm}} private` & Only entities declared inside the class are allowed to refer to ...

4

You have: \endinput \input{listings-java.prf} in listings.cfg but \endinput tells TeX to stop reading from that file. Nothing after that will be read. So you need to move your \input command before the \endinput command: \input{listings-java.prf} \endinput

23

Taken partially from my old answer here (click). This code should not be considered as a bombastic template but an easy-to-customize one. \documentclass[dvipsnames,border=15pt,preview,12pt]{standalone} \usepackage{xcolor} \usepackage{listings} \usepackage{accsupp} \newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}} ...

1

I see two possible approaches in order to automatically print (-) or (+) after the line number, where needed: Manually mark lines and do some parsing. Specify added/deleted lines at the beginning of the lstlisting environment. Approach 1 seems too complicated. Approach 2, although less user-friendly, appears easier to set up, especially if you create two ...

3

First Insert->Program listing and then insert your code into the red box and then right mouse click with the mouse cursor inside the listing box. Choose preferences and then Extended. In the right frame you can insert for example "caption={my caption}".

6

Under Document > Settings... > Listings you have to set a value for the basicstyle "listing parameter". Try, for example, to enter basicstyle={\ttfamily\small}: This will set it in TypeWriter font and size \small. You can change \small to whatever you like, taking from (say) What point (pt) font size are \Large etc.? You could also manually adjust the ...

0

\def\xstrut{\protect\rule[-2ex]{0pt}{2ex}} % The lstlisting caption is not shown here \begin{LTXexample}[pos=b,rframe={},caption={Caption of LTXexample\xstrut}] \begin{lstlisting}[language=C++,caption={Caption of lstlisting}] #include<iostream> int main{ std::cout << "Hello LaTeX\n"; } \end{lstlisting} \end{LTXexample}

0

Ok, I managed to get somewhere, but not sure how correct it is. Basically, it's all about setting basewidth=, but to a correct value, which I've obtained by using \widthof from package calc. Now, the problem is that we must have an expandable macro for basewidth= - and also, I think when basewidth= is processed, the {lstlisting} environment still doesn't ...

7

You could use the literate key; in the following example. parentheses are typeset in red: \documentclass{article} \usepackage{listings} \usepackage{xcolor} \lstset{ basicstyle=\small\ttfamily, columns=fullflexible, literate=*{(}{{\textcolor{red}{(}}}{1} {)}{{\textcolor{red}{)}}}{1}, } \begin{document} \begin{lstlisting} { ...

6

If you are willing to use the tcolorbox package and its listings library, this is easy; using \newtcbinputlisting you can define a customizable macro which behaves pretty much as \lstinputlisting and with \newtcblisting you define your customizable version of lstlisting: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{beramono}% just for the ...

3

The key is to use \getrefnumber from refcount instead of your \lineref, because \ref doesn't expand to a number, but is much more complicated when hyperref is involved, as it wants to create links. \documentclass{article} \usepackage{xcolor} \definecolor{dkgreen}{rgb}{0,0.6,0} \definecolor{mauve}{rgb}{0.58,0,0.82} \usepackage{listings} \usepackage{refcount} ...

3

Ok, I didn't find the answer to my question, but this workaround is just working: \lstset{basicstyle=\selectlanguage{english}\ttfamily} This switch my language (and font) to English everywhere I call \lstinline and \begin{lstlisting} ... \end{lstlisting}, and switch back to my main language when the scope end. So I no longer need those \pretocmd or ...

0

Just stumbled upon this thread because I had the same question. Although, the thread is old, I thought about sharing this: By accident I found the following solution which works quite perfect for me: \documentclass{article} \usepackage{inconsolata} \usepackage{listings} \usepackage{MnSymbol} \lstset{ basicstyle=\ttfamily, breaklines=true, ...

3

stackexchange uses google prettify https://code.google.com/p/google-code-prettify/wiki/GettingStarted to format code blocks. It can't be too hard, if you format your code with that first to convert the generated html markup back to tex, but I don't know of an existing package that does it

2

The “explicit space” symbols are due to the setting showstringspaces=true that's the default with lstlisting. The IEEEtran class knows just two types of captions, those for tables and those for figures. If an environment is not table, the class assumes the caption is for a figure, so it adjusts the spacing for it being placed below the picture. My ...

1

This is because the Java language in listings has morestring=[b]",% (this can be found in the file lstlang1.sty) to avoid this, you can use deletestring, as in: deletestring=[b]", Since the language also sets morestring=[b]',% you might also be interested in deletestring=[b]',% to avoid the same phenomenon with single quotes. I cannot reproduce ...

1

You have a global setting of showstringspaces anywhere. Add this to your definition of Pyshell: showstringspaces=false

2

I'm using version 1.5 (2013) of the listings package. I use lstinputlisting to include the code from the file, and I just put float inside the options of the environment. It works fine. For example, this goes in my preamble: \lstdefinestyle{freefempp}{ language=C++, basicstyle=\footnotesize\ttfamily, commentstyle=\itshape\color{violet}, ...

1

At first I thought that with a comment was enough, but I think this deserves an answer. Since is something I learned rather late (a few weeks ago). listings is much more friendly if you use latin1 as input encoding. For instance, accents work without literate, that is, out of the box (and also non-breaking spaces). What could go wrong? I don't know. What ...

3

For the line break at period, you can do as the follow: literate= {.}{}{1\discretionary{.}{}{.}}, Which does the line break at the ., however, it doesn't do it so beautifully. To tweak the output, have a look at this answer. This part of the answer tells you something: literate is some sort of hack to put unicode characters. Another solution could be to ...

1

Those visible-space characters tend to distract the reader (well, me, anyway); I can understand why you would want them to be fainter than they naturally appear when showspaces is set. The listings package defines no such spacestyle key, but you can always create one, if you want. See below. How did I find out about \lst@visiblespace? I knew showspaces ...

1

The listings package uses \lst@visiblespace for these spaces so you just need to define it: Here's the latex code. I removed your font encoding as I didn't want to generate all of the required fonts. \documentclass[a4paper, 10pt]{book} \usepackage{amsmath} \usepackage{listings} \usepackage[usenames, dvipsnames]{color} \makeatletter ...

3

The listings way is to use aboveskip and belowskip which are initially set to \medskipamount: \begin{lstlisting}[aboveskip=-1.4\medskipamount] Code: \documentclass{article} \tracingonline1 \tracingoutput1 \tracingparagraphs1 \usepackage{lua-visual-debug} \usepackage{listings} \usepackage{unravel} \makeatletter % \def\rst{\gdef\everypar={\setbox \z@ ...

1

Well, I got to a manual workaround, which is to use \vspace{-1.2\baselineskip} right after the second {minipage} starts; the output is then: ... which, I guess, is what the [t] + [t] would have been expected to do. I used the unravel package to step through the critical sections, and compare those logs in meld; the problem seems to reduce to \everypar ...

3

I too think this is a great idea! As you suggested fetching the html tags and attributes from documentation, I went to the MDN page and found out they have all that info in a single html page. Based on another question by you, I've applied the same structure to all the tags, and it does work. Took me a while to realize that the order I was declaring each ...

Top 50 recent answers are included