\makeatletter \newcommand*{\StoreCiteField}[3]{% \begingroup \global\let\StoreCiteField@Result\relax \citefield{#2}[StoreCiteField]{#3}% \endgroup \let#1\StoreCiteField@Result } \DeclareFieldFormat{StoreCiteField}{% \gdef\StoreCiteField@Result{#1}% } \makeatother
- 我尝试调整代码,使其适用于
\citeauthor
但失败了。 - 有任何想法吗?
这是我(失败的)尝试使用相同的方法\citeauthior
:
\newcommand*{\StoreAuthor}[2]{%
\begingroup
\global\let\StoreAuthor@Result\relax
\citeauthor{#2}%
\endgroup
\let#1\StoreAuthor@Result
}
\DeclareFieldFormat{StoreAuthor}{%
\gdef\StoreAuthor@Result{#1}%
}
我在这里的表现远远超出了我的能力范围,只是试图在 Heiko 的代码中找到类比并相应地进行调整。我不明白代码。昨天,之前的普通用户成本加运费对相关问题进行了评论(如何使 \citetitle 在超链接部分书签中发挥作用?),因为他/她也有同样的问题。这激励我再次尝试。
\documentclass{article}
\usepackage{xcolor}
\usepackage{biblatex}
\begin{filecontents}{\jobname.bib}
@book{key,
title = {Book Title},
year = {2000},
author = {Givenname FamilyName},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\usepackage{hyperref}
\usepackage{bookmark}
% https://tex.stackexchange.com/questions/73678
\makeatletter
\newcommand*{\StoreCiteField}[3]{%
\begingroup
\global\let\StoreCiteField@Result\relax
\citefield{#2}[StoreCiteField]{#3}%
\endgroup
\let#1\StoreCiteField@Result
}
\DeclareFieldFormat{StoreCiteField}{%
\gdef\StoreCiteField@Result{#1}%
}
%
\newcommand*{\StoreAuthor}[2]{%
\begingroup
\global\let\StoreAuthor@Result\relax
\citeauthor{#2}%
\endgroup
\let#1\StoreAuthor@Result
}
\DeclareFieldFormat{StoreAuthor}{%
\gdef\StoreAuthor@Result{#1}%
}
\makeatother
\begin{document}
%% StoreCiteField (Working)
% Store Results
\StoreCiteField\myTitle{key}{title}
% Use Results In Headings
\section{Title (Working): \textcolor{red}{\myTitle}}
\myTitle
\noindent\rule{\textwidth}{1pt}
% Store Results
\StoreCiteField\myYear{key}{year}
% Use Results In Headings
\section{Year (Working): \textcolor{red}{\myYear}}
\myTitle
\noindent\rule{\textwidth}{1pt}
%% StoreAuthor (Nor Working)
% Store Results
\StoreAuthor\myAuthor{key}
% Use Results In Headings
\section{Author (Not Working): \textcolor{red}{\myAuthor}}
\myAuthor
\end{document}
答案1
这里的问题是,姓名列表比简单字段复杂得多。
简单字段的处理相对简单,因为最终字段内容存储在宏中,该宏可直接用于biblatex
打印。我们“仅”需要掌握此宏的扩展。(这可以通过StoreCiteField
此处显示的巧妙方式或更简单的方法来完成。)具体来说,我们将得到类似
\field{year}{1998}
并.bbl
希望掌握1998
我们在此尝试完成的事情的完整情况。
然而,名单要复杂得多。它们以“抽象”的方式存储在.bbl
文件中
\name{author}{2}{}{%
{{hash=484061f383fb3b729627e12ab42c1963}{%
family={Sigfridsson},
familyi={S\bibinitperiod},
given={Emma},
giveni={E\bibinitperiod}}}%
{{hash=b7e299b632e5db12681c2decc8ce023f}{%
family={Ryde},
familyi={R\bibinitperiod},
given={Ulf},
giveni={U\bibinitperiod}}}%
}
您不能只抓取“全部”这些内容来获得不错的输出。我们需要对它们进行大量后期处理,以便得到有用的东西。这种后期处理通常由 完成biblatex
。但它是以从根本上无法扩展的方式完成的,这意味着它在这里对我们没有任何用处。
我们本质上必须以可扩展的方式复制整个名称格式代码。对于姓氏,这是按照StoreName
下面的名称格式完成的。我们将当前名称的姓氏部分添加到\StoreName@Result
in 中\protected@xappto\StoreName@Result{\namepartfamily}
。代码的其余部分以可扩展的方式处理逗号、“and”、“et al.”(因此所有内容都是硬编码的)。
\documentclass{article}
\usepackage{xcolor}
\usepackage{biblatex}
\addbibresource{biblatex-examples.bib}
\usepackage{hyperref}
\usepackage{bookmark}
% https://tex.stackexchange.com/questions/73678
\makeatletter
\newcommand*{\StoreCiteField}[3]{%
\begingroup
\global\let\StoreCiteField@Result\relax
\citefield{#2}[StoreCiteField]{#3}%
\endgroup
\let#1\StoreCiteField@Result
}
\DeclareFieldFormat{StoreCiteField}{%
\gdef\StoreCiteField@Result{#1}%
}
%
\newcommand*{\StoreName}[3]{%
\begingroup
\global\let\StoreName@Result\relax
\blx@indexnamesetup
\citename{#2}[StoreName]{#3}%
\endgroup
\let#1\StoreName@Result
}
\DeclareNameFormat{StoreName}{%
\ifnumgreater{\value{listcount}}{\value{liststart}}
{\ifboolexpr{
test {\ifnumless{\value{listcount}}{\value{liststop}}}
or
test \ifmorenames
}
{\gappto\StoreName@Result{, }}
{\gappto\StoreName@Result{ and }}}
{}%
\protected@xappto\StoreName@Result{\namepartfamily}%
\ifboolexpr{
test {\ifnumequal{\value{listcount}}{\value{liststop}}}
and
test \ifmorenames
}
{\gappto\StoreName@Result{et~al.}}
{}%
}
\newcommand*\StoreAuthor[2]{\StoreName{#1}{#2}{author}}
\makeatother
\begin{document}
\StoreCiteField\myTitle{sigfridsson}{title}
\section{Title: \textcolor{red}{\myTitle}}
\myTitle
\noindent\rule{\textwidth}{1pt}
\StoreCiteField\myYear{sigfridsson}{year}
\section{Year: \textcolor{red}{\myYear}}
\myYear
\noindent\rule{\textwidth}{1pt}
\StoreAuthor\myAuthor{sigfridsson}
\section{Author: \textcolor{red}{\myAuthor}}
\myAuthor
\end{document}