5

When trying to create any document with babel and algorithmicx, e.g.:

\documentclass{article}
\usepackage[hebrew,english]{babel}
\usepackage{algorithmicx}

\begin{document}
Hello, world.
\end{document}

I get an error in algorithmicx.sty:

...
("C:\Program Files\MiKTeX 2.9\tex\latex\algorithmicx\algorithmicx.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\base\ifthen.sty")
Document Style algorithmicx 1.2 - a greatly improved `algorithmic' style
! Missing \endcsname inserted.
<to be read again> 
                   \protect 
l.636 \algnewlanguage{default}
                          %

This is slightly related to the algorithmic + Hebrew babel conflict for which I got useful answers - but only in the sense of there seeming to be a long-standing package conflict which for some reason has not been resolved in a distribution.

I'm using MikTeX 2.9.

1
  • I also get this error with TeX Live 2011 (and also if I load the packages in the converse order).
    – N.N.
    Commented Oct 21, 2011 at 7:32

2 Answers 2

5

It is the same problem as mentioned in the question you linked to: hebrew redefines \@arabic and algorithmicx fails. Imho the faulty package is algorithmicx. It shouldn't use \arabic to get a number.

\documentclass{article}

\usepackage[hebrew,english]{babel}
\makeatletter
\def\@arabic#1{\number#1}
\makeatother
\usepackage{algorithmicx}

\begin{document}
Hello, world.
\end{document}
6
  • Of course this will break what hebrew.ldf does in order to change writing directions for numbers.
    – egreg
    Commented Oct 21, 2011 at 10:11
  • But what if I need the \@arabic as babel defines it, as egreg notes? I've tried going over the source of the modified algorithmic.sty linked to from the other question, to see if I could do something similar for algorithmicx, but I don't see where exactly in algorithmicx the problem is which causes the \csname to fail.
    – einpoklum
    Commented Oct 21, 2011 at 10:13
  • Specifically, I tried replacing the uses of \arabic with \@@arabic, which rlbabel.def makes a synonym of the 'original' \arabic - and that didn't work.
    – einpoklum
    Commented Oct 21, 2011 at 10:24
  • @egreg: Yes I know that it will break the definition of hebrew. I only wanted to show that the definition of \@arabic is the source of the problem. @Eyal: You must search for the places where algorithmicx use \arabic{<counter>}. They should probably all be replaced by \the\value{<counter>} or \number\value{<counter}. But better write to the author. He should change his code (and make the necessary tests). Commented Oct 21, 2011 at 10:28
  • @Ulrike: Have written the author, Szasz Janos. Seeing how there have been no updates for 6 years, I'm not optimistic. Also, I made this replacement (to \number\value{<counter>}), but then I get a ! Missing number, treated as zero. error.
    – einpoklum
    Commented Oct 21, 2011 at 12:23
2

Quoting from source2e, when dealing with \newcounter{foo}:

\thefoo and \p@foo must be defined in such a way that \edef\bar{\thefoo} or \edef\bar{\p@foo} defines \bar so that it will evaluate to the counter value at the time of the \edef, even after \c@foo and any other counters have been changed. This will happen if you use the standard commands \@arabic, \@Roman, etc.

(the source says \foocounter, but it should be \c@foo).

Unfortunately, the babel module for Hebrew redefines \@arabic in a way that's not compatible with the specifications set forth in source2e: this is found in

\let\@@arabic\@arabic
\def\@arabic#1{\@number{\@@arabic#1}}
\def\@number{\protect\@@number}
\def\@@number#1{\ifmmode\else\beginL\fi#1\ifmmode\else\endL\fi}

Any package that relies on \thefoo expanding to the commands for representing the counter value will suffer from the same problems.

6
  • I presume you mean \c@foo instead of \p@foo? Commented Oct 21, 2011 at 9:57
  • @wh1t3 No, that's correct. With \newcounter{foo} also \p@foo is defined; usually it does nothing (\def\p@foo{}), but it's used in \refstepcounter: with \refstepcounter{foo}, \@currentlabel is defined to be the expansion of \p@foo\thefoo.
    – egreg
    Commented Oct 21, 2011 at 10:10
  • Interesting, I see that \@definecounter lets \p@foo to \empty. What I don't understand however, is how \newcounter then defines \p@foo in such a way that \edef\bar{\p@foo} defines \bar so that it will evaluate to the counter value at the time of the \edef. Commented Oct 21, 2011 at 10:20
  • @wh1t3 That's only an example; one probably would use \edef\bar{\p@foo\thefoo}, but one is free to do whatever they want with \p@foo.
    – egreg
    Commented Oct 21, 2011 at 10:22
  • The quote sets specifications for \thefoo and \p@foo, not for commands defined with this commands. Also more importantly it doesn't force \@arabic, \@Roman or any \thefoo to expand so that they can be used in contexts where a number is required - and that is how the package is using \arabic. They should only evaluate the counter, not give the value of the counter. Commented Oct 21, 2011 at 10:44

You must log in to answer this question.

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