2

I'm trying to manually put formatting codes into the fields of my .bib file, but the final compile step crashes with a Missing \endcsname inserted error on the \printbibliography line. In particular, I need to bold particular names, which may be in an arbitrary position in the author list. The problems seems to be with \textbf{Name} breaking the final compile.

I also tried {\bfseries Name}, but that bolds all the names afterwards.

(Background, I need to do for the publications list of my CV to put it in a particular required format. I'd rather use biblatex than manually format everything.)

Below is my MNWE. I'm compiling with pdflatex; biber; pdflatex on a MikTex-64bit distribution.

\documentclass{article}

\usepackage{filecontents}
\usepackage[backend=biber]{biblatex}
% biblatex version 3.3
% biber version 2.4

\begin{filecontents}{\jobname.bib}
@misc{Article1,
author = {Last1\textsuperscript{*}, First1 and \textbf{Last2}, \textbf{First2} and Last3, First3},
year = {2016},
title = {The Title},
}
\end{filecontents}

\addbibresource{\jobname.bib}
\nocite{*}


\begin{document}

Star\textsuperscript{*} indicates student author.  \textbf{Bold} indicates corresponding author.
\subsection*{Desired output}
[1]  First1 Last1\textsuperscript{*}, \textbf{First2} \textbf{Last2},  and First3 Last3. \emph{The Title}. 2016.

\printbibliography

\end{document}
11
  • This may be a duplicate - see here for example: tex.stackexchange.com/questions/73136/…
    – PLK
    Apr 16, 2016 at 16:37
  • You should not include formatting commands into name fields (it is sometimes necessary for other fields, but can often be avoided). You can apply special formatting for certain names (such as bold my name) but what you want seems trickier.
    – moewe
    Apr 16, 2016 at 16:38
  • @PLK This is different because the bolded name may be different for each entry. Apr 16, 2016 at 16:41
  • I assume the names could come in random order? So it would not just be possible to print the student authors first and then the corresponding authors, because that would not be the proper order on the work itself
    – moewe
    Apr 16, 2016 at 16:42
  • 1
    @moeve I have an idea. What is the counter of authors when the namelist is processed? Apr 16, 2016 at 16:49

2 Answers 2

1

There is a more general way to handle this now in biblatex 3.4/biber 2.5 through data annotations since this is not an uncommon request and we need a way of allowing ad-hoc attachment of semantic information to pieces of data which doesn't require messing about with internals. Annotation in biblatexml is straighforward and done by XML attributes:

<bltx:entries xmlns:bltx="http://biblatex-biber.sourceforge.net/biblatexml">
  <bltx:entry id="Article1" entrytype="misc">
    <bltx:names type="author">
      <bltx:name>
        <bltx:namepart type="given" initial="F">First1</bltx:namepart>
        <bltx:namepart type="family" initial="L" annotation="student">Last1</bltx:namepart>
      </bltx:name>
      <bltx:name annotation="corresponding">
        <bltx:namepart type="given" initial="F">First2</bltx:namepart>
        <bltx:namepart type="family" initial="L">Last2</bltx:namepart>
      </bltx:name>
      <bltx:name>
        <bltx:namepart type="given" initial="F">First3</bltx:namepart>
        <bltx:namepart type="family" initial="L">Last3</bltx:namepart>
      </bltx:name>
    </bltx:names>
  </bltx:entry>
</bltx:entries>

With bibtex data sources, it's a bit uglier but relatively simple:

@MISC{Article1,
  AUTHOR    = {Last1, First1 and Last2, First2 and Last3, First3},
  AUTHOR+an = {1:family=student;2=corresponding},
}

and then you can use these annotations in formatting directives via three new macros:

\renewbibmacro*{name:given-family}[4]{%
  \usebibmacro{name:delim}{#2#3#1}%
  \usebibmacro{name:hook}{#2#3#1}%
  \ifdefvoid{#2}{}{\mkbibnamegiven{#2}\isdot\bibnamedelimd}%
  \ifdefvoid{#3}{}{%
    \mkbibnameprefix{#3}\isdot
    \ifprefchar
      {}
      {\ifuseprefix{\bibnamedelimc}{\bibnamedelimd}}}%
  \mkbibnamefamily{#1}%
  \ifpartannotation{family}{student}
    {\textsuperscript{*}}
    {}%
    \isdot
  \ifdefvoid{#4}{}{\bibnamedelimd\mkbibnamesuffix{#4}\isdot}}

\renewcommand*{\mkbibnamegiven}[1]{%
  \ifitemannotation{corresponding}
    {\textbf{#1}}
    {#1}}

\renewcommand*{\mkbibnamefamily}[1]{%
  \ifitemannotation{corresponding}
    {\textbf{#1}}
    {#1}}

This gives you the output you wanted without putting markup in the data and via semantic annotations. The DEV 3.4 PDF manual has the details. It needs the latest biber 2.5 release too.

1
  • I was only recently able to try this, now that biblatex 3.4 and biber 2.5 have hit the MikTeX distribution. It works well and makes my .bib files more transportable because the formatting is now separated from the data. Nice work. Jun 18, 2016 at 10:36
1

It is possible to inject commands into the name processing which are only used for certain keys + author counts. For the \textsuperscript it is not necessary but I'm inserting another one anyway as proof of concept. It is probably possible to store the info in the bib-file and one can certainly improve the interface:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{Article1,
author = {Last1\textsuperscript{*}, First1 and Last2, First2 and Last3, First3},
year = {2016},
title = {The Title},
}
\end{filecontents}

\usepackage[backend=biber]{biblatex}
% biblatex version 3.3
% biber version 2.4

\DeclareNameFormat{given-family}{%
  \nameparts{#1}%
  \ifgiveninits
    {\usebibmacro{name:given-family}
      {\namepartfamily}
      {\namepartgiveni}
      {\namepartprefix}
      {\namepartsuffix}}
    {{\csname key-\thefield{entrykey}-\the\value{listcount}-font\endcsname
      \usebibmacro{name:given-family}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}%
      \csname key-\thefield{entrykey}-\the\value{listcount}-suffix\endcsname
      }}%
  \usebibmacro{name:andothers}}
\addbibresource{\jobname.bib}


\makeatletter
\@namedef{key-Article1-2-font}{\bfseries}
\@namedef{key-Article1-1-suffix}{\textsuperscript{*}}
\makeatletter

\begin{document}
\cite{Article1}
Star\textsuperscript{*} indicates student author.  \textbf{Bold} indicates corresponding author.
\subsection*{Desired output}
[1]  First1 Last1\textsuperscript{*}, \textbf{First2} \textbf{Last2},  and First3 Last3. \emph{The Title}. 2016.

\printbibliography

\end{document}

enter image description here

5
  • I think I see how this works, but let me check to see if I understand. Does the information about which author is bolded goes in the block of \@namedef commands before \begin{document}? Apr 16, 2016 at 17:10
  • Yes. The command "name" is key-bibkey-authorcount-font (the fix words key and font are only there to avoid clashes with other commands). Apr 16, 2016 at 17:14
  • Is there any way to embed this info in the .bib file instead of the .tex file, perhaps by defining a new field? Apr 16, 2016 at 17:14
  • As I wrote: probably. Actually I'm certain that it is possible. You need some other name list where you can pull the info from. But I don't have the time now. Apr 16, 2016 at 17:16
  • This worked, but I now prefer the solution by @PLK now that I have been able to try biblatex 3.4 and biber 2.5, which were recently added to the MikTeX distribution. Jun 18, 2016 at 10:34

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.