14

I'm using the csquotes package with the modifications recommended by this answer, to detect quotation marks in my text (pasted from Microsoft Word) and make them look good in the output.

Is there any way to have it also detect single quotes, so that they are oriented the correct way and not treated as apostrophes, without messing up the existing apostrophes? (I don't want to have to manually find all of the quote-within-quotes and replace ' with `.)

\documentclass{article}

\usepackage{csquotes}
\usepackage[american]{babel}
\DeclareQuoteStyle[american]{english}% verified
  {\textquotedblleft}
  [\textquotedblleft]
  {\textquotedblright}
  [0.05em]
  {\textquoteleft}
  {\textquoteright}
\MakeOuterQuote{"}

\begin{document}
I say: "These quotes look nice, but 'if I quote someone else within a quote like this,'
or 'like this,' they don't."
\end{document}

quote screenshot

5
  • 3
    You can't make the ' character an active quote in csquotes like you did for " since it is a reserved character (see §10.3 of the documentation). Since your text is coming from MSWord, if you use a UTF8 encoding, you can use Word's smart quotes facility to make the quotes into the correct characters and then just use them directly.
    – Alan Munn
    Oct 10, 2013 at 3:08
  • @AlanMunn Thank you! Two follow-up questions: 1) How do I use the UTF8 encoding? 2) Even if I manually use the ` character to start a single quote, it doesn't look great since it blends into the letter (if it's capital)--is there a better character to use? Oct 10, 2013 at 3:11
  • 1
    On the LaTeX side: \usepackage[utf8]{inputenc}. On the Word side, I remember it just automatically converting quotation marks to the "smart" ones whether you liked it or not. Isn't that still true?
    – jon
    Oct 10, 2013 at 3:33
  • 2
    @jamaicanworm You can use \usepackage[utf8]{inputenc} in your input file (and save it as UTF8 in your editor). Or save it as UTF8 and use XeLaTeX or LuaLaTeX. See Preparing a text for conversation to LaTeX: How to convert "ejective stops" in TIPA? for an answer like that. But the idea is that you go back to your Word document source and change all the quotes to 'smart' quotes and then paste the fixed text directly into your LaTeX source.
    – Alan Munn
    Oct 10, 2013 at 3:33
  • @AlanMunn Feel free to post that as an answer, seems like other people could benefit as well. I posted my second follow-up as a new question at tex.stackexchange.com/q/137275/9757 Oct 10, 2013 at 14:57

1 Answer 1

10

Although the csquotes package allows you to define certain characters as "active" quotes, as your sample document does for the " character, the single quote character cannot be so used, since it is a reserved character in TeX.

Since you mention that you are using text from an MSWord document, a better solution in this case would be to encode your source file as UTF-8 and either use the inputenc package (if you are using pdfLaTeX) or a UTF-8 aware engine (XeLaTeX or LuaLaTeX) to compile your document. In this way you can use the "smart" quote characters ,, , and directly in your source document. MSWord is quite good at automatically converting quotes correctly. If your document doesn't currently use the smart quotes, you can turn that on and then do a global replace for both ' and " and all the quotes will then be correctly changed.

Source with these quotes can then be used in your LaTeX document. In this case, you don't need to use the csquotes package at all (although you can, still if you have a mixture of quotation marks in the source.)

Using pdfLaTeX

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}
I say: “These quotes look nice, but ‘if I quote someone else within a quote like
this,’ or ‘like this,’ they don’t.”
\end{document}

Using XeLaTeX or LuaLaTeX

\documentclass{article}
\usepackage{fontspec}
\begin{document}
I say: “These quotes look nice, but ‘if I quote someone else within a quote like
this,’ or ‘like this,’ they don’t.”
\end{document}

output of code

3
  • 5
    This is a excellent, detailed answer, just to add that if one has a trivial problem where one merely wants single marks (as I did), one may use \enquote*{Blah}. Jul 25, 2016 at 15:28
  • If one has nested quotations a posix regex replace isn't good enough to do the job. Csquotes handles these nicely with autoquote so you are probably better off replacing ' with some other symbol you can then use with \MakeAutoQuote. Ideally, it should look like a quote character so I suggest maybe using U+FF07, the full width apostrophe '.and replacing all your single quotes with that. Sep 6, 2020 at 10:25
  • @PeterGerdes My comment about global search and replace was aimed at the MSWord source text. MSWord is actually quite good at figuring out nested quotes, so if you have a document with nested " and ' quotes, and you turn on the SmartQuotes replacement and then simply replace all ' with ' and all " with " (yes, the same character in each, no regex at all) Word will typically get the quotes right. I agree that doing this with a regex in a LaTeX source document is not going to be as successful.
    – Alan Munn
    Sep 6, 2020 at 15:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .