0

I am trying to put a conditional statement within a bib file, namely in the author field. I tried with both the ifthenelse and the iftoggle commands, but to no avail. The condition is respected, but then the author names are not expanded correctly, it thinks it is a sole author and does not replace the "and" with comma, etc.

Do you know any workaround to solve this?

Below a minimal reproducer.

\documentclass{article}
\bibliographystyle{vancouver}

\usepackage{etoolbox}%iftoggle \providetoggle{blinded} \settoggle{blinded}{false}

\usepackage{ifthen} \newcommand{\amode}{\string notblinded}

\begin{document}

iftoggle: \cite{test_article}

ifthenelse: \cite{test_article2}

correct: \cite{test_article3}

\bibliography{References} \end{document}

The References.bib file:

@article{ test_article,
  title     = {a},
  author    = {\iftoggle{blinded}{b}{c c and d d and e e}},
  journal   = {j},
  volume    = {v},
  number    = {n},
  pages     = {ps},
  doi       = {doi},
  year      = {y}
}
@article{ test_article2,
  title     = {a},
  author    = {\ifthenelse{\equal{\amode}{\string blinded}}{b}{c c and d d and e e}},
  journal   = {j},
  volume    = {v},
  number    = {n},
  pages     = {ps},
  doi       = {doi},
  year      = {y}
}
@article{ test_article3,
  title     = {a},
  author    = {c c and d d and e e},
  journal   = {j},
  volume    = {v},
  number    = {n},
  pages     = {ps},
  doi       = {doi},
  year      = {y}
}

Result:

Compiled result

Thanks in advance!

Somehow related: Use toggles in biblatex `printbibliography`

  • 2
    what is the use case? – Ulrike Fischer Sep 05 '23 at 09:19
  • Some scientific journals require that you provide a blinded version of your manuscript that hides the author names of your references. I want to quickly switch between my own working version and the one I submit to the journal. – ferdymercury Sep 05 '23 at 10:07
  • Of you could use biblatex it would be easy to define such a switch in the document itself and not in the .bib file. Is bibtex required? With plain bibtex I'm not sure, but might be possible as well. Unfortunatley, I'm not very experienced with the plain version. – lukeflo Sep 05 '23 at 10:14
  • The journal requires a strict Latex template to be followed, together with a bst bibtex style, see here: https://www.bibtex.com/s/bibliography-style-elsarticle-elsarticle-num/ I can modify though the .bst file in my folder if that would help in adding an extra expansion of the author field or something like that, for example the function format.names – ferdymercury Sep 05 '23 at 10:25
  • 1
    you could try with author = {\blind{}c c and d d and e e\endblind{}}, and then define \blind as \def\blind#1\endblind{#1} or \def\blind#1\endblind{b} (add a \newcommand\blind{} before to get an error if you overwrite some existing command. – Ulrike Fischer Sep 05 '23 at 10:47
  • Great suggestion! This works: \def\ablind#1\endablind{\iftoggle{blinded}{b}{#1}} – ferdymercury Sep 05 '23 at 12:54
  • Actually, it fails if the list of authors is too long. I get:
    <to be read again> 
                       \par 
    l.22 
    
    I suspect you've forgotten a `}', causing me to apply this
    control sequence to too much text. How can we recover?
    My plan is to forget the whole thing and hope for the best.```
    
    – ferdymercury Sep 05 '23 at 14:59
  • Edit: Not when it is too long but rather when it contains any comma like Last, First and Last2, First2, which is valid syntax for bibtex. – ferdymercury Sep 05 '23 at 15:06

0 Answers0