1

I am attempting to compile an article using the XeTex engine. In my document I've used the algorithmic and algpsuedocode packages in order to describe an algorithm.

Also, the document is meant to contain both Hebrew and English therefore, I've used the polyglossia package and because the algorithm is in english I've put it inside \begin{english} environment as per polyglossia's documentation. The output contains inverted parentheses in the function's name.

Here is the complete document

\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{english}
\begin{algorithm}
    \caption{Euclid’s algorithm}
    \label{euclid}
    \begin{algorithmic}[1] % The number tells where the line numbering should start
        \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{algorithm}
\end{english}
\end{document}

However as you can see in the output the parentheses are not in the right order. Algorithm Output Screenshot

I don't know much about the internals, however in the file algpsuedocode.sty I can see the following:

\algdef{SE}[FUNCTION]{Function}{EndFunction}%
   [2]{\algorithmicfunction\ \textproc{#1}\ifthenelse{\equal{#2}{}}{}{(#2)}}%
   {\algorithmicend\ \algorithmicfunction}%

Could this be the root of the problem?

7
  • 3
    Does the problem persist if you use another font? I don't have the David font and can't reproduce the problem with e.g. Arial i.sstatic.net/acqrH.png Commented Jun 2, 2023 at 15:05
  • You are correct, changing the font to Arial does work, however in case I would have wanted to use David is there any other solution? From my testing, in case I change the document's main language to English and the other language to Hebrew it is sovled, maybe this indicates that the \begin{english} environment doesn't take care of everything?
    – ch0wner
    Commented Jun 2, 2023 at 15:52
  • 1
    Can you try to narrow down your example? For example do you actually need an algorithm or does the same happen in (test) as well? Commented Jun 2, 2023 at 15:59
  • It is working as expected. Only flips inside the algorithm environment as part of the function signature. Even inside the algorithm environment but somewhere else it doesn't invert the direction
    – ch0wner
    Commented Jun 4, 2023 at 1:29
  • 1
    I can't reproduce your problem, even with David CLM
    – Udi Fogiel
    Commented Jun 4, 2023 at 7:01

1 Answer 1

3

This was a bug in polyglossia that has been fixed in version 1.61 (2023/04/16).

Overleaf has an older version apparently. You can work around the issue by adding to your document preamble:

    \makeatletter
    \providecommand*\xpg@set@group@aux{}
    \providecommand*\xpg@unset@group@aux{}
    \renewenvironment{otherlanguage}[2][]
    {
        \xpg@set@group@aux%
        \selectlanguage[#1]{#2}%
        \xpg@set@normalfont{#2}%
    }
    {\xpg@unset@group@aux}
    \makeatother

Edit: provide \xpg@set@group@aux{} and \xpg@unset@group@aux{} as these are not in all versions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .