![Biblatex 字段值和比较](https://linux22.com/image/287650/Biblatex%20%E5%AD%97%E6%AE%B5%E5%80%BC%E5%92%8C%E6%AF%94%E8%BE%83.png)
我想改变 biblatex 中基于哈希字段打印作者姓名的行为。这篇文章应该能说明我难以理解的内容。
梅威瑟:
\documentclass{article}
\usepackage[backend=biber, style=phys, punctfont=true]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{doe_design_2013,
author = {Doe, John B.},
journaltitle = {Acme Society Journal},
date = {2013-03-08},
title = {Design of alpha widgets},
volume = {1},
issue = {1},
pages = {10}
}
@article{doe_alpha_2014,
author = {Smith, Jane J. and Doe, John B.},
journaltitle = {Acme Society Journal},
date = {2014-03-08},
title = {Alpha widgets in space},
volume = {2},
issue = {1},
pages = {5}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\newcommand*{\mystr}{7ba24cb78eaec483f680a08422f4d516}
\newcommand*{\myhash}{7ba24cb78eaec483f680a08422f4d516}
\renewcommand*{\mkbibnamefirst}[1]{
\iffieldequals{hash}{\myhash}{\mkbibbold{#1}}{#1}
}
\renewcommand*{\mkbibnamelast}[1]{
\iffieldequalstr{hash}{7ba24cb78eaec483f680a08422f4d516}
{\savefield{hash}{\myhash}\mkbibbold{#1}}
{#1}
}
\begin{document}
Commands equal: \ifdefequal{\myhash}{\mystr}{True}{False}
Replacement text equal: \ifdefstrequal{\myhash}{\mystr}{True}{False}
\nocite{*}
\printbibliography[title={Test}]
Commands equal: \ifdefequal{\myhash}{\mystr}{True}{False}
Replacement text equal: \ifdefstrequal{\myhash}{\mystr}{True}{False}
\pagenumbering{gobble}
\end{document}
输出:
我理解 \myhash 的初始值与 biblatex 哈希字段不同,即使它们的字符串值与初始JB不是粗体,而下一个出现的是粗体。
我想了解的是:
- 如何将 biblatex 字段的字符串值与命令的字符串值进行比较?
- biblatex 哈希字段的值是什么
- 我如何确定命令或 biblatex 字段的实际值?
我觉得我缺少一个核心概念,以及在 LaTeX 中调试问题的更好方法。
(我知道这个问题,但我的问题更多是关于 LaTeX/biblatex 编程)
答案1
\detokenize
在将字符串分配给宏之前,您需要先获取该字符串。最简单的方法是通过以下方式完成\edef
:
\edef\myhash{\detokenize{7ba24cb78eaec483f680a08422f4d516}}
现在\iffieldsequals
有成功的机会。将此与https://tex.stackexchange.com/a/6833/15925
\documentclass{article}
\usepackage[backend=biber, style=phys, punctfont=true]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{doe_design_2013,
author = {Doe, John B.},
journaltitle = {Acme Society Journal},
date = {2013-03-08},
title = {Design of alpha widgets},
volume = {1},
issue = {1},
pages = {10}
}
@article{doe_alpha_2014,
author = {Smith, Jane J. and Doe, John B.},
journaltitle = {Acme Society Journal},
date = {2014-03-08},
title = {Alpha widgets in space},
volume = {2},
issue = {1},
pages = {5}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\newcommand*{\mystr}{7ba24cb78eaec483f680a08422f4d516}
\edef\myhash{\detokenize{7ba24cb78eaec483f680a08422f4d516}}
\renewcommand*{\mkbibnamefirst}[1]{
\iffieldequals{hash}{\myhash}{\mkbibbold{#1}}{#1}
}
\renewcommand*{\mkbibnamelast}[1]{
\iffieldequals{hash}{\myhash}
{\mkbibbold{#1}}
{#1}
}
\begin{document}
Commands equal: \ifdefequal{\myhash}{\mystr}{True}{False}
Replacement text equal: \ifdefstrequal{\myhash}{\mystr}{True}{False}
\nocite{*}
\printbibliography[title={Test}]
Commands equal: \ifdefequal{\myhash}{\mystr}{True}{False}
Replacement text equal: \ifdefstrequal{\myhash}{\mystr}{True}{False}
\pagenumbering{gobble}
\end{document}