[Tex/LaTex] make “quote” output as “quote„

punctuation

I have a document in which everything is quoted in the form:

``quote''

How do I make them appear in the output document as

“quote„

thanks

Best Answer

Here's something that works for me. It is based on making the right single quote an active character in TeX. I must admit I have no confidence that this doesn't break something else, especially in the light of the negative comment by @egreg to the original question.

Let's start with an example that contains a number of quotations. The first line shows how we would like double quotes to appear.

\documentclass[12pt]{article}    
\usepackage[T1]{fontenc}

\begin{document}
This is the \textquotedblleft{}quote\quotedblbase{} that I'd want.

Let's play with some ``double quotes'' and
some ``more double quotes''            and yet ``some more''
and then with some `single quotes' and
some `more single quotes'          and yet `some more'
and see what happens.
\end{document}

before

Now, by adding the following lines to the preamble:

\makeatletter
\catcode`'=\active
\def'{\futurelet\@rqpeek\@rqhack}
\def\@rqhack{\ifx\@rqpeek'\expandafter\dbl@rq\else\rq\fi}
\def\dbl@rq'{\quotedblbase}
\makeatother

you can get what you want.

after


EDIT: After egreg's comment about this tweak breaking math that contains primes, like $f'(x)$, I'm providing a fix and concluding with a brief explanation and a disclaimer.

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}

\makeatletter
\catcode`\'=\active
\def'{\ifmmode\expandafter\active@math@prime\else\expandafter\@rqtext\fi}
\def\@rqtext{\futurelet\@rqpeek\@rqhack}
\def\@rqhack{\ifx\@rqpeek'\expandafter\dbl@rq\else\rq\fi}
\def\dbl@rq'{\quotedblbase}
\def\pr@m@s{%
  \ifx'\@let@token
    \expandafter\pr@@@s
  \else
    \ifx^\@let@token
      \expandafter\expandafter\expandafter\pr@@@t
    \else
      \egroup
    \fi
  \fi}
\makeatother

\begin{document}
This is the \textquotedblleft{}quote\quotedblbase{} that I'd want.

Let's play with some ``double quotes'' and
some ``more double quotes''            and yet ``some more''
and then with some `single quotes' and
some `more single quotes'          and yet `some more'
and see what happens.

Let's see some math too:
if $f(x) = x^2$ then $f'(x) = 2x$ and
$$f''(x) = 2$$

And some more `single' and ``double'' quotes.
\end{document}

math too

The fix comes in two parts. First the active quote has to check whether it's found in math mode or text mode. Second, the internal macro \pr@m@s (handling successive primes in math mode) has to be repeated here (verbatim from latex.ltx) because it checks whether the next character is ' and now it has to check for an active '.

Disclaimer: Making the single right quote an active character is expected to break everything that already treats it as an active character. Examples that cross my mind are: the babel package (some languages with accents), various math packages like euler, various verbatim-text packages like the alltt. But there are also packages, like xspace which (temporarily) set the \catcode of \' to 13. I've tested euler, alltt and xspace and they seem to work fine with this. All this said, you have been warned. If a package breaks with this, I don't expect the fix to be obvious...