@@ -52,8 +52,12 @@ export const MhchemUtils = {
5252/**
5353 * Replace these constructs in mhchem output now that we have stretchy versions
5454 * of the needed arrows
55+ *
56+ * @param {string } match The matching macro name
57+ * @param {string } arrow The arrow name (without the backslash).
58+ * @returns {string } The mhchem arrow name, if there is one.
5559 */
56- export const MhchemReplacements = new Map < string , RegExp > ( [
60+ export const MhchemReplacements = new Map < string | ( ( match : string , arrow : string ) => string ) , RegExp > ( [
5761 [
5862 '\\mhchemx$3[$1]{$2}' ,
5963 / \\ u n d e r s e t { \\ l o w e r 2 m u { ( .* ?) } } { \\ o v e r s e t { ( .* ?) } { \\ l o n g ( .* ?) } } / g,
@@ -72,7 +76,10 @@ export const MhchemReplacements = new Map<string, RegExp>([
7276 / \\ r l a p \{ \\ l o w e r \. 2 e m \{ - \} \} \\ r l a p \{ \\ r a i s e .2 e m \{ - \} \} \\ t r i p l e d a s h / g,
7377 ] ,
7478 [
75- '\\mhchem$1' ,
79+ ( match : string , arrow : string ) => {
80+ const mharrow = `mhchem${ arrow } ` ;
81+ return mhchemChars . lookup ( mharrow ) || mhchemMacros . lookup ( mharrow ) ? `\\${ mharrow } ` : match ;
82+ } ,
7683 / \\ ( x ? (?: l o n g ) ? (?: l e f t | r i g h t | [ L l ] e f t r i g h t | [ R r ] i g h t l e f t ) (?: a r r o w | h a r p o o n s ) ) / g,
7784 ] ,
7885] ) ;
@@ -90,7 +97,7 @@ export const MhchemMethods: { [key: string]: ParseMethod } = {
9097 try {
9198 tex = mhchemParser . toTex ( arg , machine ) ;
9299 for ( const [ name , pattern ] of MhchemReplacements . entries ( ) ) {
93- tex = tex . replace ( pattern , name ) ;
100+ tex = tex . replace ( pattern , name as string ) ;
94101 }
95102 } catch ( err ) {
96103 throw new TexError ( err [ 0 ] , err [ 1 ] ) ;
@@ -106,7 +113,7 @@ export const MhchemMethods: { [key: string]: ParseMethod } = {
106113/**
107114 * The command macros
108115 */
109- new CommandMap ( 'mhchem' , {
116+ const mhchemMacros = new CommandMap ( 'mhchem' , {
110117 ce : [ MhchemMethods . Machine , 'ce' ] ,
111118 pu : [ MhchemMethods . Machine , 'pu' ] ,
112119 mhchemxrightarrow : [ MhchemMethods . xArrow , 0xe429 , 5 , 9 ] ,
@@ -121,7 +128,7 @@ new CommandMap('mhchem', {
121128/**
122129 * The character macros
123130 */
124- new CharacterMap ( 'mhchem-chars' , MhchemUtils . relmo , {
131+ const mhchemChars = new CharacterMap ( 'mhchem-chars' , MhchemUtils . relmo , {
125132 tripledash : [ '\uE410' , { stretchy : false } ] ,
126133 mhchemBondTD : [ '\uE411' , { stretchy : false } ] ,
127134 mhchemBondTDD : [ '\uE412' , { stretchy : false } ] ,
0 commit comments