-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
v4 third party extension building #3086
Comments
Yes, the documentation hasn't been update for the changes to the configuration files for components. There is information about it in the ESM pull request, in the section on "The new component control files". The main change is that the individual |
I've had time to take stab at it. For the mathjax-unicode-math extension, I've tried the following {
"build": {
"id": "unicode-math",
"component": "js/unicode-math",
"targets": ["js"]
},
"webpack": {
"name": "unicode-math",
"libs": [
"components/src/input/tex-base/lib",
"components/src/core/lib"
]
}
} (Even though the build block seemed superfluous - see below.) Then ran $ npx webpack --env dir=. --env bundle=../../browser -c node_modules/mathjax-full/components/webpack.config.mjs First, I got an error that webpack couldn't find the extension. Turns out, it was looking for it in the main directory. While trying to work out where the path is passed along, I noticed that the build block didn't seem to do anything (for me). If I tried to run webpack from the To get a little further I simply copied the ESM build to the root. That got me a build which looked ok. However, using the result in the browser gave me silent failures (well, not completely silent -- there was a warning about a missing version info). Here's the resulting build I got https://gist.github.com/pkra/5ec245db7831c265267518dbab0c1fb3 (which compared to https://github.com/AmerMathSoc/mathjax-unicode-math/tree/main/browser seems to include more mathjax code). So if you have the time my first question would be: is there a way to specify the source of the ESM module? |
That is only used by the You shouldn't call The build tools expect something like
If you want users to define a path {
"build": {
"id": "[ams]/unicode-math",
"component": "input/tex/extension/unicode-math",
"targets": ["js"]
},
"webpack": {
"name": "unicode-math",
"libs": [
"components/src/input/tex-base/lib",
"components/src/core/lib"
]
}
} and import './lib/unicode-math.js'; Then you should be able to use
This is from memory, so I think it works but didn't test it. It looks like you are wanting to put the webpacked file into a cd component
../node_modules/mathjax-full/components/bin/build mjs
../node_modules/mathjax-full/components/bin/pack mjs browser instead, which I think will do the trick. Or you could rename the The reason you are getting the "no version information" message is because the version identification is added to As for why it isn't working, you identify that more of MathJax is being included, and that may mean that your extension isn't hooking into the existing MathJax structure but rather a separate one, so it not making itself available to the MathJax that is actually running. When you use the
If you are seeing a lot of See if any of that helps you out. |
Thank you! I'll report back when I've tried this. |
A quick update on trying the suggested changes. I created a I changed Next, Building ./components
node:internal/fs/utils:346
throw err;
^
Error: ENOENT: no such file or directory, stat '/tmp/mathjax-unicode-math/node_modules/mathjax-full/ts/js'
at Object.statSync (node:fs:1582:3)
at processList (/tmp/mathjax-unicode-math/node_modules/mathjax-full/components/bin/build:105:23)
at Object.<anonymous> (/tmp/mathjax-unicode-math/node_modules/mathjax-full/components/bin/build:398:1)
at Module._compile (node:internal/modules/cjs/loader:1246:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1300:10)
at Module.load (node:internal/modules/cjs/loader:1103:32)
at Module._load (node:internal/modules/cjs/loader:942:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47 {
errno: -2,
syscall: 'stat',
code: 'ENOENT',
path: '/tmp/mathjax-unicode-math/node_modules/mathjax-full/ts/js'
}
Node.js v19.5.0
Command failed: node '/tmp/mathjax-unicode-math/node_modules/mathjax-full/components/bin/build' 'mjs'
node:internal/fs/utils:346
throw err;
^
Error: ENOENT: no such file or directory, stat '/tmp/mathjax-unicode-math/node_modules/mathjax-full/ts/js'
at Object.statSync (node:fs:1582:3)
at processList (/tmp/mathjax-unicode-math/node_modules/mathjax-full/components/bin/build:105:23)
at Object.<anonymous> (/tmp/mathjax-unicode-math/node_modules/mathjax-full/components/bin/build:398:1)
at Module._compile (node:internal/modules/cjs/loader:1246:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1300:10)
at Module.load (node:internal/modules/cjs/loader:1103:32)
at Module._load (node:internal/modules/cjs/loader:942:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47 {
errno: -2,
syscall: 'stat',
code: 'ENOENT',
path: '/tmp/mathjax-unicode-math/node_modules/mathjax-full/ts/js'
}
Node.js v19.5.0
Webpacking ./components
unicode-math.js (100.82 KB)
../js/unicode-math.js (97.97 KB)
[components]/mjs/core/lib/core/MmlTree/Attributes.js (0.12 KB)
[components]/mjs/core/lib/core/MmlTree/MmlNode.js (0.59 KB)
[components]/mjs/core/lib/core/Tree/Node.js (0.14 KB)
[components]/mjs/core/lib/util/Entities.js (0.24 KB)
[components]/mjs/core/lib/util/FunctionList.js (0.08 KB)
[components]/mjs/core/lib/util/Options.js (0.67 KB)
[components]/mjs/core/lib/util/PrioritizedList.js (0.09 KB)
[components]/mjs/core/lib/util/lengths.js (0.34 KB)
[components]/mjs/core/lib/util/string.js (0.33 KB)
[components]/mjs/input/tex-base/lib/input/tex/MapHandler.js (0.17 KB)
[components]/mjs/input/tex-base/lib/input/tex/NodeUtil.js (0.07 KB)
[components]/mjs/input/tex-base/lib/input/tex/ParseUtil.js (0.07 KB)
[components]/mjs/input/tex-base/lib/input/tex/Symbol.js (0.1 KB)
[components]/mjs/input/tex-base/lib/input/tex/Tags.js (0.26 KB)
[components]/mjs/input/tex-base/lib/input/tex/TexConstants.js (0.09 KB)
[components]/mjs/input/tex-base/lib/input/tex/TexError.js (0.07 KB)
[components]/mjs/input/tex-base/lib/input/tex/TexParser.js (0.07 KB)
[components]/mjs/input/tex-base/lib/input/tex/base/BaseItems.js (1.02 KB)
[mathjax]/mjs/core/MmlTree/MmlNode.js (17.91 KB)
[mathjax]/mjs/input/tex/Configuration.js (5.69 KB)
[mathjax]/mjs/input/tex/ParseMethods.js (4.05 KB)
[mathjax]/mjs/input/tex/SymbolMap.js (3.69 KB)
[mathjax]/mjs/input/tex/base/BaseMethods.js (39.76 KB)
unicode-math.js (173.62 KB) Removing the build block from config.json avoided the errors and gave the same list of files. Next I couldn't find where the result was written -- It was identical to the result in my previous attempt. |
No, that was not a typo. The I guess I forgot some of the configuration parameters that you need when you are working outside of the MathJax directory tree itself. Try using {
"build": {
"id": "[ams]/unicode-math",
"component": "input/tex/extension/unicode-math",
"js": "../js",
"ts": "../ts",
"targets": ["unicode-math.ts"]
},
"webpack": {
"name": "unicode-math",
"js": "../js",
"libs": [
"components/src/input/tex-base/lib",
"components/src/core/lib"
],
"dist": ".."
}
} I have added I tested this out this time, and there is one more thing. It turns out you need to change the imports from In any case, see if that doesn't do the trick for you. |
Thank you so much for your patience and the additional explanation! The build process now works for me as you describe (including tweaking the The result looks similar to what I had build earlier but with noticeable changes. (As before, it's still 20kb larger than the v3 build.) Unfortunately, the build still does not work for me in the browser. Now I get
with I've updated the build at https://gist.github.com/pkra/5ec245db7831c265267518dbab0c1fb3 with what I'm currently getting. |
Oh, for completeness, the file generated at import {combineWithMathJax} from '../../node_modules/mathjax-full/mjs/components/global.js';
import {VERSION} from '../../node_modules/mathjax-full/mjs/components/version.js';
import * as module1 from '../../js/unicode-math.js';
if (MathJax.loader) {
MathJax.loader.checkVersion('[ams]/unicode-math', VERSION, 'tex-extension');
}
combineWithMathJax({_: {
"unicode-math": module1
}}); (PS: Would you suggest to commit that file or git-ignore it?) |
Work in progress, cf. the discussion at mathjax/MathJax#3086
You have correctly identified the issue as coming from I had made changes to But you don't seem to be importing
and you can see that this is including pieces of Once I change the
which looks correct to me. I have not run the extension, but it doesn't include Finally, you may want to add
to the
We don't include the generated files (the |
Oh! I'm very sorry for missing that last bit about changing from It looks like this fixes things (as you wrote) -- I'll test more and let you know if I find any other issues. Thank you again for your patience and help! |
Improve build tools for use with third-party extensions. (mathjax/MathJax#3086)
Edit: after some debugging, I realized the error was caused because we now need to I've tried to follow https://github.com/pkra/mathjax-img as close as possible to update my extension but I'm still getting ENOENT errors... here is my attempt: luavreis/xparsejax#1
|
@lucasvreis, I'm glad you worked out a solution. The On the other hand, if there are no exports, there is no need for a |
Great! Thanks for the confirmation. |
I know this might technically belong in mathjax-docs but I thought it might be more useful to have it in the main tracker.
I'm in the process of upgrading some extensions to work with v4, e.g., pkra/mathjax-img#24, AmerMathSoc/mathjax-unicode-math#27.
Adjusting to generate ESM for server-side use was straight forward. But looking through mathjax-src, I don't understand how the build process for clients-side extension has to be adjusted.
The advice from https://docs.mathjax.org/en/latest/web/webpack.html#the-webpack-configuration-1 doesn't seem to work anymore.
mathjax-full/components/bin/makeAll
expects various CLI options now but I couldn't work out how to adjust.If you had time for some short pointers, I'd be grateful.
[I'd prefer not to generate CJS but of course I'm happy to do the full adoption of mathjax-src's tsconfig setup if that's easier.]
The text was updated successfully, but these errors were encountered: