Skip to content

Commit

Permalink
Merge pull request #784 from mathjax/component-update
Browse files Browse the repository at this point in the history
Refactor usage of all packages to reduce redundant code
  • Loading branch information
dpvc committed Feb 22, 2022
2 parents 4494c51 + 5179174 commit 6d286c2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 58 deletions.
38 changes: 5 additions & 33 deletions components/src/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,11 @@ export const paths = {
sre: '[mathjax]/sre/' + (typeof window === 'undefined' ? 'sre-node' : 'sre_browser')
};

const allPackages = [
'[tex]/action',
'[tex]/ams',
'[tex]/amscd',
'[tex]/bbox',
'[tex]/boldsymbol',
'[tex]/braket',
'[tex]/bussproofs',
'[tex]/cancel',
'[tex]/centernot',
'[tex]/color',
'[tex]/colortbl',
'[tex]/configmacros',
'[tex]/enclose',
'[tex]/extpfeil',
'[tex]/html',
'[tex]/mathtools',
'[tex]/mhchem',
'[tex]/newcommand',
'[tex]/noerrors',
'[tex]/noundefined',
'[tex]/physics',
'[tex]/require',
'[tex]/setoptions',
'[tex]/tagformat',
'[tex]/texhtml',
'[tex]/textcomp',
'[tex]/textmacros',
'[tex]/unicode',
'[tex]/verb',
'[tex]/cases',
'[tex]/empheq'
];
const allPackages = Array.from(Object.keys(dependencies))
.filter(name => name.substr(0,5) === '[tex]' &&
name !== '[tex]/autoload' &&
name !== '[tex]/colorv2' &&
name !== '[tex]/all-packages');

export const provides = {
'startup': ['loader'],
Expand Down
18 changes: 8 additions & 10 deletions components/src/input/tex-full/tex-full.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import './lib/tex-full.js';

import '../tex/extensions/all-packages/all-packages.js';
import {registerTeX} from '../tex/register.js';
import {Loader} from '../../../../js/components/loader.js';
import {AllPackages} from '../../../../js/input/tex/AllPackages.js';
import '../../../../js/input/tex/require/RequireConfiguration.js';

Loader.preLoad(
'input/tex-base',
'[tex]/all-packages',
'[tex]/require'
);
if (MathJax.loader) {
MathJax.loader.preLoad(
'input/tex-base',
'[tex]/all-packages'
);
}

registerTeX(['require',...AllPackages]);
registerTeX();
14 changes: 3 additions & 11 deletions components/src/input/tex/extensions/all-packages/all-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@ import './lib/all-packages.js';
import {AllPackages} from '../../../../../../js/input/tex/AllPackages.js';
import '../../../../../../js/input/tex/autoload/AutoloadConfiguration.js';
import '../../../../../../js/input/tex/require/RequireConfiguration.js';
import {insert} from '../../../../../../js/util/Options.js';
import {registerTeX} from '../../register.js';

if (MathJax.loader) {
MathJax.loader.preLoad('[tex]/autoload', '[tex]/require');
}
if (MathJax.startup) {
if (!MathJax.config.tex) {
MathJax.config.tex = {};
}
let packages = MathJax.config.tex.packages;
MathJax.config.tex.packages = ['autoload', 'require', ...AllPackages];
if (packages) {
insert(MathJax.config.tex, {packages});
}
}

registerTeX(['require', ...AllPackages], false);
9 changes: 5 additions & 4 deletions components/src/input/tex/register.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {TeX} from '../../../../js/input/tex.js';
import {insert} from '../../../../js/util/Options.js';

export function registerTeX(packageList) {
export function registerTeX(packageList = [], tex = true) {
if (MathJax.startup) {
MathJax.startup.registerConstructor('tex', TeX);
MathJax.startup.useInput('tex');
if (tex) {
MathJax.startup.registerConstructor('tex', MathJax._.input.tex_ts.TeX);
MathJax.startup.useInput('tex');
}
if (!MathJax.config.tex) {
MathJax.config.tex = {};
}
Expand Down

0 comments on commit 6d286c2

Please sign in to comment.