Add usemhchemtexified option for mhchem texified output

Add a config option to enable passing special macros needed to
handle the output from the mhchem texify process.

Bug: T340023
Change-Id: I3553931c252184b54e7a13938e030825e5d45e59
This commit is contained in:
Moritz Schubotz (physikerwelt) 2023-07-14 22:26:30 +02:00 committed by Physikerwelt
parent f6832d0235
commit 26cfc111f9
6 changed files with 49 additions and 5 deletions

View file

@ -35,6 +35,7 @@ class ParserUtil {
$optionsBase = [ $optionsBase = [
'usemathrm' => false, 'usemathrm' => false,
'usemhchem' => false, 'usemhchem' => false,
'usemhchemtexified' => false,
'oldtexvc' => false, 'oldtexvc' => false,
'oldmhchem' => false, 'oldmhchem' => false,
'debug' => false, 'debug' => false,

View file

@ -73,7 +73,7 @@ class TexVC {
]; ];
if ( $options['report_required'] ) { if ( $options['report_required'] ) {
$pkgs = [ 'ams', 'cancel', 'color', 'euro', 'teubner', 'mhchem', 'mathoid' ]; $pkgs = [ 'ams', 'cancel', 'color', 'euro', 'teubner', 'mhchem', 'mathoid', 'mhchemtexified' ];
foreach ( $pkgs as $pkg ) { foreach ( $pkgs as $pkg ) {
$pkg .= '_required'; $pkg .= '_required';
@ -92,6 +92,16 @@ class TexVC {
]; ];
} }
} }
if ( !$options['usemhchemtexified'] ) {
if ( $result['mhchemtexified_required'] ??
$input->containsFunc( $this->tu->getBaseElements()['mhchemtexified_required'] )
) {
return [
'status' => 'C',
'details' => 'virtual mhchemtexified package required.'
];
}
}
return $result; return $result;
} catch ( Exception $ex ) { } catch ( Exception $ex ) {
if ( $ex instanceof SyntaxError && !$options['oldtexvc'] if ( $ex instanceof SyntaxError && !$options['oldtexvc']

View file

@ -1386,18 +1386,34 @@
"\\log": { "\\log": {
"latex_function_names": true "latex_function_names": true
}, },
"\\longLeftrightharpoons": {
"mhchemtexified_required": true,
"nullary_macro": true
},
"\\longRightleftharpoons": {
"mhchemtexified_required": true,
"nullary_macro": true
},
"\\longleftarrow": { "\\longleftarrow": {
"nullary_macro": true "nullary_macro": true
}, },
"\\longleftrightarrow": { "\\longleftrightarrow": {
"nullary_macro": true "nullary_macro": true
}, },
"\\longleftrightarrows": {
"mhchemtexified_required": true,
"nullary_macro": true
},
"\\longmapsto": { "\\longmapsto": {
"nullary_macro": true "nullary_macro": true
}, },
"\\longrightarrow": { "\\longrightarrow": {
"nullary_macro": true "nullary_macro": true
}, },
"\\longrightleftharpoons": {
"mhchemtexified_required": true,
"nullary_macro": true
},
"\\looparrowleft": { "\\looparrowleft": {
"ams_required": true, "ams_required": true,
"nullary_macro": true "nullary_macro": true
@ -2320,6 +2336,10 @@
"ams_required": true, "ams_required": true,
"nullary_macro": true "nullary_macro": true
}, },
"\\tripledash": {
"mhchemtexified_required": true,
"nullary_macro": true
},
"\\twoheadleftarrow": { "\\twoheadleftarrow": {
"ams_required": true, "ams_required": true,
"other_delimiters1": true "other_delimiters1": true

View file

@ -238,4 +238,16 @@ class ApiTest extends MediaWikiUnitTestCase {
[ 'usemhchem' => true, 'oldmhchem' => true ] ); [ 'usemhchem' => true, 'oldmhchem' => true ] );
$this->assertEquals( ']_{x}^{2}', $result['output'] ); $this->assertEquals( ']_{x}^{2}', $result['output'] );
} }
public function mhchemtexifiedTest() {
$result = $this->texVC->check( '\\longleftrightarrows',
[ 'usemhchemtexified' => true ] );
$this->assertEquals( '\\longleftrightarrows', $result['output'] );
}
public function mhchemtexifiedTestFail() {
$result = $this->texVC->check( '\\longleftrightarrows' );
$this->assertEquals( 'C', $result['status'] );
$this->assertFalse( $result['success'] );
}
} }

View file

@ -27,8 +27,8 @@ class MMLGenerationTexUtilTest extends MediaWikiUnitTestCase {
private static $SIMILARITYTRESH = 0.7; private static $SIMILARITYTRESH = 0.7;
private static $SKIPXMLVALIDATION = true; private static $SKIPXMLVALIDATION = true;
private static $APPLYFILTER = false; private static $APPLYFILTER = false;
private static $APPLYCATEGORYFILTER = false; private static $APPLYCATEGORYFILTER = true;
private static $FILTEREDCATEGORIES = [ "fun_ar1" ]; private static $SKIPPEDCATEGORIES = [ "mhchemtexified_required" ];
private static $FILTERSTART = 15; private static $FILTERSTART = 15;
private static $FILTERLENGTH = 1; private static $FILTERLENGTH = 1;
@ -215,7 +215,7 @@ class MMLGenerationTexUtilTest extends MediaWikiUnitTestCase {
$overAllCtr = 0; $overAllCtr = 0;
$finalCases = []; $finalCases = [];
foreach ( $groups as $category => $group ) { foreach ( $groups as $category => $group ) {
if ( self::$APPLYCATEGORYFILTER && !in_array( $category, self::$FILTEREDCATEGORIES, true ) ) { if ( self::$APPLYCATEGORYFILTER && !in_array( $category, self::$SKIPPEDCATEGORIES, true ) ) {
continue; continue;
} }
$indexCtr = 0; $indexCtr = 0;

View file

@ -61,6 +61,7 @@ class TexUtilTest extends MediaWikiUnitTestCase {
'mhchem_macro_2pc', 'mhchem_macro_2pc',
'mhchem_macro_2pu', 'mhchem_macro_2pu',
'mhchem_required', 'mhchem_required',
'mhchemtexified_required',
'mhchem_single_macro', 'mhchem_single_macro',
'nullary_macro', 'nullary_macro',
'nullary_macro_in_mbox', 'nullary_macro_in_mbox',