我正在撰写我的论文,该论文(当然)是用 (Xe)LaTeX 编写的,并大量使用了软件包natbib
和bibtex
引用,包括诸如 等功能\citeauthor{reference}
。由于我的论文将使用德语,因此我遇到了一个问题,如这个问题(取代 BibTeX 的标准和输出母语单词),并独立得出了如下解决方案:这个问题的 回答— 复制.bst
文件,搜索并替换输出的函数和。
我想我可以更进一步。而不是添加纯文本德语和进入函数后,我想到在那里放一个宏:(\undbefehl
德语为and
命令)。首次测试成功,宏正确展开,正如我在文档前言中定义的那样。初始定义是\newcommand\undbefehl{und\ }
。
现在我的论文摘要需要用英文撰写,我打算使用英文polyglossia
及其语言选择功能。我遇到了这个问题,这表明代码\iflanguage{english}{and\ }{und\ }
。不幸的是,结果并非我所预期的那样。比较以下 MWE:
\documentclass[12pt,a4paper,twoside]{scrreprt}
\usepackage{xunicode}
\usepackage{polyglossia} % for languages
\setmainlanguage[babelshorthands=true,spelling=new]{german} % sets the main language
\setotherlanguage[variant=british]{english} % sets the other language
\usepackage[square, super, sort&compress, comma, numbers]{natbib} % for citations
\setmainfont[Mapping=tex-text]{LiberationSerif} % set a font
\newcommand\undbefehl{\iflanguage{english}{and\ }{und\ }} % create the \undbefehl command
\begin{document}
The first paper was written by \citeauthor{MyersAlkylierung}.\\
The second paper was written by \citeauthor{Gieseler_PBu3}.\\
\undbefehl.
\begin{english}
The first paper was written by \citeauthor{MyersAlkylierung}.\\
The second paper was written by \citeauthor{Gieseler_PBu3}.\\
\undbefehl.
\end{english} % commented out in the second MWE
\bibliographystyle{myangew2} % derived from angew.bst as supplied by the rsc package.
\bibliography{literatur} % includes my literatur.bib
\end{english} % commented out in the first MWE
\end{document}
第一个 MWE 编译后给出以下输出:
第二个给出了这个输出:
显然,\undbefehl
在 级别进行解释\bibliography{literatur}
。我假设\citeauthor
宏抓取扩展的文本以输入到文档本身中。
有什么方法可以修改宏吗,要么通过向.bst
文件添加内容,要么通过相应地修改定义,以便它可以评估语言环境并扩展到和或者和取决于语言?
该文件的两个相关条目literatur.bib
(出于隐私原因,实际文件路径已被删除):
@article{MyersAlkylierung,
author = {Myers, Andrew G and Yang, Bryant H and Chen, Hou and McKinstry, Lydia and Kopecky, David J and Gleason, James L},
doi = {10.1021/ja970402f},
file = {(redacted)},
issn = {0002-7863},
journal = {J. Am. Chem. Soc.},
month = {jul},
number = {28},
pages = {6496--6511},
title = {{Pseudoephedrine as a Practical Chiral Auxiliary for the Synthesis of Highly Enantiomerically Enriched Carboxylic Acids, Alcohols, Aldehydes, and Ketones}},
url = {http://pubs.acs.org/doi/abs/10.1021/ja970402f},
volume = {119},
year = {1997}
}
@article{Gieseler_PBu3,
abstract = {The first total synthesis of angiolam A has been accomplished in 18 steps. Key steps include vinylogous Mukaiyama aldol reactions of aldehyde-derived dienol ethers, conjugate reduction of the resulting double bond followed by diastereoselective protonation and the Witzeman protocol for macrolactamization. Comparison of the optical rotation of the synthesized material with the isolation data established that the absolute configuration of angiolam A is opposite from the proposed structure.},
author = {Gieseler, Marc Timo and Kalesse, Markus},
doi = {10.1021/ol403423r},
file = {(redacted)},
issn = {1523-7060},
journal = {Org. Lett.},
month = {jan},
number = {2},
pages = {548--551},
pmid = {24341445},
title = {{Synthesis of Angiolam A}},
url = {http://pubs.acs.org/doi/abs/10.1021/ol403423r},
volume = {16},
year = {2014}
}
该文件myangew2.bst
是angew.bst
rsc
包裹。我只修改了一行:
FUNCTION {bbl.and}
{ "and" }
成为
FUNCTION {bbl.and}
{ "\undbefehl" }
答案1
我修复了你的代码中的问题;除了拼写错误之外,加载是错误的xunicode
,fontspec
应该加载。
问题在于 的扩展不及时\undbefehl
,而 应该是健壮的。我使用了\newrobustcmd
提供的etoolbox
,它由 加载polyglossia
。
此外,文件中的更改.bst
应该是
FUNCTION {bbl.and}
{ "\undbefehl{}" }
并且我也相应地改变了的定义\undbefehl
。
\documentclass[12pt,a4paper,twoside]{scrreprt}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage[square, super, sort&compress, comma, numbers]{natbib}
\setmainlanguage[
babelshorthands=true,
spelling=new,
]{german}
\setotherlanguage[
variant=british
]{english}
\setmainfont{LiberationSerif}
\newrobustcmd\undbefehl{\iflanguage{english}{and}{und}}
\begin{document}
The first paper was written by \citeauthor{MyersAlkylierung}.
The second paper was written by \citeauthor{Gieseler_PBu3}.
\undbefehl.
\begin{english}
The first paper was written by \citeauthor{MyersAlkylierung}.
The second paper was written by \citeauthor{Gieseler_PBu3}.
\undbefehl.
\end{english}
\bibliographystyle{myangew2} % derived from angew.bst as supplied by the rsc package.
\bibliography{literatur} % includes my literatur.bib
\end{document}
\undbefehl
可以通过以下方式获得更灵活的接口xparse
:
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\undbefehl}{}
{
\str_case_x:nn { \languagename }
{
{english}{and}
{german}{und}
}
}
\ExplSyntaxOff
它可以轻松扩展以处理两种以上的语言。