4
votes
2answers
138 views

How can I automatically replace subscripts and highlight GoTo labels?

I have to show a lot of autogenerated code throughout my document. The generated code represents loops with explicit block labels and gotos. The following code applies function f to each element of ...
5
votes
2answers
99 views

How can I force lstlisting to expand an argument?

I'm trying to use the listings package with a variable language (it's actually for a package). However, I can't seem to pass a macro as the value half of a key-value pair. Here's a simple example: ...
5
votes
1answer
75 views

Lstinline macro inside another environment

Why does the MWE below compile with errors only if I use ths \lstnewenvironment line? And how to define the verbatim macro inside an environment? I heard it's possible using plain TeX? ...
2
votes
0answers
58 views

Different colours for each argument and value in listings

This recent question (Print blue brackets in one language and black in another) made me come up with (up to) two more questions regarding the listings package: Is there an option similar to opstyle ...
4
votes
1answer
74 views

Print blue brackets in one language and black in another

In addition to that question i wonder if it is possible to have that settings for one language and default settings for another ? How to highlight operators and brackets in a C listing? ...
18
votes
2answers
348 views

How can I redefine my macro to accept a charcode instead of a character?

I recently posted this answer to How to highlight all words of the form [0-9][A-Za-z0-9]* immediately following an equal sign?. It works, but it suffers from (a lot) of code duplication. What I have ...
4
votes
1answer
227 views

Combining newenvironment, quote and lstlisting (mcode)

I am trying to combine various packages and commands with PdfLaTeX (through MikTex on MS Windows), including newenvironment, quote, mcode and lstlisting, to create an environment to define multiple ...
5
votes
2answers
215 views

How do I extract repeated functionality (exsheets workaround) to make it reusable?

