latex3 / babel

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

extras layout is broken #246

Closed Udi-Fogiel closed 1 year ago

Udi-Fogiel commented 1 year ago

The extras layout is patching \underline with \bbl@sreplace\underline{$\@@underline}{\bbl@nextfake$\@@underline}, but \underline was robustified a few years back.

I think this patch fails as \bbl@sreplace is not really aware of robustified commands (and the output they give in \meaning).

Here is a small example to demonstrate the error

\documentclass{article}
\usepackage[layout = extras]{babel}

\begin{document}

\end{document}

With \xpatchcmd it seems to work:

\documentclass{article}

\usepackage[bidi = basic, hebrew, provide=*, layout = tabular]{babel}

\babelfont[hebrew]{rm}{David CLM}

\usepackage{xpatch}
\makeatletter
\xpatchcmd\underline{$\@@underline}{\bgroup\bbl@nextfake$\@@underline}{}{}
\xpatchcmd\underline{$\relax}{$\egroup\relax}{}{}
\makeatother

\begin{document}
    \underline{שלום $C^n$}
\end{document}

or maybe redefinition would be preferable:

\documentclass{article}

\usepackage[bidi = basic, hebrew, provide=*, layout = tabular]{babel}

\babelfont[hebrew]{rm}{David CLM}

\makeatletter
\DeclareRobustCommand\underline[1]{%
    \relax
    \ifmmode\@@underline{#1}%
    \else 
    \bgroup\bbl@nextfake$\@@underline{\hbox{#1}}\m@th$\egroup\relax\fi} 
\makeatother

\begin{document}
    \underline{שלום $C^n$}
\end{document}

Related post from TeX.SE

jbezos commented 1 year ago

Fixed in https://github.com/latex3/babel/commit/ea1b21935952d73638a8be4fbd23ba331ff1eec7