2

This is a question about how BibTeX and TeX interact.

In this question: Apalike style several languages the OP asks for a way to get citation callouts with French in one part of the document, and English in the other part of the document. A biblatex solution is suggested, which of course works, but doesn't use natbib anymore.

I'm not trying to solve this problem directly, but instead trying to understand why it is that the following simple minded approach to the problem won't work. The approach simply makes the natbib \harvardand macro a conditional that checks for the current language, and inserts the appropriate word. I assume the problem is that at the point that \harvardand is expanded, the language name is unavailable. I'd like to understand the details of how this works, and if there's a way to do this at all using an approach along these lines.

\begin{filecontents}{\jobname.bib}
@article{twoauthors,
title={A cool paper},
author={Duck, A. and Marmot, A.},
journal={Journal of Irrelevant Science},
year={2019},
volume={1}}
\end{filecontents}

\documentclass{article}
\usepackage{natbib}
\usepackage[french,english]{babel}
\usepackage{iflang}
\bibliographystyle{agsm}
\usepackage{etoolbox}
\AtBeginDocument{\gdef\harvardand{\IfLanguageName{french}{et}{and}}}
\begin{document}
\cite{twoauthors} Manually: {Duck \harvardand\ Marmot}

\begin{otherlanguage}{french}
\cite{twoauthors} Manually: {Duck \harvardand\ Marmot}
\end{otherlanguage}
\bibliography{\jobname}

\end{document}

output of code

Alan Munn
  • 218,180

1 Answers1

3

You should make the command robust (so that it survives the travel throught the aux-file), and you should redefine it after \begin{document}.

\documentclass{article}
\usepackage{natbib}
\usepackage[french,english]{babel}
\usepackage{iflang}
\bibliographystyle{agsm}
\usepackage{etoolbox}
\begin{document}
\DeclareRobustCommand{\harvardand}{\IfLanguageName{french}{et}{and}}

\cite{twoauthors} Manually: {Duck \harvardand\ Marmot}

\begin{otherlanguage}{french}
\cite{twoauthors} Manually: {Duck \harvardand\ Marmot}
\end{otherlanguage}
\bibliography{\jobname}

\end{document}

The difference between the robust definition and the \gdef can be seen in the aux-file:

\bibcite{twoauthors}{{1}{2019}{{Duck \harvardand  \ Marmot}}{{}}}

\bibcite{twoauthors}{{1}{2019}{{Duck and\ Marmot}}{{}}}

enter image description here

Ulrike Fischer
  • 327,261
  • Thanks, Ulrike. Could you possibly add a bit of explanation as to why this solution works (since my question is really about why the simple solution doesn't work.) – Alan Munn Mar 31 '19 at 20:54
  • @AlanMunn I added a short comment. – Ulrike Fischer Mar 31 '19 at 21:29
  • I hope "Duck and Marmot" is only because in the field they insist on alphabetic ordering. ;-) –  Apr 01 '19 at 02:41
  • Thank yo very much. For some reason I cannot compile my file when using `\usepackage[french,english]{babel}', I can only compile with the english option. Would it be possible to have a solution not based on language but based on chapter? I.e. if chapter X, use "et", and for any other chapter, use "and". Thanks a lot. – user6441253 Oct 04 '20 at 21:25