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 tend to use the minted package for including code samples within my documents, which produces very nice output. However, because Pygments always produces a verbatim environment there's no way to inline the code if I need to discuss particular features of it. What is the best way to typeset inline code to go alongside code produced by minted?

Using the listings package just for \lstinline is one option I've considered, but it seems a bit odd to use both minted and listings together. I've used listings in the past, but (in my opinion and with the samples I've tried) I don't think the output is as nice as that produced with minted. Are there any other means of producing inline code that I'm unaware of?

share|improve this question
The output of listings can be configured quite a bit, see for example this question: tex.stackexchange.com/questions/8230/… – Jan Hlavacek Feb 11 '11 at 18:40
up vote 5 down vote accepted

You can do it with minted if you are willing to patch it:

\newcommand*{\TestAppExists}[1]{% there is no `which -s` on Linux
  \immediate\write18{which -- '#1' > /dev/null && touch -- '\jobname.aex'}%
% avoid space tokens since we're in horizontal mode
  \def\minted@cmd{pygmentize -l #2 -f latex -F tokenmerge
    \minted@opt{gobble} \minted@opt{texcl} \minted@opt{mathescape}
    \minted@opt{linenos} -P "verboptions=\minted@opt{extra}"
    -o \jobname.out.pyg #1}%
This is some inline code \mint{c++}|for i=1;i<20;i++| and more \ldots
share|improve this answer
This hack doesn't work anymore. It makes everything inline instead of just the \mint command. – green diod Mar 4 '13 at 18:57

AFIK this is an area, where you cannot use Pygments.

The simplest way to achieve it from a "typing" point of view is to use a "short verbatim".

This is some inline code |for i=1;i<20;i++| and more \ldots

The package fancyvrb offers a number of customizations as well.

share|improve this answer
This loses me all of the syntax analysis offered by a package such as listings or minted. See here for a comparison between this suggestion and the accepted minted solution. – Edd Feb 13 '11 at 14:08

Just for reference, see also issue 15 on the minted project page, and in particular a temporary fix that I posted there (but which probably does much the same as Philipp’s hack anyway).

In summary, this is on the “to do” list but not yet officially supported since I’m currently busy and don’t have time to work on minted.

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.