在 Babel 存在的情况下,scrltt2 的自定义带字母编号的 \thebibliography 不起作用

在 Babel 存在的情况下,scrltt2 的自定义带字母编号的 \thebibliography 不起作用

我想在不提供参考书目的字母类别中使用按字母顺序编号的参考书目(scrlttr在我的情况下,但下面提供的示例letter也适用于)。基于这个答案我想出了一小段代码,其运行效果非常令人满意 — — 直到我加载 babel我也需要的包。

我的调查显示,babel似乎提供了自己的定义\@citex,并且它与纯 LaTeX 有很大不同。具体来说,\org@@citex似乎是我必须\csname b@\@citeb \endcsname使用将存储在宏中的数字转换为字母数字的地方\@Alph

> \@citex=macro:
[#1]#2->\@safe@activestrue 
        \edef \@tempa {#2}\@safe@activesfalse \org@@citex [#1]{\@tempa }.

> \org@@citex=macro:
[#1]#2->\leavevmode \let \@citea \@empty 
        \@cite {\@for \@citeb :=#2\do {%
        \@citea \def \@citea {,\penalty \@m \ }%
        \edef \@citeb {\expandafter \@firstofone \@citeb \@empty }%
        \if@filesw \immediate \write \@auxout {\string \citation {\@citeb }}\fi
        \@ifundefined {b@\@citeb }%
          {\hbox {\reset@font \bfseries ?}\G@refundefinedtrue \@latex@warning {Citation `\@citeb ' on page \thepage \space undefined}}%
          {\@cite@ofmt {\csname b@\@citeb \endcsname }}%  <--- this is what I would like to modify, I think
        }}{#1}.

但是,与普通的 LaTeX 版本相比,babel此命令不仅存储数字,而且前面还有\@safe@activesfalse,我不知道如何去掉它。例如,\csname b@test1 \endcsname包含:

> \b@test1=macro:
->\@safe@activesfalse 1.

对于我的目的来说它应该只包含1

我想知道如何修复这个问题,但我也希望得到关于如何使这样的代码更加健壮以抵御其他软件包可能对它造成的诸多影响的意见。

可以通过以下链接获取最小示例这个要点和这里:

\documentclass{scrlttr2}

%% These two lines will break everything:
% \usepackage[english,german]{babel}
% \selectlanguage{english}

%% Some of the following taken from
%% https://tex.stackexchange.com/questions/18033/using-bibtex-with-letter-class
\makeatletter
\newenvironment{thebibliography}[1]
{\list{\@biblabel{\@Alph\c@enumiv}}%  LATIN LETTERS AS REFERENCES
  {\settowidth\labelwidth{\@biblabel{#1}}%
    \leftmargin\labelwidth
    \advance\leftmargin\labelsep
    \usecounter{enumiv}%
    \let\p@enumiv\@empty
    \renewcommand\theenumiv{\@Alph\c@enumiv}}% SAME HERE
  \sloppy
  \clubpenalty4000
  \@clubpenalty \clubpenalty
  \widowpenalty4000%
  \sfcode`\.\@m}
{\def\@noitemerr
  {\@latex@warning{Empty `thebibliography' environment}}%
  \endlist}
\newcommand\newblock{\hskip .11em\@plus.33em\@minus.07em}
\let\bibsection\relax
\def\section*#1{\relax}
\def\@citex[#1]#2{\leavevmode 
  \let \@citea \@empty \@cite {%
    \@for \@citeb :=#2\do {%
      \@citea \def \@citea {,\penalty \@m \ }%
      \edef \@citeb {\expandafter \@firstofone \@citeb \@empty }%
      \if@filesw \immediate \write \@auxout {\string \citation {\@citeb }}\fi%
      \@ifundefined {b@\@citeb }%
      {\hbox {\reset@font \bfseries ?}\G@refundefinedtrue \@latex@warning {Citation `\@citeb ' on page \thepage \space undefined}}%
      {\@cite@ofmt {\expandafter\@Alph\csname b@\@citeb \endcsname }}%
    }%
  }%
  {#1}%
}
\makeatother

\bibliographystyle{unsrt}
\begin{document}
\begin{letter}{TeX.SE}

  \opening{Hello,}

  When writing scientific reports I like to refer to the references in
  the main document using the citation style that has been used
  there. Sometimes I need to mention additional references, and for
  those I like to use capital latin characters to number them. Of
  course I rely on Bib\TeX\ when writing reports. 

  Thus, I like to cite \cite{test1} and \cite{test2} separately, but
  also \cite{test1,test2}. This all works just fine, as long as I do
  not include the babel package.

  How can I make commands defined above more robust?

  \vspace{2cm}
  \noindent References:

  \begin{thebibliography}{A}
  \bibitem{test1} First reference.
  \bibitem{test2} Second reference.
  \end{thebibliography}

\end{letter}
\end{document}

答案1

的定义\@citex是无用的,因为它与内核的相同。您不需要定义,\bibsection因为您没有使用natbib,也不需要执行\def\section*#1{}

问题在于,你\@bibitem总是写数字,而你想要的是字母。

不要\selectlanguage在序言中发布。最后指定主要语言(或使用main=<languagename>)。

\documentclass{scrlttr2}

\usepackage[ngerman,english]{babel} % english is the default

\makeatletter
% redefine \@bibitem to write out the counter and not a number
\def\@bibitem#1{%
  \item
  \if@filesw
    \immediate\write\@auxout{\string\bibcite{#1}{\csname the\@listctr\endcsname}}%
  \fi\ignorespaces
}
\newenvironment{thebibliography}[1]
  {\list{\@biblabel{\Alph{enumiv}}}%  LATIN LETTERS AS REFERENCES
    {\settowidth\labelwidth{\@biblabel{#1}}%
     \leftmargin\labelwidth
     \advance\leftmargin\labelsep
     \usecounter{enumiv}}%
   \let\p@enumiv\@empty
   \renewcommand\theenumiv{\Alph{enumiv}}% SAME HERE
   \sloppy
   \clubpenalty4000
   \@clubpenalty \clubpenalty
   \widowpenalty4000
   \sfcode`\.\@m}
  {\def\@noitemerr{\@latex@warning{Empty `thebibliography' environment}}%
   \endlist}
\newcommand\newblock{\hskip .11em\@plus.33em\@minus.07em}
\makeatother

\bibliographystyle{unsrt}

\begin{document}
\begin{letter}{TeX.SE}

  \opening{Hello,}

  When writing scientific reports I like to refer to the references in
  the main document using the citation style that has been used
  there. Sometimes I need to mention additional references, and for
  those I like to use capital latin characters to number them. Of
  course I rely on Bib\TeX\ when writing reports. 

  Thus, I like to cite \cite{test1} and \cite{test2} separately, but
  also \cite{test1,test2}. This all works just fine, as long as I do
  not include the babel package.

  How can I make commands defined above more robust?

  \vspace{2cm}
  \noindent References:

  \begin{thebibliography}{A}
  \bibitem{test1} First reference.
  \bibitem{test2} Second reference.
  \end{thebibliography}

\end{letter}
\end{document}

在此处输入图片描述

相关内容