1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-02-24 09:33:19 +01:00
BezierInfo-2/tools/cleanup.js

30 lines
876 B
JavaScript
Raw Normal View History

2016-01-22 17:43:40 -08:00
module.exports = function cleanUp(latex) {
// strip any \[ and \], which is an block-level LaTeX markup indicator for MathJax:
latex = latex.replace(/^'/,'').replace(/'$/,'').replace('\\[','').replace('\\]','');
2017-02-27 11:01:13 -08:00
// wrap some known functor words in italics markup
['Bézier'].forEach(term => {
latex = latex.replace(new RegExp(term, 'g'), '\\textit{' + term + '}');
});
2016-01-22 17:43:40 -08:00
// also unindent the LaTeX.
var indent = false;
var lines = latex.split('\n').filter(function(line) { return !!line.trim(); });
var clean = function(line, idx) {
if(line.trim()) {
if (!indent) {
var matched = line.match(/^(\s+)/);
if (matched) {
indent = matched[0];
}
}
if (indent) {
lines[idx] = line.replace(indent,'').trim();
}
}
}
lines.forEach(clean);
latex = lines.join('\n');
return latex;
};