6

I would like to change the behavior of printing author names based on the hash field in biblatex. This mwe should demonstrate what I am having difficulty understanding.

MWE:

\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}

Output:

mwe output


I understand that the initial value for \myhash is not the same as the biblatex hash field, even if their string values are the same as the initial J.B. is not bold and the next occurrence is.

What I would like to understand is:

  1. How do I compare the string value of a biblatex field to the string value of a command?
  2. What is the value of the biblatex hash field
  3. How do I determine what the value of a command or biblatex field actually is?

I feel like I am missing a core concept, and a better means of debugging issues in LaTeX.

(I am aware of this question, but my question is more about LaTeX/biblatex programing)

6

You need to \detokenize the string before assigning it to your macro. This is easiest to do via an \edef:

\edef\myhash{\detokenize{7ba24cb78eaec483f680a08422f4d516}}

Now \iffieldsequals has a chance of succeeding. Compare this with the nice discussion at https://tex.stackexchange.com/a/6833/15925

Sample output

\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}
  • \detokenize is solving some other problems I have been having. This was the major concept that I was missing, thanks. – Alex Grede Apr 4 '14 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.