# Babel and hyperref prevent changes to the \LaTeX logo

I once copied the definition of the \LaTeX command, put it as an argument to \renewcommand{}{} in order to tweak it to the font I was using. I've noticed that my redefinition has not had any effect for quite a while, and I've narrowed it down to it being due to both babel and hyperref being loaded.

In this MWE, I've changed the original \kern -.36em to \kern -.99em so that the change would be clearly visible. With both babel and hyperref loaded, the \LaTeX logo appears unchanged:

\documentclass{article}

\usepackage{babel}
\usepackage{hyperref}
\makeatletter
\renewcommand{\LaTeX}{L\kern -.99em{\sbox \z@ T\vbox to\ht \z@ {\hbox {\check@mathfonts \fontsize \sf@size \z@ \math@fontsfalse \selectfont A}\vss }}\kern -.15em\TeX}
\makeatother

\begin{document}

\LaTeX

\end{document}


With any of the two packages removed, this is the output:

My question is, how can I redefine the \LaTeX logo while at the same time load babel and hyperref?

• Do you know about metalogo? Jul 19 at 17:43

The explanation is in lines 667–702 of babel.sty

    667 \bbl@trace{Encoding and fonts}
668 \newcommand\BabelNonASCII{LGR,X2,OT2,OT3,OT6,LHE,LWN,LMA,LMC,LMS,LMU,PU,PD1}
669 \newcommand\BabelNonText{TS1,T3,TS3}
670 \let\org@TeX\TeX
671 \let\org@LaTeX\LaTeX
672 \let\ensureascii\@firstofone
673 \AtBeginDocument{%
674   \in@false
675   \bbl@foreach\BabelNonASCII{% is there a text non-ascii enc?
676     \ifin@\else
677       \lowercase{\bbl@xin@{,#1enc.def,}{,\@filelist,}}%
678     \fi}%
679   \ifin@ % if a text non-ascii has been loaded
680     \def\ensureascii#1{{\fontencoding{OT1}\selectfont#1}}%
681     \DeclareTextCommandDefault{\TeX}{\org@TeX}%
682     \DeclareTextCommandDefault{\LaTeX}{\org@LaTeX}%
683     \def\bbl@tempb#1\@@{\uppercase{\bbl@tempc#1}ENC.DEF\@empty\@@}%
684     \def\bbl@tempc#1ENC.DEF#2\@@{%
685       \ifx\@empty#2\else
686         \bbl@ifunset{T@#1}%
687           {}%
688           {\bbl@xin@{,#1,}{,\BabelNonASCII,\BabelNonText,}%
689            \ifin@
690              \DeclareTextCommand{\TeX}{#1}{\ensureascii{\org@TeX}}%
691              \DeclareTextCommand{\LaTeX}{#1}{\ensureascii{\org@LaTeX}}%
692            \else
693              \def\ensureascii##1{{\fontencoding{#1}\selectfont##1}}%
694            \fi}%
695       \fi}%
696     \bbl@foreach\@filelist{\bbl@tempb#1\@@}%  TODO - \@@ de mas??
697     \bbl@xin@{,\cf@encoding,}{,\BabelNonASCII,\BabelNonText,}%
698     \ifin@\else
699       \edef\ensureascii#1{{%
700         \noexpand\fontencoding{\cf@encoding}\noexpand\selectfont#1}}%
701     \fi
702   \fi}


which basically check, at begin document, whether some “strange” encoding has been loaded. In this case, \LaTeX (and \TeX, for what it's worth) is changed to be an encoding specific command, using as replacement text the meaning of \LaTeX valid when babel.sty has been loaded.

Why this is done is not difficult to understand: the LGR encoding has different glyphs in the standard ASCII positions and several others in the \BabelNonASCII list do as well. In this case, hyperref loads PU and PD1.

Solution: refresh also the meaning of \org@LaTeX. But probably there should be a different way to cope with this at the babel level, perhaps omitting PU and PD1 from the list.

\documentclass{article}

\usepackage{babel}
\usepackage{hyperref}

\makeatletter
\renewcommand{\LaTeX}{L\kern -.99em{\sbox \z@ T\vbox to\ht \z@ {\hbox {\check@mathfonts \fontsize \sf@size \z@ \math@fontsfalse \selectfont A}\vss }}\kern -.15em\TeX}
\let\org@LaTeX\LaTeX
\makeatother

\begin{document}

\LaTeX

\end{document}


The issue should be solved with babel version 3.62

hyperref and babel between them conspire to make this an encoding-specific command so one way is simply to define it (for OT1 here) or for T1 if you are using that, or TU for Unicode fonts in XeLaTeX or LuaLaTeX.

\documentclass{article}

\usepackage{babel}
\usepackage{hyperref}
\makeatletter

\DeclareTextCommand{\LaTeX}{OT1}{L\kern -.99em{\sbox \z@ T\vbox to\ht \z@ {\hbox {\check@mathfonts \fontsize \sf@size \z@ \math@fontsfalse \selectfont A}\vss }}\kern -.15em\TeX}
\makeatother

\begin{document}

\LaTeX

\end{document}

• no it is not hyperref's fault. babel detects at begin document that puenc.def has been loaded and then reverts the \LaTeX definition. No idea why it thinks that puenc is a "non-ascii encoding". Jun 19 at 14:41
• @UlrikeFischer I was going to check exactly why that was happening. Can I blame you anyway? Jun 19 at 14:43
• A simple \g@addto@macro\@filelist{,puenc.def} has the same effect, one doesn't need to load hyperref. Jun 19 at 14:46
• @UlrikeFischer I changed the wording but suggested the same fix for now. Jun 19 at 14:49
• Actually, I'm using lualatex, loading a font with fontspec, so I assume this trick won't work? My MWE uses pdflatex, since I got the exact same result with pdflatex, xelatex and lualatex. Jun 19 at 15:03