3

Using the moderncv + biblatex, I created the list of publications with label prefix and index number. For a specific index, I would like to include an image/icon at the bottom of the label index as shown below:

enter image description here

I was wondering if there is any way or reference to generate such customized Biblatex styles?

pippp
  • 133

2 Answers2

2

If your bibliography items are very short, an icon placed below the label number may clash with the label number of the next item. So I suggest to place the icon to the left of the label, together with the code from Audrey's answer to Creating bibliographies with biblatex and moderncv for better moderncv compatibility of the bibliography environment there is ample space there.

The icon can be taken from fontawesome5 and can be positioned with \raisebox (that bit of code is inspired by Werner's answer to How to add a symbol next to an enumerated item?) and a sprinkle of \hspace.

There are many possible ways to tell biblatex which entries are supposed to be shown with an icon. The biggest question is whether you want to tell biblatex about the icon in the .bib file or in the .tex file.

Set icon from the .bib file: options

Here I used entry options from the .bib entry, but the same principle could be applied with categories (see below).

\documentclass[british]{moderncv}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=numeric, backend=biber]{biblatex}

\usepackage{fontawesome5}

\newcommand*{\printmedalicon}{%
  \raisebox{-1pt}[0pt][0pt]{\faIcon{medal}\hspace{1em}}}

\newtoggle{bbx:showicon}
\DeclareEntryOption[boolean]{showicon}{\settoggle{bbx:showicon}{#1}}

\newbibmacro*{showmedalicon}{%
  \iftoggle{bbx:showicon}
    {\printmedalicon}
    {}}

\defbibenvironment{bibliography}
  {\list
     {\usebibmacro{showmedalicon}%
      \printtext[labelnumberwidth]{% label format from numeric.bbx
        \printfield{labelprefix}%
        \printfield{labelnumber}}}
     {\setlength{\topsep}{0pt}% layout parameters from moderncvstyleclassic.sty
      \setlength{\labelwidth}{\hintscolumnwidth}%
      \setlength{\labelsep}{\separatorcolumnwidth}%
      \leftmargin\labelwidth%
      \advance\leftmargin\labelsep}%
      \sloppy\clubpenalty4000\widowpenalty4000}
  {\endlist}
  {\item}

\moderncvstyle{classic}
\moderncvcolor{burgundy}
\firstname{Jane}
\familyname{Doe}


\begin{filecontents}{\jobname.bib}
@book{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  date    = {1980},
  options = {showicon},
}
@book{elk,
  author  = {Anne Elk},
  title   = {A Theory on Brontosauruses},
  date    = {1972},
  options = {showicon},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}


\begin{document}
\nocite{sigfridsson,aksin,appleby,elk}
\printbibliography
\end{document}

Bibliography: Two items have a medal icon on the left

Set icon from the .tex file: Categories

\documentclass[british]{moderncv}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=numeric, backend=biber]{biblatex}

\usepackage{fontawesome5}

\newcommand*{\printmedalicon}{%
  \raisebox{-1pt}[0pt][0pt]{\faIcon{medal}\hspace{1em}}}

\DeclareBibliographyCategory{showicon}

\newbibmacro*{showmedalicon}{%
  \ifcategory{showicon}
    {\printmedalicon}
    {}}

\defbibenvironment{bibliography}
  {\list
     {\usebibmacro{showmedalicon}%
      \printtext[labelnumberwidth]{% label format from numeric.bbx
        \printfield{labelprefix}%
        \printfield{labelnumber}}}
     {\setlength{\topsep}{0pt}% layout parameters from moderncvstyleclassic.sty
      \setlength{\labelwidth}{\hintscolumnwidth}%
      \setlength{\labelsep}{\separatorcolumnwidth}%
      \leftmargin\labelwidth%
      \advance\leftmargin\labelsep}%
      \sloppy\clubpenalty4000\widowpenalty4000}
  {\endlist}
  {\item}

\moderncvstyle{classic}
\moderncvcolor{burgundy}
\firstname{Jane}
\familyname{Doe}


\addtocategory{showicon}{sigfridsson,nussbaum}

\addbibresource{biblatex-examples.bib}


\begin{document}
\nocite{sigfridsson,aksin,worman,nussbaum}
\printbibliography
\end{document}

Bibliography with medal icons

moewe
  • 175,683
1

An alternative approach would be to adapt the begentry bibmacro to display the icon in the left margin. I haven’t tested this with numerical bibliography styles, but it works with author–year styles.

More precisely, I use it to include icons that are linked to DOIs and URLs (inspired by the American Economic Review):

% !BIB program = biber

\documentclass{article}

\usepackage{fontawesome5} \usepackage[colorlinks = true, urlcolor = blue]{hyperref}

\usepackage[backend = biber, bibstyle = authoryear]{biblatex} \renewbibmacro*{begentry}{% \hspace{-1.67em}% Protrude into left margin \makebox[1.67em][l]{% \iffieldundef{doi}{% Check if DOI provided % DOI not provided: \iffieldundef{url}{% Check if URL provided % URL not provided: Print nothing }{% % URL provided: \href{% \thefield{url}% Link to URL }{% \raisebox{0.1ex}{\footnotesize\faIcon{external-link-alt}}% Print icon } } }{% % DOI provided: \href{% https://doi.org/\thefield{doi}% Link to DOI website }{% \raisebox{0.067ex}{\small\faIcon[regular]{file-alt}}% Print icon }% }% }% } %\DeclareFieldFormat{doi}{} % Suppress output of DOI %\DeclareFieldFormat{url}{} % Suppress output of URL \addbibresource{biblatex-examples.bib}

\begin{document}

\nocite{markey, nussbaum, sigfridsson, worman} \printbibliography

\end{document}

This is the output:

Output with icons and DOI/URL

If you consider printing the DOI and URL unnecessary, you can suppress output of these fields via

\DeclareFieldFormat{doi}{}  % Suppress output of DOI
\DeclareFieldFormat{url}{}  % Suppress output of URL

This makes the bibliography less cluttered:

Output with icons and without DOI/URL

  • Thanks for this well-documented and easy-to-follow example! My document uses numeric citation style, and I found that works too, just requires a little horizontal adjustments. But in the end I simply replaced begentry with finentry and let the icon show after \finentry. I would never have figured this out without your example :-) Can't post code here, so I posted my version on my linkblog https://links.solarchemist.se/shaare/iyy4lQ – solarchemist Jul 14 '23 at 02:05