TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to define a command which produces inline LaTeX listings via the package listings. However, the language definition for LaTeX contains [] which seems to be the cause of the error:

\documentclass{scrartcl}

\usepackage[american]{babel}
\usepackage{listings}

\newcommand*{\Lcode}{\lstinline[language=[LaTeX]TeX]}% does not work
%\newcommand*{\Lcode}{\lstinline}% works

\begin{document}
   If you like LaTeX, you write \Lcode|\LaTeX| which gives \LaTeX
\end{document}
share|improve this question
up vote 5 down vote accepted

You need braces for optional arguments in optional arguments:

\documentclass{scrartcl}

\usepackage[american]{babel}
\usepackage{listings}

\newcommand*{\Lcode}{\lstinline[{language=[LaTeX]TeX}]}% works, too
% \newcommand*{\Lcode}{\lstinline} % works

\begin{document}
   If you like LaTeX, you write \Lcode|\LaTeX| which gives \LaTeX
\end{document}
share|improve this answer
    
Thanks, works like a charm! – Marius Hofert Jan 17 '13 at 9:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.