[Tex/LaTex] Pass variable from LaTeX to bibtex (for easy anonymization)


I typically use a variable for my name in .bib bibliography entries, for instance:

@String {myname = "Prof. Dr. Hortensia Audactor"}
String {myname = "Anonymized" }

  title = {Wie Pflanzen hören... die Geheimnisse der Sonobotanik},
  author = myname,
  journal = {Draft: \url{http://www.inventionen.de/vortrag_audactor.html}},
  year = {2005}

… since some article submissions require anonymization. Then, in principle, I can just change the at sign @ in front of the String command, to determine which one is active; so if I want to anonymize, I'd simply make sure that instead of the above, I have something like:

String {myname = "Prof. Dr. Hortensia Audactor"}
@String {myname = "Anonymized" }

However, now I've ran into a problem, where I have to work on two articles, both fed from the same bibtex file and referring to the same citation — in the one, anonymization is required; in the other, it isn't. Which means, in essence, that now I have to maintain two .bib files — one with anonymized name, other without — if I don't want to manually change the @ sign each time I compile the one or the other article … and of course, I find either of these approaches to be a pain.

Ideally, what I'd want to do is to pass an option to the \bibliography command in the .tex file; say the article which requires anonymization would "pass a variable" to bibtex in the LaTeX code, as in:


… and then, there would be some code in the .bib file, which if it encounters anon=yes, would set the @String {myname to "Anonymized" — otherwise, the actual name would remain (which would be the case for the article with no anonymization requirements, which would call \bibliography without any arguments).

So, any ideas if what I want to do is possible? (In section "19 Some practical tricks" of Tame the BeaST there are some functions using if$, which makes me think what I'd want to do is possible — unfortunately, I cannot as of yet determine whether that is the case; EDIT: that section is for .bst files, so it's not applicable here; I wouldn't want to mess with .bst, only .bib)

Best Answer

You can include multiple bibliography files.

For instance, you can have two (very short) Bibtex files: anon.bib that defines the anonymised version of your macro and myname.bib defines it in the usual way. Then you have mybibliography.bib with everything else.

Now it is easy to use either




in your Latex source depending on which version you want. No need to edit any *.bib files.

A minimal working example.


@STRING{test = {Xxxx}}


@STRING{test = {Yyyy}}


    author = test,
    title = test,
    year = {2000}





The following files are generated by Bibtex.



\newblock Xxxx, 2000.




\newblock Yyyy, 2000.


In general, including multiple Bibtex files is a powerful technique with which you can easily control the behaviour of Bibtex by including the right combination of Bibtex files. Here is another example of the trick.