53

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

lockstep
  • 250,273
Mil
  • 1,197

6 Answers6

70

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
Tobi
  • 56,353
  • 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 08 '15 at 18:09
  • The approach of Tobi works perfectly for me – BlueWizard Nov 16 '15 at 14:54
  • Works with french quotation, in LaTeX and on overleaf (online LaTeX editor) - thanks a lot. It's so easy now ! – Metal3d Feb 12 '19 at 23:32
22

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}
klingt.net
  • 1,176
  • I was using \MakeOuterQuote{"} approach by @Tobi until today, but because one of my bibliography entries generated by zotero plugin had also ", there were some warnings. After applying this and commenting out MakeOuterQuote, i was able to get rid of it. Thank you very much! – nbsp Apr 30 '23 at 22:57
21

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

karlkoeller
  • 124,410
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

rolfn
  • 939
  • 4
  • 13
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.

Javier Bezos
  • 10,003
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.

fifaltra
  • 1,977
  • 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 09:30
  • Using \enquote{something}, you can change the style of qoutes globally, for example to »something« or «something». – Johannes_B Dec 22 '13 at 09: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 09: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 09:50
  • Two commas give the same output, thats a good tip! – Mil Dec 22 '13 at 11:57