Page MenuHomePhabricator

Can't parse array elements
Closed, ResolvedPublic

Description

It seems Mathoid (texvcinfo) can't parse the array element. Reported for https://de.wikipedia.org/wiki/St%C3%B6chiometrische_Matrix (which has other alignment problems as well)

math-Stöchiometrische_Matrix.png (500×772 px, 64 KB)

Event Timeline

mobrovac added a subscriber: Physikerwelt.

https://en.wikipedia.org/wiki/Stoichiometry#Stoichiometry_matrix uses bmatrix which works. Also, array works in PNG mode, so it's definitely a regression caused by T131177: Enable MathML by default

Its the option [h] parameter in

\begin{array}[h]{rcl}

remove that and things work fine

\begin{array}{rcl}

From T131177#2344157 it is likely connected to the optional [h] parameter, not \array itself.

The root cause for this problem is in texvc

vagrant/srv/texvcjs/bin (master)
$ ./texvcjs '\begin{array}[h]{crcl}
R_1 := & \text{A} & \rightarrow & \text{B},\\
R_2 := & 4 \text{C} + 2 \text{B} & \rightarrow & 5 \text{C} + \text{B},\\
R_3 := & \text{C} & \rightarrow & \text{D},\\
R_4 := & \text{D} & \rightarrow & \text{A},
\end{array}'
(node) util.print is deprecated. Use console.log instead.
F\begin{array}

Is there documentation of the optional parameter of the array envirnoment in standard TeX/LaTeX?
That would be really helpful.

I can only find documentation on the tcb but not h. Thus I have no clue what the expected behaviour is?

I don't use that much TeX/LaTeX, but you could try testing it in PNG mode which I believe we know to work and see what it does in different situations. I don't know if you can look at the code, but you could try that too although that would be more difficult you would get a definite answer. There must be something about it somewhere though as why would people use it if they have never heard of it or did not know what it did. It is possible it was written in a non-English language which might make searching more difficult.

Is there documentation of the optional parameter of the array envirnoment in standard TeX/LaTeX?

There is no such option. TeX ignores it

Pardon my hurry earlier. The value h will simply ignored in TeX (and in MathJax).

If there is no option and it is ignored then why is it causing problems now but not with PNG only mode? What happens if one that page with the problems you remove it?

There is a slight difference in the list of whitelisted commands.
The new rendering mode allows for tcb only.
https://github.com/wikimedia/texvcjs/blob/master/lib/parser.pegjs#L217-L219
The old png seems to allow h as well
https://github.com/wikimedia/mediawiki-extensions-Math/blob/master/math/util.ml#L7-L9

Would it be possible to remove all usages of h?

I will put out an RFC on en-Wikipedia, but it is not possible to add some rule that translates the "h"'s to "tcb" before parsing them? It might be less elegant, but it could work.

I did a scan of my 2014 dump of the english wikipedia and found no instances of the [h] parameter, but there was one instance of \begin{array}[l] in
https://en.wikipedia.org/wiki/Spin_angular_momentum_of_light
which I've fixed.

I think the option derives from the tabular environment in
http://texdoc.net/texmf-dist/doc/latex/latex2e-help-texinfo/latex2e.pdf
page 31 we have

pos Specifies the vertical position; default is alignment on the centre of the environment.
  t align on top row 
  b align on bottom row

@Hungryce, I think it would be good to get rid of all the invalid alternatives. Allowing h would not be a problem, but it would take about two weeks until the change gets online.

+1 for removing [h]. Creating per-case work-arounds and ignore lists is not feasible in the long run, IMHO.

The way these appear in standard latex is shown below

latex array.png (440×329 px, 37 KB)

Source latex is

Standard  $\begin{array}{rl} a & b \\ c & d  \\ e & f \end{array}$ bar.

Center aligned [c]  $foo \begin{array}[c]{rl} a & b \\ c & d \\ e & f \end{array}$ bar.

Top aligned [t]  $foo \begin{array}[t]{rl} a & b \\ c & d \\ e & f \end{array}$ bar.

bottom aligned [b]  $foo \begin{array}[b]{rl} a & b \\ c & d \\ e & f \end{array}$ bar.

Mysterious [h]  $foo \begin{array}[h]{rl} a & b \\ c & d \\ e & f \end{array}$ bar.

Mysterious [l]  $foo \begin{array}[l]{rl} a & b \\ c & d \\ e & f \end{array}$ bar.

On wikipedia they all appear as the no option version. Client-side mathjax has same behavior as latex.

@SalixAlba how did you test the ClientSide mathjax rendering?

Just a standard webpage with normal mathjax

  <script type="text/javascript"
         src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
   </script>
   <script type="text/javascript">
   	MathJax.Hub.Config({
	  jax: ["input/TeX","output/HTML-CSS"],
	  extensions: ["tex2jax.js"],
	  "HTML-CSS": {    scale: 100  },
	  tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
  	});
  </script>
  <body>
  <p>  Top aligned [t]  $foo \begin{array}[t]{rl} a & b \\ c & d \\ e & f \end{array}$ bar.
  </body >

@Physikerwelt I have made an RFC at https://en.wikipedia.org/wiki/Wikipedia:Village_pump_(proposals)#RFC:_Replace_all_instances_of_.5Bh.5D_in_TeX.2FLaTeX_.28and_in_MathJax.29_with_.5Btcb.5D (I did this because I can't make a bot/AWB script myself) to get rid of [h]'s. I am not sure there are any on en-wiki, but I wish to make sure.

Physikerwelt claimed this task.

the example
\begin{array}[t]{rl} a & b \\ c & d \\ e & f \end{array}
works
https://wikimedia.org/api/rest_v1/media/math/render/mml/89afa838cef7fae338deb1a86762fb92793a6cea
now