algpseudocode/algorithmicx 패키지는 히브리어 babel 패키지와 함께 사용할 수 없습니다.

algpseudocode/algorithmicx 패키지는 히브리어 babel 패키지와 함께 사용할 수 없습니다.

다음 LaTeX 문서:

\documentclass{article}

\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\usepackage[hebrew, english]{babel}

\usepackage{amsmath}
\usepackage{algorithm}
\usepackage[]{algpseudocode}

\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother

\begin{document}
\selectlanguage{hebrew}{להלן אלגוריתם לדוגמא}\selectlanguage{english}
Here is an example algorithm:

\begin{algorithm}
\caption{My algorithm}\label{euclid}
\begin{algorithmic}[1]
\Procedure{MyProcedure}{}
\State $\textit{stringlen} \gets \text{length of }\textit{string}$
\State $i \gets \textit{patlen}$
\BState \emph{top}:
\If {$i > \textit{stringlen}$} \Return false
\EndIf
\State $j \gets \textit{patlen}$
\BState \emph{loop}:
\If {$\textit{string}(i) = \textit{path}(j)$}
\State $j \gets j-1$.
\State $i \gets i-1$.
\State \textbf{goto} \emph{loop}.
\State \textbf{close};
\EndIf
\State $i \gets i+\max(\textit{delta}_1(\textit{string}(i)),\textit{delta}_2(j))$.
\State \textbf{goto} \emph{top}.
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document} 

다음 오류가 발생합니다.

 /usr/local/texlive/2020/texmf-dist/tex/latex/algorithmicx/algorithmicx.sty, line 636

Missing \endcsname inserted.

<to be read again> 
                   \protect 
l.636 \algnewlanguage{default}
                              %
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.

줄을 다음 \usepackage[hebrew, english]{babel}으로 바꾸면 \usepackage[english]{babel}오류가 지워지지만 히브리어는 사용할 수 없습니다.

이 문제를 해결하려면 어떻게 해야 합니까?

답변1

다음은 LuaLaTEX로 컴파일된 실제 예제입니다:

\documentclass{article}

\usepackage[main=english, bidi=basic, layout=sectioning.tabular]{babel}
\usepackage{fontspec}
\babelprovide[import]{hebrew}

\babelfont{rm}
          [Ligatures={Common,Discretionary,TeX}]{Libertinus Serif} % Or any font that supports Hebrew.
\babelfont{sf}
          [Ligatures={Common,Discretionary,TeX}]{Libertinus Sans}
\babelfont{tt}
          [Ligatures=TeX]{Libertinus Mono}


\usepackage{amsmath}
\usepackage{algorithm}
\usepackage[]{algpseudocode}

\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother

\begin{document}
\selectlanguage{hebrew}{להלן אלגוריתם לדוגמא}\selectlanguage{english}

Here is an example algorithm

\begin{algorithm}
\caption{My algorithm}\label{euclid}
\begin{algorithmic}[1]
\Procedure{MyProcedure}{}
\State $\textit{stringlen} \gets \text{length of }\textit{string}$
\State $i \gets \textit{patlen}$
\BState \emph{top}:
\If {$i > \textit{stringlen}$} \Return false
\EndIf
\State $j \gets \textit{patlen}$
\BState \emph{loop}:
\If {$\textit{string}(i) = \textit{path}(j)$}
\State $j \gets j-1$.
\State $i \gets i-1$.
\State \textbf{goto} \emph{loop}.
\State \textbf{close};
\EndIf
\State $i \gets i+\max(\textit{delta}_1(\textit{string}(i)),\textit{delta}_2(j))$.
\State \textbf{goto} \emph{top}.
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document} 

도움을 주신 @ulrike-fischer에게 감사드립니다.

관련 정보