pkra / mathjax-node-page

mathjax-node for pages
Apache License 2.0
42 stars 20 forks source link

`\newcommand` parsing seems to sometimes glitch out or skip commands #69

Closed Discordius closed 6 years ago

Discordius commented 6 years ago

Ok, I am really quite confused by this and am trying to figure this out, so sorry if this turns out to be some kind of bug in MathJax.

I am trying to parse the following HTML document:

<p>This is some random text</p>
<p>\[\newcommand{\NN}{\mathbb{N}}\]
\[\newcommand{\cL}{\mathcal{L}}\]
\[\newcommand{\RR}{\mathbb{R}}\]
\[\newcommand{\dom}{\mathrm{dom}}\]
\[\newcommand{\Pow}{\mathrm{Pow}}\]
\[\newcommand{\cU}{\mathcal{U}}\]</p>
<h1>The new &quot;truth predicate&quot;</h1>
<p>The &quot;truth predicate&quot; we'll discuss in this post will actually be a real-valued two-argument function, \(\theta : \NN\times\NN\to[0,1]\). Let \(\cL\) be the language of set theory, and let \(\cL_\theta\) be \(\cL\) extended with a single constant symbol, also written \(\theta\) (because this constant symbol will represent the function \(\theta(\cdot,\cdot)\) inside our object language); then the arguments to \(\theta(\cdot,\cdot)\) that we're interested in will be the Gödel numbers of sentences in \(\cL_\theta\). Roughly speaking, the reflection principle for \(\theta(\cdot,\cdot)\) will be as follows: If \(\varphi\) and \(\psi\) are mutually exclusive sentences in \(\cL_\theta\) which satisfy a certain topological condition, then will equal \(0\) if \(\varphi\) is true, will equal \(1\) if \(\psi\) is true, and will be arbitrary otherwise</p>

However, if I do this, then the \cL macro fails to be parsed, and I am getting the following error:

W20180814-21:31:36.355(-7)? (STDERR) Formula \psi contains the following errors:
W20180814-21:31:36.355(-7)? (STDERR)  [ 'TeX parse error: Undefined control sequence \\cL' ]

And now this is where it gets confusing. If I change the order of the first two \newcommands, i.e. change the first few lines to the following:

<p>This is some random text</p>
<p>\[\newcommand{\cL}{\mathcal{L}}\]
\[\newcommand{\NN}{\mathbb{N}}\]
\[\newcommand{\RR}{\mathbb{R}}\]

Then I instead get the error that \NN isn't found.

And even weirder, if I just add a random newcommand to the second line like this:

<p>This is some random text</p>
<p>\[\newcommand{\cL}{\mathcal{L}}\]
\[\newcommand{\asdf}{asdf}\]
\[\newcommand{\NN}{\mathbb{N}}\]
\[\newcommand{\RR}{\mathbb{R}}\]

Then everything works fine and I don't get any errors.

Here is my complete mathjax-node-page setup:

mjpage(html, 
  {format: ["TeX"], displayErrors: true, extensions: "TeX/autoload-all.js"}, 
  {html: true, css: true, useGlobalCache: true}, 
  (html) => {
     resolve(html)
  })
pkra commented 6 years ago

Thanks for the report!

pkra commented 6 years ago

Ok, I can reproduce this. One workaround is to move the macro definitions to the mathjax-node part of the configuration (if that's feasible).

Since nothing obvious jumps out at me, I'll try to find time to dig into this.

pkra commented 6 years ago

@roman-spiridonov any thoughts on why the error message is for the wrong equation?

pkra commented 6 years ago

Looks like a regression in 3.0.0 so downgrading to 2.0.0 may be another workaround.

pkra commented 6 years ago

Ah, got it. This regression due to the fix for #47 - the sorting moves a script with \cL before the script with the macro definition.

Discordius commented 6 years ago

Yeah, sadly moving the macro definitions to the mathjax-node part doesn't work, because I am doing a content import from a database that had them defined in the body, and I would really like to avoid having to extract them from there.

pkra commented 6 years ago

Right, that was just a first thought for a workaround. Now that I'm reasonably sure about the cause, I just need to find some time to fix it.

pkra commented 6 years ago

v3.0.1 is out.