[Tex/LaTex] Creating new commands inside the bibfile

biblatexbibliographiesbibtexmacros

Is it possible to create a new command by \newcommand or \def "inside" the .bib-file?

I am using LuaLaTeX and biblatex and organize my bibliography with BibDesk on a mac. I also store information about reprints of paper x in collection y. I add this information in the Addendum-field of biblatex by something like

\bibstring{reprintin}\intitlepunct\addspace\citeauthor{author:1986}\labelnamepunct\addspace\citetitle{author:1986}\addcomma\space\citeyear{author:1986}

etc.

For that I had to define some bibstrings in the preamble fo the .tex-files:

\NewBibliographyString{reprintin}
\DefineBibliographyStrings{american}{
    reprintin = {Reprint in},
    }
\DefineBibliographyStrings{british}{
    reprintin = {Reprint in},
    }
\DefineBibliographyStrings{german}{
    reprintin = {Nachdruck in},
    }
\DefineBibliographyStrings{ngerman}{
    reprintin = {Nachdruck in},
    }

I now would like to create a newcommand \bibreprintin that allows me to just prompt in the addendum-field \bibreprintin{author:1986} instead of entering the above code bibstring{reprintin} ....

Thereby I'd enable myself to change the look of the reprint-information later with "one click" should it become necessary later, and also make it safe that all reprint information for all publications in my bibliorgaphy look the same.

My question now is, if there is any possibility to use commands like \def, \newcommand, and \NewBibliographyString inside the .bib-file (for this is only one file) and not just inside every single .tex-file (for these are many different files I am working on).

Best Answer

You can define (La)TeX commands in the bib file via @preamble and the execute field. The latter is intended for definitions on a per-entry basis.

New bibliography strings should be initialized elsewhere, in one of:

  • User configuration file (biblatex.cfg)
  • Document preamble (tex file)
  • All relevant localization modules (lbx files)
  • Style files (bbx or cbx)

For your case Ulrike's suggestion (the configuration file) seems most appropriate.

Reprints are now best handled with the "related entries" feature in the soon-to-be-released development versions of biblatex and biber. Here's an example (using only the tex file, for simplicity).

\documentclass{article}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[backend=biber]{biblatex}
\usepackage{hyperref}

\NewBibliographyString{reprintin}
\DefineBibliographyStrings{english}{reprintin = {Reprint in}}
\DefineBibliographyStrings{german}{reprintin = {Nachdruck in}}

\renewcommand*{\relatedpunct}{\intitlepunct}

\begin{filecontents}{\jobname.bib}
@article{orwell,
  title = {Reflections on Gandhi},
  author = {Orwell, George},
  year = {1949},
  journal = {Partisan Review},
  number = {6},
  pages = {85--92},
  related = {gariepy},
  relatedtype = {reprintin}}
@book{gariepy,
  title = {Twentieth-Century Literary Criticism},
  editor = {Gariepy, Jennifer},
  volume = {59},
  year = {1995},
  publisher = {Gale}}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\cite{orwell}
\printbibliography
\end{document}

enter image description here

Related entry information is formatted by the bibliography macro related:default defined in biblatex.def. This format can be overridden by defining a bibliography macro related:<relatedtype> that takes the related entry key as a single argument. The following will emulate the formatting you currently do in the addendum field.

\newbibmacro*{related:reprintin}[1]{%
  \entrydata{#1}{%
    \printnames{labelname}%
    \setunit{\labelnamepunct}%
    \printfield[citetitle]{title}%
    \setunit{\addcomma\space}%
    \printfield{year}}}