# Can't get babel and amsthm to play nice once Hebrew is loaded

I am working in LaTeX, and I am trying to get babel and amsthm to play nice together.

I produced a minimal example (which gives a different error than the full project, but getting this to work could be the stepping stone I need for success in that)

\documentclass[hebrew,english]{memoir}
\usepackage[utf8x]{inputenc}
\usepackage{babel}
\selectlanguage{english}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[chapter]
\begin{document}
\chapter{Hello}
This is some text.\newline
\begin{theorem}
This is a theorem.
\end{theorem}
\begin{otherlanguage}{hebrew}
שלום
\end{otherlanguage}
\hfill\newline
English again!
\end{document}


This does not compile. It would compile if:

1. I comment out the \begin{theorem}...\end{theorem} part,
2. I remove the use of babel completely, or
3. I simply remove the Hebrew from loading (and comment out the relevant part).

The error message is:

! Missing { inserted.
T
l.14 T
his is a theorem.
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing I}' now.)


This error is pointed at the \begin{theorem} part and there is another which seems to be related to the \end{theorem} line, it's slightly different:

)
Runaway text?
This is a theorem. \end {theorem} \begin {otherlanguage}{hebrew} \\ש\ETC.
! File ended while scanning text of \dth@everypar.
<inserted text>
}
<*> babeltest.tex

I suspect you have forgotten a \}', causing me
to read past where you wanted me to stop.
I'll try to recover; but if the error is serious,
you'd better type \E' or \X' now and fix your file.

! Emergency stop.


For the purpose of the project I don't need any theorems to be stated in Hebrew. I just need some text and minor mathematical symbols, these will be appended to the end of the document, too.

Is there a way to make babel ignore amsthm each other, so that I can have one big project for everything, or do I need to create a separate project for the Hebrew part?

Edit:

It seems that the main problem with my big project is the fact that I define a long list of \newtheorem and counters (using aliascnt) and I think that babel is just getting confused by all those new counters and theorem styles.

Any information on what and how to correct this would be mighty useful as well!

Edit II:

I just noticed that when only removing the \begin{theorem} and \end{theorem} lines it compiles without errors, but the "Chapter 1" is gone. I am also adding the [memoir] tag because I think it might be an internal clash between babel and memoir.

P.S.

It doesn't work if I change the class from memoir to something else. I just use memoir in my main project so I figured it would be best to keep it here as well.

-
I suggest you switch your example to use the 'article' (or 'minimal') documentclass, so as not to complicate things with 'memoir' (which doesn't have much to do with the fundamental issue). Here are more general guidelines to writing a Minimal Working Example. Also, aliascnt is not the problem: aliascnt + babel + Hebrew work fine (sort of) with ntheorem instead of amsthm. – einpoklum Aug 9 '12 at 22:44

This is a well-known and painful problem: rlbabel.def redefines \everypar, which is used by amsthm.

Here's a flakey workaround (not a minimal workaround - I'm basing this on @WD40's not-so-MWE):

\documentclass[hebrew,english]{memoir}
\usepackage[utf8x]{inputenc}
\usepackage{babel}
\makeatletter
\let\everypar\o@everypar
\makeatother
\selectlanguage{english}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[chapter]
\begin{document}
\chapter{Hello}
This is some text.\newline
\begin{theorem}
This is a theorem.
\end{theorem}
\begin{otherlanguage}{hebrew}
שלום
\end{otherlanguage}
\hfill\newline
English again!
\end{document}


(\o@everypar is the command that rlbabel.def stores as an alias of the original \everypar.) This might interfere with amsthms operation.

PS:

• The problem indeed has not much to do with the memoir class.
• This workaround was communicated to me in 2006 by Enrico Gregorio.
-
Hah, it works! Now babel throws hyperref off course by adding all sort of \beginL to things, is there a way to fix that too? – WD40 Aug 10 '12 at 19:49
Also, it breaks the custom chapter headers for some reason. So there is a minor clash with memoir. – WD40 Aug 10 '12 at 19:53
@WD40: First of all, I do suggest you switch to ntheorem or thmtools; you won't get very far in life with Hebrew + amsthm + hyperref. Other than that, ask a new TeX.SX question... – einpoklum Aug 11 '12 at 20:36

amsthm and babel with the hebrew option just don't work together. If I recall correctly it's because they both define a \R macro. You'll probably have more luck switching to xelatex and using the polyglossia package.

-
How painful is the move from pdflatex to xelatex? – WD40 Aug 9 '12 at 7:04
Also, is there a way to simply make amsthm unload and load babel at the end of the current document? – WD40 Aug 9 '12 at 8:00
@WD40: Can be somewhat painful. There are all sorts of bustage (although it's not Vafa's fault.) – einpoklum Aug 9 '12 at 22:38
@EyalRozenberg: I see. I suppose I'll do my next multilingual project in XeTeX from the start. – WD40 Aug 10 '12 at 19:39