# TeX equations not rendering the not-equal symbol correctly

My answer uses \neq but it doesn't work. I tried other ways but it didn't help. Am I doing something wrong or is it a bug, i.e. does it work in questions and in comments but not in answers?

I've looked at http://meta.math.stackexchange.com/q/9906/191910 and http://meta.math.stackexchange.com/q/5020/191910 (number 12).

UPDATE

It's something else:

$$d_{1}\left(x,y\right)=\cases{ 0,&x=y\cr 1,&x\neq y}$$
renders

$$d_{1}\left(x,y\right)=\cases{ 0,&x=y\cr 1,&x\neq y}$$

while
$$d_{1}\left(x,y\right)=\cases{ 0&\text{if }x=y\cr 1&\text{if }x\neq y}$$
renders

$$d_{1}\left(x,y\right)=\cases{ 0&\text{if }x=y\cr 1&\text{if }x\neq y}$$

So \text{if } made the difference, but why?

• Actually, I think I remember now, the second part of \cases is text, not a formula. But \text (drhab told me about it) makes it a formula? Hmm... How about $$d_{1}\left(x,y\right)=\cases{ 0,&x=y\cr 1,&x\neq y}$$? $$d_{1}\left(x,y\right)=\cases{ 0,&x=y\cr 1,&x\neq y}$$Yes, it works. – Heimdall May 17 '16 at 10:21

This is mainly by design. The explanation you give yourself in the comment is correct.

The (TeX) command \cases is unusual, in that while it is mainly "math" the part after the ampersand (&) is "text" as you said.

Indeed, this initially was not handled properly in MathJax but by now is fixed see https://github.com/mathjax/MathJax/issues/32

Yet, in fact the fix is what causes the problem for you.

To see this note how the letter I is rendered differently depending on its position before or after the amersand.

$$\cases{ I & I \cr I & I }$$


$$\cases{ I & I \cr I & I }$$

That adding the \text puts the remainder after the text in math-mode and fixes the problem is quite odd, I think. This may qualify as bug, not sure. It ought to be due to the fact that you somehow manage to start text-mode while in text-mode, which should do nothing and not even be possible (note it only works when you start it right after the ampersand). When you leave text-mode you are "back" in (default) math-mode.

$$\cases{ I & \text{I}I \cr I & I }$$


$$\cases{ I & \text{I}I \cr I & I }$$

$$\cases{ I & I\text{I}I \cr I & I }$$


$$\cases{ I & I\text{I}I \cr I & I }$$

All that said, I would just not use \cases at all. Rather use \begin{cases} ... \end{cases} which does not have this unusual feature, and generally is more in line with other constructs. (I'd use \\ instead of \cr but both seem to work.)

$$\begin{cases} 0,&x=y\cr 1,&x\neq y \end{cases}$$


$$\begin{cases} 0,&x=y\cr 1,&x\neq y \end{cases}$$

If you really want to use \cases (and not switch to \begin{cases}) in the way you intended to, you can start the math-mode after the ampersand explicitly adding dollars, like:

$$d_{1}\left(x,y\right)=\cases{ 0,& x=y \cr 1,& x \neq y }$$


$$d_{1}\left(x,y\right)=\cases{ 0,& x=y \cr 1,& x \neq y }$$

• Thanks. The explicit dollars in \cases looks right for me. I'm more of a plain TeXacker, not too keen on some LaTeX constructs. (I would use them occasionally if they make it easier.) – Heimdall May 18 '16 at 10:05

As quid mentioned in his post, MathJax originally didn't implement \cases properly. Specifically, the second column was in math mode rather than text mode as it is supposed to be. This was fixed in version 2.0, but prior to that, people had been using \text{} in the second column as a work-around in order to get the text mode that should have been there in the first place.

Since version 1.x was in use for a year before 2.0 came out, there were a number of equations extant that used this work-around. In order not to break those equations, the fix in v2.0 included a test to see if the second column started with \text{}, and if it did, the column was left in math mode (and the \text{} macro handled conversion to text mode); if not, text-mode was set automatically.

The was a compromise in order to be backward compatible with the existing usage, and it does mean that the result is not exactly the same as $\rm\LaTeX$ itself, but it did mean that people's existing equations didn't break. It does lead to the situation that you have experienced, here, however. But since that comes basically from a misunderstanding of the \cases macro to begin with, it seemed a reasonable compromise.

The testing for \text{} could be made more robust, I suppose, so that leaving the column in math mode would only occur if the \text{} macro enclosed the entire column. In that case, your second example

$$d_{1}\left(x,y\right)=\cases{ 0&\text{if }x=y\cr 1&\text{if }x\neq y}$$


would produce

$$d_{1}\left(x,y\right)=\cases{ 0&\text{\text{if }x=y}\cr 1&\text{\text{if }x\neq y}}$$

I suppose that would at least make it clear that what you have written isn't what you want.

• I opened an issue tracker for the improved handling of \text around the second column. – Davide Cervone May 19 '16 at 13:51