Generaleqref fails in local compilation, but works on Overleaf?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Shai-Avr
Posts: 8
Joined: Tue Aug 22, 2023 11:30 am

eqref fails in local compilation, but works on Overleaf?

Post by Shai-Avr »

I am trying to transition from Overleaf to a local workspace and set up VSCode with the Latex Workshop extension as my Latex IDE, and I faced a weird problem. I work on Hebrew documents and I use babel and lualatex. Here's the example I was playing with:

Code: Select all

% !TEX lualatex
\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]{David CLM}
\babelfont[hebrew]{sf}[Renderer=HarfBuzz]{Miriam CLM}
\babelfont[hebrew]{tt}[Renderer=HarfBuzz]{Miriam Mono CLM}

\babelfont{david}[Renderer=HarfBuzz]{David CLM}

\usepackage{amsmath}
\usepackage{xparse}

\NewDocumentCommand{\OverSet}{ O{0cm} m m }{
	\overset{\raise #1 \hbox{\(#2\)}}{#3}
}

\begin{document}
\begin{equation}\label{eq:pythagoras}
    a^2 + b^2 = c^2
\end{equation}
לפי משוואה
\eqref{eq:pythagoras}
נסיק כי
\begin{align*}
c^4 \OverSet[0.05cm]{\scriptstyle\eqref{eq:pythagoras}}{=} (a^2 + b^2)^2
\end{align*}
נמשיך
\end{document}
Compiling this example with Luatex both on overleaf and locally makes the reference above the equal sign to be out of place:
kxX9s.png
kxX9s.png (13.6 KiB) Viewed 5662 times
The weird part is that this seems to happen only in the align and gather environments. Using an equation environment (or simply \[ \]) doesn't cause this problem. I found that wrapping the align environment in the \babelsublr{} command fixes this issue:

Code: Select all

\babelsublr{
\begin{align*}
c^4 \OverSet[0.05cm]{\scriptstyle\eqref{eq:pythagoras}}{=} (a^2 + b^2)^2
\end{align*}}
EJAx7.png
EJAx7.png (13 KiB) Viewed 5662 times
So it looks like the problem is solved and this is the solution I have been using until now. When I tried the same example on my local machine in VSCode, it didn't compile and it claimed it couldn't find the eq:pythagoras reference. Removing the \babelsublr{} command made it compile, but the problem of the reference not being centered has returned. Another weird result I found is that if I comment out the remainder of the code (The line "נמשיך" in the above example) and end the document with this align environment wrapped inside \babelsublr{}, then it compiles successfully, and the result is correct.

I am very confused by this. I thought that using \babelsublr{} solves this issue and it always worked for me on Overleaf, but when I try it locally, it doesn't work unless it's the end of the document. On my machine, I use TexLive 2023, and I compile using the default "latexmk (lualatex)" recipe of the Latex Workshop extension.

Can somebody explain why the solution of \babelsublr{} works on Overleaf, but not locally? Alternatively, can somebody suggest a better solution that works both locally and on Overleaf?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10319
Joined: Mon Mar 10, 2008 9:44 pm

eqref fails in local compilation, but works on Overleaf?

Post by Stefan Kottwitz »

It seems that the detection and handling of digits don't work well in this combination of luatex, bidi text, and amsmath with the \eqref command. It works without the bidi option; and it works with explicitly using \babelsublr.

You can use \ref with parentheses instead, then you have the proper alignment:

Code: Select all

c^4 \OverSet[0.05cm]{\scriptstyle(\ref{eq:pythagoras})}{=} (a^2 + b^2)^2
Stefan
LaTeX.org admin
Shai-Avr
Posts: 8
Joined: Tue Aug 22, 2023 11:30 am

eqref fails in local compilation, but works on Overleaf?

Post by Shai-Avr »

I would prefer to use \eqref (It might be silly, but I like that the link is on the entire reference including the parenthesis). It doesn't explain why \eqref fails to make references inside the \babelsublr command and why it fails only locally and not on Overleaf.
Post Reply