0

I have this if case I run for deciding some options for publist. I tried to use the \ExecutePublistOptions{ } to change the publist options, but it seems this doesn't work in the .cls file/ preamble. I could import biblatex differently for every document class option, but this seems ineficcient as most of the options are the same.

I would like to modify publist options without importing biblatex every time. Is this possible? (the solution must work in preamble/ .cls file)

Here is the MWE:

\documentclass{article}

\usepackage{xcolor}
\definecolor{soft}{rgb}{0.45,0.45,0.45}
\newcommand{\softbullet}{\textcolor{soft}{\small\textbullet}\hspace{0.5em}}

\makeatletter
\newif\if@displayvon
%\DeclareOption{vonname=true}{\@displayvontrue}

\newif\if@publistnormal
%\DeclareOption{bib=normal}{\@publistnormaltrue}

\newif\if@publisthighlight
%\DeclareOption{bib=highlightname}{\@publisthighlighttrue}

\newif\if@publisthideonly
%\DeclareOption{bib=hidenameonly}{\@publisthideonlytrue}

\newcommand{\firstname}[1]{\def\@firstname{#1}}
\newcommand{\vonname}[1]{\def\@vonname{#1}}
\newcommand{\lastname}[1]{\def\@lastname{#1}}

\@publisthideonlytrue

\if@publistnormal
    \RequirePackage[%
            backend=biber,
            %bibstyle=publist,
            style=authoryear,
            hyperref=auto
        ]{biblatex}
    \AtEveryBibitem{\makebox[\bibhang][l]{\softbullet}}
\else
    \RequirePackage[%
            backend=biber,
            bibstyle=publist,
            labeldateparts=false,
            hyperref=auto
        ]{biblatex}
    \defbibenvironment{bibliography}
      {\list
         {\labelitemfont\softbullet}
         {\setlength{\leftmargin}{\bibhang}%
          \setlength{\itemsep}{\bibitemsep}%
          \setlength{\parsep}{\bibparsep}%
          \def\makelabel##1{\hss\llap{##1}}}}%
      {\endlist}
      {\item}
    \if@displayvon
        \plauthorname[\@firstname][\@vonname]{\@lastname}
    \else
        \plauthorname[\@firstname]{\@lastname}
    \fi
    \if@publisthideonly
        \ExecutePublistOptions{hlyear=false}
    \else\fi
    \if@publisthighlight
        \ExecutePublistOptions{plauthorhandling=highlight}
    \else\fi
\fi
\makeatother

\begin{filecontents}[overwrite]{sample.bib}
@book{dirac,
    title = {The Principles of Quantum Mechanics},
    author = {Paul Adrien Maurice Dirac},
    isbn = {9780198520115},
    series = {International series of monographs on physics},
    year = {1981},
    publisher = {Clarendon Press},
}
\end{filecontents}
\addbibresource{sample.bib}


\firstname{Paul Adrien Maurice}
\lastname{Dirac}

\begin{document}
Hello

\nocite{*}
\printbibliography

\end{document}

This is the currently best I can do with the if cases (that works):

Edit: seems like putting \defbibenvironment .. at the end of the publistnormal ifcase: \if@publistnormal ... \else ... \defbibenvironment \fi did not work. So this is what I have:

\if@publistnormal
    \RequirePackage[%
            backend=biber,
            %bibstyle=publist,
            style=authoryear,
            hyperref=auto
        ]{biblatex}
    \AtEveryBibitem{\makebox[\bibhang][l]{\softbullet}}
\else
    \if@publisthideonly
        \RequirePackage[%
                hlyear=false, % 
                backend=biber,
                bibstyle=publist,
                labeldateparts=false,
                hyperref=auto
            ]{biblatex}
        \defbibenvironment{bibliography}
          {\list
             {\labelitemfont\softbullet}
             {\setlength{\leftmargin}{\bibhang}%
              \setlength{\itemsep}{\bibitemsep}%
              \setlength{\parsep}{\bibparsep}%
              \def\makelabel##1{\hss\llap{##1}}}}%
          {\endlist}
          {\item}
    \else
        \if@publisthighlight
            \RequirePackage[%
                    plauthorhandling=highlight, % 
                    backend=biber,
                    bibstyle=publist,
                    labeldateparts=false,
                    hyperref=auto
                ]{biblatex}
            \defbibenvironment{bibliography}
              {\list
                 {\labelitemfont\softbullet}
                 {\setlength{\leftmargin}{\bibhang}%
                  \setlength{\itemsep}{\bibitemsep}%
                  \setlength{\parsep}{\bibparsep}%
                  \def\makelabel##1{\hss\llap{##1}}}}%
              {\endlist}
              {\item}
        \else
            \RequirePackage[%
                    backend=biber,
                    bibstyle=publist,
                    labeldateparts=false,
                    hyperref=auto
                ]{biblatex}
            \defbibenvironment{bibliography}
              {\list
                 {\labelitemfont\softbullet}
                 {\setlength{\leftmargin}{\bibhang}%
                  \setlength{\itemsep}{\bibitemsep}%
                  \setlength{\parsep}{\bibparsep}%
                  \def\makelabel##1{\hss\llap{##1}}}}%
              {\endlist}
              {\item}
        \fi
    \if@displayvon
        \plauthorname[\@firstname][\@vonname]{\@lastname}
    \else
        \plauthorname[\@firstname]{\@lastname}
    \fi
    \fi
\fi

It feels like there should be some simpler way to do this. Maybe it is possible to pass the optional directly to biblatex in \DeclareOption somehow?

It may very well also be that there is no better way to do it, in which case I'll accept it and just use what I have.

To clairify: all \if@publisthighlight is doing is including hlyear=false when importing biblatex, and \if@publisthideonly includes plauthorhandling=highlight.

2
  • 2
    as mentioned last time, don't do \let\if@publisthideonly\iftrue do \@publisthideonlytrue Nov 3 at 23:32
  • you can use \PassOptionsToPackage to pass options to a package loaded later. And you don't have to use backend=biber and hyperref=auto all the time. These are the defaults anyway. Nov 4 at 9:34

1 Answer 1

1

\ExecutePublistOptions does work in the preamble, but only after publist has been loaded (as the command is defined there).

So something like this (untested) should actually work:

    \if@publistnormal
        \RequirePackage[%
                backend=biber,
                %bibstyle=publist,
                style=authoryear,
                hyperref=auto
            ]{biblatex}
        \AtEveryBibitem{\makebox[\bibhang][l]{\softbullet}}
    \else
       \RequirePackage[%
                    backend=biber,
                    style=publist,
                    labeldateparts=false,
                    hyperref=auto
                ]{biblatex}
    \fi
    \if@publisthideonly
        \ExecutePublistOptions{hlyear=false}
         \defbibenvironment{bibliography}
              {\list
                 {\labelitemfont\softbullet}
                 {\setlength{\leftmargin}{\bibhang}%
                  \setlength{\itemsep}{\bibitemsep}%
                  \setlength{\parsep}{\bibparsep}%
                  \def\makelabel##1{\hss\llap{##1}}}}%
              {\endlist}
              {\item}
      \else
          \if@publisthighlight
               \ExecutePublistOptions{plauthorhandling=highlight}
                \defbibenvironment{bibliography}
                  {\list
                     {\labelitemfont\softbullet}
                     {\setlength{\leftmargin}{\bibhang}%
                      \setlength{\itemsep}{\bibitemsep}%
                      \setlength{\parsep}{\bibparsep}%
                      \def\makelabel##1{\hss\llap{##1}}}}%
                  {\endlist}
                  {\item}
            \else
                \defbibenvironment{bibliography}
                  {\list
                     {\labelitemfont\softbullet}
                     {\setlength{\leftmargin}{\bibhang}%
                      \setlength{\itemsep}{\bibitemsep}%
                      \setlength{\parsep}{\bibparsep}%
                      \def\makelabel##1{\hss\llap{##1}}}}%
                  {\endlist}
                  {\item}
            \fi
        \if@displayvon
            \plauthorname[\@firstname][\@vonname]{\@lastname}
        \else
            \plauthorname[\@firstname]{\@lastname}
        \fi
        \fi
    \fi

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.