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 know about the fragility of verbatim-like commands, and that they should not be used as an argument of another macro, but a need to write a description environment in which the terms to be defined are programming variables and functions, and thus I need use \lstinline with them.

I know about Verbatim description list item, but my question is somewhat different, for the following reasons:

  • I don't want only verbatim output and tt font, I want the syntax highlighting provided by \lstinline.
  • I don't write those description environments, they are automatically generated with a tool (pandoc).

In essence, I have a markdown source file containing for example:

The arguments of the function are:

   : Name of the file
   : Permissions

(the syntax is a markdown extension for descriptions, implemented by pandoc). When processed through pandoc with the appropiate options, the following tex code is generated:

The arguments of the function are:

Name of the file

And of course when latex compiles this, it chokes (strangely enough, it does not produce compiling errors, but in the resulting pdf the defined terms disappeared, and they appear later, all overlayed at the same place, at first \item in the next itemize).

So my questions are (in order of preference):

  1. There is some way to redefine \item or \lstinline so that the above works without changes in the generated tex code?
  2. If not, is it possible to define some other command instead of \item (say, \lstitem) which would produce the defined term typeset (and syntax-highlighted) by listings. In this second case I would write a script which searches the tex file for the \item[\lstinline!.*!] stuff and replaces it by \lstitem{.*}.
share|improve this question
up vote 18 down vote accepted

You could redefine \item so that it reads the stuff between [ ] as horizontal box, which can hold verbatim. For this you need to scan for the beginning [, start the box storing process and make ] an active character (i.e. like a macro) which adds the end of the box and call the original \item with the box as argument.

Tell me if you need further help understanding the code.









The arguments of the function are:

    Name of the file \\[1cm] % other [ ] still work as normal!
%\item[\lstinline!stuff! {doesn't work[]}]
%No other ] allowed in the argument

share|improve this answer
Fantastic! It works as advertised :-) I'm not sure why the last item (which contains a ] inside \lstinline) also works against my expectatives, but it's great. I guess that \lstinline redefines again ]'s catcode. Thank you so much. – JLDiaz Jan 15 '13 at 18:59
@JLDiaz: Indeed \lstinline redefines ]'s catcode again until the trailing !. – Martin Scharrer Jan 15 '13 at 19:00
@JLDiaz: Many thanks for the bounty! I really appreciate it. – Martin Scharrer Jan 19 '13 at 13:21

If you're happy with a new command, here is something I am using now (inspired by the previous answer):

  % \item[\hbox{\lstinline{#1}}]
  \hfill \\

\lstitem{sleep} Waits some time

I don't know, why the uncommented part does not work. But this code works for me, for now. Improvements always welcome.

share|improve this answer

Your Answer


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.