5

I see this with TeXLive 2018, which includes version 3.26 of babel.sty (2018/10/16 3.26"). I think this works with some earlier versions of babel.sty, but I'm not sure where the cutoff is.

\documentclass[english]{article}
\usepackage{babel}
\usepackage{textcomp}
\renewcommand*{\LaTeX}{hello}
\begin{document}

Testing: \LaTeX

\end{document}

When I run PDFLaTeX on this, I do not see "Testing: hello" but instead see "Testing: LaTeX". Why can't I redefine the macro \LaTeX?

Note that I only see the problem if I use both packages babel and textcomp; omit either and things work as they should.

1 Answer 1

10

This happens because textcomp loads a non-ASCII encoding (ts1enc.def), and babel explicitly checks for that and, if that's the case, it changes the definition of the \LaTeX macro. The relevant part of the file:

When babel is being loaded it defines the list of non-ASCII encodings:

\newcommand\BabelNonASCII %                   vvv Here's the one loaded by textcomp
  {LGR,X2,OT2,OT3,OT6,LHE,LWN,LMA,LMC,LMS,LMU,TS1,T3,TS3}

then it saves the original definitions of \TeX and \LaTeX:

\let\org@TeX\TeX
\let\org@LaTeX\LaTeX
\let\ensureascii\@firstofone

Now, when the \begin{document} is executed, babel checks if any of the encodings defined above were loaded:

\AtBeginDocument{%
  \in@false
  \bbl@foreach\BabelNonASCII{% is there a non-ascii enc?
    \ifin@\else
      \lowercase{\bbl@xin@{,#1enc.def,}{,\@filelist,}}%
    \fi}%

if any, then it redefines \LaTeX to be \ensureascii{\org@LaTeX} (and a couple more things):

  \ifin@ % if a non-ascii has been loaded
    \def\ensureascii#1{{\fontencoding{OT1}\selectfont#1}}%
    \DeclareTextCommandDefault{\TeX}{\org@TeX}%
    \DeclareTextCommandDefault{\LaTeX}{\org@LaTeX}%
    \def\bbl@tempb#1\@@{\uppercase{\bbl@tempc#1}ENC.DEF\@empty\@@}%
    \def\bbl@tempc#1ENC.DEF#2\@@{%
      \ifx\@empty#2\else
        \bbl@ifunset{T@#1}%
          {}%
          {\bbl@xin@{,#1,}{,\BabelNonASCII,}%
           \ifin@
             \DeclareTextCommand{\TeX}{#1}{\ensureascii{\org@TeX}}%
             \DeclareTextCommand{\LaTeX}{#1}{\ensureascii{\org@LaTeX}}%
           \else
             \def\ensureascii##1{{\fontencoding{#1}\selectfont##1}}%
           \fi}%
      \fi}%
    \bbl@foreach\@filelist{\bbl@tempb#1\@@}%  TODO - \@@ de mas??
    \bbl@xin@{,\cf@encoding,}{,\BabelNonASCII,}%
    \ifin@\else
      \edef\ensureascii#1{{%
        \noexpand\fontencoding{\cf@encoding}\noexpand\selectfont#1}}%
    \fi
  \fi}

The problem is that \org@LaTeX is defined when babel is loaded, and \LaTeX is _re_defined \AtBeginDocument, so your \renewcommand is overwritten.

To overcome this you'll need to redefine \LaTeX either before babel is loaded, after the \begin{document}, or \AtBeginDocument after babel is loaded:

\documentclass{article}
% \renewcommand*{\LaTeX}{hello} % Option 1
\usepackage{babel}
\usepackage{textcomp}
% \AtBeginDocument{\renewcommand*{\LaTeX}{hello}} % Option 2
\begin{document}
% \renewcommand*{\LaTeX}{hello} % Option 3

Testing: \LaTeX

\end{document}
  1. Option 1 works because when babel is loaded, \LaTeX is hello, so \org@LaTeX becomes hello and your definition is used.

  2. Option 2 works because the \AtBeginDocument command adds the argument to the end of the token list, so your redefinition is executed after babel's. It is essentially the same as doing it after the \BeginDocument.

  3. Option 3 trivially works because nothing happens between your redefinition and the usage of the command.

This change happened in babel version 3.23, when the encodings TS1, T3, TS3 were added to the non-ASCII list:

% Line 8996 of an up-to-date (26-10-2018) `babel.dtx`:
% \changes{babel~3.23}{2018/08/28}{Added TS1, T3, TS3}
3
  • This is very helpful. This is presumably not a bug (right?), but as you point out, it is new behavior. In my case, I am dealing with a partially autogenerated LaTeX file, via Sphinx, and I think option 2 will work. Oct 26, 2018 at 20:53
  • 1
    @JohnPalmieri It's documented so it's certainly not a bug. According to the documentation it's introduced to fix a bug when using other scripts (section 1.20 Selecting scripts). I couldn't yet manage to reproduce the bug with an older version of babel... Oct 26, 2018 at 21:01
  • 2
    There was a bug, indeed, but the fix is not correct either. I'll fix it. Oct 28, 2018 at 5:19

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.