Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/mjs/input/tex/extensions/mhchem/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"targets": ["input/tex/mhchem"],
"excludeSubdirs": true
},
"copy": {
"to": "[bundle]/input/tex/extensions/mhchem",
"from": "[ts]/input/tex/mhchem",
"copy": ["__locales__"],
"excludes": ["__locales__/Component.ts"]
},
"webpack": {
"name": "input/tex/extensions/mhchem",
"libs": [
Expand Down
6 changes: 5 additions & 1 deletion testsuite/tests/input/tex/Mhchem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,14 @@ describe('Mhchem-Ams', () => {
).toMatchSnapshot();
});

it('Mhchem Error', () => {
it('Mhchem Bond Error', () => {
expectTexError('\\ce{A\\bond{x}B}').toBe('mhchem bug T. Please report.');
});

it('Mhchem Brace Error', () => {
expectTexError('\\ce{{x^${x}}}').toBe('Extra close brace or missing open brace');
});

it('Mhchem stretchy <-', () => {
expect(tex2mml('\\ce{A <-[text] B}')).toMatchSnapshot();
});
Expand Down
18 changes: 16 additions & 2 deletions ts/input/tex/mhchem/MhchemConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import BaseMethods from '../base/BaseMethods.js';
import { AmsMethods } from '../ams/AmsMethods.js';
import { mhchemParser } from '#mhchem/mhchemParser.js';
import { TEXCLASS } from '../../../core/MmlTree/MmlNode.js';
import { COMPONENT } from './__locales__/Component.js';
export { COMPONENT };

/**
* Creates mo token elements with the proper attributes
Expand Down Expand Up @@ -104,8 +106,20 @@ export const MhchemMethods: { [key: string]: ParseMethod } = {
for (const [name, pattern] of MhchemReplacements.entries()) {
tex = tex.replace(pattern, name as string);
}
} catch (err) {
throw new TexError(null, err[0], err[1]);
} catch ([id, msg]) {
if (id === 'MhchemErrorBond') {
const match = msg.match(/\((.*)\)/);
throw new TexError(COMPONENT, id, match[1]);
}
if (id.startsWith('MhchemBug')) {
const match = msg.match(/mhchem bug (.).*\((.*)\)/);
if (match) {
throw new TexError(COMPONENT, 'MhchemBug2', match[1], match[2]);
} else {
throw new TexError(COMPONENT, 'MhchemBug', id.charAt(9));
}
}
throw new TexError('input/tex', id);
}
parser.string = tex + parser.string.substring(parser.i);
parser.i = 0;
Expand Down
28 changes: 28 additions & 0 deletions ts/input/tex/mhchem/__locales__/Component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*************************************************************
*
* Copyright (c) 2026 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file Locale component registration for [tex]/mhchem
*
* @author [email protected] (Davide P. Cervone)
*/

import { Locale } from '../../../../util/Locale.js';

export const COMPONENT = '[tex]/mhchem';

Locale.registerLocaleFiles(COMPONENT, '../ts/input/tex/mhchem');
5 changes: 5 additions & 0 deletions ts/input/tex/mhchem/__locales__/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"MhchemBug": "mhchem-Fehler %1. Bitte melden.",
"MhchemBug2": "mhchem-Fehler %1. Bitte melden. (%2)",
"MhchemErrorBond": "mhchem-Fehler. Unbekannter Bindungstyp (%1)"
}
5 changes: 5 additions & 0 deletions ts/input/tex/mhchem/__locales__/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"MhchemBug": "mhchem bug %1. Please report.",
"MhchemBug2": "mhchem bug %1. Please report. (%2)",
"MhchemErrorBond": "mhchem Error. Unknown bond type (%1)"
}