1

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

  • where is the bib style from? – Ulrike Fischer Mar 31 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 at 20:30
2

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

  • 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 at 20:54
  • @AlanMunn I added a short comment. – Ulrike Fischer Mar 31 at 21:29
  • I hope "Duck and Marmot" is only because in the field they insist on alphabetic ordering. ;-) – user121799 Apr 1 at 2:41

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.