I am starting to lose my mind because of this weird bug that I don't understand how to solve. I do my homework with latex in Hebrew and I use babel
to set it up. I have a custom package and class to define my style and commands. After fighting for hours to get it to compile without errors I found out that the \Longrightarrow
is broken:
I tried to create a minimal example to reproduce the issue:
% !TeX spellcheck = he_HE
\documentclass[a4paper, 12pt]{extarticle}
\usepackage{amsmath}
\usepackage{enumitem}
\usepackage{witharrows}
\usepackage[bidi=basic, provide=*]{babel}
\babelprovide[alph=letters, Alph=letters]{hebrew}
\babelprovide{english}
\babelfont[hebrew]{rm}[Renderer=Harfbuzz, ItalicFont=*-Regular, ItalicFeatures={FakeSlant=0.3}]{Assistant}
\babelfont[hebrew]{sf}[Renderer=Harfbuzz, ItalicFont=*-Regular, ItalicFeatures={FakeSlant=0.3}]{Assistant}
\babelfont[hebrew]{tt}[Renderer=Harfbuzz, ItalicFont=*-Regular, ItalicFeatures={FakeSlant=0.3}]{Assistant}
\AddToHook{begindocument/end}{\selectlanguage{hebrew}}
\begin{document}
דוגמה \textit{לחישוב}:
\begin{DispWithArrows*}
A &= (a + b)^2 \Arrow{נפתח את הסוגריים בביטוי} \\
&= a^2 + 2ab + b^2
\end{DispWithArrows*}
\underline{דוגמה} \textbf{נוספת}:
\begin{align*}
A &= (a + b)^2\\
&= a^2 + 2ab + b^2
\end{align*}
\begin{otherlanguage}{english}
Some English example.
\end{otherlanguage}
\begin{enumerate}[leftmargin=*, label=\alph*.]
\item
בדיקה ראשונה.
\item
בדיקה שנייה.
\end{enumerate}
\[ AB = I \Longrightarrow B = A^{-1} \]
\end{document}
but when compiling it, it worked as expected:
I went over the code trying to disable single features but couldn't find the source of this problem. The code that handles babel
is identical to the code in the example above. Here are stripped versions of my files:
my-style.sty
:
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{my-style}[2023/03/06 My personal style and custom commands]
\RequirePackage[table]{xcolor}
\RequirePackage{tikz}
\RequirePackage{tkz-base, tkz-euclide}
\RequirePackage{pgfplots}
\RequirePackage{graphicx}
\RequirePackage[most]{tcolorbox}
\RequirePackage{wrapfig}
\RequirePackage{titlesec}
\RequirePackage{xifthen}
\RequirePackage{xparse}
\RequirePackage{geometry}
\RequirePackage{amsmath}
\RequirePackage{amsfonts}
\RequirePackage{amssymb}
\RequirePackage{amsthm}
\RequirePackage{mathrsfs}
\RequirePackage{enumitem}
\RequirePackage{moreenum}
\RequirePackage{bm}
\RequirePackage{upgreek}
\RequirePackage[euler]{textgreek}
\RequirePackage{import}
\RequirePackage{esint}
\RequirePackage{mathtools}
\RequirePackage[thicklines]{cancel}
\RequirePackage[per-mode=fraction, exponent-product=\cdot]{siunitx}
\RequirePackage[italicdiff]{physics}
\RequirePackage{nicefrac}
\RequirePackage{parskip}
\RequirePackage{setspace}
\RequirePackage{dsfont}
\RequirePackage{etoolbox}
\RequirePackage[bottom]{footmisc}
\RequirePackage{multicol}
\RequirePackage{ulem}
\RequirePackage{pgfkeys}
\RequirePackage{nicematrix}
\RequirePackage{witharrows}
% Hebrew option
\newboolean{hebrew}
\setboolean{hebrew}{false}
\DeclareOption{hebrew}{\setboolean{hebrew}{true}}
\DeclareOption*{\PackageWarning{my-style}{Unknown '\CurrentOption'}}
\ProcessOptions\relax
% Font and lanuguage settings
\RequirePackage[bidi=basic, provide=*]{babel}
\babelprovide{english}
\babelprovide[alph=letters, Alph=letters]{hebrew}
\babelfont[hebrew]{rm}[Renderer=Harfbuzz, ItalicFont=*-Regular, ItalicFeatures={FakeSlant=0.3}]{Assistant}
\babelfont[hebrew]{sf}[Renderer=Harfbuzz, ItalicFont=*-Regular, ItalicFeatures={FakeSlant=0.3}]{Assistant}
\babelfont[hebrew]{tt}[Renderer=Harfbuzz, ItalicFont=*-Regular, ItalicFeatures={FakeSlant=0.3}]{Assistant}
\ifthenelse{\boolean{hebrew}}{
\AddToHook{begindocument/end}{\selectlanguage{hebrew}}
}{
\AddToHook{begindocument/end}{\selectlanguage{english}}
}
% witharrows options
\WithArrowsOptions{displaystyle}
\tikzset{
WithArrows/arrow/.append style = {
font= \small
}
}
\RequirePackage{hyperref}
\RequirePackage{fancyhdr}
\hypersetup{
colorlinks,
linkcolor=blue
}
\NewDocumentCommand{\OverSet}{ O{0cm} m m }{
\overset{\raise #1 \hbox{\(#2\)}}{#3}
}
\NewDocumentCommand{\UnderSet}{ O{0cm} m m }{
\underset{\lower #1 \hbox{\(#2\)}}{#3}
}
\NewDocumentCommand{\claptext}{ m }{\mathclap{\text{#1}}}
\NewDocumentCommand{\Transpose}{ s m }{
{\IfBooleanTF{#1}{\pqty{#2}}{#2}}^{\mathrm{t}}
}
\NewDocumentCommand{\InverseTranspose}{ s m }{
{\IfBooleanTF{#1}{\pqty{#2}}{#2}}^{-\mathrm{t}}
}
\NewDocumentCommand{\HermitianTranspose}{ s m }{
{\IfBooleanTF{#1}{\pqty{#2}}{#2}}^{\dagger}
}
\NewDocumentCommand{\InverseHermitianTranspose}{ s m }{
{\IfBooleanTF{#1}{\pqty{#2}}{#2}}^{-\dagger}
}
\NewDocumentCommand{\Conjugate}{ s m }{
\IfBooleanTF{#1}{\pqty{#2}}{#2}^{\ast}
}
% Physics commands
\NewDocumentCommand{\IdentityOperator}{}{\hat{I}}
\NewDocumentCommand{\Change}{ m }{\mathop{\Delta#1}}
homework.cls
:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{homework}[2022/11/01 My custom class for homework]
\LoadClass[a4paper, 12pt]{extarticle}
\RequirePackage{my-style}
\DeclareOption{hebrew}{\PassOptionsToPackage{hebrew}{my-style}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{extarticle}}
\ProcessOptions\relax
\geometry{left=2cm, right=2cm, top=2cm, bottom=2cm}
% HomeWork options
\NewExpandableDocumentCommand{\Course}{}{}
\NewExpandableDocumentCommand{\StudentId}{}{#########}
\NewExpandableDocumentCommand{\StudentEmail}{}{[email protected]}
\NewExpandableDocumentCommand{\HWDate}{}{\today}
\ifthenelse{\boolean{hebrew}}{
\NewExpandableDocumentCommand{\Homework}{}{תרגיל בית}
\NewExpandableDocumentCommand{\StudentName}{}{שם הסטודנט}
}
{
\NewExpandableDocumentCommand{\Homework}{}{Homework assignment}
\NewExpandableDocumentCommand{\StudentName}{}{}
}
\NewDocumentCommand{\SetCourse}{ m }{\RenewDocumentCommand{\Course}{}{#1}}
\NewDocumentCommand{\SetHomework}{ m }{\RenewDocumentCommand{\Homework}{}{#1}}
\NewDocumentCommand{\SetStudentName}{ m }{\RenewDocumentCommand{\StudentName}{}{#1}}
\NewDocumentCommand{\SetStudentId}{ m }{\RenewDocumentCommand{\StudentId}{}{#1}}
\NewDocumentCommand{\SetStudentEmail}{ m }{\RenewDocumentCommand{\StudentEmail}{}{#1}}
\NewDocumentCommand{\SetHWDate}{ m }{\RenewDocumentCommand{\HWDate}{}{#1}}
% Styling customizations
\ifthenelse{\boolean{hebrew}}{
% Customize title
\titlelabel{חלק \thetitle}
}{}
\NewDocumentCommand{\Appendix}{ s }{
\IfBooleanF{#1}{\newpage}
\appendix
\ifthenelse{\boolean{hebrew}}{
\renewcommand{\thesection}{\arabic{section}}
% Customize title
\titlelabel{נספח \thetitle\quad}
}{}
}
% Homework functions
\newcounter{ProblemNum}
\newcounter{SubProblemNum}[ProblemNum]
\NewExpandableDocumentCommand{\TheProblemNum}{}{\arabic{ProblemNum}}
\ifthenelse{\boolean{hebrew}}{
\NewExpandableDocumentCommand{\TheSubProblemNum}{}{\alph{SubProblemNum}}
}{
\NewExpandableDocumentCommand{\TheSubProblemNum}{}{\arabic{SubProblemNum}}
}
\NewDocumentCommand{\Section}{ m }{
\phantomsection
\addcontentsline{toc}{section}{#1}
\section*{#1}
}
\NewDocumentCommand{\Problem}{ s o }{
\IfBooleanF{#1}{\newpage}
\stepcounter{ProblemNum}
\phantomsection
\ifthenelse{\boolean{hebrew}}{
\addcontentsline{toc}{subsection}{שאלה \TheProblemNum \IfNoValueF{#2}{\; #2}}
\subsection*{שאלה \TheProblemNum \IfNoValueF{#2}{\; #2}}
}{
\addcontentsline{toc}{subsection}{Question \TheProblemNum \IfNoValueF{#2}{\; #2}}
\subsection*{Question \TheProblemNum \IfNoValueF{#2}{\; #2}}
}
}
\NewDocumentCommand{\Solution}{}{
\phantomsection
\ifthenelse{\boolean{hebrew}}{
\addcontentsline{toc}{subsubsection}{פתרון}
\subsubsection*{פתרון}
}{
\addcontentsline{toc}{subsubsection}{Solution}
\subsubsection*{Solution}
}
}
\NewDocumentCommand{\Part}{ o }{
\IfNoValueTF{#1}{
\stepcounter{SubProblemNum}
\phantomsection
\ifthenelse{\boolean{hebrew}}{
\addcontentsline{toc}{subsubsection}{סעיף \texorpdfstring{\TheSubProblemNum}{\arabic{SubProblemNum}}}
\subsubsection*{סעיף \TheSubProblemNum}
}{
\addcontentsline{toc}{subsubsection}{Part \texorpdfstring{\TheSubProblemNum}{\arabic{SubProblemNum}}}
\subsubsection*{Part \TheSubProblemNum}
}
}{
\phantomsection
\ifthenelse{\boolean{hebrew}}{
\addcontentsline{toc}{subsubsection}{סעיף #1}
\subsubsection*{סעיף #1}
}{
\addcontentsline{toc}{subsubsection}{Part #1}
\subsubsection*{Part #1}
}
}
}
% Theorems and proofs
\ifthenelse{\boolean{hebrew}}{
\newtheorem{lemma}{למה}[ProblemNum]
}{
\newtheorem{lemma}{Lemma}[ProblemNum]
}
% Lists
\newlist{QuestionParts}{enumerate}{2}
\setlist[QuestionParts, 1]{align=left, leftmargin=*, label=\alph*.}
\setlist[QuestionParts, 2]{align=right, label=\arabic*.}
\newlist{SubParts}{enumerate}{1}
\setlist[SubParts, 1]{align=left, labelsep=0pt, leftmargin=0pt, labelwidth=*, label=\uline{חלק \arabic*}}
\NewDocumentCommand{\nitem}{ o }{
\IfNoValueTF{#1}{
\item\mbox{}\\
}{
\item[#1]\mbox{}\\
}
}
% Hyperref and fancyhdr setup
\hypersetup{
pdfauthor={\StudentName},
pdftitle={\Homework},
}
\pdfstringdefDisableCommands{\let\;\empty}
\setlength{\headheight}{15pt}
\ifthenelse{\boolean{hebrew}}{
\lhead{שאלה \arabic{ProblemNum}}
}{
\lhead{Question \arabic{ProblemNum}}
}
\chead{\Course}
\rhead{\Homework}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
\pagestyle{fancy}
main.tex
:
% !TeX spellcheck = he_HE
\documentclass[hebrew]{homework}
\SetCourse{פיזיקה קוונטית 1}
\SetHomework{תרגיל בית 3}
\begin{document}
\tableofcontents
\import{./}{q1.tex}
\end{document}
q1.tex
:
% !TeX spellcheck = he_HE
\Problem[צמוד הרמיטי]
\[
\HermitianTranspose*{\hat{O}^{-1}}\HermitianTranspose{\hat{O}} = \HermitianTranspose*{\hat{O}\hat{O}^{-1}} = \HermitianTranspose{\IdentityOperator} = \IdentityOperator
\Longrightarrow \tcbhighmath{\HermitianTranspose*{\hat{O}^{-1}} = \pqty{\HermitianTranspose{\hat{O}}}^{-1}}
\]
Compiling main.tex
with lualatex
produces the first picture. As I said before, I compared these files with the example above for hours, but couldn't find the source of this annoying bug. If someone could figure out what is happening here and how how to solve it, I'd really appreciate it.
P.S: I am using the font Assistant.
amsmath
(and all packages loading it) after the loading ofbabel
adn the\babelfont
commands. It should fix it. Details in the answers...amsmath
,amsfonts
,amssymb
,amsthm
,mathtools
,pgfplots
,upgreek
,tcolorbox
(the latter probably because of[most]
,moreenum
. (some I did not check really, at least moving all of them after the font set-up appears to work at my locale).unicode-math
beforefontspec
. It also fix the distortion when using12pt
font size.unicode-math
internally loadsamsmath
, so you don't need to load both, andfontspec
isunicode-math
aware. Alsoamssymb
loadsamsfonts
so you don't need to load the latter if you use the former.