1

I am typesetting a set of instructions which includes several (Unix) command line arguments. I have been using the listings package to include these arguments, but the colouring is less than ideal. Weird words like "test" are bolded. Is there something more like Pygments, which can highlight flags and filenames and the like?

As an example something like

program-name -some-option-flag -some-other-option-flag -i /location/of/input/file -o /location/of/output/file
4
  • 1
    Would you please provide an example of what you're doing?
    – egreg
    Commented Nov 9, 2011 at 17:32
  • @Dave: You can use the package minted which uses pygments. Commented Nov 9, 2011 at 17:49
  • 1
    It is possible to specify the language used in a listing, and even define your own language or formatting. As suggested, provide an MWE to allow others to work with something.
    – Werner
    Commented Nov 9, 2011 at 18:43
  • Thanks for providing the command line that you are tying to typeset, but it would be even more helpful to have a complete MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. That way we can see exactly what the problem is. Commented Nov 9, 2011 at 23:53

1 Answer 1

4

Without a full MWE it not clear exactly what issue you are having. But, you can define you own keywords that you want highlighted. Below I have defined cd, man, ls,and uptime to be emphasized in blue, and the keyword filename to be emphasized in red. So when these appear in the listing the specified formatting is applied.

enter image description here

\documentclass{article}
\usepackage{listings}%
\usepackage{xcolor}

\lstset{%
    backgroundcolor=\color{yellow!20},%
    basicstyle=\small\ttfamily,%
    numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=5pt,%
    }%

\lstset{emph={%  
    cd, man, ls,uptime%
    },emphstyle={\color{blue}\bfseries\underbar},%
    morekeywords={filename},
    keywordstyle={\color{red}\ttfamily}
}%


\begin{document}
\begin{lstlisting}
man cd
ls -lF test/
rm filename
uptime
\end{lstlisting}
\end{document}

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