Page MenuHomePhabricator

Add additional statements from mhchemParser to texvc-php grammar
Closed, ResolvedPublic

Description

mhchemParser in PHP used as a preprocessor introduces new tex-statements to the texVC-grammar based check. For further processing to MathML it is required that texvc also recognizes the new statements.

A basic prototype of integrating mhchemParser as preprocessor can be found here. It also contains prototypical recognition of some new statements. The recognition is not necessarily correct yet.

From the running the tests in MMLmhchemTestLocal.php, these statements are not recognized currently (this test has the same testcases as test.html in mhchemParser in javascript):

  • \mkern -> \mkern #1 (fun_ar1)
  • \mskip -> \mskip #1 (fun_ar1)
  • \smash -> \smash[#1]{#2} (fun_ar1opt)
  • \mathchoice -> \\mathchoice #1 #2 #3 #4 (fun_ar4, new)
  • \longleftrightarrows (literal, change)
  • \longrightleftharpoons (literal, change)
  • \longRightleftharpoons (literal, change)
  • \longLeftrightharpoons (literal, change)
  • \tripledash (literal, change)
  • \rlap -> \rlap #1 (fun_ar1)
  • \llap -> \llap #1 (fun_ar1)
  • \raise -> \raise #2 #2 (fun_ar2)
  • \lower -> \lower #1 #2 (fun_ar2)

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change 926293 had a related patch set uploaded (by Stegmujo; author: Stegmujo):

[mediawiki/extensions/Math@master] Create prototype of mhchemParser-PHP TexVC integration

https://gerrit.wikimedia.org/r/926293

Stegmujo renamed this task from Add additional statements to texvc-php grammar to Add additional statements from mhchemParser to texvc-php grammar .Jun 21 2023, 11:39 AM
Stegmujo updated the task description. (Show Details)

@Stegmujo can you provide sample arguments for each of the commands, we need that to update https://github.com/wikimedia/mediawiki-services-texvcjs/blob/master/doc/main.pdf ? For the subsequent rendering task, it might be also a good idea to check out the matjax and also latexml renderings for each command.

Yes, I sent you file for this. This file can be also be (re)generated locally with a JsonToMathML maintenance script for now in https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/923597/89

It contains tex cases with their parametrization as well as descriptions and rendered MathML from LaTeXML.

This is hard to read, and I still don't understand the parameters.

Could you please extract just the parameters like that

\mkern 
\mskip
\smash -> \smash[a]{b}
\mathchoice
\longleftrightarrows 
\longrightleftharpoons
\longRightleftharpoons
\longLeftrightharpoons
\tripledash
\rlap

It seems that it will be pretty challenging to support commands like

https://www.tutorialspoint.com/tex_commands/mkern.htm

as the grammar has no idea of <dim>. I suggest using
\mkern{dim}
instead.
When you generate all the commands programmatically, I think it would be easier to add curlies instead of defining what dim means in the grammar.

Please specify required format upfront, this saves lots of time
Here the parameters extracted from the file. Statements without arrow don't have additional parameters.

 \mkern -> \mkern <dimen>
 \mskip  -> \mskip <dimen> 
 \smash -> \smash[a]{b}
 \mathchoice -> \\mathchoice #1 #2 #3 #4    Example: \mathchoice{D}{T}{S}{SS}
 \longleftrightarrows
 \longrightleftharpoons
 \longRightleftharpoons
 \longLeftrightharpoons
 \tripledash
 \rlap -> \rlap #1
\llap -> \llap #1
\raise -> \raise <dim> #1
\lower -> \lower <dim> #1

Having an output for mkern and mskip's dim in curlies will mess up many testcases of mhchemParser in PHP.
Maybe this could be activated as a flag in mhchemParser (~~i.e. TexVC-Optimized output or something) so the testcases can still be used.

Having an output for mkern and mskip's dim in curlies will mess up many testcases of mhchemParser in PHP.
Maybe this could be activated as a flag in mhchemParser (~~i.e. TexVC-Optimized output or something) so the testcases can still be used.

Sounds like a plan. Let's do it that way.

Ok, I added the flag for adding curly for mkern and mskip for mhchem in the current implementation, seems to work.

Just noted while checking the mhchemTexify (which produces the tex-output in mhchem) component while implemetation, that these statements would be probably not implemented in current TexVC parsetree.

\llap #1
\raise<dim> #1
\lower <dim> #1

They are not part of the erroneous test-output notifications for doing texvc checks with upgraded math, but i guess somewhere these will also produced as tex-output. For raise and lower i implemented the previously mentioned workaround by surrounding dim with curlies.

On the other hand if you can provide a regexp for valid dim expressions this can implemented by one additional line in the grammar...

Let's stick to the plan, it's already implemented with curlies now.

So the final list ist, correct?

 \mkern -> \mkern #1 (fun_ar1)
 \mskip  -> \mskip #1 (fun_ar1)
 \smash -> \smash[#1]{#2} (fun_ar1opt)
 \mathchoice -> \\mathchoice #1 #2 #3 #4 (fun_ar4, new)
 \longleftrightarrows (literal)
 \longrightleftharpoons  (literal)
 \longRightleftharpoons  (literal)
 \longLeftrightharpoons  (literal)
 \tripledash  (literal)
 \rlap -> \rlap #1 (fun_ar1)
\llap -> \llap #1 (fun_ar1)
\raise -> \raise #2 #2 (fun_ar2)
\lower -> \lower #1 #2 (fun_ar2)

Change 938264 had a related patch set uploaded (by Physikerwelt; author: Physikerwelt):

[mediawiki/extensions/Math@master] Add tex node with 4 arguments

https://gerrit.wikimedia.org/r/938264

Change 938303 had a related patch set uploaded (by Physikerwelt; author: Physikerwelt):

[mediawiki/extensions/Math@master] Add usemhchempost option to enable mhchem postprocessing

https://gerrit.wikimedia.org/r/938303

Change 938264 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Add tex node with 4 arguments

https://gerrit.wikimedia.org/r/938264

Change 938303 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Add usemhchemtexified option for mhchem texified output

https://gerrit.wikimedia.org/r/938303

Change 939259 had a related patch set uploaded (by Physikerwelt; author: Physikerwelt):

[mediawiki/extensions/Math@master] Add remaining mhchemtexified macros:

https://gerrit.wikimedia.org/r/939259

Change 939259 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Add remaining mhchemtexified macros:

https://gerrit.wikimedia.org/r/939259

Change 926293 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Create prototype of mhchemParser-PHP TexVC integration

https://gerrit.wikimedia.org/r/926293