2

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}

enter image description here

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

enter image description here

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

Sverre
  • 20,729

2 Answers2

1

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}

enter image description here

Addition

The issue should be solved with babel version 3.62

egreg
  • 1,121,712
  • This part has been rewritten from scratch (see the following commit: https://github.com/latex3/babel/commit/4969492b424c57371cce33e10b2b941b40af405b ). – Javier Bezos Jul 20 '21 at 05:41
0

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}

David Carlisle
  • 757,742