7

I'd like to get syntax highlighted code in LaTeX, but want to preserve the monospaced font (no curly quotes either). pygments doesn't seem to have an option to avoid curly quotes that I could find.

Edit:

\mint{python}|'banana'|

Produces curly single quotes.

  • Have you tried minted package? – user11232 Mar 2 '12 at 11:11
  • Do you know the listings package? – matth Mar 2 '12 at 11:12
  • Yes, minted produces the correct double quotes but not single ones. – nimish Mar 2 '12 at 11:14
  • 1
    +1, good question, never noticed that. Incidentally, this is unrelated to Pygments, the culprit is fancyvrb. – Konrad Rudolph Mar 2 '12 at 12:57
  • @KonradRudolph Is there any way to fix this in minted? I prefer its style over listings. – nimish Mar 3 '12 at 15:06
11

I use the listings package. Adding this code to the header loads the package and sets the font to be monospace for the source code. I use a black and white printer, so highlighting isn't enabled here. There are options for setting keyword colors in the package documentation.

\usepackage{courier}
\usepackage{listings}
\lstset{
         basicstyle=\footnotesize\ttfamily, 
         numberstyle=\tiny,          
         numbersep=5pt,             
         tabsize=2,                
         extendedchars=true,      
         breaklines=true,        
         showspaces=false,      
         showtabs=false,       
         xleftmargin=17pt,
         framexleftmargin=17pt,
         framexrightmargin=5pt,
         framexbottommargin=4pt,
         showstringspaces=false 
 }
 \lstloadlanguages{
         Python
 }

Then the code can be included using \lstinputlisting[language=python]{src/main.py}.

| improve this answer | |
  • listings is great. Also if you (@nt01) want to do additional manual coloring, take a look at this answer I got from a question of mine. – Shahbaz Mar 2 '12 at 14:10
  • I'm going to accept this, but if you can add how to do this with minted, that would be excellent. – nimish Mar 4 '12 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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