Tag Info

New answers tagged

3

another escape way is to define escapeinside field. \lstset{escapeinside={\%*}{*)} means that between %* and *) characters you can write latex commmands. For example, \begin{lstlisting} void setPorts(int recvHere, %*\newline*) int sendFrom) The answer is similar to Peters' but i couldn't add the comment to his answer since i have not enough ...


2

Cleveref has to be informed of the name you want to give to the environment. Here is a solution which uses the name of the environment dynamically (partially!). The code can be written in a cleveref.cfg file: \documentclass{scrreprt} \usepackage{etex} \usepackage[T1]{fontenc} \usepackage{textcomp} \usepackage{bm} \usepackage[utf8]{inputenc} ...


4

The package cleveref is one of the packages that should be loaded last, even after hyperref, since it does a lot of redefinitions on counters and labelling/referring (of course, since this is the topic cleveref is about). \documentclass{scrreprt} \usepackage{etex} \usepackage[T1]{fontenc} \usepackage{textcomp} \usepackage{bm} \usepackage[utf8]{inputenc} ...


1

There is simpler solution to your problem with the chapternumbering. The listings package provides the \lstset command to configure the output. The numberbychapter=false option does exactly whats advertised. The Code: \documentclass{scrbook} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[english]{babel} \usepackage{xcolor} ...


1

This should work, but could require some adjustment according to settings made by the class you are using. \documentclass{report} \usepackage{chngcntr} \usepackage{listings} \AtBeginDocument{% the counter is defined later \counterwithout{lstlisting}{chapter}% } \makeatletter \renewcommand{\l@lstlisting}[2]{% ...


0

lstlistings does not work well with UTF-8. By adding \lstset{ literate={’}{\textquoteright}1 {ʹ}{\textquoteright}1 } The UTF-8 chars were replaced with close LaTeX produced counterparts. Solution provided by daleif above.


5

The listings package provides an option called final that you can use for that. See section 2.2 of the listings doc: final Overwrites [sic] a global draft option. Simply pass the final option to listings when you load the package: \documentclass[draft]{book} \usepackage[numbers,sort&compress]{natbib} ...


1

The listings package has a make option: \documentclass{article} \usepackage{listings} \begin{document} \begin{lstlisting}[language=make] # I am a comment CC=g++ # CFLAGS options passed to the compiler. CFLAGS=-c -Wall all: hello hello: main.o factorial.o hello.o $(CC) main.o factorial.o hello.o -o hello clean: rm *.o hello ...


4

The lstlisting package only boxes the contents if it starts in horizontal mode (which is the reason why it boxes the contents in a tabular). A solution is to coerce horizontal mode, but there's the added problem of setting the caption, which can be done with the help of \captionof, persuading LaTeX into thinking this is a listings and not a figure. In ...


2

I had the same problem. It does not seem to be possible to add keywords to an existing language definition, when you do not always want to explicitly set it before opening a listing (i.e. there is no \lstupdatelanguage equivalent to \lstdefinelanguage). However, I found it convenient to use the \lstnewenvironment command to define a new environment which ...


2

You could use the minipage environment coupled with the mdframed package. Of course, there's also the listings package for the code. This example answer is tweaked for margins of 1.5cm on each. If you increase the margin (reducing the available space for the content) you should also fix the \textwidths of the minipages. Since the minipage on the right is ...


0

My second solution is not exactly what I wanted. I should find whether I'm inside my moredelim or not. Instead I check the font properties specific for that moredelim. Test against font family I make Doxygen comment the only style which uses \sffamily moredelim=[s][\color{ForestGreen}\sffamily]{/**}{*/}, %doxygen comment Inside literate rule I use a ...


0

My first solution for formatting Annotation inside Doxygen is not autamatic. It requires manual edition of source code. While defining MyCode I set escapechar to enable formatting of the desired words \lstnewenvironment{MyCode} {\lstset{language=C++, escapechar=~, ... }{} Inside MyCode pasted source is manually extended with formatting \begin{MyCode} ...


1

The following code solves the first question: \lstinputlisting[firstnumber=6]{{pics/met/binarysearch.m}} firstnumber defines the starting line number. The second question: Wrong order of the code. The following code is correct: \begin{figure}[htb] \centering \lstinputlisting[firstnumber=6]{pics/met/binarysearch.m} \caption[Matlab code for ...


3

The breaklines option, pointed out by Jubobs, works indeed and without any warnings. Here is how you can do it: \documentclass[11pt,a4paper,oneside]{article} \usepackage[utf8]{inputenc} \usepackage{listings} \usepackage{xcolor} \lstset{ frame=tb, % draw a frame at the top and bottom of the code block tabsize=4, % tab space width ...


3

Minimal example with citation and frame: \documentclass{article} \usepackage{listings} \lstset{frame=tb,language=XML} \begin{document} \begin{lstlisting}[float,caption=Some caption,label=lst:ref] <balise1> 1 </balise1> <balise2> 2 </balise2> \end{lstlisting} Refer to Listing~\ref{lst:ref}. \end{document} More information can be ...


1

I improved upon my own question by taking some bits from this SO question. My code for Python syntax coloring and layout is now like this: \usepackage{color} \DeclareFixedFont{\ttb}{T1}{txtt}{bx}{n}{12} % for bold \DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{12} % for normal \definecolor{deepblue}{rgb}{0,0,0.5} \definecolor{deepred}{rgb}{0.6,0,0} ...


0

Just leave a blank line after the environment, if you want indentation: \documentclass{article} \usepackage{listings,lipsum} \lstnewenvironment{mycode}{}{} \begin{document} \lipsum[1] \begin{mycode} \def\cmd#1{\cs{\expandafter\cmd@to@cs\string#1}} \def\cmd@to@cs#1#2{\char\number`#2\relax} \DeclareRobustCommand\cs[1]{\texttt{\char`\\#1}} \end{mycode} ...


0

Use etoolbox and its \AfterEndEnvironment hook to insert \par \documentclass{article} \usepackage{listings,lipsum} \lstnewenvironment{mycode}{}{} \usepackage{etoolbox} \AfterEndEnvironment{mycode}{\par} \begin{document} \lipsum[1] \begin{mycode} \def\cmd#1{\cs{\expandafter\cmd@to@cs\string#1}} \def\cmd@to@cs#1#2{\char\number`#2\relax} ...


1

You don't want to define a dialect but a new language based on xml, so your syntax is wrong. It should be \documentclass{article} \usepackage{listings} \lstdefinelanguage{XSLT2}[]{XML}% changed {morekeywords={xsl:for-each-group},% alsodigit={-},% }% \lstloadlanguages{XSLT2} \begin{document} This is a test \begin{lstlisting}[language=XSLT] ...



Top 50 recent answers are included