1

\LaTeX newbie here. I figured out that csquotes can be used to automate smart curly quotes, and have added this to my preamble:

\usepackage{csquotes}
\MakeOuterQuote{"}

This has the effect of letting me use " and ' in my .tex files and they will be rendered as the appropriate curly quotes or apostrophes. However, in the documents I'm writing, I'd also like to have several code samples. These should be able to contain single or double quote marks without being, er, smartened.

Currently, I am using \texttt{ } to wrap my code blocks. Single quotes inside this structure appear "curly" (although maybe that's just the font?) and the first double quote turns into a \ for some reason, and the second one rendered as I want it. For example:

\texttt{print("hello world")}

is rendered: print(\hello world")

How can I get smart single and double quotes in my document, while setting code blocks as exceptions? I am willing to use something other than csquotes and am hoping to adopt some useful library for code samples (with line numbering, syntax highlighting, etc), so I'm open to radical therapy options.

  • \texttt isn't a code block. – Sean Allred Feb 13 '15 at 21:46
  • No doubt. So what's the best way to do code blocks? – workerjoe Feb 13 '15 at 21:48
  • 1
    Just answered. Oh! And welcome to TeX.SX! :) You can have a look at our starter guide to familiarize yourself further with our format. – Sean Allred Feb 13 '15 at 21:49
2

You want to use a proper solution for presenting code. The listings package provides some useful tools for both inline and display code environments with optional syntax highlighting. See Syntax Coloring in LaTeX for more information on listings and other code options.

  • 3
    listings didn't work well for me, but your link led me to minted which does the trick for code blocks. The other thing that was necessary for me to solve my problem was to use the upquote package to change the curly single quotes to straight ones. – workerjoe Feb 13 '15 at 23:27

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.