# Automatic german quotation marks

I would like to compile a file according to German standards, in which quotation marks are to be put like this: \glqq text \grqq

In my LaTeX document I use quotation marks in the standard way: ''text''

Is there a possibility to change in the preamble that '' will be compiled - depending on its location to \glqq or \grqq? Or an even simpler solution?

EDIT: Sorry for the incomplete desciption. I was referring to the german standards which are: „“

-
You might want to have a look at the csqoutes package –  Henri Menke Dec 22 '13 at 8:35
Thats a great package, thanks for the suggestion! Using this one I will have to replace all ''...'' that I have with environments like \enquote etc. I was wondering if there was a simpler way without changing the ''? –  Mil Dec 22 '13 at 9:02
@HenriMenke you means csquotes. –  ppr Dec 22 '13 at 11:16
''text'' is not the standard way, text'' is. But for German I recommend using babel's shorthands "text"' –  clemens Dec 22 '13 at 11:31
Yes, very good point @cgnieder. –  Mil Dec 22 '13 at 11:54

Probably this will cause some other troubles, but here it is.

Elaborating a bit on this answer of Martin Scharrer, this is the result:

Code:

\documentclass{article}
\usepackage[ngerman]{babel}

\let\oldquote'
\newif\ifquoteopen
\catcode\'=\active
\makeatletter
\DeclareRobustCommand*{'}{%
\@ifnextchar'{%
\ifquoteopen
\global\quoteopenfalse\grqq\expandafter\@gobble
\else
\global\quoteopentrue\glqq\expandafter\@gobble
\fi
}{\oldquote}%
}
\makeatother

\begin{document}
\section{Using ''quotes''}
A ''quote'' and one with a period that follows: ''quote''. And a single 'quote'.

\noindent
And this is the original one: \glqq quote\grqq.
\end{document}


If the meaning of ' in math mode is to be preserved, some other hacks are needed:

\documentclass{article}
\usepackage[ngerman]{babel}

\let\oldquote'
\newif\ifquoteopen
\catcode\'=\active
\makeatletter
% we have to redefine \pr@m@s to use an active '
\def\pr@m@s{%
\ifx'\@let@token
\expandafter\pr@@@s
\else
\ifx^\@let@token
\expandafter\expandafter\expandafter\pr@@@t
\else
\egroup
\fi
\fi}
\protected\def'{%
\ifmmode
\expandafter\active@math@prime
\else
\expandafter\active@text@prime
\fi}
\def\active@text@prime{%
\@ifnextchar'{%
\ifquoteopen
\global\quoteopenfalse\grqq\expandafter\@gobble
\else
\global\quoteopentrue\glqq\expandafter\@gobble
\fi
}{\oldquote}%
}
\makeatother

\begin{document}
\section{Using ''quotes''}
A ''quote'' and one with a period that follows: ''quote''. And a single 'quote'.

\noindent
And this is the original one: \glqq quote\grqq.

\noindent
Some derivatives $f'(x)+g''(x)$.
\end{document}


This last solution also transforms single quotes into German ones:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{xspace}

\let\oldquote'
\newif\ifquoteopen
\catcode\'=\active
\makeatletter
% we have to redefine \pr@m@s to use an active '
\def\pr@m@s{%
\ifx'\@let@token
\expandafter\pr@@@s
\else
\ifx^\@let@token
\expandafter\expandafter\expandafter\pr@@@t
\else
\egroup
\fi
\fi}
\protected\def'{%
\ifmmode
\expandafter\active@math@prime
\else
\expandafter\active@text@prime
\fi}
\def\active@text@prime{%
\@ifnextchar'{%
\ifquoteopen
\global\quoteopenfalse\grqq\expandafter\@gobble
\else
\global\quoteopentrue\glqq\expandafter\@gobble
\fi
}{%
\ifquoteopen
\global\quoteopenfalse\grq\xspace
\else
\global\quoteopentrue\glq
\fi
}%
}
\makeatother

\begin{document}
\section{Using ''quotes''}
A ''quote'' and one with a period that follows: ''quote''. A single 'quote' and one with a period that follows: 'quote'.

\noindent
And these are the original ones: \glqq quote\grqq{} and \glq quote\grq.

\noindent
Some derivatives $f'(x)+g''(x)$.
\end{document}


-
This will break the usage of ' in math formulas; just to make it known. Maybe one should use \global\quoteopenfalse and \global\quoteopentrue. –  egreg Dec 22 '13 at 10:51
@egreg, I was quite sure that it would have broken something else... Do you know a workaround? –  karlkoeller Dec 22 '13 at 10:56
I've added it (and also added \global where needed). –  egreg Dec 22 '13 at 11:10
@egreg Thanks a lot. I'll take a look at your changes to learn something about them. –  karlkoeller Dec 22 '13 at 11:12
The upper quotation marks are upside down. They should look like a 66 and not like a 99 –  clemens Dec 22 '13 at 11:24

