I do my homework in Latex, and I recently learned about the witharrows package which allows me to draw arrows between lines explaining what I did there. I find this very helpful for my homework assignments. However, there is a weird problem when I try to use the package. I do my homework in our native language, Hebrew, an RTL language. I use the polyglossia and fontspec packages to configure the language settings and fonts of the document.
When I tried to use the witharrows package with this simple example:
דוגמה לחישוב:
\begin{DispWithArrows*}
A &= (a + b)^2 \Arrow{נפתח את הסוגריים בביטוי} \\
&= a^2 + 2ab + b^2
\end{DispWithArrows*}
As you can see, the text next to the arrow is reversed. It looks like it's trying to write it in an LTR setting for some reason. After reading this question,
I tried to use the option font=\selectlanguage{hebrew} like so:
\tikzset{
WithArrows/arrow/.append style = {
font = \selectlanguage{hebrew},
}
}
However, it didn't work. I got the same output. Note that I did it in tikzset so it applies to all arrows, but doing it inside the arrow itself:
\Arrow[tikz={font={\selectlanguage{hebrew}}}]{נפתח את הסוגריים בביטוי} doesn't work either.
I did some more experiments and I found something very weird: If I add another setting to the font such as changing the color:
\tikzset{
WithArrows/arrow/.append style = {
color=blue,
font = \selectlanguage{hebrew},
}
}
It suddenly works and renders correctly from right to left, and that's extremely weird. Another solution that I found to work is using \texthebrew:
דוגמה לחישוב:
\begin{DispWithArrows*}
A &= (a + b)^2 \Arrow{\texthebrew{נפתח את הסוגריים בביטוי}} \\
&= a^2 + 2ab + b^2
\end{DispWithArrows*}
which also renders correctly. The first solution is just weird and I'd like to know why adding the color option suddenly fixes it (of course I can use color=black so the color doesn't change but this feels like a dirty hack and not a real solution), and while the second solution makes sense, I don't want to always have to surround the text in my arrows with a \texthebrew command and I couldn't find a way to apply it globally.
Does anyone know how I can fix these issues and get Hebrew text to render correctly in arrows?
Full example code (Note I use the font Assistant):
% !TeX spellcheck = he_HE
\documentclass{article}
\usepackage{witharrows}
% Font and language settings
\usepackage[no-math]{fontspec}
\usepackage{polyglossia}
\newfontfamily\hebrewfont[
Script=Hebrew,
ItalicFont=*-Regular,
ItalicFeatures={FakeSlant=0.3},
]{Assistant}
\setmainlanguage{hebrew}
\setotherlanguage{english}
\setsansfont{Assistant}
\setmonofont{Assistant}
\WithArrowsOptions{displaystyle}
\tikzset{
WithArrows/arrow/.append style = {
font = \selectlanguage{hebrew},
}
}
\begin{document}
דוגמה לחישוב:
\begin{DispWithArrows}
A &= (a + b)^2 \Arrow{נפתח את הסוגריים בביטוי} \
&= a^2 + 2ab + b^2
\end{DispWithArrows}
\end{document}


no-mathoption forfontspec? Because if not you could drop\usepackage{fontspec}as it is already loaded bypolyglossia. Your MWE compiles without\usepackage[no-math]{fontspec}. – Niranjan Apr 21 '23 at 14:16no-mathoption. It fixed a different issue I had a month ago. I don't even remember what it was. – Shai Avr Apr 21 '23 at 14:38\def\ArrowRL#1{\Arrow{\texthebrew{#1}}}then\ArrowRL{נפתח את הסוגריים בביטוי}– Salim Bou Apr 21 '23 at 14:38align*environments are put on the right side of the page instead of the center as it's supposed to be. It's really annoying. – Shai Avr Apr 22 '23 at 14:04