Straight Quotes in LaTeX
How LaTeX turns typed quote marks into curly ones, how to get straight single and double quotes in text and code, and what to check before copying or sharing the PDF.
Short answer: when straight quotes are the right choice
For ordinary prose, keep LaTeX's default curly quotes. Readers expect them, and they are what LaTeX produces when you type the standard input. Use straight quotes when the output has to match literal characters. That covers code, shell commands, configuration snippets, file contents and data that readers will retype or paste somewhere else.
The main benefit is fidelity: a straight quote in a code listing is the same character a compiler or terminal expects. The tradeoff matters most in each direction's failure case. Straight quotes in prose look like typewriter output. Curly quotes in code can break the command when someone copies it out of the PDF.
Some readers need exact, runnable text, such as a long script or a configuration file. For those cases, a separate plain-text file is the safer delivery. Do not rely on the PDF's copy-and-paste behavior.
What LaTeX actually changes
LaTeX does not print the quote characters in your source as they are. It reads the keyboard apostrophe and the backtick as instructions, and the font encoding then decides which glyph appears in the output. Your source file still contains plain ASCII characters, so nothing changes there. The change happens at typesetting. Once the PDF is produced, though, it contains curly glyphs. Anyone who copies text from the PDF will usually get curly characters back. For readers of the output, the transformation is effectively a character substitution.
| You type | Typical result in text mode |
| ` | left single quote ‘ |
| ' | right single quote ’ (also used as the apostrophe) |
| `` | left double quote “ |
| '' | right double quote ” |
| " with the default OT1 font encoding | right double quote ” |
| " with T1 font encoding | straight double quote " |
| \textquotesingle | straight single quote ' |
| \textquotedbl (T1 encoding) | straight double quote " |
The double-quote key is the inconsistent one. Its result depends on the font encoding: under the old OT1 default it gives a curly closing quote, and under T1 it gives a straight mark. Some babel language settings turn " into a shorthand prefix, and then it may not print a quote at all.
XeLaTeX and LuaLaTeX with fontspec usually apply a TeX-style ligature mapping to the main text font. That mapping turns the backtick and apostrophe sequences into curly quotes in the same way. Fonts and options differ, so check the Ligatures setting for each font you load, especially the monospaced one. Do not assume the behavior matches pdfLaTeX.
Getting a straight single quote
In running text, use \textquotesingle. Current LaTeX releases provide it without extra packages. Older installations needed the textcomp package. Add an empty group or a space after the command when a letter follows, so the command name ends where you intend.
Getting a straight double quote
Load T1 font encoding and use \textquotedbl, or type " directly under T1, provided no babel shorthand claims the character. The explicit command is easier to read in the source and does not depend on whether a language package has made " active.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{upquote}
\begin{document}
Prose with curly quotes: `single' and ``double''.
Straight marks in text: \textquotesingle x\textquotesingle{} and \textquotedbl y\textquotedbl{}.
\begin{verbatim}
echo 'hello' "world"
\end{verbatim}
\end{document}
Straight quotes in code and verbatim text
Verbatim text is not safe by default. Inside \verb and the verbatim environment, LaTeX still maps the apostrophe and backtick to the font's curly-quote slots, so a command like echo 'hello' can come out with typographic quotes. The upquote package changes this. It makes the apostrophe print as a straight single quote and the backtick as a straight grave accent in \verb and verbatim.
The listings package has a matching option. If you use listings for code, turn it on explicitly.
\usepackage{listings}
\lstset{basicstyle=\ttfamily, upquote=true}
These packages only change how characters are printed. If the source already contains curly quotes, for example text pasted from a word processor, verbatim keeps them. Fix the source characters themselves.
Common pitfalls
- Typing ' and expecting a straight quote in prose: it becomes a curly apostrophe.
- Typing " without checking the font encoding: the result can be curly or straight depending on OT1 or T1.
- Language packages that make " a shorthand, which can swallow or alter the following character.
- Verbatim or listings code without upquote, which can print curly quotes in commands.
- Fonts that lack a straight-quote glyph. LaTeX may then substitute a glyph or warn, so check the log.
Will the result stay usable after copying or sharing?
Copying from the PDF: what a reader gets depends on the font's Unicode mapping inside the PDF and on the viewer used for extraction. A straight quote that looks right on the page is not guaranteed to paste as the ASCII character. Test with the fonts and engine you actually use. Compile, copy a code sample from the PDF into a plain-text editor, and compare it with the source. Pasting it into the target shell or interpreter is an even better test. One successful test covers that font, engine and viewer combination only. Copied code can also pick up line breaks, lost indentation or ligature artifacts, which is another reason to ship runnable code as plain text.
Search: some PDF viewers treat straight and curly apostrophes as equivalent in search, and others do not. A reader searching for don't with a straight apostrophe may miss text typeset with a curly one. Check this in the viewers your readers are likely to use.
Accessibility: screen readers may announce straight and curly quotes differently, or skip them, depending on their punctuation settings. Whether the PDF is tagged probably matters more for reading order and structure than which quote style you pick. This review has no documentation or test results for any specific screen reader, so treat those effects as unverified.
Editing: the source stays plain ASCII whichever output you choose, so collaborators and version control see the same characters. The difference only appears in the compiled output.
What could not be verified here
No test results were supplied for specific PDF viewers, fonts, LaTeX distributions or assistive technologies. The behavior described above follows LaTeX's documented font-encoding and package conventions. Confirm copy-and-paste fidelity, search matching and screen-reader output in your own toolchain before relying on them.