我想按照德国标准编译一个文件,其中的引号应像这样放置:
\glqq text \grqq
在我的 LaTeX 文档中,我以标准方式使用引号:''text''
是否有可能改变''
将要编译的序言 - 取决于其位置或\glqq
?\grqq
或者甚至更简单的解决方案?
编辑:抱歉描述不完整。我指的是德国标准:“”
答案1
这或许会引起一些其他麻烦,但事实就是如此。
详细说明一下回答Martin Scharrer 的结果如下:
代码:
\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}
如果要保留数学模式中的含义'
,则需要一些其他的技巧:
\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}
最后的解决方案还将单引号转换为德语引号:
\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}
答案2
我会用csquotes
,使用"
defined 作为外引号,例如
\documentclass[ngerman]{article}
\usepackage{babel}
\usepackage{csquotes}
\MakeOuterQuote{"}
\begin{document}
"Deutscher" Text
\end{document}
您还可以定义一个用于内部引号的符号,\MakeInnerQuote{<symbol>}
或者一个自动化解决方案,决定是否使用外部引号或内部引号,\MakeAutoQuote{<open>}{<close>}
其中两个字符必须不同,例如\MakeAutoQuote{<}{>}
(使用:<Deutscher> Text
)...
请注意,这会覆盖某些语言中的某些 简写,例如\MakeOuterQuote{"}
。在这种情况下,最好使用另一个字符来表示活动引号或不使用活动引号。否则,您可以为 babel 简写定义自己的宏,例如babel
"=
(n)german
\enquote
\makeatletter
\newcommand{\diviswithhiphenation}{\penalty\@M-\hskip\z@skip}
% defined like "= in babel-contrib/german/ngermanb.dtx
\makeatother
答案3
最可移植的方法是使用\enquote
在引用包。也许你稍后想将引号样式更改为吉耶梅(>> foo <<),那么您要做的就是将包选项更改为\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}
答案4
我假设您正在使用babel
,因此另一个解决方案是(在序言中):
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[ngerman,math=normal]{babel}
\useshorthands{'}
\newif\ifclosequote
\defineshorthand{''}{%
\ifclosequote
\closequotefalse\dq
\else
\closequotetrue\glqq
\fi}
作为副作用,'
它是一种简写字符并且表现得如此——例如,诸如{'}
引发错误之类的事情。