标准\cite{some_ref}
命令生成类似 的引用文本[1]
,但我正在寻找类似 的引用[1*]
。我该如何为此类行为定义新的 cite 命令?
答案1
由于您正在使用natbib
,因此无需定义任何新命令;您可以使用\citetext
和\citealp
命令来实现所需的效果:
\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{test,
author={Steve Somebody},
title= {The Title},
year={2011},
publisher={The publisher}
}
\end{filecontents}
\documentclass{article}
\usepackage[numbers]{natbib}
\begin{document}
\citetext{\citealp{test}*}
\bibliographystyle{plain}
\bibliography{\jobname}
\end{document}
答案2
\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{test,
author={Steve Somebody},
titel= {The Title},
year={2011},
}
\end{filecontents}
\documentclass{article}
\makeatletter
\DeclareRobustCommand\mycite{%
\@ifnextchar [{\@tempswatrue\@mycitex}{\@tempswafalse\@mycitex[]}}
\def\@mycitex[#1]#2{\leavevmode
\let\@citea\@empty
\@mycite{\@for\@citeb:=#2\do
{\@citea\def\@citea{,\penalty\@m\ }%
\edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
\if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
\@ifundefined{b@\@citeb}{\hbox{\reset@font\bfseries ?}%
\G@refundefinedtrue
\@latex@warning
{Citation `\@citeb' on page \thepage \space undefined}}%
{\@cite@ofmt{\csname b@\@citeb\endcsname}}}}{#1}}
\def\@mycite#1#2{[{#1*\if@tempswa , #2\fi}]}%
\makeatother
\begin{document}
\cite{test}\qquad \mycite{test} \qquad \mycite[p.~1]{test}
\bibliography{\jobname}
\bibliographystyle{plain}
\end{document}
答案3
使用第二个开关,它会短一点。使用\cite
或cite*
\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{test,
author={Steve Somebody},
titel= {The Title},
year={2011},
}
\end{filecontents}
\documentclass{article}
\makeatletter
\newif\if@tempswb
\DeclareRobustCommand\cite{%
\@ifnextchar*{\@tempswbtrue\cite@i}{\@tempswbfalse\cite@i*}}
\def\cite@i*{\@ifnextchar[{\@tempswatrue\@citex}{\@tempswafalse\@citex[]}}
\def\@cite#1#2{[{#1\if@tempswb*\fi\if@tempswa , #2\fi}]}%
\makeatother
\begin{document}
\cite{test}\qquad \cite*{test} \qquad \cite*[p.~1]{test}
\bibliography{\jobname}
\bibliographystyle{plain}
\end{document}