latex3 / babel

The babel system for LaTeX, LuaLaTeX and XeLaTeX
LaTeX Project Public License v1.3c
123 stars 34 forks source link

`\@tempa` in `\@citex` can be overwritten. #277

Closed lstonys closed 4 months ago

lstonys commented 5 months ago

babel pushes citation label as \@tempa to \@citex but this command is too general and can be changed inside \@citex. It would be safer to expand \@tempa before passing it to \@citex (I had an issue with this case but can't find it now).

Babel code

  \bbl@redefine\@citex[#1]#2{%
    \@safe@activestrue\edef\@tempa{#2}\@safe@activesfalse
    \org@@citex[#1]{\@tempa}}
  \AtBeginDocument{%
    \@ifpackageloaded{natbib}{%
    \def\@citex[#1][#2]#3{%
      \@safe@activestrue\edef\@tempa{#3}\@safe@activesfalse
      \org@@citex[#1][#2]{\@tempa}}%
    }{}}

As a fix I had this code in my class file.

\AfterPackage{babel}{
  \def\@citex[#1]#2{%
    \@safe@activestrue\edef\@tempa{#2}\@safe@activesfalse
    \edef\@tmp{\noexpand\org@@citex[\unexpanded{#1}]{\@tempa}}%
    \@tmp
    }
  \AtBeginDocument{%
    \@ifpackageloaded{natbib}{%
      \def\@citex[#1][#2]#3{%
        \@safe@activestrue\edef\@tempa{#3}\@safe@activesfalse
        \edef\@tmp{\noexpand\org@@citex[\unexpanded{#1}][\unexpanded{#2}]{\@tempa}}%
        \@tmp}
    }{}}
  }

could it be fixed in the future version?