mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-27 17:01:07 +00:00
Add rendering to MathmL visual results to MathMLTest
* fix maintenance script in parametrization for generating correct reference MathML * update MathML references for MMLmhchemTest * and update the reference formulas, which not display MathML correctly * tests which have math enviroment switch (which is currently not defined) are currently skipped Bug: T329620 Change-Id: I09f2c393880daa8fef3e2763821df59048c3c98c
This commit is contained in:
parent
846edd1611
commit
b26a8805c1
|
@ -203,9 +203,14 @@ class JsonToMathML extends Maintenance {
|
|||
* @return string MathML as string
|
||||
*/
|
||||
public function fetchMathML( string $tex, string $type, string $renderingMode ): string {
|
||||
$params = [ "type" => $type ];
|
||||
if ( $type == "chem" ) {
|
||||
$params["chem"] = true;
|
||||
$tex = "\\ce{ " . $tex . " }";
|
||||
}
|
||||
/** @var MathRenderer $renderer */
|
||||
$renderer = MediaWikiServices::getInstance()->get( 'Math.RendererFactory' )
|
||||
->getRenderer( $tex, [ "type" => $type ], $renderingMode );
|
||||
->getRenderer( $tex, $params, $renderingMode );
|
||||
$renderer->render();
|
||||
$mml = $renderer->getMathml();
|
||||
return $mml;
|
||||
|
|
|
@ -26,15 +26,16 @@ final class MMLmhchemTest extends MediaWikiUnitTestCase {
|
|||
private static string $FILENAMEREF = __DIR__ . "/Mhchemv4mml.json";
|
||||
|
||||
private static bool $APPLYFILTER = false;
|
||||
private static int $FILTERSTART = 93;
|
||||
private static int $FILTERSTART = 92;
|
||||
private static int $FILTERLENGTH = 1;
|
||||
private static bool $GENERATEHTML = false;
|
||||
private static string $GENERATEDHTMLFILE = __DIR__ . "/MMLmhchemTest-Output.html";
|
||||
private static array $SKIPPEDINDICES = [];
|
||||
private static array $SKIPPEDINDICES = [ 36,40,50,51,91,92,93,94 ];
|
||||
|
||||
public static function setUpBeforeClass(): void {
|
||||
MMLTestUtilHTML::generateHTMLstart( self::$GENERATEDHTMLFILE, [ "name","TeX-Input",
|
||||
"Tex-MhchemParser","Tex-PHP-Mhchem" ], self::$GENERATEHTML );
|
||||
"Tex-MhchemParser","Tex-PHP-Mhchem", "MathML-LaTeXML", "MathML-TexVC" ],
|
||||
self::$GENERATEHTML );
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void {
|
||||
|
@ -56,18 +57,24 @@ final class MMLmhchemTest extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
# Fetch result from TexVC(PHP)
|
||||
$texVC->check( $tc->tex, [
|
||||
'debug' => false,
|
||||
'usemathrm' => false,
|
||||
'oldtexvc' => false,
|
||||
'usemhchem' => true
|
||||
] );
|
||||
|
||||
$mhchemParser = new MhchemParser( self::$LOGMHCHEM );
|
||||
$mhchemOutput = $mhchemParser->toTex( $tc->tex, $tc->typeC );
|
||||
|
||||
$warnings = [];
|
||||
$resTexVC = $texVC->check( $mhchemOutput, [
|
||||
'debug' => false,
|
||||
'usemathrm' => true,
|
||||
'oldtexvc' => false,
|
||||
'usemhchem' => true,
|
||||
"usemhchemtexified" => true
|
||||
], $warnings, false );
|
||||
|
||||
$mathMLtexVC = isset( $resTexVC["input"] ) ? MMLTestUtil::getMMLwrapped( $resTexVC["input"] ) :
|
||||
"<math> error texvc </math>";
|
||||
|
||||
MMLTestUtilHTML::generateHTMLtableRow(
|
||||
self::$GENERATEDHTMLFILE, [ $title, $tc->tex, $tc->texNew, $mhchemOutput ],
|
||||
self::$GENERATEDHTMLFILE, [ $title, $tc->tex, $tc->texNew, $mhchemOutput, $tc->mml_latexml ?? "no mathml",
|
||||
$mathMLtexVC ],
|
||||
false, self::$GENERATEHTML );
|
||||
|
||||
if ( !self::$SKIPXMLVALIDATION ) {
|
||||
|
@ -85,16 +92,16 @@ final class MMLmhchemTest extends MediaWikiUnitTestCase {
|
|||
$ctr = 0;
|
||||
foreach ( $fileTestcases as $tcF ) {
|
||||
$tc = [
|
||||
"ctr" => $ctr,
|
||||
"tex" => $tcF->tex,
|
||||
"texNew" => $tcF->texNew,
|
||||
"type" => $tcF->type,
|
||||
"typeC" => $tcF->typeC,
|
||||
"mml_mathoid" => $tcF->mmlMathoid,
|
||||
"mml_latexml" => $tcF->mmlLaTeXML,
|
||||
"ctr" => $ctr,
|
||||
"tex" => $tcF->tex,
|
||||
"texNew" => $tcF->texNew,
|
||||
"type" => $tcF->type,
|
||||
"typeC" => $tcF->typeC,
|
||||
"mml_mathoid" => $tcF->mmlMathoid,
|
||||
"mml_latexml" => $tcF->mmlLaTeXML,
|
||||
];
|
||||
$f[] = [ "tc#" . str_pad( $ctr, 3, '0', STR_PAD_LEFT ) . " " . $tcF->description,
|
||||
(object)$tc ];
|
||||
(object)$tc ];
|
||||
$ctr++;
|
||||
}
|
||||
// Filtering results by index if necessary
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -195,7 +195,7 @@
|
|||
"type":"ce"
|
||||
},
|
||||
{
|
||||
"tex": "CH4 + 2 $\\left( \\ce{O2 + 79/21 N2} \\right)$",
|
||||
"tex": "CH4 + 2 \\begin{math} \\left( \\ce{O2 + 79/21 N2} \\right) \\end{math}",
|
||||
"texNew": "{\\mathrm{CH}{\\vphantom{A}}_{\\smash[t]{4}} {}+{} 2\\,\\left( \\mathrm{O}{\\vphantom{A}}_{\\smash[t]{2}} {}+{} \\mathchoice{\\textstyle\\frac{79}{21}}{\\frac{79}{21}}{\\frac{79}{21}}{\\frac{79}{21}}\\,\\mathrm{N}{\\vphantom{A}}_{\\smash[t]{2}} \\right) }",
|
||||
"type": "ce"
|
||||
}
|
||||
|
@ -217,7 +217,7 @@
|
|||
"type":"ce"
|
||||
},
|
||||
{
|
||||
"tex": "NaOH(aq,$\\infty$)",
|
||||
"tex": "NaOH(aq, \\begin{math} \\infty \\end{math})",
|
||||
"texNew": "{\\mathrm{NaOH}\\mskip2mu (\\mathrm{aq},\\infty )}",
|
||||
"type": "ce"
|
||||
}
|
||||
|
@ -275,12 +275,12 @@
|
|||
],
|
||||
"(Italic) Math": [
|
||||
{
|
||||
"tex": "NaOH(aq,$\\infty$)",
|
||||
"tex": "NaOH(aq, \\begin{math} \\infty$)",
|
||||
"texNew": "{\\mathrm{NaOH}\\mskip2mu (\\mathrm{aq},\\infty )}",
|
||||
"type":"ce"
|
||||
},
|
||||
{
|
||||
"tex": "Fe(CN)_{$\\frac{6}{2}$}",
|
||||
"tex": "Fe(CN)_{ \\begin{math} \\frac{6}{2} \\end{math}}",
|
||||
"texNew": "{\\mathrm{Fe}(\\mathrm{CN}){\\vphantom{A}}_{\\smash[t]{\\frac{6}{2} }}}",
|
||||
"type":"ce"
|
||||
},
|
||||
|
@ -502,22 +502,22 @@
|
|||
],
|
||||
"Complex Examples": [
|
||||
{
|
||||
"tex": "Zn^2+ <=>[+ 2OH-][+ 2H+] $\\underset{\\text{amphoteres Hydroxid}}{\\ce{Zn(OH)2 v}}$ <=>[+ 2OH-][+ 2H+] $\\underset{\\text{Hydroxozikat}}{\\ce{[Zn(OH)4]^2-}}$",
|
||||
"tex": "Zn^2+ <=>[+ 2OH-][+ 2H+] \\begin{math} \\underset{\\text{amphoteres Hydroxid}}{\\ce{Zn(OH)2 v}}\\end{math} <=>[+ 2OH-][+ 2H+] \\begin{math} \\underset{\\text{Hydroxozikat}}{\\ce{[Zn(OH)4]^2-}}\\end{math}",
|
||||
"texNew": "{\\mathrm{Zn}{\\vphantom{A}}^{2+} {}\\mathrel{\\underset{\\lower6mu{ {}+{} 2\\,\\mathrm{H}{\\vphantom{A}}^{+}}}{\\overset{ {}+{} 2\\,\\mathrm{OH}{\\vphantom{A}}^{-}}{\\longrightleftharpoons}}}{} \\underset{\\text{amphoteres Hydroxid}}{\\ce{Zn(OH)2 v}} {}\\mathrel{\\underset{\\lower6mu{ {}+{} 2\\,\\mathrm{H}{\\vphantom{A}}^{+}}}{\\overset{ {}+{} 2\\,\\mathrm{OH}{\\vphantom{A}}^{-}}{\\longrightleftharpoons}}}{} \\underset{\\text{Hydroxozikat}}{\\ce{[Zn(OH)4]^2-}} }",
|
||||
"type":"ce"
|
||||
},
|
||||
{
|
||||
"tex": "$K = \\frac{[\\ce{Hg^2+}][\\ce{Hg}]}{[\\ce{Hg2^2+}]}$",
|
||||
"tex": " \\begin{math} K = \\frac{[\\ce{Hg^2+}][\\ce{Hg}]}{[\\ce{Hg2^2+}]}\\end{math}",
|
||||
"texNew": "{K = \\frac{[\\ce{Hg^2+}][\\ce{Hg}]}{[\\ce{Hg2^2+}]} }",
|
||||
"type":"ce"
|
||||
},
|
||||
{
|
||||
"tex": "$K = \\ce{\\frac{[Hg^2+][Hg]}{[Hg2^2+]}}$",
|
||||
"tex": " \\begin{math} K = \\ce{\\frac{[Hg^2+][Hg]}{[Hg2^2+]}}\\end{math}",
|
||||
"texNew": "{K = \\frac{[\\mathrm{Hg}{\\vphantom{A}}^{2+}][\\mathrm{Hg}]}{[\\mathrm{Hg}{\\vphantom{A}}_{\\smash[t]{2}}{\\vphantom{A}}^{2+}]}}",
|
||||
"type":"ce"
|
||||
},
|
||||
{
|
||||
"tex": "Hg^2+ ->[I-] $\\underset{\\mathrm{red}}{\\ce{HgI2}}$ ->[I-] $\\underset{\\mathrm{red}}{\\ce{[Hg^{II}I4]^2-}}$",
|
||||
"tex": "Hg^2+ ->[I-] \\begin{math} \\underset{\\mathrm{red}}{\\ce{HgI2}}\\end{math} ->[I-] \\begin{math} \\underset{\\mathrm{red}}{\\ce{[Hg^{II}I4]^2-}}\\end{math}",
|
||||
"texNew": "{\\mathrm{Hg}{\\vphantom{A}}^{2+} {}\\mathrel{\\xrightarrow{\\mathrm{I}{\\vphantom{A}}^{-}}}{} \\underset{\\mathrm{red}}{\\ce{HgI2}} {}\\mathrel{\\xrightarrow{\\mathrm{I}{\\vphantom{A}}^{-}}}{} \\underset{\\mathrm{red}}{\\ce{[Hg^{II}I4]^2-}} }",
|
||||
"type":"ce"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue