我試圖找出兩個參考文獻是否具有相同的作者natbib
。但我似乎無法進行基本的字串比較。由於沒有更深入的了解,我已經嘗試了我能找到的一切(,,,,xstring
... )。沒有什麼真正有效。如果有人可以修復我的功能,我會很高興。\detokenize
\expandafter\relax
Test
\documentclass{article}
\usepackage{natbib}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{ArticleX, author = "AuthorA", year = "2000"}
@article{ArticleY, author = "AuthorA", year = "2010"}
@article{ArticleZ, author = "AuthorB", year = "2010"}
\end{filecontents}
\newcommand{\Test}[2]{
\ifx\citeauthor{#1}\citeauthor{#2}
Yes!
\else
No!
\fi
}
\begin{document}
Oh, \cite{ArticleX} and \cite{ArticleZ} don't have the same author? \Test{ArticleX}{ArticleZ} Ok!
But \cite{ArticleX} and \cite{ArticleY} surely have! \Test{ArticleX}{ArticleY} No, either??
\bibliographystyle{unsrtnat}
\bibliography{\jobname}
\end{document}
答案1
這有效:
% https://tex.stackexchange.com/questions/8981/
\newcommand{\ignoreoutput}[1]{\setbox0\vbox{\everypar{}#1}}
\makeatletter
\newcommand{\Test}[2]{
\ignoreoutput{\citeauthor{#1}}
\edef\NumberOne{\NAT@name}
\ignoreoutput{\citeauthor{#2}}
\edef\NumberTwo{\NAT@name}
\ifx\NumberOne\NumberTwo
Yes!
\else
No!
\fi
}
我仍然歡迎更優雅的答案,但這解決了我的問題。