BibTeX, biblatex and biberWeird Problem with Cmd to Bold Certain Bib Entries

Information and discussion about BiBTeX - the bibliography tool for LaTeX documents.
Post Reply
ValeYard
Posts: 8
Joined: Thu Mar 01, 2018 1:22 pm

Weird Problem with Cmd to Bold Certain Bib Entries

Post by ValeYard »

So, at some point I added the code below to bold entries in the bib file which have the keyword keywords = {bold}.

I need to do this for a massive report, in which in each section some references should be bolded.

The weird thing is that, if this code is present in the main .tex doc's preamble, after printing the bibliography, the formatting of the paragraphs is shot. There is no indent anymore at the beginning of paragraphs and the page margin is smaller.

I haven't built a minimal example yet, but perhaps I forgot to close something obvious in this code?


\usepackage{etoolbox} % for \apptocmd

% At the start of every bib item: if keyword “bold” is present, begin a group and switch to bold

\AtEveryBibitem{%
\ifkeyword{bold}{\begingroup\bfseries}{\begingroup}%
}

% At the end of every bib item, append an \endgroup to close the group.
\apptocmd{\finentry}{%
\ifkeyword{bold}{\endgroup\bfseries}{\endgroup}%
}{}{}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
ValeYard
Posts: 8
Joined: Thu Mar 01, 2018 1:22 pm

Re: Weird Problem with Cmd to Bold Certain Bib Entries

Post by ValeYard »

I messed up the code:
No second \bfseries, but it doesn't make a difference for the problem. I'm kinda desperate to fix this, as I need to function and was super happy when I thought it was working.


\usepackage{etoolbox} % for \apptocmd

% At the start of every bib item: if keyword “bold” is present, begin a group and switch to bold
\AtEveryBibitem{%
\ifkeyword{bold}{\begingroup\bfseries}{\begingroup}%
}

% At the end of every bib item, append an \endgroup to close the group.
\apptocmd{\finentry}{%
\ifkeyword{bold}{\endgroup}{\endgroup}%
}{}{}
ValeYard
Posts: 8
Joined: Thu Mar 01, 2018 1:22 pm

Re: Weird Problem with Cmd to Bold Certain Bib Entries

Post by ValeYard »

For anyone trying to do the same thing, this code does the job:

% Declare a custom category
\DeclareBibliographyCategory{bold}

% Assign entries with "bold" keyword to the category
\AtEveryBibitem{%
\iffieldequalstr{keywords}{bold}
{\addtocategory{bold}{\thefield{entrykey}}}
{}%
}

% Apply bold formatting to entries in that category
\AtEveryBibitem{%
\ifcategory{bold}
{\bfseries}
{}%
}
Post Reply