8000 hbox inside equation is problematic · Issue #285 · latex3/babel · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

hbox inside equation is problematic #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Udi-Fogiel opened this issue Feb 17, 2024 · 17 comments
Open

hbox inside equation is problematic #285

Udi-Fogiel opened this issue Feb 17, 2024 · 17 comments
Labels
⚙️ under study Exact behavior to be decided

Comments

@Udi-Fogiel
Copy link
Contributor
Udi-Fogiel commented Feb 17, 2024

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
Copy link
Contributor
seloumi commented Feb 17, 2024

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
Copy link
Contributor
jbezos commented Feb 17, 2024

@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
Copy link
Contributor
jbezos commented Mar 7, 2024

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
Copy link
Contributor Author

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
Copy link
Contributor
jbezos commented Mar 8, 2024

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}

@jbezos jbezos added the ⚙️ under study Exact behavior to be decided label Mar 9, 2024
@Udi-Fogiel
Copy link
Contributor Author

@jbezos I worked on a port of ConTeXt's code to OpTeX, and it also works with LaTeX and Plain (the requirement is a subset of luaotfload). The code only implements character level bidi, it is not about tabulars or page layout. You can find it here https://github.com/Udi-Fogiel/UAX9-LuaTeX. I thinght about mentioning it as this code works with the examples here and the one in #301.

@jbezos
Copy link
Contributor
jbezos commented Jan 19, 2025

@Udi-Fogiel 👍 Great! One of the reasons for requiring the bidi option was to open babel to different options, without imposing any in particular. I’ll take a look at it and make some tests.

@jbezos
Copy link
Contributor
jbezos commented Jan 19, 2025

@Udi-Fogiel A question. How fast is it? At first glance, it seems it translates more or less directly the Unicode implementation of the algorithm, with lots of loops, something I avoided for efficiency reasons.

@Udi-Fogiel
Copy link
Contributor Author

@jbezos I did not test it with long documents yet, but I think it is slower than your code. In ConTeXt itself it is probably even slower as the data file is huge.

The code originates from a port of minibidi.c from Arabeyes to Lua made by Khaled Hosny:
https://github.com/khaledhosny/context-bidi

Even after making the original code running, it had many problems so I eventually decided to use the more up to date code from ConTeXt.

I also tried to port your code to OpTeX, and it almost worked smoothly, I don't remember exactly what broke but I think it was related to code written outside the Lua module in TeX, so it got a bit convoluted...

@Udi-Fogiel
Copy link
Contributor Author

BTW, any suggestions for a package name? CTAN does not like uax9, and bidi, unicode-bidi and luabidi are taken.

@jbezos
Copy link
Contributor
jbezos commented Jan 19, 2025

Naming things is always a headache for me! 🙂

@jbezos
Copy link
Contributor
jbezos commented Jan 21, 2025

@Udi-Fogiel It passed my tests with RTL as the main text and LTR as secondary one. On the other hand, embedded Arabic in LTR text is not correctly rendered (without markup). The reason is the directionality of characters is not enough and the font with the proper language system is also required. This is something babel already does, but I’m not sure how easy it will be to integrate your method with babel. I have to investigate.

@Udi-Fogiel
Copy link
Contributor Author

@jbezos Can you give an example with the expected output?

@Udi-Fogiel
Copy link
Contributor Author

If you have one with Hebrew it will be better, but Arabic is fine as well.

@Udi-Fogiel
Copy link
Contributor Author
Udi-Fogiel commented Jan 21, 2025

but I’m not sure how easy it will be to integrate your method with babel.

And if this will be the case, maybe the other way around will be easier, i.e. adding an option in unibidi-lua to address this. I'll just need to understand what this is about...

@jbezos
Copy link
Contributor
jbezos commented Jan 24, 2025
\documentclass{article}
\usepackage[bidi=basic]{babel}
\babelfont{rm}{FreeSerif}
\babelprovide[ fonts]{arabic}
\begin{document}

بى 19 az 29 تى 19 29 39 ثى 49-59 سى 69/79 شى 19.29 صى 39,49

\end{document}

prints correctly:
Image

However, the following:

\documentclass{article}
\usepackage{unibidi-lua}
\usepackage{babel}
\babelfont{rm}{FreeSerif}
\babelprovide[ fonts]{arabic}
\begin{document}

بى 19 az 29 تى 19 29 39 ثى 49-59 سى 69/79 شى 19.29 صى 39,49

\end{document}

prints:
Image

I’d like to note that, as there is already a (mostly) working bidi mechanism in babel, having another one is not regrettably one of my priorities, particularly because its seems adapting it is not straightforward.

@Udi-Fogiel
Copy link
Contributor Author

\documentclass{article}
\usepackage[bidi=basic]{babel}
\babelfont{rm}{FreeSerif}
\babelprovide[ fonts]{arabic}
\begin{document}

بى 19 az 29 تى 19 29 39 ثى 49-59 سى 69/79 شى 19.29 صى 39,49

\end{document}
prints correctly: Image

However, the following:

\documentclass{article}
\usepackage{unibidi-lua}
\usepackage{babel}
\babelfont{rm}{FreeSerif}
\babelprovide[ fonts]{arabic}
\begin{document}

بى 19 az 29 تى 19 29 39 ثى 49-59 سى 69/79 شى 19.29 صى 39,49

\end{document}
prints: Image

Thank you for the example. Since you seem to know what the problem is, when you will have time, can you describe what needs to be done, or even just points me where in the code babel address it?

I opened a ticket if you prefer to describe it there, but here is fine as well.

I’d like to note that, as there is already a (mostly) working bidi mechanism in babel, having another one is not regrettably one of my priorities, particularly because its seems adapting it is not straightforward.

I mainly ported the code to be used with OpTeX, so I don't have a strong opinion on whether it should be integrated with babel, this is really up to you. But I would like to fix the bug you found... any help is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️ under study Exact behavior to be decided
Projects
None yet
Development

No branches or pull requests

3 participants
0