Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

javascript - Mathjax configuration latex to center

I'm trying to use mathjax-node in javascript.

as you can see in picture, I want to make tex to center not left.

this is rendered picture

is there any configuration on mathjax-node?

I tried text-align and displayAlign to center, but it doesn't worked.

function convert(tex, options, callback) {
    mathjax.typeset({
        width: options.width,
        ex: 10,
        math: tex,
        format: "TeX",
        // style: "text-align: center;",
        svg: true, // SVG output
        linebreaks: true,
    }, function (data) {
        if (data.errors) return callback(data.errors);
        callback(undefined, data.svg);
    });
}


const mathjax = require('mathjax-node');
mathjax.config({
    TeX: {
        extensions: ["color.js"]
    },
    MathJax: {
        displayAlign: "center",
        // 'text-align': "center"
        extensions: ["TeX/color.js"],
        'fast-preview':{disabled:false}
    },
});
mathjax.start();

this is code of mathjax.typeset and config


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When writing MathJax in display mode, MathJax will automatically center the MathJax code for you.

To print your equations in display mode use one of these delimiters: [ ... ], egin{displaymath} ... end{displaymath} or egin{equation} ... end{equation}. $$ ... $$ is discouraged as it can give inconsistent spacing, and may not work well with some math packages.

<p>
The mass-energy equivalence is described by the famous equation
[ E=mc^2 ]
discovered in 1905 by Albert Einstein. 
In natural units ((c = 1 )), the formula expresses the identity
egin{equation}
E=m
end{equation}
</p>

<script type="text/javascript" async  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML">
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...