1

Running the usual pdflatex-bibtex loop on

\documentclass{article}
\usepackage[american,ngerman]{babel}%%% The book is in German.
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
  @misc{TheTerminator,
    author={James Cameron},
    title={The {Terminator}},
    year=1984,
    language={american}
  }
  @misc{TerminatorTwo,
    author={James Cameron},
    title={Terminator 2: Judgement Day},
    year=1991,
    language={american}
  }
  @misc{TerminatorThree,
    author={Jonathan Mostow},
    title={Terminator 3: Rise of the Machines},
    year=2003,
    language={american}
  }
\end{filecontents}
\usepackage{babelbib} % Multilingual bibliographies
\begin{document}
Wir schauten \cite{TheTerminator,TerminatorTwo,TerminatorThree}.
\bibliographystyle{babalpha-fl-gs-sort}%%% Avoid problematic abbreviations such as SS and SA, see https://tex.stackexchange.com/a/441877/165772. Also disabmiguate "Ber89"; see https://tex.stackexchange.com/a/472956/165772.
\bibliography{\jobname}
\end{document}

yields the output

Wir schauten [Cam84, Cam91, Mos03].

followed by the literature list. How can one get

Wir schauten [Cam84, Cam91 und Mos03].

automatically (i.e., not by writing something like \cite{TheTerminator, TerminatorTwo}, and \cite{TerminatorThree}) without changing the workflow, i.e., still using pdflatex, babel, babelbib, bibtex? We are allowed to patch the style file (thx to @moewe!!!) and allowed to write macros.

2
  • Maybe reversing the order of the languages in the options of babel might change it, because the first language set (in the new way ngerman) determines the main language of the document.
    – Max R
    Commented Mar 14, 2019 at 20:50
  • Changing the order didn't change anything :(
    – Max R
    Commented Mar 14, 2019 at 20:56

1 Answer 1

1

The general idea of this implementation is heavily inspired by Juan A. Navarro's answer to Natbib: How to replace the last comma in a \citet-based citation list with "and"?.

When LaTeX processes the \cite list, it just loops through the list with \@for and applies the same steps for each item. As far as I know there is no simple way to tell that you are at the last item yet and so it needs a bit of trickery to insert a different separator before the last cite.

The idea here is basically to "delay" the loop by one step at the cost of adding an additional processing step after the loop. That way we know where the last processing step happens.

\@citex is the standard definition from the LaTeX kernel and \@citexi is the bit that does the loop action.

\documentclass{article}
\usepackage[american,ngerman]{babel}
\usepackage{babelbib}

\makeatletter
\newcommand*{\@citexi}[1]{%
  \if@filesw\immediate\write\@auxout{\string\citation{#1}}\fi
  \@ifundefined{b@#1}
    {\hbox{\reset@font\bfseries ?}%
     \G@refundefinedtrue
     \@latex@warning
       {Citation `#1' on page \thepage \space undefined}}%
    {\@cite@ofmt{\csname b@#1\endcsname}}}

\def\@citex[#1]#2{\leavevmode
  \let\@last@citeb\relax
  \let\@citea\@empty
  \@cite
    {\@for\@citeb:=#2\do
       {\ifx\@last@citeb\relax\else
          \@citea\def\@citea{,\penalty\@m\ }%
          \@citexi{\@last@citeb}%
        \fi
        \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
        \let\@last@citeb\@citeb}%
     \ifx\@last@citeb\relax\else
       \ifx\@citea\@empty\else
         \ \btxandcomma{}\btxandshort{}\ %
       \fi
       \@citexi{\@last@citeb}%
     \fi}
    {#1}}
\makeatother

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
  @misc{TheTerminator,
    author={James Cameron and Anne Elk},
    title={The {Terminator}},
    year=1984,
    language={american}
  }
  @misc{TerminatorTwo,
    author={James Cameron},
    title={Terminator 2: Judgement Day},
    year=1991,
    language={american}
  }
  @misc{TerminatorThree,
    author={Jonathan Mostow and Anne Elk and Emma Sigfridsson},
    title={Terminator 3: Rise of the Machines},
    year=2003,
    language={american}
  }
\end{filecontents}

\begin{document}
Wir schauten \cite{TheTerminator,TerminatorTwo,TerminatorThree}.

Wir schauten \cite{TheTerminator,TerminatorTwo}.

Wir schauten \cite{TheTerminator}.

\bibliographystyle{babalpha-fl}
\bibliography{\jobname}
\end{document}

Wir schauten [CE84, Cam91 und MES03].//Wir schauten [CE84 und Cam91].//Wir schauten [CE84].

Since the bibliography style is completely irrelevant to the answer I changed back to babalpha-fl to make the example more easily accessible to those who have not followed the story of how babalpha-fl-gs-sort was born and where to get it.

You must log in to answer this question.