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

2
  • where is the bib style from? – Ulrike Fischer Mar 31 '19 at 20:26
  • @UlrikeFischer Sorry that was left over from my testing. I've changed the code to use a standard one. – Alan Munn Mar 31 '19 at 20:30
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

4
  • 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. ;-) – user121799 Apr 1 '19 at 2: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 4 '20 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.