I know this is not quite what you've been asking, but I can't comment, so I'll answer for completeness: For the future, do you know that ,,text'' (,,text'') will produce exactly the same output as \glqq text'' (\dq just looks weird when I compile it)? This is probably more convenient to type, if that is what you're looking for.

-
In order to type „ (U+201E)you have to know where to find it on your keyboard. It is not available on my standard setup, i have to change to the german layout and then use <atl + gr> + v. This is not easier to type. –  Johannes_B Dec 22 '13 at 9:30
Using \enquote{something}, you can change the style of qoutes globally, for example to »something« or «something». –  Johannes_B Dec 22 '13 at 9:31
No, at least in my setup (the important part of which seems to be to have \usepackage[T1]{fontenc} in the preamble), if I type two commas, that will compile to the exact same thing as the \glqq ... and finding a comma on a keyboard shouldn't be too hard. –  fifaltra Dec 22 '13 at 9:37
It wasn't obvious at first, that this are two commas (thatś why highlighting code is important). But this approach still isn't handy when you want to change the style of your quotes. –  Johannes_B Dec 22 '13 at 9:50
Two commas give the same output, thats a good tip! –  Mil Dec 22 '13 at 11:57

I presume you are using babel, so another solution is (in the preamble):

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

\usepackage[ngerman,math=normal]{babel}

\useshorthands{'}

\newif\ifclosequote
\defineshorthand{''}{%
\ifclosequote
\closequotefalse\dq
\else
\closequotetrue\glqq
\fi}


As a side effect, ' is a shorthand character and behaves as such -- for example, things like {'} raise an error.

-
Use the code between \begin{document} and \end{document} in the last edit of my answer and you'll see some strange behaviors... –  karlkoeller Dec 22 '13 at 12:11
@karlkoeller \useshorthands is a "only preamble" macro. I edited my answer. –  Javier Bezos Dec 22 '13 at 18:10
I know, but as I said, see what happens with this code: A single 'quote' and some derivatives $f'(x)+g''(x)$. –  karlkoeller Dec 22 '13 at 18:16
@karlkoeller This is one of the side effects I was talking about. As to the primes, just use math=active. I've edited my answer. –  Javier Bezos Dec 23 '13 at 12:06
Oops! I meant math=normal. –  Javier Bezos Dec 23 '13 at 12:15

The most portable way is to use the \enquote command which is defined in the csquotes package. Maybe you want to change the quote style later to guillemets (>> foo <<), then all you have to do is to change the package option to \usepackage[german=guillemets]{csquotes}.

\documentclass[a4paper]{scrartcl}

\usepackage[german]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[german=quotes]{csquotes}

\begin{document}
Text without quotes. \enquote{Text with quotes}.
\end{document}

-

I’d use csquotes, with " defined as outer quotation mark, like in

\documentclass[ngerman]{article}

\usepackage{babel}
\usepackage{csquotes}
\MakeOuterQuote{"}

\begin{document}
"Deutscher" Text
\end{document}


You can also define a symbol for inner quotations with \MakeInnerQuote{<symbol>} or an automated solution which decides wether to use outer or inner quote with \MakeAutoQuote{<open>}{<close>} where the two characters must be different, e.g. \MakeAutoQuote{<}{>} (use: <Deutscher> Text) …

-
This solution does not work ideally in my case as I use '' (twice ') and not " for quotations. –  Mil Dec 22 '13 at 11:18
@Mil: Sorry, I overread that. You could search and replace '' by " in your editor … –  Tobi Dec 22 '13 at 12:18
@Mil That’s wrong use in the source, then already. See Anführungszeichen – Wikipedia. –  Speravir Jan 21 '14 at 21:15
@Mil: In some editors (I use TexStudio for instance) you have the possibility to choose an option like "replace quotation marks", which will automatically replace " with something of your choise (\enquote{ for instance). The next time your enter " this will be replaced by }. I quite like this feature. –  Wamseln Jul 8 at 18:09

I don't think ''text'' is the standard way. Use the babel short hands. Here is an example which combines the short hands with the functionality of the csquotes package:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage[autostyle=true,german=guillemets,maxlevel=3]{csquotes}
\defineshorthand{"}{\openautoquote}
\defineshorthand{"'}{\closeautoquote}

\begin{document}

Das ist ein "deutscher Text"'.

\end{document}


...Rolf

-