Skip to content

The problem of using algorithm2e with Persian algorithms

Algorithm2e.texAlgorithm2e.pdfAlgorithm2e.log

Brief outline of the issue

I used algorithm2e to write some algorithms with Persian commands and it worked fine. But when I compile the same files with the current version of TexLive 2018, some of the lines moves to left. I guess its problem is when the algorithm wants to indent some lines which are within the condition or loop commands. The caption of the algorithm is also in wrong order.

Minimal example showing the issue

\documentclass{book}

  % Any packages other than the xepersian package must be loaded here
\usepackage[algochapter,linesnumbered]{algorithm2e}

  % The xepersian package must be loaded as the last package
\usepackage{xepersian}
\settextfont[Scale=1]{Yas}
\setlatintextfont[Scale=0.9]{Arial}
\setdigitfont[Scale=0.9]{Yas}

  % Any preamble code goes here
\SetAlgorithmName{الگوریتم}{الگوریتم}{لیست الگوریتم‌ها}
\SetKwInput{KwIn}{ورودی}
\SetKwInput{KwOut}{خروجی}
\SetKw{KwRet}{برگردان}
\SetKw{Return}{را~برگردان}
\SetKw{ReturnZero}{برگرد}
\SetKw{Start}{شروع}
\SetKw{End}{پایان}
\SetKw{Get}{را~بگیر}
\SetKw{Print}{را~چاپ~کن}
\SetKwFor{For}{برای}{..}{...}
\SetKwIF{If}{ElseIf}{Else}{اگر}{آنگاه}{درغیراینصورت اگر}{درغیراینصورت}{پایان~اگر}
 
\begin{document}

  % Demonstration of issue here
  \chapter{}
\section{}

\begin{algorithm}[H]
\DontPrintSemicolon
 \Start\;
$n$   \Get\;
$i\leftarrow 1$ و $FACT\leftarrow 1$\;
\If{$i\leq n$}{
		$FACT\leftarrow FACT \times i$\;
		$i\leftarrow i+1$\;
		به خط 4 برو\;
	}
$FACT$ \Print\;
 \End
 \caption{ الگوریتم  محاسبۀ فاکتوریل  یک عدد }\label{alg:fact}
\end{algorithm}

\end{document}

Log and PDF files

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information