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

Incorrect mathjax rendering of certain arrays of equations #2289

Closed
fperez opened this issue Aug 11, 2012 · 10 comments
Closed

Incorrect mathjax rendering of certain arrays of equations #2289

fperez opened this issue Aug 11, 2012 · 10 comments
Milestone

Comments

@fperez
Copy link
Member

fperez commented Aug 11, 2012

As reported on the list, certain equations are being incorrectly rendered. Consider:

$$
\begin{array}{c}
y_1 \\\
y_2 \mathtt{t}_i \\\
z_{3,4}
\end{array}
$$

it simply produces a line of plain text with all of the above. As it turns out, removing the mathtt call or the _i subscript or making the z subscript be a single character (say z_3) produces correct rendering. But somehow, the mathtt call in combination with the others makes it simply not work.

@bfroehle
Copy link
Contributor

Preliminary word on the mailing list is that this is getting pre-processed by markdown (or similar) which adds some stray <em> tags, interfering with MathJax.

@matthew-brett
Copy link
Contributor

(copied from http://mail.scipy.org/pipermail/ipython-dev/2012-August/010042.html)

I think what is happening is that some other script (?markdown) is getting to the TeX before it gets to mathjax.

Specifically, if I put the mal-functioning TeX into a cell:

$$
\begin{array}{c}
y_1 \cr
y_2 \mathtt{t}_i \cr
y_{3}
\end{array}
$$

and put a breakpoint on the line:

MathJax.Hub.Queue(["Typeset",MathJax.Hub]);

in cell.js, the html in the cell before rendering is this:

<p>$$
\begin{array}{c}
y_1 \cr
y_2 \mathtt{t}<em>i \cr
y</em>{3}
\end{array}
$$</p>

Notice the stray <em> .. </em> tags. If I do a tiny edit to the malfunctioning TeX so that it renders correctly (removing the {} round the last '3'):

$$
\begin{array}{c}
y_1 \cr
y_2 \mathtt{t}_i \cr
y_3
\end{array}
$$

then the html before MathJax gets it is:

<p>$$
\begin{array}{c}
y_1 \cr
y_2 \mathtt{t}_i \cr
y_3
\end{array}
$$</p>

So I think something in the notebook is inserting the <em> .. </em> tags into the TeX, and this is busting the rendering.

What could be doing this? Is there a way of stopping this preprocessing of TeX? Could this also explain the need for three \ for end-of-line instead of two reported in issue #1381

@matthew-brett
Copy link
Contributor

Some other mis-rendered examples boil down to:

$X_*X_*$

@fperez
Copy link
Member Author

fperez commented Aug 16, 2012

Great! (not great that we misrender, but great that at least we're getting
a few test cases to validate this against). Thanks.

@antonl
Copy link

antonl commented Aug 21, 2012

Similarly, this doesn't work right:

$$\begin{eqnarray} 
x' &=& &x \sin\phi &+& z \cos\phi \\
z' &=& - &x \cos\phi &+& z \sin\phi \\
\end{eqnarray}$$

Replacing the double backslashes with \\\\ fixes it.

I think the problem is in Markdown.Converter.js. There is a function in there that is supposed to escape markdown magic characters in code blocks (escapeCharacters called from _DoCodeBlocks) but apparently it isn't working correctly. I don't know regexes and js well enough to fix it though. In python_markdown2 they solved this problem by just removing code blocks from processing entirely, cutting them out and replacing them later after markup was done.

@minrk
Copy link
Member

minrk commented Aug 21, 2012

Yes, I think the problem is mainly that markdown is totally unaware of MathJax (if I remember correctly), which then runs on the HTML markdown generates. So it's probably not in a code block or anything. Essentially what we want is for the markdown parser to be aware of the mathjax blocks, and leave them totally untouched, as it should already be doing with <pre> tags or similar.

@minrk
Copy link
Member

minrk commented Aug 22, 2012

Another example reported in #2325 that falls victim to markdown parsing inside mathjax:

$\mathbf{A}_{i}B_{j}$

The workaround being to add spaces so it doesn't match the regex:

$\mathbf{A}_{i}B _{j}$

which is still valid, if slightly weird latex.

Or escape underscores:

$\mathbf{A}\_{i}B\_{j}$

which will get the right value in MathJax, but cannot be copied/pasted into regular latex without removing the escapes.

@fperez
Copy link
Member Author

fperez commented Sep 6, 2012

I've just tested #2349, and it's looking great. I'd make this a candidate for backport to 0.13.1, since it's really annoying to have some latex not work. @minrk, what do you think?

@fperez fperez closed this as completed in 2962dae Nov 2, 2012
@mattions
Copy link

I'm on the latest Ipython (0.13.2) and I have the same problem as pointed out by antoni #2289 (comment) few message above.

The problem is that the two \\ are not interpret by MathJs and everything is rendered as one line. Using four \\\\ fix the issue.

Could this be a regression?

@Carreau
Copy link
Member

Carreau commented Jul 10, 2013

@mattions, Fix has been merge for 1.0, not in 0.13.2 , there will most probably don't b any 0.13.3 as 1.0 is due soon.

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
Addresses the javascript errors resulting in a blank notebook pointed out in ipython#2349 as well as significant performance degradations that were introduced by that merge.

It also disables equation numbering/references, fixes broken offline access and re-typesets individual Notebook Cells instead of the entire document on edit.

Closes ipython#2289.
leetschau added a commit to leetschau/mlOperatorIntro that referenced this issue Oct 16, 2018
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

7 participants