# Creating new commands inside the bibfile

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).

-
As far as I know: no. But a similar hack could be achieved by adding to your entry/entries: addendum = {Reprint in \cite{<bibkey>}},. Note that what this requires is an extended cycle (latex, bibtex/biber, latex, bibtex/biber, latex) since the cite command won't be 'noticed' until the second latex run. –  jon Jun 27 '12 at 7:05
You could put your definitions in a biblatex.cfg. If such a file is at a place where LaTeX can found it, it will be read after the citation and bibliography styles have been loaded. –  Ulrike Fischer Jun 27 '12 at 8:45
@jon : the downside of \cite here is that it is context-sensitive and produces a fullcitation if the reprint is after the present entry and a abbreviated citation if the reprint is in front of the entry. Since - I think - I couldn't find \shortcite command, I decided to create my own: Reprint in: Author. Title, Year. My question remains for any case in which the user wants to define his own reprint-string. –  ClintEastwood Jun 28 '12 at 7:36
@ClintEastwood -- if the entry has a shorttitle field, it will use that in the x-ref; and if you use an author-date system, it will use the last name and date only. Anyway, I think you can combine my idea with bibliography strings put in the .cfg file as suggested. You will not violate any licence: they are meant as '(user) ConFiGuration' files. biblatex.cfg even has the line '% Put your definitions here.' –  jon Jun 28 '12 at 7:46
The file is meant for user configuration. But don't edit an existing file in the main folder of biblatex - changes there can easily get lost at updates -, generate a new bibtex.cfg and put it in a local texmf tree in a similar location so that it is found first. –  Ulrike Fischer Jun 28 '12 at 9:28

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}

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


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}%

this is great news. I am glad to learn about the "related entries"-feature. One further question at this point: what is the default format of the output of the related entry? Is it a context-sensitive \cite command or is does it always produce the same string? In your example it was Title. Editor. Publisher, Year. (No location presumably because you did not enter one.) –  ClintEastwood Jul 1 '12 at 12:35
The location is printed; refer to the related:default bibliography macro defined in biblatex.def. biber makes data from related entries accessible. Unless you cite a related entry directly, it will have dataonly=true set so that it won't be printed in the bibliography. The manual gives further details on the new feature. –  Audrey Jul 1 '12 at 15:44