Recently I’ve worked on a Hebrew document in LaTeX and wanted to use the split environment to typeset some multiline formula. The document which compiled just fine till that point, failed to compile with the following error:
Package amsmath Error: \begin{split} won't work here.
I was using LyX, so I’ve assumed that it would generate the correct syntax for this environment. But the error clearly said that the \begin{split}
was used wrong. I’ve went through the user’s guide for the amsmath
package and rechecked the syntax. The document has a very handy section that contain common error messages and explanations. I was happy to find out that the error I got was documented there. Unfortunately, the explanation only confirmed that LyX generated the appropriated code for the split
environment.
At this point, I’ve decided to export the document to a LaTeX file and manually tweak it till I find a solution. I’ve removed everything from the document apart from some Hebrew text and the split
formula. I’ve suspected this error had to do with the Hebrew, as nobody else reported errors using split
to the LyX mailing list. I’ve remembered that someone mentioned to me once that LaTex is very sensitive to the order the packages are added. So I’ve started to play with the order and moved the \usepackage
statements around. When I’ve put the \usepackage{babel}
above the \usepackage{amsmath}
the document suddenly compiled fine.
Some further testing showed that in order for the split
environment to work properly in an Hebrew document the babel
package must be included before amsmath
and any other package that depends on it (like mathtools
).
Getting things to work back in LyX was a bit more tricky. LyX automatically adds the babel
package after the LaTeX preamble, and by default it adds the amsmath
when needed, but it does so before the LaTeX preamble. This, as you can see, results in the \usepackage{amsmath}
appearing before the \usepackage{babel}
. The solution had to override the placements of both statements.
The first step is to go to Document->Settings->Math Options and uncheck both “Use the AMS math package automatically” and “Use the AMS math package”. This won’t prevent you from using any to the amsmath
package feature if you include it manually (like we will do). The next step is to go to Documents->Settings->LaTeX Preamble, and insert directly at the top of the preamble the following two lines:
\usepackage{babel}
\usepackage{amsmath}
Now the Hebrew document will compile fine even if you use the amsmath
‘s split
environment. Note that LyX will add \usepackage
statement for for babel
after the preamble despite the fact you already have one. But don’t worry, LaTeX will ignore that second statement and no harm will be done.
Thank you! I didn’t get the commandos \underline and \overline and a few others to work in LyX, searched all over the web for an explanation without finding any, but when doing what you are proposing here, it all went fine!
Meant \underset and \overset, of course.
Hi Harold, if take a look at Add Explanation to LaTeX Formulas (Equations) it features a latex macros which is a good example of using \underset and \overset.
I get a similar problem when attempting to use hyperref. Adding the \usepackage[…]{hyperref} to the preamble works whereas checking it in the document settings doesn’t.
I can’t get bookmarks to display hebrew anyway, but at least the bookmarks are generated. It would be great if someone could help me with this though.
Thanks for all your tips, they are of great help 🙂