我想编写一个 BibLaTeX 文件,用于法语和英语文档。唯一的区别是法语标题在法语文档中必须保持原样,而在英语文档中则需要翻译。
在我看来,使用 BibLaTeX 数据注释应该可以实现这一点。书目文件的形式如下:
@article{bibkey,
author = {...},
title = {Original title, possibly in French},
title+an:english = {="Translated title, if the original is in French"},
...
}
然后,如果我是正确的,我需要覆盖一些宏,有点\mkbibcompletename
像此主题他们使用 BibLaTeX 数据注释来处理多种作者姓名格式。但是,无论是在 BibLaTeX 文档中还是在网络上,我都找不到如何针对我的情况执行此操作。
编辑:title
经过进一步搜索,我认为我应该使用重新定义字段 的格式\DeclareFieldFormat
。这就是我想到的方法,但它不起作用:即使有英文翻译,也不会使用。
\documentclass{article}
\usepackage{iflang}
\usepackage[english]{babel}
\usepackage{biblatex}
\usepackage{filecontents}
\begin{filecontents}{biblio.bib}
@article{test1,
author = {Author, A.},
title = {Original title, possibly in French},
title+an:english = {="Translated title, if the original is in French"},
year = {1999},
}
@article{test2,
author = {Author, A.},
title = {Original title, possibly in French},
year = {2000},
}
\end{filecontents}
\addbibresource{biblio.bib}
\DeclareFieldFormat*{title}{%
\IfLanguageName{french}
{#1}
{\hasfieldannotation[english]
{\getfieldannotation[english]}
{#1}}}
\begin{document}
\autocite{test1,test2}
\printbibliography
\end{document}
我希望第一个参考文献包含英文标题,第二个参考文献包含原标题。
答案1
我最终找到了解决方案此源代码我原来的方法存在几个问题:
\DeclareFieldFormat*{title}
代替\DeclareFieldFormat*{titleformat}
。- 和
[]
中缺失。\hasfieldannotation
\getfieldannotation
对于任何感兴趣的人,正确的源代码是:
\documentclass{article}
\usepackage{iflang}
\usepackage[english]{babel}
\usepackage{biblatex}
\usepackage{filecontents}
\begin{filecontents}{biblio.bib}
@article{test1,
author = {Author, A.},
title = {Original title, possibly in French},
title+an:english = {="Translated title, if the original is in French"},
year = {1999},
}
@article{test2,
author = {Author, A.},
title = {Original title, possibly in French},
year = {2000},
}
\end{filecontents}
\addbibresource{biblio.bib}
\DeclareFieldFormat*{titlecase}{%
\IfLanguageName{french}
{#1}
{\hasfieldannotation[][english]
{\getfieldannotation[][english]}
{#1}}}
\begin{document}
\autocite{test1,test2}
\printbibliography
\end{document}