2016-01-22 17:43:40 -08:00
|
|
|
module.exports = function cleanUp(latex) {
|
2017-09-18 20:39:25 -07:00
|
|
|
// strip any \[ and \], which is a block-level LaTeX markup indicator for MathJax:
|
2016-01-22 17:43:40 -08:00
|
|
|
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;
|
|
|
|
};
|