Speaking with Clemens (exsheets maintainer) he pointed me to a workaround by Gonzalo Medina, that helps put verbatim and listings code in the exsheets pseudo (Clemens' word choice) question and ...
4
votes
1answer
182 views

lstlistings in defined Tikz box

I have created a box using \newcommand, based on TikZ named "mybox". The equation easily insertable in it. But I want to insert a \lstlisting environment in it. But it doesn't work. How can I do it? ...
4
votes
1answer
190 views

Problem with \newcommand that mimics lstinline

I'm trying to replicate a part of a scanned book. Book is about programming (pure C). I need to use many commands with a same name but with different surrounding, for example, background color etc. ...
2
votes
1answer
2k views

Compilation fails with “! Missing \endcsname inserted.”

Hi I've got a strange problem. I've defined a new command to print Linux commands line in the document: \documentclass[12pt,a4paper]{article} \usepackage{listings} \newcommand{\shellcmd}[1] { ...
6
votes
1answer
144 views

listings package and latex3 variable

I'm trying to change a custom environment from a lot of optional parameters to a ;-separated list (using this answer as a template and writing its main functionality as a latex3 macro). The macro ...
4
votes
1answer
390 views

How can I create wrapper macro for lstinline?

Using \lstinline I can include inline code snippets in a paragraph. I would like to provide a macro that selects formatting, etc, for lstinline so I can just do, say, \codeinline{snippet}. I had ...
4
votes
1answer
244 views

Command to insert filename in caption of a listing

I would like to have a command to insert listings that contain the filename in the caption. This works well as long as there is no "_" etc. in the filename. I also tried the suggestion from a ...
2
votes
1answer
223 views

Define listings language using variable

I'm using the listings package to document excerpts from my programs. I have been creating new environments for the various programming languages and wondering whether there was a way to hack the ...
7
votes
1answer
878 views

lstlisting in a newenvironment

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 ...
6
votes
1answer
65 views

`advise` Environment in listings package

I was reading the documentation for the latex listings package and there are advises in it which look like so: I had a quick look in the source code for the documentation and it turns out that ...
5
votes
1answer
312 views

Getting incorrect underscores from macro in an lstlisting

I have a macro that I define as \newcommand{\versionPath}{5\textunderscore0\textunderscore7} to denote the word *5_0_7*, which I use in lstlisting's like this: \begin{lstlisting} ...
2
votes
1answer
252 views

Define a macro for inserting a \begin \end listings block

Can you define a macro that would take a listings code as a parameter and insert it inside a \begin{lstlistings} \end{lstlistings} block? My idea is something like this: ...
4
votes
1answer
409 views

\lstinline & \colorbox

Why the command below don't work? How can I fix it? \documentclass[11pt]{book} \usepackage[dvipsnames]{xcolor} \usepackage{listings} \lstset{language=[LaTeX]Tex, ...
6
votes
1answer
965 views

\newcommand throws error: Runaway Argument? Paragraph ended before \lstKV@OptArg@@ was complete

I'm using the listings package in a document. In order to simplify the use of the \lstinline command I created a new command that looks like this: ...
3
votes
1answer
549 views

Problem defining a new command using lstinputlisting

I am trying to define a new command to easily insert SQL queries (from a file) on my document. I define it like that \newcommand{\sqlfile}[2]{\lstinputlisting[language=SQL, caption={#1}, ...
2
votes
2answers
119 views

A macro that behaves like a font-changing command (affects the rest of the current group)

Many LaTeX packages provide an interface to modify the typesetting of certain elements with the standard "parameterless" font commands, such as \bfseries, \sffamily or \color{red}. All of these ...
4
votes
1answer
514 views

lstinline loses braces when used as an argument to another command

I'm using the listings package, for the Java language (which, as all C-like languages, uses braces as a block delimiter). I intend to use \lstinline{...} as the second argument to a command for ...
5
votes
1answer
505 views

How to define macro that only makes argument substitution?

I am having some problems when I define a macro whose content has the lstlisting environment. For example, (assume ! is the escape char inside the lstlisting environment) \def\mycode#1{ ...
0
votes
2answers
150 views

Mysteriously fails to compile when I comment a line

I set up a github repo with a not-so minimal working environment (sorry for that). As the README at github says, uncommenting the following stupid line solves the problem and makes the ...
9
votes
1answer
788 views

Highlighting line ranges in a lstlisting: partial solution, but expansion issues

In my quest for a better solution for How to change appearance of a particular line when using \lstincludelisting, I came across the linebackground= option Martin Scharrer added to the listings ...
6
votes
3answers
265 views

Failsafe ways of using verbatim commands

All my ideas on how to do clever things with code examples and listings results further or later in 'Emergency Stop' errors. Let me briefly review what I am doing now and what I actually wanted to ...
4
votes
2answers
726 views

Why can lstlisting not be saved in a command?

This code fails with Emergency stop: \documentclass{scrbook} \usepackage{listings} \newcommand{\demo}{% \begin{lstlisting} foobar \end{lstlisting} } \begin{document} \demo \end{document} Why?
2
votes
1answer
434 views

Execute own command in listing

I create an own command like this \newcommand{\hostname}{this.is.my.hostname} Now I want to use this command in normal text (no problem) and inside of a listing Nun kann die Funktionsweise ...
2
votes
3answers
2k views

Any ideas why this \newcommand{\n}{\lstinline|\n|} macro doesn't work?

So I created a new macro \newcommand{\n}{\lstinline|\n|} but for some reason when I use it, all I get is bold 'n' letter and not a nice \n. Any ideas?
1
vote
1answer
272 views

Passing listing-environment as option to command [duplicate]

I have a simple command which takes one argument. Now I want to pass a small listing-environment to the command. Here is the code: \documentclass{article} \usepackage{listings} \begin{document} ...
2
votes
2answers
632 views

ignorespace and unskip in verbatim/listings?

I am writing a \bashDemo macro that will (a) execute its argument in a shell, e.g., bash, script, and (b) display the argument in a listings. So, \bashDemo ls -ls > myfiles \END will both run ls ...