Closed g0x69lbo closed 1 year ago
I think I've just figured it out.. consider the following:
\begin{english}
\begin{algorithm}[H]
\caption{CREATE-P-SIZED-COUNTING-ARRAY PSUEDOCODE}
\begin{algorithmic}[1]
\Function{CREATE-P-SIZED-COUNTING-ARRAY}{A}
\If{$length[A] = 0$}
\State \Return NIL \Comment{Edge-case when A is empty}
\EndIf
\State $n \gets length[A]$
\State $p \gets A[1]$
\For{$i \gets 2$ to $n$}
\State $A[i] \gets A[i] - n$
\If{$A[i] > p$}
\State $p \gets A[i]$
\EndIf
\EndFor
\LeftComment{Let c be a new array of size p, initialized with zeroes}
\State \Return c
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{english}
But when I enclose the arguments in dollar signs
\Function{CREATE-P-SIZED-COUNTING-ARRAY}{$A$}
The parentheses are flipped:
Tested compiled using XeTex+MikTex and the David font for hebrew both on overleaf and LYX
Please always provide a full minimal example case in the ticket, not only a snippet.
Anyway, if I compile the MWE you gave at stackexchange, I (like others there) fail to reproduce:
Like @Udi-Fogiel I suspect your David CLM
font is defective.
I've tested on overleaf and there are no warnings about missing scripts. Maybe the problem is that the algorithm environment is a float, so the font switches from the english environment are not applied properly. With the following I get the correct result on overleaf
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\usepackage{polyglossia}
\usepackage{fontspec}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily{\englishfont}{Latin Modern Roman}
\newfontfamily{\hebrewfont}[Script=Hebrew]{David CLM}
\newfontfamily{\hebrewfontsf}[Script=Hebrew]{Miriam CLM}
\newfontfamily{\hebrewfonttt}[Script=Hebrew]{Miriam Mono CLM}
\begin{document}
\section{אלגוריתם לדוגמה}
\begin{algorithm}
\begin{english} % <---- english inisde algorithm
\caption{Euclid’s algorithm}
\label{euclid}
\begin{algorithmic}
\Procedure{Euclid}{$a,b$} \Comment{The g.c.d. of a and b}
\State $r\gets a \bmod b$
\While{$r\not=0$} \Comment{We have the answer if r is 0}
\State $a \gets b$
\State $b \gets r$
\State $r \gets a \bmod b$
\EndWhile\label{euclidendwhile}
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{english}
\end{algorithm}
\end{document}
I don't know why on an updated version it works ok, maybe something in floats has changed in 2023, or maybe it was a defect in bidi.
Either way, It does not seem like a problem with polyglossia (at least I did not find anything).
As to float, d4ae868f4ad154499b4 (as of v. 1.58 of polyglossia
) might be relevant (see #542)..
Which version of polyglossia
does overleaf have?
Which version of
polyglossia
does overleaf have?
polyglossia 2022/04/20 v1.56
Tried to "apply" the patch in overleaf, did not change anything, and no errors.
I've already described my problem here
Do you have any suggestions?