17
votes
2answers
252 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
163 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
182 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
152 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
140 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
130 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 ...
3
votes
1answer
278 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
198 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
177 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 ...
4
votes
1answer
582 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
62 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
201 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
214 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
318 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
739 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
488 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
117 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
389 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
434 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
148 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
698 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
259 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 ...
3
votes
2answers
594 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
332 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
259 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
609 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 ...