latex3 / babel

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

hbox inside equation is problematic #285

Open Udi-Fogiel opened 4 months ago

Udi-Fogiel commented 4 months ago

see https://tex.stackexchange.com/questions/709365/inline-equation-breaks-when-adding-hebrew-text-with-the-witharrows-package for an example. Here are more minimal example

\documentclass{article}
\usepackage[bidi=basic, hebrew,provide=*]{babel}
\babelfont{rm}{David CLM}
\begin{document}
שלום $\hbox{$abc$ שלום}$
\end{document}
\documentclass{article}
\usepackage[bidi=basic, hebrew,provide=*]{babel}
\babelfont{rm}{David CLM}
\begin{document}
שלום $\hbox{abc שלום}$
\end{document}
seloumi commented 4 months ago

If \hbox start with hebrew letter we will get a correct result.

\documentclass{article}
\usepackage[bidi=basic, hebrew,provide=*]{babel}
\babelfont{rm}{DavidLibre}

\begin{document}

\begingroup
\everyhbox{‏}% Right-To-Left Mark (U+200F)
שלום $\hbox{$abc$ שלום}$

שלום $\hbox{abc שלום}$
\endgroup

\end{document}
jbezos commented 4 months ago

@Udi-Fogiel @seloumi Thanks. I usually take a short break when TeXLive is about to be published (I don't like to make any last minute changes, unless it's a severe bug). When it's frozen, I'll start investigating.

jbezos commented 3 months ago

The title summarizes very well the whole point here: \hbox inside equation is problematic. I copy here what I wrote in tex.stackexchange.com:

I’m trying to find a general solution, but below there is as a workaround [...]. Why is this happening? Well, it’s related with the fact \hbox’es [...] are used internally for quite a lot of purposes and there is no way to know if they contain real text or serve to build some special combination of letters, symbols, graphics, etc. Babel attempts to guess how to deal with them, but it may fail.

Udi-Fogiel commented 3 months ago

it’s related with the fact \hbox’es [...] are used internally for quite a lot of purposes and there is no way to know if they contain real text or serve to build some special combination of letters, symbols, graphics, etc. Babel attempts to guess how to deal with them, but it may fail.

I think it would be much easier to solve it upstream (at least in the case of big packages such as tikz). \hboxes meant for intrinsic LTR material could be flagged using a reserved attribute, or use \hpack instead of an \hbox so that the code that babel add to the hpack_filter callback won't affect this box.

jbezos commented 3 months ago

I think it would be much easier to solve it upstream (at least in the case of big packages such as tikz). \hboxes meant for intrinsic LTR material could be flagged using a reserved attribute, or use \hpack instead of an \hbox so that the code that babel add to the hpack_filter callback won't affect this box.

Indeed, in an ideal world— 🙂. But even \put in the humble picture can be used to place either text or graphics (or both). So, I’m thinking of a helper function like the following, which can be useful in the meanwhile:


\documentclass{article}
\usepackage[bidi=basic, hebrew, provide=*]{babel}
\babelfont{rm}{David CLM}

\makeatletter
\newcommand\localebox[1]{%
  {\def\bbl@insidemath{0}%
   \mbox{\foreignlanguage{\languagename}{#1}}}}

\begin{document}

אחת שתיים $\localebox{$abc$ שלום}$

אחת שתיים $\localebox{abc שלום}$

אחת שתיים $\mbox{abc שלום}$ % Just to compare

\end{document}