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{.*}.

2 Answers 2


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

  • 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, 2013 at 18:59
  • @JLDiaz: Indeed \lstinline redefines ]'s catcode again until the trailing !. Jan 15, 2013 at 19:00
  • @JLDiaz: Many thanks for the bounty! I really appreciate it. Jan 19, 2013 at 13:21
  • Unfortunately, your solution doesn't work with beamer class in case of incremental overlay specifications. Dec 17, 2017 at 18:33
  • @Denis: Beamer also redefines \item, so I'm Not surprised. Dec 17, 2017 at 18:56

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.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .