11

In his book, Practical Typography, Butterick makes the following remark.

Com­put­er sci­en­tists and doc­u­men­ta­tion writ­ers, take note: straight quotes and back­ticks in soft­ware code should nev­er be con­vert­ed to curly quotes. Those marks are, of course, part of the func­tion­al syn­tax of the code and must be re­pro­duced lit­er­al­ly. While fans of La­TeX have of­ten writ­ten me to trum­pet its type­set­ting su­pe­ri­or­i­ty, I’ve nev­er seen any La­TeX-cre­at­ed doc­u­men­ta­tion that’s got­ten this right.

I am confused by these comments. It is my understanding that the correct way to obtain open quotes in LaTeX is to use the backtick character. Is Butterick (a man who seems to know his stuff) objecting to the standard LaTeX syntax or is there a better way to do opening quotes in LaTeX that I don't know about?

11

Neither a computer scientist, nor a documentation writer. I'm a humanities student! But I think this is what he means.

When writing in ordinary LaTeX (ie outside the verbatim environment), we use the grave accent, also known as the backtick (`), to open apostrophe or speech mark pairs. Meanwhile, we use the apostrophe (’) or the typewriter apostrophe (') to close. This produces the correct curly quotes when put through LaTeX. It therefore does not cause a problem, as exemplified by the following:

enter image description here

Butterick is not a fan, however, of the the LaTeX practice of continuing to use the grave accent to replace opening apostrophes and speech marks when put into the verbatim or coding environment. Most writers would present the following:

\documentclass{article}
\begin{document}
\section*{Incorrect usage}
    \begin{verbatim}
        if(``James Bond'' = trustworthy)
        smile
        if(`turkey-bacon' = bacon)
        cry
    \end{verbatim}
\end{document}

enter image description here

Notice how the result produces curly apostrophes. Butterick argues that this is bad practice because the code is meant to have typewriter apostrophes. When writing in code, you want to have the original symbol because it serves a unique functional purpose as part of the code, so to use a different symbol is to be inaccurate. This is in contrast to ordinary LaTeX, where the grave accent and typewriter apostrophe are just the curly quotes' typographically poor stand-ins, specifically designed to be replaced during compilation by better-looking alternatives. Even if you try to use a typewriter apostrophe, LaTeX gives you a curly closing apostrophe instead.

You can easily solve these concerns by:

  1. Loading the upquote package (documentation) with \usepackage{upquote}; and
  2. Replacing any grave accents in your code with apostrophes

Applying those two steps to our existing example:

\documentclass{article}
\usepackage{upquote}
\begin{document}
\section*{Incorrect usage}
    \begin{verbatim}
        if(``James Bond'' = trustworthy)
        smile
        if(`turkey-bacon' = bacon)
        cry
    \end{verbatim}
\end{document}

enter image description here

This has the twin benefits of making the code exactly the same as you would want to copy into anything you were working on and removing any semantic ambiguity.

  • 1
    This is still an unsatisfying answer (IMHO): one could argue that `` should be printed as `` and not as "... (e.g. if I want to explain (La)TeX :) – clemens May 17 '14 at 19:33
  • I think the point is that, if you want to, you can type ````, but rarely will you actually want to - the argument is that people generally get this wrong, even though there is the capacity in LaTeX to deal with it. – William Thong May 18 '14 at 10:53
16

I’m not a LaTeX user. But for code samples, using verbatim (or \verb) is, in general, the right answer. If you need to mix straight quotes into non-verbatim text, for instance with foot and inch marks, try this approach.

The reason I put that footnote in my book is that I often get mail from LaTeX users asserting that simply by using LaTeX, their typesetting is infallible. Not so. If you want examples of books made with LaTeX that get it wrong, try Kent Dybvig, The Scheme Programming Language, 4th ed., or The Structure and Interpretation of Computer Programs, 2nd ed.

E.g., from Dybvig — in this chunk of Scheme code, the opening-quote marks are supposed to be backticks; the closing-quote mark is supposed to be a single straight quote:

enter image description here

“But code samples like these aren’t really ambiguous, because everyone knows that you don’t type the curly quotes.” A sloppy argument, though it may be true for languages that only accept ASCII input. But many contemporary languages (e.g., Racket) accept UTF-8 input. In that case, curly quotes can legitimately be part of the input stream, so ambiguity is a real possibility.

Bottom line: this isn’t a matter of taste. Within code samples, curly-quote substitution — and any other kind of “prettifying” — is semantically wrong.

  • 1
    Welcome to TeX.SE! – Mico May 17 '14 at 18:46
  • Wow, that book example is truly awful. – lblb May 12 '17 at 14:29

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.