Comments (7)
@pkra Thank you, it worked. I had to use the result.css
in the style of the web page. In the code above, I changed the server part:
app.post('/example', async(req, res) => {
let result = await returnMathJax(req.body.latexFormula);
let head = "<head><style>" + result.css.toString() + "</style></head>";
let body = "<body>" + result.html.toString() + "</body>";
let mypage = "<html>"+ head + body + "</html>";
res.send(mypage);
});
And as you said, I could avoid calculating result.css
everytime and just use its predetermined result.
from mathjax-node.
The second screenshot indicates you want display mode but your configuration sets format: "inline-TeX"
. Try format: "TeX"
instead (and check the readme for more information).
(Also: consider switching to MathJax v3 which works in nodejs directly, see https://github.com/mathjax/MathJax-demos-node for some examples.)
from mathjax-node.
@pkra The problem with MathJax v3 is that it does not allow the user to select (underline) portions of the rendered formula or even it as a whole, a feature that I need. I have only achieved that when the returned HTML code consists on <span> objects, that v2 gives.
(I hadn't put the backlash (\) in my original comment, so the <span> was not shown. Sorry for that).
With "mathjax-node" the returned code consists on <span> objects when I put html:true
in the typeset, and then use result.html
, but it does not render as desired. I already tried with format:"TeX"
, but I got:
from mathjax-node.
That image looks like the CSS is missing completely. Try posting a full self-contained output example somewhere people can access.
from mathjax-node.
@pkra Ok, I am working with two files. The first one is called "index.html". The user inputs a formula in there and sends it to a server. The code is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>MathJax example V3</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
</head>
<body>
<form action="http://localhost:90/example" method="POST">
Formula: <input type="text" name="latexFormula"><br>
<button type="submit">Send to backend</button>
</form>
<p>Click on the submit button, and the input will be sent to a page on the server.</p>
</body>
</html>
The second one is called App.js, which has the server that runs "mathjax-node" and returns the HTML code on a different page. In need to have running it with the instruction "node App.js" in the console.
// ----------------- Express server -----------------
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/example', async(req, res) => {
let result = await returnMathJax(req.body.latexFormula);
res.send(result.html);
});
const port = 90;
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
// --------------- MathJax configuration -----------
var mjAPI = require("mathjax-node");
mjAPI.config({
MathJax: {
jax: ["input/TeX","output/HTML-CSS"],
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true,
processEnvironments: true,
},
TeX: {extensions: ["AMSmath.js","AMSsymbols.js"]},
"HTML-CSS": {
linebreaks: { automatic: true },
fonts: ["TeX"],
}
},
});
mjAPI.start();
// ---------------- Execute MathJax -----------------
async function returnMathJax(formula){
let result = await mjAPI.typeset({
"format":"TeX",
"math": formula,
"html": true,
"htmlNode": true,
"css": true,
});
return result;
}
The formula I was using for tests is "\sum_{i=0}^ni>2"
from mathjax-node.
You never do anything with result.css
so the necessary CSS is missing.
Since result.css
is actually fixed for each mathjax version, you could just call it once during development and store its output in a regular stylesheet to load into the page.
from mathjax-node.
Glad to hear you could work it out. (FYI This might be interesting: mathjax/MathJax-src#734)
from mathjax-node.
Related Issues (20)
- tex2svg converted image further rendering problem HOT 1
- how to set it to a transparent background? HOT 1
- Do mathjax-node support MathJax@3 HOT 2
- Mathjax- node:Latex Error converting latex to SVG with "\ \ [" HOT 3
- Cannot read property 'childNodes' of null HOT 3
- Rendering problems of latex $$\cong$$ in SVG HOT 5
- '\nolimits is allowed only on operators' which render right in mathjax v3 HOT 2
- width of svg is too small HOT 2
- Unknown node type "mstack" HOT 1
- Undefined control sequence even after defining it HOT 2
- "Error: TeX parse error: Missing \end{array}" HOT 2
- MathJax on Linkedom.. HOT 2
- Vercel - Error: Could not load script: "file:///var/task/node_modules/mathjax/unpacked/jax/element/mml/jax.js?V=2.7.9" HOT 5
- Correct mapping for prime symbol HOT 3
- MathJax node does not work with HTML HOT 4
- Cannot read properties of null (reading 'childNodes') HOT 4
- how to fix “missing open brace on subscript”? HOT 6
- use 'tex2svg' cannot generate formula correctly HOT 1
- Setting background-color style to SVG element HOT 1
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-node.