Friday, July 29, 2005

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:


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.

10 Comments RSS · Twitter

... using T1 encoding is a bad idea when you want to get nice PDFs (basically T1 means you're using the richer EC fonts rather than the CM family, but only the CM family has been converted to proper PostScript fonts).

I haven't used the lmodern package yet but I assume that it'll use the new latin modern PS fonts instead which should be the way to go.

Other reasonably correct ways of cheating might be (a) \texttt{"} or (b) $''$.

Yes, it uses the Latin Modern fonts. I now see that you wrote a post about them a couple years ago. That's interesting reading.

I used a workaround similar to (a) last month, but wanted to get it right. It still looks a little odd, actually; for some reason \textquotesingle is a bit taller than \textquotedbl.

I don't know anything about Latex, but I just wanted to point out something utterly nitpicky. When referring to feet and inches, one technically shouldn't use straight single and double quotes. One should technically use glyphs called "prime" and "double prime." Whereas straight marks are, duh, straight, the prime and double

Latex may not even support these glyphs, so it might be moot. I just felt like throwing it out there.

Doggone it. I obviously meant to say there that prime and double prime are angled marks, not straight like the other marks. Sorry about that.

Thanks, Jeff. I did not know that. I'm used to seeing them typeset as straight quotes everywhere. Getting primes in LaTeX is easy: $'$ and $''$. The $ means math-mode; for instance, one often sees $f'$ to mean the derivative of f.

I've fixed this my own way. I insist on the straight lines for things like "5'9" tall." So, I've created my own tags. There are two, one that's a very soft line, the other uses primes, but rotates them to be straight. They work beautifully in pdflatex.

Hard lines (rotated primes):
\def\feet{\hspace{-0.1em}\rotatebox{20}{\hbox{$'$} }\hspace{-0.5em}}

Soft Lines:
\def\feet{\hspace{-0.15em}\rotatebox{45}{\hbox{\textrm\'{}} }\hspace{-0.5em}}

Thats for single quotes. Double quotes are just:

The spacing might need to be changed for you. Personally, I use the soft lines when I'm writing.

Straight Quotes shouldn't be this hard!

Oops. Okay, so I copy/pasted poorly. For double quotes I meant:

I use the same definitions for \minutes and \seconds when typing longitude/latitude markers, and I copied the second one from that code. Good Luck!

Note that \verb!"! is another possibility.

Kieran: That will use the wrong font.

"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."

Is this quote your own creation? If so I must commend you; it is the most concise and accurate summary of the pros and cons of LaTeX I have ever seen!

On a semi-related note- thanks to 'ssp' who's solution of \texttt{"} has just ended my hours long search for a way write straight quotes!

Leave a Comment