Currency symbols inside lstlisting

3.8k views Asked by At

I am trying to add a GBP \pounds symbol inside lstlisting

\begin{lstlisting}
Lorem ipsum 3£ \pounds
\end{lstlisting}

However this results in the following line:

Lorem ipsum 3Â \pounds

How do I draw correct GBP symbol inside lstlisting?

Thank you very much!

2

There are 2 answers

0
Stéphane Gimenez On

This should work even if it is a bit hackish:

\begin{lstlisting}[mathescape=true]
Lorem ipsum 3$\mbox{\pounds}$ \pounds
\end{lstlisting}

Move the question to tex.stackexchange.com and you'll have better answers wrt character encodings.

0
Tony Power On

This even works inside verbatim and using xelatex compiler:

\usepackage{newunicodechar}
\newunicodechar{£}{\textsterling}

\begin{lstlisting}
Lorem ipsum 3£
\end{lstlisting}

\begin{verbatim}
Lorem ipsum 3£
\end{verbatim}