
我對這個問題很頭疼,沒有在網路上找到任何可以幫助的東西:
最初的問題是我用法語寫一篇文章,但我需要包括一些用英語寫的文章,因此引用風格不同。由於法語是主要語言,我使用包unsrtnat-fr
中的參考書目風格natbib
,它生成的引用為“Name1等Name2」(兩位作者)使用\citet
。我想恢復給定英文部分「Name1 的正常樣式和名稱」。我的解決方案是定義一個自訂命令,比方說\encitet
,它替換“等”經過“ 和 ”在 的結果中\citet
。
我嘗試了不同的定義,但最終我無法理解如何做到這一點......每次參數擴展都會出現問題。
這是我想定義的命令的偽代碼:
\newcommand{\encitet}[1]{%
% 1 : store the result of \citet{#1} in tmp (as a simple string)
% 2 : test if 'et al.' is found into the string
% 3 : if found then return tmp
% 4 : else return the replacement of every " et " by " and " in tmp
}
這是我用於測試的 TeX 檔案:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{trace}
\usepackage{xspace}
\usepackage{xstring}
\usepackage{etoolbox}
\usepackage{stringstrings}
\usepackage[square,numbers]{natbib}
\bibliographystyle{abbrvnat-fr}
% Here is the problem
\newcommand{\encitet}[1]{%
\def\tmp{\expandafter\citet{#1}}%
%\edef\tmp\expandafter{\mytemp{#1}}%
%
\expandafter\IfSubStr{\tmp}{et al.}{%
\tmp%
}{%
\StrSubstitute{\tmp}{ et }{ and }%
}\xspace%
}
% Example that works
\newcommand{\encitett}[1]{%
\def\mytemp{\expandafter\citet{#1}}%
\expandafter\ifstrequal\mytemp{#1}{a}{"a" was given}{not a}, %
\expandafter\ifstrequal\mytemp{#1}{b}{"b" was given}{not b}%
}
\begin{document}
% Example with two authors
\encitet{einstein}
% Example with more than two authors
\encitet{latexcompanion}
\citep{knuthwebsite}
\medskip
\bibliography{sample}
\end{document}
和圍兜文件:
@article{einstein,
author = "Albert Einstein and AnotherGuy ForTheTest",
title = "{Zur Elektrodynamik bewegter K{\"o}rper}. ({German})
[{On} the electrodynamics of moving bodies]",
journal = "Annalen der Physik",
volume = "322",
number = "10",
pages = "891--921",
year = "1905",
DOI = "http://dx.doi.org/10.1002/andp.19053221004"
}
@book{latexcompanion,
author = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
title = "The \LaTeX\ Companion",
year = "1993",
publisher = "Addison-Wesley",
address = "Reading, Massachusetts"
}
@misc{knuthwebsite,
author = "Donald Knuth",
title = "Knuth: Computers and Typesetting",
url = "http://www-cs-faculty.stanford.edu/\~{}uno/abcde.html"
}
和編譯命令:
pdflatex test.tex && pdflatex test.tex && bibtex test && pdflatex test.tex && pdflatex test.tex
我預先感謝您的幫助
答案1
這行不通。 \citet 是一個非常複雜的巨集,您無法透過簡單的方法檢索其輸出。如果您確實想堅持使用 natbib (內建了 biblatex 語言支援),您應該操作 .bst 檔案。將其以另一個名稱保存在文件資料夾中,然後更改固定單字以便它們發出命令。例如
FUNCTION{fr.and}{ %% le "et" entre les deux derniers auteurs
" \authorand{} "
}
然後,您可以在文件中為命令提供合理的定義。