3

I use the xfrac package to make nice-looking fractions and I encountered a problem with it. I use the babel package to write my documents in Hebrew, and I found that using xfrac inside an align* environment causes the numerator and denominator to reverse:

The corresponding code:

\documentclass{article}

\usepackage[amsthm, libertine, varbb]{newtxmath}

\PassOptionsToPackage{no-math}{fontspec}
\usepackage[bidi=basic, layout=tabular, headfoot=hebrew]{babel}

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

\usepackage{amsmath}
\usepackage{xfrac}

\begin{document}
\begin{align*}
\sfrac{x}{y}
\end{align*}
\[ \sfrac{x}{y} \]
\end{document}

Commenting out the babel setup produces the correct result:

How can I fix these fractions to work correctly with babel?

1 Answer 1

4

Sorry not a real solution but too long for a comment.

xfrac builds in math the fraction by placing a number of \hbox side by side inside a \text command.

In normal text with active TRT direction the order of such a row of hboxes are normally reversed, and obviously in some places babel tries to achieve the same effect inside the \text command and in align this happens.

Imho the right place to correct the frac would be in xfrac which should ensure that the direction is TLT, as a workaround you can put the frac in mbox:

\documentclass{article}
\usepackage[bidi=basic]{babel}
\babelprovide[main, import]{hebrew}
\usepackage{amsmath,xfrac}
      
\begin{document}

\leavevmode\hbox{a}\hbox{b}\hbox{c}

$\text{\hbox{a}\hbox{b}\hbox{c}}$

\[ \text{\hbox{a}\hbox{b}\hbox{c}}\]

\begin{align*}
\text{\hbox{a}\hbox{b}\hbox{c}}
\end{align*}

% xfrac should do this:
\begin{align*}
\text{\textdir TLT \hbox{a}\hbox{b}\hbox{c}}
\end{align*}

%workaround
\begin{align*}
\mbox{\sfrac{x}{y}}
\end{align*}

\end{document}

enter image description here

5
  • 1
    +1. \mbox{\sfrac{$x$}{$y$}} inside align*might be an even better workaround.
    – Mico
    Commented Jul 8 at 10:49
  • @Mico Why would it be better?
    – Shai Avr
    Commented Jul 8 at 16:11
  • 1
    @ShaiAvr - It's better if you prefer getting the math-mode rather than the text-mode forms of x and y.
    – Mico
    Commented Jul 8 at 17:49
  • I can certainly agree with that
    – Shai Avr
    Commented Jul 8 at 18:22
  • I just tried this solution and found that the result is uglier (in my opinion) than how \sfrac usually looks in math mode. Is there a way to fix this bug and keep \sfrac in math mode so it looks good?
    – Shai Avr
    Commented Jul 11 at 8:03

You must log in to answer this question.

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