[Tex/LaTex] List of Currency Symbols in Listings

listingslistingsutf8unicode

I'm getting unicode errors when using currency symbols in a listing environment.
I tried to add \usepackage{textcomp} but then I'm getting other (bibtex) errors. So maybe there is a cleaner option?

\documentclass[a4paper,12pt,parskip=half]{report}
\usepackage[utf8]{inputenc} 

\usepackage{listings}

\begin{document}


\begin{lstlisting}[language=Python, caption=Example, label=lst:example]

currencies = ["£","€","$","¥","¢","₩","§"]


\end{lstlisting}

\end{document}

Best Answer

You can use LateX commands to typeset them in listings mode, so you have to escape them. For that, use \lstset. The commands to type them are located in textcomp package.

Something like this:

\documentclass[a4paper,12pt,parskip=half]{report}
\usepackage[utf8]{inputenc} 
\usepackage{textcomp}
\usepackage{listings}

\lstset{
escapeinside={(*@}{@*)}
}
\begin{document}

This is it in TeX mode: currencies =[\texteuro \textlira \textcent     \textdollar \textyen \textwon \textsection]

\begin{lstlisting}[language=Python, caption=Example, label=lst:example]
This is it in listings mode:    
currencies = [(*@{\pounds \texteuro \textdollar \textyen \textcent \textwon             \textsection}@*)]   
\end{lstlisting}
\end{document}
Related Question