распечатать список цитат с "und" на немецком языке

распечатать список цитат с "und" на немецком языке

Запуск обычного цикла pdflatex-bibtex на

\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}

дает выходной результат

Мы рады [Cam84, Cam91, Mos03].

затем следует список литературы. Как можно получить

Мы рады [Cam84, Cam91 и Mos03].

автоматически (т. е. не путем написания чего-то вроде \cite{TheTerminator, TerminatorTwo}, and \cite{TerminatorThree}) без изменения рабочего процесса, т. е. по-прежнему используя pdflatex, babel, babelbib, bibtex? Нам разрешено патчить файл стиля (спасибо @moewe!!!) и разрешено писать макросы.

решение1

Общая идея этой реализации во многом вдохновленаХуан А. Наварро'sотвечатьк Natbib: Как заменить последнюю запятую в списке цитирования на основе \citet на «и»?.

Когда LaTeX обрабатывает \citeсписок, он просто проходит по списку \@forи применяет те же шаги для каждого элемента. Насколько мне известно, пока нет простого способа узнать, что вы находитесь на последнем элементе, поэтому требуется немного хитрости, чтобы вставить другой разделитель перед последней цитатой.

Идея здесь в основном заключается в том, чтобы "задержать" цикл на один шаг за счет добавления дополнительного шага обработки после цикла. Таким образом, мы узнаем, где происходит последний шаг обработки.

\@citex— это стандартное определение ядра LaTeX и \@citexiбит, который выполняет циклическое действие.

\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}

Мы рады [CE84, Cam91 и MES03].//Мы рады [CE84 и Cam91].//Мы рады [CE84].

Поскольку стиль библиографии совершенно не соответствует ответу, я вернулся к предыдущему, babalpha-flчтобы сделать пример более доступным для тех, кто не следил за историей его babalpha-fl-gs-sortрождения и где его можно получить.

Связанный контент