Skip to content
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

eqref is misaligned when placed above equal sign in align and gather environments #301

Open
ShaiAvr opened this issue Jun 12, 2024 · 0 comments
Labels
🐞 bug Something isn't working

Comments

@ShaiAvr
Copy link

ShaiAvr commented Jun 12, 2024

I write my documents in Hebrew and I noticed a weird issue. If I try to put a reference above an equal sign in the align or gather environments, it's not aligned correctly. This problem only happens in Hebrew. Switching the current language to English fixes it:

Screenshot 2024-06-12 180509
The code for this example:

\documentclass{article}

\PassOptionsToPackage{no-math}{fontspec}

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

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

% Font setup
\babelfont[hebrew]{rm}[Renderer=HarfBuzz]{Assistant}
\babelfont[hebrew]{sf}[Renderer=HarfBuzz]{Assistant}

\usepackage{amsmath}

\begin{document}
\begin{equation}\label{eq:he-pythagoras}
    a^2 + b^2 = c^2
\end{equation}
לפי משוואה
\eqref{eq:he-pythagoras}
נסיק כי
\begin{align*}
c^4 \overset{\scriptscriptstyle\eqref{eq:he-pythagoras}}{=} (a^2 + b^2)^2
\end{align*}
נמשיך

\selectlanguage{english}
\begin{equation}\label{eq:en-pythagoras}
    a^2 + b^2 = c^2
\end{equation}
According to equation \eqref{eq:en-pythagoras}, we can conclude that:
\begin{align*}
	c^4 \overset{\scriptscriptstyle\eqref{eq:en-pythagoras}}{=} (a^2 + b^2)^2
\end{align*}
Let's continue
\end{document}

When I was working on Overleaf, I would wrap the align/gather environments with the \babelsublr command to fix this, but for a weird reason, this workaround didn't work when I tried to transition to a local compiler and caused the reference to break. I asked this on tex.stackexchange and got a working workaround:

\documentclass{article}

\PassOptionsToPackage{no-math}{fontspec}

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

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

% Font setup
\babelfont[hebrew]{rm}[Renderer=HarfBuzz]{Assistant}
\babelfont[hebrew]{sf}[Renderer=HarfBuzz]{Assistant}

\usepackage{amsmath}

\makeatletter
\NewDocumentCommand{\exref}{ m }{%
	\let\bbl@ams@lap\relax%
	\eqref{#1}%
}%
\makeatother

\begin{document}
\begin{equation}\label{eq:he-pythagoras}
    a^2 + b^2 = c^2
\end{equation}
לפי משוואה
\exref{eq:he-pythagoras}
נסיק כי
\begin{align*}
c^4 \overset{\scriptscriptstyle\exref{eq:he-pythagoras}}{=} (a^2 + b^2)^2
\end{align*}
נמשיך

\selectlanguage{english}
\begin{equation}\label{eq:en-pythagoras}
    a^2 + b^2 = c^2
\end{equation}
According to equation \exref{eq:en-pythagoras}, we can conclude that:
\begin{align*}
	c^4 \overset{\scriptscriptstyle\exref{eq:en-pythagoras}}{=} (a^2 + b^2)^2
\end{align*}
Let's continue
\end{document}

which produces:

Screenshot 2024-06-12 181122
According to Javier's answer to my question, it looks like babel patches an internal macro in some amsmath environments to correctly align the tag. \eqref uses this macro in its original form in the text, but in the context of my example the modified form is the active one.

In other words, it seems to be a bug with babel and this should be fixed.

@jbezos jbezos added the 🐞 bug Something isn't working label Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants