Skip to content

Add fontExtensions configuration option. (mathjax/MathJax#3410) #1337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
38 changes: 29 additions & 9 deletions components/mjs/output/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,29 @@ import {combineDefaults, combineWithMathJax} from '#js/components/global.js';
import {Package} from '#js/components/package.js';
import {hasWindow} from '#js/util/context.js';

export const FONTPATH = hasWindow ?
'https://cdn.jsdelivr.net/npm/@mathjax/%%FONT%%-font':
'@mathjax/%%FONT%%-font';
export const FONTPATH = hasWindow
? 'https://cdn.jsdelivr.net/npm/@mathjax/%%FONT%%-font'
: '@mathjax/%%FONT%%-font';

export function configFont(font, jax, config, extension = '') {
const path = (config.fontPath || (FONTPATH + extension));
const name = (font.match(/^[a-z]+:/) ? (font.match(/[^/:\\]*$/) || [jax])[0] : font);
combineDefaults(MathJax.config.loader, 'paths', {
[name+extension]: (name === font ? path.replace(/%%FONT%%/g, font) : font)
});
return `[${name}${extension}]`;
}

export function configExtensions(jax, config) {
const extensions = [];
for (const name of (config.fontExtensions || [])) {
const font = configFont(name, jax, config, '-extension');
const module = `${font}/${jax}`
extensions.push(module);
}
return extensions;
}

export const OutputUtil = {
config(jax, jaxClass, defaultFont, fontClass) {

Expand All @@ -20,15 +40,15 @@ export const OutputUtil = {
}

if (font.charAt(0) !== '[') {
const path = (config.fontPath || FONTPATH);
const name = (font.match(/^[a-z]+:/) ? (font.match(/[^/:\\]*$/) || [jax])[0] : font);
combineDefaults(MathJax.config.loader, 'paths', {
[name]: (name === font ? path.replace(/%%FONT%%/g, font) : font)
});
font = `[${name}]`;
font = configFont(font, jax, config);
}
const name = font.substring(1, font.length - 1);

const extensions = configExtensions(jax, config);
if (extensions.length) {
MathJax.loader.addPackageData(`${font}/${jax}`, {extraLoads: extensions});
}

if (name !== defaultFont || !fontClass) {

MathJax.loader.addPackageData(`output/${jax}`, {extraLoads: [`${font}/${jax}`]});
Expand Down
1 change: 1 addition & 0 deletions ts/output/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export abstract class CommonOutputJax<
LinebreakVisitor: null, // The LinebreakVisitor to use
},
font: '', // the font component to load
fontExtensions: [], // the font extensions to load
htmlHDW: 'auto', // 'use', 'force', or 'ignore' data-mjx-hdw attributes
wrapperFactory: null, // The wrapper factory to use
fontData: null, // The FontData object to use
Expand Down