3

I'm trying to create my own biblatex style, and I want to give an option to show titles in italics or bold.

Based on other style files, I tried this:

\newtoggle{bftitle}
\DeclareBibliographyOption{bftitle}[true]{
    \settoggle{bftitle}{#1}}
\ExecuteBibliographyOptions{bftitle=true}
\iftoggle{bftitle}{
    \DeclareFieldFormat{title}{\bfseries{#1}}
    \DeclareFieldFormat{journaltitle}{\bfseries{#1}}
    \DeclareFieldFormat{issuetitle}{\bfseries{#1}}
    \DeclareFieldFormat{maintitle}{\bfseries{#1}}
    \DeclareFieldFormat{booktitle}{\bfseries{#1}}
    \DeclareFieldFormat{citetitle}{\bfseries{#1}}
    }{}

And this:

\newbool{bftitle}
\DeclareBibliographyOption{bftitle}{
  \ifstrequal{#1}{true}
    {\global\booltrue{bftitle}}
    {\global\boolfalse{bftitle}}}
\ifbool{bftitle}{
    \DeclareFieldFormat{title}{\bfseries{#1}}
    \DeclareFieldFormat{journaltitle}{\bfseries{#1}}
    \DeclareFieldFormat{issuetitle}{\bfseries{#1}}
    \DeclareFieldFormat{maintitle}{\bfseries{#1}}
    \DeclareFieldFormat{booktitle}{\bfseries{#1}}
    \DeclareFieldFormat{citetitle}{\bfseries{#1}}
    }{}

Neither option works. Whatever I use when I call biblatex (bftitle=true or bftitle=false), the result is always the same (sometimes always bold, sometimes always italics).

I don't know if the problem could be ExecuteBibliographyOptions… I couldn't figure out how to use these commands, the documentation says very little about them.

So what am I doing wrong? Is there a better way to do what I'm trying to do?

  • Can you come up with a full MWE? That way it is easier for us to see exactly what you are seeing. If you drop the toggle and move all the formatting commands directly into the option declaration it should work. – moewe Apr 22 '16 at 7:18
  • 1
    Please not that \bfseries is a switch and not a macro (see here ), it is probably nicer to use \mkbibbold here anyway: \DeclareFieldFormat{title}{\mkbibbold{#1}}. – moewe Apr 22 '16 at 7:23
  • @moewe Thanks for the tip about mkbibbold. I also use scshape in my code, do you know if there's a macro for that? I tired googling it now but didn't find anything about it. – dbmrq Apr 22 '16 at 7:40
  • There is no dedicated biblatex wrapper for small caps, but \scshape{foo} is still wrong, use \textsc{foo} instead (or {\scshape foo} if you insist on \scshape ). – moewe Apr 22 '16 at 13:06
4

You have a 'timing issue'. The command \ExecuteBibliographyOptions applies some settings 'now' (to set defaults) but doesn't pick up any users choices. Those apply after your file has been read. As such

\ifbool{bftitle}{
    \DeclareFieldFormat{title}{\bfseries{#1}}
    \DeclareFieldFormat{journaltitle}{\bfseries{#1}}
    \DeclareFieldFormat{issuetitle}{\bfseries{#1}}
    \DeclareFieldFormat{maintitle}{\bfseries{#1}}
    \DeclareFieldFormat{booktitle}{\bfseries{#1}}
    \DeclareFieldFormat{citetitle}{\bfseries{#1}}
    }{}

will always get the value of the bool you've set up in your code, not what you've passed as an option.

You need to arrange that the settings are 'dynamic' and alter each time the option(s) are called. The typical way is to put the check 'inside' the formatting

\DeclareFieldFormat{citetitle}{\ifbool{bftitle}{\mkbibbold{#1}}{#1}}

or to make the option itself do a test

\DeclareBibliographyOption{bftitle}[true]{
    \ifstrequal{#1}{true}
     {
       \DeclareFieldFormat{title}{\mkbibbold{##1}}
       \DeclareFieldFormat{journaltitle}{\mkbibbold{##1}}
       \DeclareFieldFormat{issuetitle}{\mkbibbold{##1}}
       \DeclareFieldFormat{maintitle}{\mkbibbold{##1}}
       \DeclareFieldFormat{booktitle}{\mkbibbold{##1}}
       \DeclareFieldFormat{citetitle}{\mkbibbold{##1}}
     }
     {
       \DeclareFieldFormat{title}{##1}
       \DeclareFieldFormat{journaltitle}{##1}
       \DeclareFieldFormat{issuetitle}{##1}
       \DeclareFieldFormat{maintitle}{##1}
       \DeclareFieldFormat{booktitle}{##1}
       \DeclareFieldFormat{citetitle}{##1}
     }
}
  • Fantastic! Thank you so much. I couldn't figure out that first option, but the second one, with @moewe's correction, worked like a charm! The first option could be useful in other cases, so it would be great if you could clarify it a little. How exactly should I declare the option and the bool in that case? I tried it like in my example, changing just the DeclareFieldFormat parts to how you mentioned, but it didn't work. – dbmrq Apr 22 '16 at 7:37
  • Ha! Ok, I figured out the first option too. Thanks again! :) – dbmrq Apr 22 '16 at 7:47

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.