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. I'm using listings package.
I created with newcommand, something like an alias for \lstinline. Later, maybe, I'll surround it with background color or different font/size or something like that. I want to be able to do this kind of things on-the-fly (to tweak every thing later easy).
Main problem is with a source code in the book (specifically reserved or special characters, like # or \). At the moment, I just use different names for a plain commands, which I'm going to define (expand) later, something like this:
\usepackage{listings}
\newcommand{\test}[1]{\lstinline{#1}}
\test{"\nA marathon is %f kilometers.\n\n"}
\lstinline{"\nA marathon is %f kilometers.\n\n"}
problem is with this command:
\test{"\nA marathon is %f kilometers.\n\n"}
while this command, as expected, works fine:
\lstinline{"\nA marathon is %f kilometers.\n\n"}
I get errors (Undefined Control Sequence. \nA), but soon as I remove (La)TeX special characters (#, \), everything runs normally.
My question is, is there a clean way to create newcommands (or an aliases) which are dealing with source code, or, there is some other, more elegant way that you know?
Any help apreciated.
\newcommand{\test}{\lstinline}– cgnieder May 29 '13 at 17:18