I have add the following code as an extension of mathjax.
UserCustom extension
to obtain the following function:userCustom.onPagedownConfigure = function(editor) { editor.hooks.chain("onPreviewRefresh", function() { MathJax.Hub.Queue(["resetEquationNumbers", MathJax.InputJax.TeX]); }); }; userCustom.onPagedownConfigure = function (editor) { var converter = editor.getConverter(); var preConversion = converter.hooks.preConversion; var array = { "thm": "Theorem", "lem": "Lemmma", "cor": "Corollary", "prop": "Property", "defn": "Definition", "rem": "Remark", "prob": "Problem", "excs": "Exercise", "examp": "Example", "proof": "Proof" }; converter.hooks.preConversion = function (text) { text = text.replace(/\\begin{(thm|lem|cor|prop|defn|rem|prob|examp|excs|proof)}\n*([\s\S]*?)\\end{\1}/g, function (wholeMatch, m1, m2) { return '<' + m1 + '>' + m2 + '</' + m1 + '>'; }); text = text.replace(/\\ref{(thm|lem|cor|prop|defn|rem|prob|examp|excs|proof):([\s\S]*?)}/g, function (wholeMatch, m1, m2) { return '<a class="latex_ref" href="#' + m1 + ':' + m2 + '">' + array[m1] + ' ' + m2 + '</a><span class="latex_ref_nodisplay">' + m1 + ':' + m2 + '</span>'; }); text = text.replace(/\\(section|subsection|subsubsection|title|author|date){([\s\S]*?)}/g, function (wholeMatch, m1, m2) { if (m1 == 'section') { return '###' + m2; } else if (m1 == 'subsection') { return '####' + m2; } else if (m1 == 'subsubsection') { return '#####' + m2; } else if (m1 == 'title') { return '##' + m2; } else if (m1 == 'author') { return '<div class="latex_author">' + m2 + '</div>'; } else if (m1 == 'date') { return '<div class="latex_date">' + m2 + '</div>'; } }); return preConversion(text); }; converter.hooks.chain("preBlockGamut", function (text, blockGamutHookCallback) { var num_thm = 0; var num_excs = 0; return text.replace(/<(thm|lem|cor|prop|defn|rem|prob|examp|excs|proof)>([\s\S]*?)<\/\1>/g, function (wholeMatch, m1, m2) { var strreturn; if (m1 == "proof") { strreturn = '<div class="latex_proof"><span class="latex_strong"><strong>' + array[m1] + '.</strong></span>' + m2 + '<span class="latex_proofend" style="float:right">□</span></div>'; strreturn = blockGamutHookCallback(strreturn); } else if (m1 == "excs" | m1 == "examp" | m1 == "prob") { strreturn = '<a class="latex_link" id="' + m1 + ':' + ++num_excs + '"></a>\n<div class="latex_' + m1 + '"><span class="latex_strong"><strong>' + array[m1] + ' ' + num_excs + '. </strong></span>' + m2 + '</div>'; strreturn = blockGamutHookCallback(strreturn); } else { strreturn = '<a class="latex_link" id="' + m1 + ':' + ++num_thm + '"></a>\n<div class="latex_' + m1 + '"><span class="latex_strong"><strong>' + array[m1] + ' ' + num_thm + '. </strong></span>' + m2 + '</div>'; strreturn = blockGamutHookCallback(strreturn); } return strreturn; }); }); }; userCustom.onReady = function () { $("head") .append($( '<style type="text/css">\n@import url("https://yandex.st/highlightjs/7.3/styles/solarized_light.min.css");\n\ .latex_ref_nodisplay{display:none;}\n\ .latex_thm, .latex_lem, .latex_cor, .latex_defn, .latex_prop, .latex_rem{\n\ border:solid 1px #ccc;\n\ font-style:normal;\n\ margin:15px 0;\n\ padding:5px;\n\ background: lightcyan;\n\ border: solid 3px green;\n\ -moz-border-radius: 1.0em;\n\ -webkit-border-radius: 7px;\n\ box-shadow: 0 0 0 green;\n\ }\n\ .latex_prob, .latex_examp, .latex_excs {\ font-style:normal;\n\ margin:10px 0;\n\ padding:5px;\n\ background: lightgoldenrodyellow;\n\ border: solid 3px rgb(255, 203, 136);\n\ -moz-border-radius: 1.0em; \n\ -webkit-border-radius: 7px; \n\ box-shadow: 0 0 0 green;\n\ }\n\ </style>')); };
TeX
code, this is quite useful when you use stackedit as a mid-step (as an WYSIWYG editor) , but finally you want to obtain a tex
code. add the following to Button HTML code
<% var output=$ ( "<div>").html(documentHTML); output.find( ".MathJax, .MathJax_SVG_Display, .MathJax_Display, .MathJax_SVG, .MathJax_Preview, .latex_link, .latex_ref, .latex_strong, .latex_proofend").remove(); output.find( 'script[type="math/tex"]').each(function() { $(this).replaceWith( '$' + this.innerHTML + '$'); }); output.find( 'script[type="math/tex; mode=display"]').each(function() { $(this).replaceWith( '$$' + this.innerHTML + '$$'); }); output.find( 'h2').each(function() { $(this).replaceWith( '\\title{' + this.innerHTML + '}'); }); output.find( 'h3').each(function() { $(this).replaceWith( '\\section{' + this.innerHTML + '}'); }); output.find( 'h4').each(function() { $(this).replaceWith( '\\subsection{' + this.innerHTML + '}'); }); output.find( 'h5').each(function() { $(this).replaceWith( '\\subsubsection{' + this.innerHTML + '}'); }); output.find( 'p').each(function() { $(this).replaceWith( this.innerHTML); }); output.find( ".latex_author").each(function() { $(this).replaceWith( '\\author{'+ this.innerHTML+'}'); }); output.find( ".latex_date").each(function() { $(this).replaceWith( '\\date{'+ this.innerHTML+'}'); }); output.find( ".latex_ref").each(function() { $(this).replaceWith( '\\ref{' +this.innerHTML+'}'); }); output.find( ".latex_ref_nodisplay").each(function() { $(this).replaceWith( '\\ref{' +this.innerHTML+'}'); }); output.find( ".latex_thm").each(function() { $(this).replaceWith( '\\begin{thm}' +this.innerHTML+'\\end{thm}'); }); output.find( ".latex_lem").each(function() { $(this).replaceWith( '\\begin{lem}' +this.innerHTML+'\\end{lem}'); }); output.find( ".latex_prop").each(function() { $(this).replaceWith( '\\begin{prop}' +this.innerHTML+'\\end{prop}'); }); output.find( ".latex_rem").each(function() { $(this).replaceWith( '\\begin{rem}' +this.innerHTML+'\\end{rem}'); }); output.find( ".latex_cor").each(function() { $(this).replaceWith( '\\begin{cor}' +this.innerHTML+'\\end{cor}'); }); output.find( ".latex_defn").each(function() { $(this).replaceWith( '\\begin{defn}' +this.innerHTML+'\\end{defn}'); }); output.find( ".latex_prob").each(function() { $(this).replaceWith( '\\begin{prob}' +this.innerHTML+'\\end{prob}'); }); output.find( ".latex_examp").each(function() { $(this).replaceWith( '\\begin{examp}' +this.innerHTML+'\\end{examp}'); }); output.find( ".latex_excs").each(function() { $(this).replaceWith( '\\begin{excs}' +this.innerHTML+'\\end{excs}'); }); output.find( ".latex_proof").each(function() { $(this).replaceWith( '\\begin{proof}' +this.innerHTML+'\\end{proof}'); }); var str=output.html(); output.html(str.replace(/\n+/gi, '\n') .replace(/\\begin{(.*)?}(\[.*\])?(.*)\\end{\1}/, '\\begin{$1}$2\n$3\n\\end{$1}\n')); print(output.html()); %>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4