我对未解析的引用有疑问(我正在使用纳特比布和 pdflatex/bibtex) 以及打印的默认行为(?)
。我想要的是以下内容:
- 替换
(?)
为(citation-key)
(仅适用于缺失的参考),以及 - 缺失引用键的列表将被打印在生成的 PDF 中的某个位置(例如,在参考列表的开头)。
我读了这个问题关于使用展示钥匙包,但结果并不是我真正想要的,因为(1)它并没有替换,(?)
而只是在顶部打印了引用键,(2)它似乎对所有参考文献都这样做,而我只想要缺失的参考文献,(3)它没有生成缺失参考文献的列表。
这是一个最小的例子(虽然我怀疑它对于这个问题来说可能没有必要)。
\documentclass{article}
\usepackage{natbib}
%\usepackage{showkeys} % not what I'm looking for
\bibpunct{(}{)}{;}{a}{}{,}
\title{Example}
\author{Me}
\begin{document}
\maketitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Mauris vel sem id nulla cursus vulputate at et erat \citep{Author2001}.
Nunc rutrum nibh lorem, eget posuere nibh sollicitudin vitae \citep{Author1993}.
\bibliography{Example}
\end{document}
我完全接受新的包,以及解析example.log
文件以提取行的方法,例如:
Package natbib Warning: Citation `Author2001' on page 1 undefined on input line
14.
答案1
我已谈及以下几点:
- 找出那些不在参考文献列表中的参考文献。(本题未问。)
- 找出那些没有被引用的参考文献。
- 用引用键替换缺失的参考文献(?)。
\documentclass{article}
\usepackage{natbib}
%\usepackage{showkeys} % not what I'm looking for
\bibpunct{(}{)}{;}{a}{}{,}
\makeatletter
\let\oldcitation\citation
\def\xcomma{}
\def\bibList{}
\def\citation#1{%
\@for\xx:=#1\do{%
\expandafter\ifx\csname bbl@\xx\endcsname\relax%
\expandafter\gdef\csname bbl@\xx\endcsname{0}%
\xdef\bibList{\bibList\xcomma\xx}%
\def\xcomma{,}%
\fi%
}%
\oldcitation{#1}%
}
\AtEndDocument{\@bsphack
\protected@write\@auxout{}%
{\string\BibList{\bibList}}%
\@esphack}
\def\xComma{}
\def\biblostkeys{}
\def\BibList#1{%
\@for\xx:=#1\do{%
\expandafter\ifx\csname BBL@\xx\endcsname\relax%
\xdef\biblostkeys{\biblostkeys\xComma\xx}%
\def\xComma{,\space}%
\fi%
}%
}
\def\refnotcalled{}
\def\Xcomma{}
\let\oldbibcite\bibcite
\def\bibcite#1{%
\expandafter\gdef\csname BBL@#1\endcsname{0}%
\expandafter\ifx\csname bbl@#1\endcsname\relax% Not cited
\xdef\refnotcalled{\refnotcalled\Xcomma#1}%
\def\Xcomma{,\space}%
\fi%
\oldbibcite{#1}%
}
\def\NAT@citex%
[#1][#2]#3{%
\NAT@reset@parser
\NAT@sort@cites{#3}%
\NAT@reset@citea
\@cite{\let\NAT@nm\@empty\let\NAT@year\@empty
\@for\@citeb:=\NAT@cite@list\do
{\@safe@activestrue
\edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
\@safe@activesfalse
\@ifundefined{b@\@citeb\@extra@b@citeb}{\@citea%
{\reset@font\bfseries\@citeb}\NAT@citeundefined
\PackageWarning{natbib}%
{Citation `\@citeb' on page \thepage \space undefined}\def\NAT@date{}}%
{\let\NAT@last@nm=\NAT@nm\let\NAT@last@yr=\NAT@year
\NAT@parse{\@citeb}%
\ifNAT@longnames\@ifundefined{bv@\@citeb\@extra@b@citeb}{%
\let\NAT@name=\NAT@all@names
\global\@namedef{bv@\@citeb\@extra@b@citeb}{}}{}%
\fi
\ifNAT@full\let\NAT@nm\NAT@all@names\else
\let\NAT@nm\NAT@name\fi
\ifNAT@swa\ifcase\NAT@ctype
\if\relax\NAT@date\relax
\@citea\NAT@hyper@{\NAT@nmfmt{\NAT@nm}\NAT@date}%
\else
\ifx\NAT@last@nm\NAT@nm\NAT@yrsep
\ifx\NAT@last@yr\NAT@year
\def\NAT@temp{{?}}%
\ifx\NAT@temp\NAT@exlab\PackageWarningNoLine{natbib}%
{Multiple citation on page \thepage: same authors and
year\MessageBreak without distinguishing extra
letter,\MessageBreak appears as question mark}\fi
\NAT@hyper@{\NAT@exlab}%
\else\unskip\NAT@spacechar
\NAT@hyper@{\NAT@date}%
\fi
\else
\@citea\NAT@hyper@{%
\NAT@nmfmt{\NAT@nm}%
\hyper@natlinkbreak{%
\NAT@aysep\NAT@spacechar}{\@citeb\@extra@b@citeb
}%
\NAT@date
}%
\fi
\fi
\or\@citea\NAT@hyper@{\NAT@nmfmt{\NAT@nm}}%
\or\@citea\NAT@hyper@{\NAT@date}%
\or\@citea\NAT@hyper@{\NAT@alias}%
\fi \NAT@def@citea
\else
\ifcase\NAT@ctype
\if\relax\NAT@date\relax
\@citea\NAT@hyper@{\NAT@nmfmt{\NAT@nm}}%
\else
\ifx\NAT@last@nm\NAT@nm\NAT@yrsep
\ifx\NAT@last@yr\NAT@year
\def\NAT@temp{{?}}%
\ifx\NAT@temp\NAT@exlab\PackageWarningNoLine{natbib}%
{Multiple citation on page \thepage: same authors and
year\MessageBreak without distinguishing extra
letter,\MessageBreak appears as question mark}\fi
\NAT@hyper@{\NAT@exlab}%
\else
\unskip\NAT@spacechar
\NAT@hyper@{\NAT@date}%
\fi
\else
\@citea\NAT@hyper@{%
\NAT@nmfmt{\NAT@nm}%
\hyper@natlinkbreak{\NAT@spacechar\NAT@@open\if*#1*\else#1\NAT@spacechar\fi}%
{\@citeb\@extra@b@citeb}%
\NAT@date
}%
\fi
\fi
\or\@citea\NAT@hyper@{\NAT@nmfmt{\NAT@nm}}%
\or\@citea\NAT@hyper@{\NAT@date}%
\or\@citea\NAT@hyper@{\NAT@alias}%
\fi
\if\relax\NAT@date\relax
\NAT@def@citea
\else
\NAT@def@citea@close
\fi
\fi
}}\ifNAT@swa\else\if*#2*\else\NAT@cmt#2\fi
\if\relax\NAT@date\relax\else\NAT@@close\fi\fi}{#1}{#2}}
\title{Example}
\author{Me}
\begin{document}
\maketitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Mauris vel sem id nulla cursus vulputate at et erat \citep{Author2001}.
Nunc rutrum nibh lorem, eget posuere nibh sollicitudin vitae \citep{Author2001,Author1993}.
Nunc rutrum nibh lorem, eget posuere nibh sollicitudin vitae \citep{Author1993}.
\noindent\fbox{Keys not in reference list: \biblostkeys} % Keys which are not in reference list
\begin{thebibliography}{99}
\bibitem[Author(2001)]{Author2001} Author (2001).
%not cited
\bibitem[Author(2004)]{Author2004} Author (2004).
%not cited
\bibitem[Author(2005)]{Author2005} Author (2005).
\end{thebibliography}
\noindent\fbox{Keys not cited in text: \refnotcalled} % Keys which are not cited in text
\end{document}
您需要编译三次才能正确完成所有操作。请参阅命令\biblostkeys
和refnotcalled
。