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}
Option 1 works because when babel
is loaded, \LaTeX
is hello
, so \org@LaTeX
becomes hello
and your definition is used.
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
.
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}