polyglossia and algorithmicx - Missing \endcsname inserted

Trying to compile a simple document using polyglossia with Hebrew as the default language:

\documentclass[a4paper]{article}
\TeXXeTstate=1
\usepackage{amsmath, amssymb}
\usepackage{polyglossia}
\setdefaultlanguage[calendar=hebrew, numerals=hebrew]{hebrew}
\setotherlanguage{english}
\setmainfont{David CLM}
\usepackage[noend]{algpseudocode}

\begin{document}
\section{}
שלום
\begin{english}
Procedure(A)
\begin{algorithmic}[1]
\State $A = 0$
\end{algorithmic}
\end{english}
\end{document}


Results in this using XeTeX:

! Missing \endcsname inserted.
\relax
l.15     \begin{algorithmic}[1]


If I set the default language to English and other language to Hebrew it works fine though.

-
This is due to numerals=hebrew. If you delete it, no error happens. I am not sure about details. You can make a bug report at github.com/reutenauer/polyglossia/issues – IRAN Nov 23 '11 at 12:18
Also there is no need for \TeXXeTstate=1. And it is much safer to load algpseudocode package before loading polyglossia package. – IRAN Nov 23 '11 at 12:19
@VafaKhalighi: as a matter of fact I wanted numerals=arabic but that doesn't compile at all. Deleting the numerals also doesn't compile. – daniel.jackson Nov 23 '11 at 13:20
If I delete the \section{} it does compile without the numerals, but the original error is stil there. – daniel.jackson Nov 23 '11 at 13:23
See my answer, do you still get any error with the minimal example that I posted in my answer. – IRAN Nov 23 '11 at 13:30

A workaround can be the following code to be put in the preamble:

\usepackage{etoolbox}
\makeatletter
\let\ORI@arabic\@arabic
\expandafter\pretocmd\csname\string\algorithmic\endcsname
{\let\@arabic\ORI@arabic}{}{}
\renewcommand{\theALG@storecount}{\ORI@arabic\c@ALG@storecount}
\makeatother


The strange code is meant to inject the code in the "real" macro that does the work intended for \algoritmic.

-
Should this be put in a specific location in the preamble (before/after polygossia/algorithmic etc)? I tried several positions but all resulted in the same error. – daniel.jackson Nov 23 '11 at 13:20
After loading algorithmic. Just put the loading of etoolbox with the other packages and rest of the code before \begin{document}. – egreg Nov 23 '11 at 13:23
Not much has changed. Here's the modified file with the output at the bottom: paste.pocoo.org/show/511861 – daniel.jackson Nov 23 '11 at 13:27
bidi package automatically loads biditools package (the programming infrastructure of bidi package) that provides some tools similar to what etoolbox provides. Hence there is no need to load etoolbox, instead change \pretocmd to \bidi@pretocmd. – IRAN Nov 23 '11 at 13:33
@daniel.jackson I get no error. – egreg Nov 23 '11 at 13:34

Since, in the comment you said that you want arabic numerals, then changing your minimal example to the following works without problems with arabic numerals:

\documentclass[a4paper]{article}
\usepackage{amsmath, amssymb}
\usepackage[noend]{algpseudocode}
\usepackage{polyglossia}
\setdefaultlanguage[calendar=hebrew]{hebrew}
\setotherlanguage{english}
\setmainfont{David CLM}

\begin{document}
\section{}
שלום
\begin{english}
Procedure(A)
\begin{algorithmic}[1]
\State $A = 0$
\end{algorithmic}
\end{english}
\end{document}

-
I'm getting this error: ! Undefined control sequence. \@sect ...stepcounter {#1}\protected@edef \@svsec {\@seccntformat {#1}\relax... l.10 \section{} – daniel.jackson Nov 23 '11 at 13:32
I do not get that error. Maybe your TeX distribution is not updated. – IRAN Nov 23 '11 at 13:36
Probably. Thanks for trying. – daniel.jackson Nov 23 '11 at 13:37