0

I'm using the listings package to include some source code files in a LaTeX document.

I'm having 2 problems:

  1. characters - are not shown in the resulting file
  2. characters % are shown overlapped with characters that appear after it.

This is my lstset:

\lstset{
showstringspaces=false,
extendedchars=true,
frameround=fttt,
frame=single,
upquote=true,
breaklines=true
}

And this is how I insert listings:

\begin{figure}[t]
{\small{
\lstinputlisting[language=Python,numbers=left, numberstyle=\tiny]{modProblem.txt}
\caption{\label{fig:modProblem} El problema del operador \%}
}}
\end{figure}
  • 3
    Please provide a minimal working example. Moreover the command \lstinputlisting has the option caption. – Marco Daniel Jun 16 '12 at 17:24
  • 1
    Welcome to TeX.SE. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. In this case it will actually help to ensure that the solution actually solves your specific problem. – Peter Grill Jun 16 '12 at 18:48
3

Tried to make you MWE:

\documentclass{article}
\usepackage{listings}
\usepackage{textcomp}

\lstset{
showstringspaces=false,
extendedchars=true,
frameround=fttt,
frame=single,
upquote=true,
breaklines=true
}

\begin{document}
\lstinputlisting[caption=El problema del operador \%  resuelto,language=Python,numbers=left, numberstyle=\small]{primes.py}
\end{document}

It produces normal output (on Windows, using both pdfLaTeX and XeLaTeX on TexWorks):

Listing of Python code

Only thing that needed to be added was \usepackage{textcomp} in order to use upquote=true,.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.