我正在尝试找出两个参考文献是否具有相同的作者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
}
我仍然欢迎更优雅的答案,但这解决了我的问题。