Comments (5)
OK, it looks like using .mjs
requires you to use import
and export
, so you can't use the usual node require()
command. Sigh.
How about switching to one of the other versions of tex2svg
, say the one in the components
directory? If you change the default for the --dist
option (by changing default: false
to default: true
in
dist: {
boolean: true,
default: false,
describe: 'true to use webpacked version, false to use MathJax source files'
}
then you can use node tex2svg
without error.
from mathjax-demos-node.
I tried using the components code:
#! /usr/bin/env -S node -r esm
/*************************************************************************
*
* component/tex2svg
*
* Uses MathJax v3 to convert a TeX string to an SVG string.
*
* ----------------------------------------------------------------------
*
* Copyright (c) 2019 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.
*/
//
// The default TeX packages to use
//
const PACKAGES = 'base, autoload, require, ams, newcommand';
const latex = `$$MAD = \\frac{\\sum_{i=1}^n | x_i - \\bar{x} |} n$$`;
//
// Get the command-line arguments
//
var argv = require('yargs')
.demand(0).strict()
.usage('$0 [options] "math" > file.svg')
.options({
inline: {
boolean: true,
describe: "process as inline math"
},
em: {
default: 16,
describe: 'em-size in pixels'
},
ex: {
default: 8,
describe: 'ex-size in pixels'
},
width: {
default: 80 * 16,
describe: 'width of container in pixels'
},
packages: {
default: PACKAGES,
describe: 'the packages to use, e.g. "base, ams"; use "*" to represent the default packages, e.g, "*, bbox"'
},
css: {
boolean: true,
describe: 'output the required CSS rather than the HTML itself'
},
fontCache: {
boolean: true,
default: true,
describe: 'whether to use a local font cache or not'
},
assistiveMml: {
boolean: true,
default: false,
describe: 'whether to include assistive MathML output'
},
dist: {
boolean: true,
default: true,
describe: 'true to use webpacked version, false to use MathJax source files'
}
})
.argv;
//
// Configure MathJax
//
MathJax = {
options: {
enableAssistiveMml: argv.assistiveMml
},
loader: {
paths: {mathjax: 'mathjax-full/es5'},
source: (argv.dist ? {} : require('mathjax-full/components/src/source.js').source),
require: require,
load: ['adaptors/liteDOM']
},
tex: {
packages: argv.packages.replace('\*', PACKAGES).split(/\s*,\s*/)
},
svg: {
fontCache: (argv.fontCache ? 'local' : 'none')
},
startup: {
typeset: false
}
}
//
// Load the MathJax startup module
//
require('mathjax-full/' + (argv.dist ? 'es5' : 'components/src/tex-svg') + '/tex-svg.js');
//
// Wait for MathJax to start up, and then typeset the math
//
MathJax.startup.promise.then(() => {
MathJax.tex2svgPromise(latex, {
display: !argv.inline,
em: argv.em,
ex: argv.ex,
containerWidth: argv.width
}).then((node) => {
const adaptor = MathJax.startup.adaptor;
//
// If the --css option was specified, output the CSS,
// Otherwise, output the typeset math as SVG
//
if (argv.css) {
console.log(adaptor.textContent(MathJax.svgStylesheet()));
} else {
console.log(adaptor.outerHTML(node));
};
});
}).catch(err => console.log(err));
Here's what happens when I run it:
ole@mkt:~/Temp/MathJax-demos-node/MathJax-demos-node/component$ node tex2svg
/home/ole/Temp/MathJax-demos-node/MathJax-demos-node/node_modules/mathjax-full/components/src/source.js:3
export const source = {
^^^^^^
SyntaxError: Unexpected token export
at Module._compile (internal/modules/cjs/loader.js:720:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.<anonymous> (/home/ole/Temp/MathJax-demos-node/MathJax-demos-node/component/tex2svg:112:35)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
from mathjax-demos-node.
Are you sure you are running the modified version and not ehe original? Your code works for me without trouble.
If you really are running this version, then just remove the
source: (argv.dist ? {} : require('mathjax-full/components/src/source.js').source),
entirely.
Also, you might want to fetch the most recent version of the MAthJax-demos-node repository, as it was updated for the recent 3.1.4 release.
from mathjax-demos-node.
OK - I fetched the most recent version and now it works. I'm able to run with node tex2svg
. Brilliant - So happy about this! Thanks again! I think this should be pretty easy to wrap now.
from mathjax-demos-node.
OK, glad it is working now. I will close the issue.
from mathjax-demos-node.
Related Issues (20)
- How can I load my external package by mathjax-full v3.0.5 in Node Env HOT 2
- tex2svg-page: global svg cache not rendering in safari HOT 2
- simple/tex2mml-page HOT 3
- Chrome language preference affects chtml output HOT 4
- How to use mathjax tex2svg-page without separate components? HOT 1
- Rendering Multiple Pages HOT 4
- MathML symbols are not converted correctly HOT 3
- 'No version information available...' messages output when using simple/tex2chtml.js HOT 2
- why mathjax in node 16, after init , mathjax is null HOT 1
- Numbers without text don't render when using tex2svg HOT 3
- Using MathJax node in an ES module HOT 2
- Cannot process german umlaute when using demo example tex2svg-page HOT 2
- v4 beta 2 fails to find (dynamic parts of the) default font HOT 2
- Force MathJax to try to render the equation even though there are syntax errors (and ideally: to automatically fix the errors it self) HOT 8
- SVG output not showing in XHTML HOT 21
- Many demos fail to run on Node version 21 with "Function.prototype.apply was called on undefined" errors HOT 8
- Unable to add contextual menus when using component/tex2svg-page HOT 3
- let wrapper = MathJax.tex2svg('y', {display: true}); 字符y获取到的svg,右上角缺少 HOT 4
- tex2mml-page with inlineMath HOT 2
- text2svg cannot fully show formula HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mathjax-demos-node.