1

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}
2
  • 2
    Related tex.stackexchange.com/q/89638 (although personally I've found it simpler to use lualatex instead of pdflatex for UTF-8 listings). May 6, 2017 at 16:15
  • You have to literate all those characters. Please read the documentation.
    – TeXnician
    May 6, 2017 at 17:45

1 Answer 1

3

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}

You must log in to answer this question.

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