48

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: „“

10
  • 12
    You might want to have a look at the csqoutes package 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
  • 17
    ''text'' is not the standard way, ``text'' is. But for German I recommend using babel's shorthands "`text"'
    – cgnieder
    Dec 22 '13 at 11:31
  • Yes, very good point @cgnieder.
    – Mil
    Dec 22 '13 at 11:54
19

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

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

enter image description here

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} 

enter image description here


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} 

enter image description here

13
  • 1
    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? 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. Dec 22 '13 at 11:12
  • The upper quotation marks are upside down. They should look like a 66 and not like a 99
    – cgnieder
    Dec 22 '13 at 11:24
61

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}

german quotes

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) …


Please note, that \MakeOuterQuote{"} overwrites some of babel’s shorthands in certain languages like "= in (n)german. In that was it might be better to use another character for active quotes or no active quotes and \enquote instead. Otherwise on could define own macros for babel shorthands like

\makeatletter
\newcommand{\diviswithhiphenation}{\penalty\@M-\hskip\z@skip}
% defined like "= in babel-contrib/german/ngermanb.dtx
\makeatother
6
  • 1
    This solution does not work ideally in my case as I use '' (twice ') and not " for quotations.
    – Mil
    Dec 22 '13 at 11:18
  • 9
    @Mil: Sorry, I overread that. You could search and replace '' by " in your editor …
    – Tobi
    Dec 22 '13 at 12:18
  • 1
    @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 '15 at 18:09
  • The approach of Tobi works perfectly for me
    – BlueWizard
    Nov 16 '15 at 14:54
18

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}
10

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

9

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.

5
  • Use the code between \begin{document} and \end{document} in the last edit of my answer and you'll see some strange behaviors... Dec 22 '13 at 12:11
  • @karlkoeller \useshorthands is a "only preamble" macro. I edited my answer. 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)$. Dec 22 '13 at 18:16
  • 1
    @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. Dec 23 '13 at 12:06
  • Oops! I meant math=normal. Dec 23 '13 at 12:15
7

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.

5
  • 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
  • 1
    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
  • 3
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.