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 = [
'usemathrm' => false,
'usemhchem' => false,
'usemhchemtexified' => false,
'oldtexvc' => false,
'oldmhchem' => false,
'debug' => false,

View file

@ -73,7 +73,7 @@ class TexVC {
];
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 ) {
$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;
} catch ( Exception $ex ) {
if ( $ex instanceof SyntaxError && !$options['oldtexvc']

View file

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

View file

@ -238,4 +238,16 @@ class ApiTest extends MediaWikiUnitTestCase {
[ 'usemhchem' => true, 'oldmhchem' => true ] );
$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 $SKIPXMLVALIDATION = true;
private static $APPLYFILTER = false;
private static $APPLYCATEGORYFILTER = false;
private static $FILTEREDCATEGORIES = [ "fun_ar1" ];
private static $APPLYCATEGORYFILTER = true;
private static $SKIPPEDCATEGORIES = [ "mhchemtexified_required" ];
private static $FILTERSTART = 15;
private static $FILTERLENGTH = 1;
@ -39,7 +39,7 @@ class MMLGenerationTexUtilTest extends MediaWikiUnitTestCase {
/** @var bool export the updated TexUtil-Tex to "./ExportedTexUtilKeys.json" */
private static $EXPORT_KEYS = false;
private static $SKIPPEDINDICES = [ 15,33, 90, 383,554 ];
private static $SKIPPEDINDICES = [ 15, 33, 90, 383, 554 ];
/**
* @dataProvider provideTestCases
@ -215,7 +215,7 @@ class MMLGenerationTexUtilTest extends MediaWikiUnitTestCase {
$overAllCtr = 0;
$finalCases = [];
foreach ( $groups as $category => $group ) {
if ( self::$APPLYCATEGORYFILTER && !in_array( $category, self::$FILTEREDCATEGORIES, true ) ) {
if ( self::$APPLYCATEGORYFILTER && !in_array( $category, self::$SKIPPEDCATEGORIES, true ) ) {
continue;
}
$indexCtr = 0;

View file

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