我如何才能访问当前 bibitem 的标签名称?

我如何才能访问当前 bibitem 的标签名称?

我想使用“当前”bibitem 的名称(在标签定义中,但实际上我认为这可能无关紧要)。考虑一下我现在要做的事情:

\documentclass{article}
\makeatletter
% Define the label #1 to be #2 (so \ref{X} gives Y):
\def\LABEL#1#2{\protected@edef\@currentlabel{#2}\label{#1}}
% Display \label{URL:#1} in tty font:
\def\URL#1{\texttt{\ref{URL:#1}}}   

\begin{document}

The URL of the Wikipedia article on ``plain text''~\cite{WP:plain} is \URL{WP:plain}. 

\begin{thebibliography}{WW}
% define and immediately use a label for the URL of a WP page
\def\WPURL#1#2{\LABEL{URL:#1}{https://en.wikipedia.org/\hspace{0pt}wiki/#2}\URL{#1}}

\bibitem{WP:plain} Wikipedia: ``Plain text''. Last accessed: ... URL:
\WPURL{WP:plain}{Plain\_text}

\end{thebibliography}
\end{document}

正如预期的那样,它给出了:

维基百科关于“纯文本” [1] 的文章的 URL 是https://en.wikipedia.org/ wiki/Plain_text

参考

[1] 维基百科:“纯文本”。上次访问:... URL:https://en.wikipedia.org/wiki/Plain_text

我希望\WPURL只需要一个参数,即当前的第二个参数(URL 的“basename”),并WP:plain从当前的推断出第一个参数(此处,用于 URL 标签)\bibitem

答案1

您可以修改\bibitem以保存其参数以供稍后在同一项目中使用。

\documentclass{article}

\makeatletter
% Define the label #1 to be #2 (so \ref{X} gives Y):
\newcommand{\LABEL}[2]{\protected@edef\@currentlabel{#2}\label{#1}}
\NewCommandCopy{\original@bibitem}{\bibitem}
\renewcommand{\bibitem}[1]{%
  \def\@currentbiblabel{#1}%
  \original@bibitem{#1}%
}
\newcommand{\WPURL}[1]{%
  \LABEL{URL:\@currentbiblabel}{https://en.wikipedia.org/\hspace{0pt}wiki/#1}%
  \URL{\@currentbiblabel}%
}
% Display \label{URL:#1} in tty font:
\newcommand{\URL}[1]{\texttt{\ref{URL:#1}}}   
\makeatother

\begin{document}

The URL of the Wikipedia article on ``plain text''~\cite{WP:plain} is \URL{WP:plain}. 

The URL of the Wikipedia article on ``whatever''~\cite{WP:whatever} is \URL{WP:whatever}. 

\begin{thebibliography}{WW}
% define and immediately use a label for the URL of a WP page

\bibitem{WP:plain} Wikipedia: ``Plain text''. Last accessed: ... URL:
\WPURL{Plain\_text}

\bibitem{WP:whatever} Wikipedia: ``Whatever''. Last accessed: ... URL:
\WPURL{Whatever}

\end{thebibliography}
\end{document}

在此处输入图片描述

相关内容