Page MenuHomePhabricator

User-defined macros
Open, Needs TriagePublicFeature

Description

Please develop, or document, if already developed, a way to inject user-defined macros from LocalSettings.php, e.g., \tg = \operatorname{tg} when either client-side MathJax or server-side Mathoid is used.

Both site-wide and formula or wiki-page specific macros will be useful for tasks like math localisation (as in the example above) or more advanced tasks like wikilinks in formulæ, provided that the necessary package is available (see T288188).

Setting services.conf.mj_config.MathJax.macros for Mathoid in config.yaml does not appear to work.

In pure MathJax this is done via window.MathJax.tex.macros setting.

Event Timeline

Client-side MathJax was removed years ago. For mathoid you can create side-wide simple macros like that by adjusting texvcjs on your server, i.e., adding entries here https://github.com/wikimedia/mediawiki-services-texvcjs/blob/master/lib/texutil.js#L517 page wide and formula wide macros won't be supported. Is that something you can work with? I think if you establish proper naming conventions for LaTeX macros page specific macros cause more problems than you might think first. Different authors, copy and paste etc.

Client-side MathJax was removed years ago.

Oh, that's why I couldn't get it working.

For mathoid you can create side-wide simple macros like that by adjusting texvcjs on your server, i.e., adding entries here https://github.com/wikimedia/mediawiki-services-texvcjs/blob/master/lib/texutil.js#L517 page wide and formula wide macros won't be supported. Is that something you can work with?

I tried to add '\\tg': '\\operatorname{tg}' to module.exports.nullary_macro_aliase, but a formula with \tg was not rendered. Also I would prefer not to meddle with files overwriteable by git/npm.

I think if you establish proper naming conventions for LaTeX macros page specific macros cause more problems than you might think first. Different authors, copy and paste etc.

Be per-formula macros I meant macros that are generated automatically in a way controlled by wiki server admin, not wikiusers. I use this technique with an extension I wrote to render formulæ with client-side MathJax to automatically add wikilinks to articles about them to trigonometric functions, etc (example). A list of such articles is controlled by wiki admin.

I tried to add '\\tg': '\\operatorname{tg}' to module.exports.nullary_macro_aliase, but a formula with \tg was not rendered. Also I would prefer not to meddle with files overwriteable by git/npm.

I understand that you don't want to overwrite files, however, that might be a good way to see what can be done and whatnot. In a second step, we can discuss how to turn that into some easy-to-maintain package.

I think if you establish proper naming conventions for LaTeX macros page specific macros cause more problems than you might think first. Different authors, copy and paste etc.

Be per-formula macros I meant macros that are generated automatically in a way controlled by wiki server admin, not wikiusers. I use this technique with an extension I wrote to render formulæ with client-side MathJax to automatically add wikilinks to articles about them to trigonometric functions, etc (example). A list of such articles is controlled by wiki admin.

Cool. I guess you will be more flexible to continue with your own extension than trying to adapt mathoid to your needs. I.e., we intentionally (reproducibility, performance) do not support context-dependent behavior at this moment.