Archive for July 29, 2005

Friday, July 29, 2005 [Tweets] [Favorites]

Roman Straight Quotes in pdfLaTeX

LaTeX is amazingly powerful. Nearly anything is possible if you know the right incantations. But sometimes you need incantations for even the simplest of tasks, and finding them isn’t always easy.

In this case, I wanted to use straight quotation marks (' and ") in LaTeX’s roman font. In a word processor or HTML or pretty much any other system, you can simply type these characters on the keyboard: WYSIWYG. (Some applications “smarten” quotes by default, and you can often override this by holding down the Control key.) Typing the characters directly works in LaTeX’s monospaced font, which it expects you to use for code, but in the Roman font ' renders as . LaTeX wants to produce curly quotes from its 7-bit input; in fairness, this is nearly always the right thing to do. So it uses `` to mean and '' to mean , and there just isn’t another character on the keyboard left to mean '.

But sometimes you want ' or " so that you can abbreviate feet or inches, or write about punctuation. Turning to the Comprehensive LaTeX Symbol List (thanks to Maarten Sneep for the pointer), we see that these characters are accessible using the \textquotesingle and \textquotedbl commands. However, the commands are not built into LaTeX; before you can use them you need to import three packages:

\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{lmodern}

The fontenc package provides \textquotedbl, and the textcomp package provides \textquotesingle. Unfortunately, fontenc has a bad side effect on pdfLaTeX (on Mac OS X, at least). When you use that package, LaTeX is no longer able to find the characters it needs as font glyphs. It falls back on generating the glyphs as PostScript curves. This means that the text in the PDF output isn’t searchable—because it’s not actually text. And it is hard to read on-screen because Preview can’t use Quartz’s font smoothing technology. In fact, the PDF looks even worse than you would expect from this description, so there may be something else going on—anti-aliasing of poorly scaled bitmaps, perhaps. In any case, the lmodern package seems to be the answer to this problem. It makes the fonts look the way they did before importing fontenc.