2

I use Latex and babel to do my homework in Hebrew. I also use the witharrows package to make arrows explaining steps in equations. It usually works fine:

However, when I try to add Hebrew text to explain what I did, the inline equation in the \Arrow{} breaks and uses RTL direction, which is obviously wrong for math:

Why does this happen and how can I fix this?

Here's a MWE:

\documentclass[a4paper, 12pt]{article}

\PassOptionsToPackage{no-math}{fontspec}

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

% For Hebrew
\babelprovide[main, import, alph=letters, Alph=letters]{hebrew}
\babelprovide[import]{english}

% For English
% \babelprovide[main, import]{english}
% \babelprovide[import, alph=letters, Alph=letters]{hebrew}

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

\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{witharrows}

% witharrows options
\WithArrowsOptions{displaystyle}

\tikzset{text=.}
\tikzset{
    WithArrows/arrow/.append style = {
        font= \small
    }
}

\begin{document}
נחשב את הגבול
\( \lim_{x \to \infty} f(x) \):
\begin{DispWithArrows*}
    L &= \lim_{x \to \infty} f(x) \\
    &= \lim_{x \to \infty} xP(x) e^{-x^2} \Arrow{\( Q(x) \coloneq xP(x) \) פולינום} \\
    &= \lim_{x \to \infty} Q(x) e^{-x^2}
\end{DispWithArrows*}
\end{document}
1

2 Answers 2

0
+50

I don't have any explanation for that problem but, as workaround, you can put the equation in a \hbox of TeX.

\documentclass[a4paper, 12pt]{article}

\PassOptionsToPackage{no-math}{fontspec}

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

% For Hebrew
\babelprovide[main, import, alph=letters, Alph=letters]{hebrew}
\babelprovide[import]{english}

% For English
% \babelprovide[main, import]{english}
% \babelprovide[import, alph=letters, Alph=letters]{hebrew}

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

\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{witharrows}

% witharrows options
\WithArrowsOptions{displaystyle}

\tikzset{text=.}
\tikzset{
    WithArrows/arrow/.append style = {
        font= \small
    }
}

\begin{document}
נחשב את הגבול
\( \lim_{x \to \infty} f(x) \):
\begin{DispWithArrows*}
    L &= \lim_{x \to \infty} f(x) \\
    &= \lim_{x \to \infty} xP(x) e^{-x^2} \Arrow{\hbox{\( Q(x) \coloneq xP(x)\)} פולינום} \\
    &= \lim_{x \to \infty} Q(x) e^{-x^2}
\end{DispWithArrows*}
\end{document}

Output of the above code

3
  • while this works, I can't get the equation to show before the text. It keeps displaying as "Polynom Q(x)" instead of "Q(x) Polynom" no matter if I put the equation before or after the text.
    – Shai Avr
    Commented Mar 2 at 15:33
  • I don't see Q(x) Polynom in your text... Commented Mar 3 at 13:19
  • I just translated it. "Polynom" is the word ״פולינום״ in the text
    – Shai Avr
    Commented Mar 3 at 18:53
0

Sorry for the late answer. I’m trying to find a general solution, but below there is as a workaround (@f-pantigny almost got it). Why is this happening? Well, it’s related with the fact \hbox’es (a TeX primitive which shouldn’t be used at the user level) are used internally for quite a lot of purposed 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.


\documentclass[a4paper, 12pt]{article}

\PassOptionsToPackage{no-math}{fontspec}

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

\babelprovide[main, import, alph=letters, Alph=letters]{hebrew}
\babelprovide[import]{english}

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

\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{witharrows}

% witharrows optionsפולינום
\WithArrowsOptions{displaystyle}

\tikzset{text=.}
\tikzset{
    WithArrows/arrow/.append style = {
        font= \small
    }
}

\begin{document}
נחשב את הגבול
\( \lim_{x \to \infty} f(x) \):
\begin{DispWithArrows*}
    L &= \lim_{x \to \infty} f(x) \\
    &= \lim_{x \to \infty} xP(x) e^{-x^2}
    \Arrow{\mbox{\(Q(x) \coloneq xP(x)\)} \mbox{פולינום}}\\
    &= \lim_{x \to \infty} Q(x) e^{-x^2}
\end{DispWithArrows*}
\end{document}

enter image description here

1
  • Maybe tikz can use different macros for boxes that are meant for text, then babel can redefine those that are not meant for text from hbox to hpack.
    – Udi Fogiel
    Commented Mar 6 at 20:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .