3

I want to make bold specific author, wherever it placed (i.e., 1st, 2nd does not matter) when only citing at the text area (i.e., should not get bold in reference section).

For full citation in the text/normal section, I used the method described here. For changing it to bold, I found this answer might be useful, but don't how to incorporate it in the \printpublication command.

MWE:

\documentclass{article}
\usepackage[backend=biber,natbib=true,style=ieee,
   citestyle=numeric-comp,sorting=none,doi=false,isbn=false,url=true,]{biblatex}

\usepackage{filecontents}

\begin{filecontents}{\cite.bib}
@misc{A01,
  author = {Author, Arik and Author, Jaz and Author, Ricky},
  year = {2100},
  title = {An unnecessary long title},
}
@book{A02,
  author = {Author, Jaz and Author, Arik and Author, Ricky},
  year = {2100},
  title = {An unnecessary long title},
}
\end{filecontents}
\addbibresource{\cite.bib}


\newcommand{\printpublication}[1]{\AtNextCite{\defcounter{maxnames}{3}\defcounter{minnames}{1}}\fullcite{#1}}

\begin{document}
    \printpublication{A01}
    \printpublication{A02}

\printbibliography
\end{document}
1
  • 1
    Please mark the question as solved if the given answer suits your needs (see check mark next to the answer) – bonanza Apr 29 '19 at 13:11
2

Building on my answer to Make specific author bold using biblatex, which has a slightly more convenient user interface for the bold names, we can define the new command \printpublication.

The exact working of the code for bold names is explained in the linked answer: The gist is that we write the names to an external .bib and can then extract the hash automatically from the .bbl file. With the hashes we can then go on to highlight the names, the hashes of interest are stored in a list.

The command \mkboldifhashinlist highlights exactly those names for which the hashes are in the list of interest. With the definition in \DeclareNameWrapperFormat{given-family:hash:bold} this macro can be applied to the complete name if so desired.

\printpublication is a copy of \fullcite with the \defcounters as well as the new bold name format thrown directly into the precode of \usedriver.

\documentclass{article}
\usepackage[backend=biber, natbib=true, style=ieee, sorting=none,
  doi=false, isbn=false, url=true]{biblatex}

\makeatletter
% auxiliary bibfile
\def\hlblx@bibfile@name{\jobname -boldnames.bib}
\newwrite\hlblx@bibfile
\immediate\openout\hlblx@bibfile=\hlblx@bibfile@name

\newcounter{hlblx@name}
\setcounter{hlblx@name}{0}

\newcommand*{\hlblx@writenametobib}[1]{%
  \stepcounter{hlblx@name}%
  \edef\hlblx@tmp@nocite{%
    \noexpand\AfterPreamble{%
      \noexpand\setbox0\noexpand\vbox{%
        \noexpand\hlblx@getmethehash{hlblx@name@\the\value{hlblx@name}}}}%
  }%
  \hlblx@tmp@nocite
  \immediate\write\hlblx@bibfile{%
    @misc{hlblx@name@\the\value{hlblx@name}, author = {\unexpanded{#1}}, %
          options = {dataonly=true},}%
  }%
}

\AtEndDocument{%
  \closeout\hlblx@bibfile}

\addbibresource{\hlblx@bibfile@name}

\newcommand*{\hlbxl@boldhashes}{}
\DeclareNameFormat{hlblx@hashextract}{%
  \xifinlist{\thefield{hash}}{\hlbxl@boldhashes}
    {}
    {\listxadd{\hlbxl@boldhashes}{\thefield{fullhash}}}}

\DeclareCiteCommand{\hlblx@getmethehash}
  {}
  {\printnames[hlblx@hashextract][1-999]{author}}
  {}
  {}

% user-level macros
\newcommand*{\addboldnames}{\forcsvlist\hlblx@writenametobib}
\newcommand*{\resetboldnames}{\def\hlbxl@boldhashes{}}


\newcommand*{\mkboldifhashinlist}[1]{%
  \xifinlist{\thefield{hash}}{\hlbxl@boldhashes}
    {\mkbibbold{#1}}
    {#1}}
\makeatother

\DeclareNameWrapperFormat{given-family:hash:bold}{%
  \renewcommand*{\mkbibcompletename}{\mkboldifhashinlist}%
  #1}

\DeclareCiteCommand{\printpublication}
  {\usebibmacro{prenote}}
  {\usedriver
     {\DeclareNameAlias{sortname}{default}%
      \DeclareNameWrapperAlias{default}{given-family:hash:bold}%
      \defcounter{maxnames}{3}%
      \defcounter{minnames}{1}}
     {\thefield{entrytype}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\addboldnames{{Author, Arik}}

\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, Arik and Author, Jaz and Author, Ricky},
  year   = {2100},
  title  = {An unnecessary long title},
}
@book{A02,
  author = {Author, Jaz and Author, Arik and Author, Ricky},
  year   = {2100},
  title  = {An unnecessary long title},
}
\end{filecontents}
\addbibresource{\jobname.bib}


\begin{document}
  \printpublication{A01}

  \printpublication{A02}

  \printbibliography
\end{document}

"**A. Author**, J. Author, and R. Author, An unnecessary long title, 2100"//"J. Author, **A. Author**, and R. Author, An unnecessary long title. 2100." Bibliography the same but without bold highlights for names.

edited to use a more elegant version to format complete names. \DeclareNameWrapperFormat and \mkbibcompletename are only available in biblatex v3.12 (2018-10-30) and v3.13 (2019-08-17), respectively. Please refer to the edit history if you are using an older version of biblatex.

4
  • Thanks so much its working great in general. However, I have a problem for publications with four or more authors: It prints "A. Author et al." instead of all authors. Unfortunately, the author I would like to highlight is not the first author. How to fix this? I have seen that maxcitenames might be a related option. How to apply this to \printpublcation only? – bonanza Apr 23 '19 at 7:19
  • 1
    @bonanza Try changing the \defcounter{maxnames}{3}% in the code above to to \defcounter{maxnames}{999}% or whatever you want. If that does not help, please consider asking a new question with an MWE and more details about your setup. – moewe Apr 23 '19 at 7:30
  • the latest version of biblatex seems to bring its down definition of \mkbibcompletename which does not seem to work (I have therefore useed \renewcommand). Would it make any sense to adjust this answer based on the current developments? – bonanza Mar 23 '20 at 17:51
  • 1
    @bonanza Thanks for the hint. Code updated to avoid the name clash. – moewe Mar 23 '20 at 19:38

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.