How to typeset - - with lstlisting package?
You can use the option literate
to modify the output:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{listings} %for listings of the source code
\begin{document}
\lstset{language=sh,literate={--}{{-{}-}}1}
\begin{lstlisting}
-- <-- Works!
a--b <-- Does not work!
-{}- <-- Won't help!
\end{lstlisting}
\end{document}
Furthermore you shouldn't use the option utf8x
. An explanation can be found in the question utf8x vs. utf8 (inputenc)
use
\lstset{language=sh,basicstyle=\ttfamily}
and if you want to use bold chracters than use a font like Bera Mono or Luxi Mono!
\documentclass[10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[scaled=0.83]{beramono}
\usepackage{listings} %for listings of the source code
\lstset{basicstyle=\ttfamily}
\begin{document}
\lstset{language=sh}
\begin{lstlisting}
-- # Works!
a--b # Works
if else fi # Keywords work too!
\end{lstlisting}
\end{document}
First, if you use long dashes for options, then this works:
a --b
Second, the choice of propotional fonts for listings is ugly. Unfortunately, CM typewriter does not have bold or italic variants, so just setting \lstset{basicstyle=\ttfamily}
is not what you want. I prefer courier, which gives more satisfactory results:
\documentclass[10pt]{standalone}
\usepackage[utf8x]{inputenc}
\usepackage{courier}
\usepackage{listings} %for listings of the source code
\lstset{basicstyle=\ttfamily}
\begin{document}
\lstset{language=sh}
\begin{lstlisting}
-- # Works!
a--b # Works
if else fi # Keywords work too!
\end{lstlisting}
\end{document}