Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with TeX \cases construct #32

Closed
Stevenparsons opened this issue Nov 24, 2010 · 6 comments
Closed

problem with TeX \cases construct #32

Stevenparsons opened this issue Nov 24, 2010 · 6 comments

Comments

@Stevenparsons
Copy link

There is a problem with the \cases command. It doesn't seem to be working properly in MathJax. The cases test from TeXbook pg 175 runs as follows:

$$ |x|=\cases{x,&if $x\ge0$;\cr -x,&otherwise. \cr}$$

MathJax appears to typeset the text in math italic whereas TeX typesets it in an upright font with normal text spacing. See http://screencast.com/t/eX3lcHOJGu for image.

Is anyone else running into this?

@dpvc
Copy link
Member

dpvc commented Nov 25, 2010

Robert:

Because MathJax doesn't really process text-mode material (only math-mode), its parser doesn't handle the Plain TeX \cases command properly. (To my knowledge, this is the only standard macro that has mixed math/text mode material like this.) You are correct that this is not consistent with actual TeX (one of a handful of differences).

One could use the \text{} macro on the second column entries to make it work, but that is not required in actual TeX. It is one of the things that could be improved, but I haven't looked into what it would take. BTW, jsMath processed this the same way.

Davide

@dpvc
Copy link
Member

dpvc commented Dec 9, 2010

Well, as a temporary measure, if you add this to your configuration right after the MathJax.Hub.Config() call, it will redefine \cases so that it will work better in most cases.

MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
  var TEX = MathJax.InputJax.TeX;
  TEX.Definitions.macros.Cases = TEX.Definitions.macros.cases;
  TEX.Definitions.macros.cases = "myCases";
  TEX.Parse.Augment({
    myCases: function (name) {
      var tex = this.GetArgument(name);
      var tex = '\\begin{cases}' +
                  tex.replace(/\&/g,'\&\\text{').replace(/\\cr/g,'}\\\\') + '}' +
                '\\end{cases}'
      this.string = tex + this.string.slice(this.i); this.i = 0;
    }
  });
});

It also makes the old \cases available as \Cases.

The problem is that it won't work properly if the entries in the \cases include other macros that have arrays in them (e.g., if one of the cases included a matrix). In that case, this "fix" will foul up the equation completely.

The real solution is to write a specialized implementation for \cases, but that is not likely to happen before the new year.

Davide

@dpvc
Copy link
Member

dpvc commented May 8, 2011

I have worked out the details for making \cases typeset the second column in text mode automatically. The cases branch of my fork of MathJax includes the patch.

@dpvc dpvc reopened this May 8, 2011
@fred-wang
Copy link
Contributor

I've prepared a reftest for this issue and check that the branch "cases" fixes it.

==> In testsuite

@fred-wang
Copy link
Contributor

LaTeXToMathML/cases-1.html

@dpvc dpvc closed this as completed Feb 27, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants