{"id":4733,"date":"2016-05-13T09:54:42","date_gmt":"2016-05-13T01:54:42","guid":{"rendered":"https:\/\/lttt.blog.ustc.edu.cn\/?p=4733"},"modified":"2016-05-13T09:54:42","modified_gmt":"2016-05-13T01:54:42","slug":"stackeditzhuanweitexbiaodashidezhengzetihuanguize","status":"publish","type":"post","link":"https:\/\/lttt.vanabel.cn\/?p=4733","title":{"rendered":"stackedit\u8f6c\u4e3aTeX\u8868\u8fbe\u5f0f\u7684\u6b63\u5219\u66ff\u6362\u89c4\u5219"},"content":{"rendered":"<p>stackedit\u662f\u4e00\u4e2a\u6bd4\u8f83\u597d\u7684\u5728\u7ebf\u6570\u5b66\u7f16\u8f91\u5668, \u53ef\u4ee5\u968f\u65f6\u5199\u51fa\u6f02\u4eae\u7684\u6570\u5b66\u516c\u5f0f. \u652f\u6301mathjax\u8bed\u6cd5. \u4f7f\u7528<code>UserCustom extension<\/code>\u4e2d\u5982\u4e0b\u4ee3\u7801:<\/p>\n<pre class=\"lang:js decode:true \" >userCustom.onPagedownConfigure = function (editor) {\n        var thmCounter  = { num: 0 };\n        var excsCounter = { num: 0 };\n        var environmentMap = {\n            thm:   { title: \"Theorem\"    ,counter: thmCounter  },\n            lem:   { title: \"Lemma\"      ,counter: thmCounter  },\n            cor:   { title: \"Corollary\"  ,counter: thmCounter  },\n            prop:  { title: \"Property\"   ,counter: thmCounter  },\n            defn:  { title: \"Definition\" ,counter: thmCounter  },\n            rem:   { title: \"Remark\"     ,counter: thmCounter  },\n            prob:  { title: \"Problem\"    ,counter: excsCounter },\n            excs:  { title: \"Exercise\"   ,counter: excsCounter },\n            examp: { title: \"Example\"    ,counter: excsCounter },\n            proof: { title: \"Proof\" },\n            claim: { title: \"Claim\" }\n        };\n        var converter = editor.getConverter();\n        \/\/ Save the preConversion callbacks stack\n        var preConversion = converter.hooks.preConversion;\n        converter.hooks.preConversion = function (text) {\n            \/\/ Change \\begin...\\end to \/begin...\/end to avoid MathJax processing\n            text = text.replace(\/\\\\begin{(\\w+)}([\\s\\S]*?)\\\\end{\\1}\/g, function (wholeMatch, m1, m2) {\n                if(!environmentMap[m1]) return wholeMatch;\n                \/\/ At this stage we need to keep the same number of characters for accurate section parsing\n                return '\/begin{' + m1 + '}' + m2 + '\/end{' + m1 + '}';\n            });\n            \/\/ Transform \\title and \\section into markdown title to take benefit of partial rendering\n            text = text.replace(\/\\\\(\\w+){([^\\r\\n}]+)}\/g, function (wholeMatch, m1, m2) {\n                \/\/ At this stage we need to keep the same number of characters for accurate section parsing\n                if (m1 == 'section') {\n                    \/\/ \\section{} has to be replaced by 10 chars\n                    return '\\n###     ' + m2 + '\\n';\n                }\n                if (m1 == 'subsection') {\n                    \/\/ \\subsection{} has to be replaced by 13 chars\n                    return '\\n####       ' + m2 + '\\n';\n                }\n                if (m1 == 'subsubsection') {\n                    \/\/ \\subsubsection{} has to be replaced by 16 chars\n                    return '\\n#####         ' + m2 + '\\n';\n                }\n                if (m1 == 'title') {\n                    \/\/ \\title{} has to be replaced by 8 chars\n                    return '\\n##    ' + m2 + '\\n';\n                }\n                return wholeMatch;\n            });\n            \/\/ We are replacing the preConversion stack, call the other preConversion callbacks from the old stack\n            return preConversion(text);\n        };\n        converter.hooks.chain(\"preBlockGamut\", function (text, blockGamutHookCallback) {\n            text = text.replace(\/\\\\ref{(\\w+):(\\d+)}\/g, function (wholeMatch, m1, m2) {\n                if(!environmentMap[m1]) return wholeMatch;\n                return '&lt;a class=\"latex_ref\" href=\"#' + m1 + ':' + m2 + '\"&gt;' + environmentMap[m1].title + ' ' + m2 + '&lt;\/a&gt;';\n            });\n            text = text.replace(\/\\\\(author|date){([\\s\\S]*?)}\/g, '&lt;div class=\"latex_$1\"&gt;$2&lt;\/div&gt;');\n            return text.replace(\/\\\/begin{(\\w+)}([\\s\\S]*?)\\\/end{\\1}\/g, function (wholeMatch, m1, m2) {\n                if(!environmentMap[m1]) return wholeMatch;\n                var result = '&lt;div class=\"latex_' + m1 + '\"&gt;&lt;span class=\"latex_title\"&gt;&lt;\/span&gt;' + blockGamutHookCallback(m2);\n                if (m1 == \"proof\") {\n                    result += '&lt;span class=\"latex_proofend\" style=\"float:right\"&gt;$\u25a0$&lt;\/span&gt;';\n                }\n                return result + '&lt;\/div&gt;';\n            });\n        });\n        var previewContentsElt = document.getElementById('preview-contents');\n        editor.hooks.chain('onPreviewRefresh', function() {\n            thmCounter.num = 0;\n            excsCounter.num = 0;\n            _.each(previewContentsElt.querySelectorAll('[class^=\"latex_\"]'), function(elt) {\n                var key = elt.className.match(\/^latex_(\\S+)\/)[1];\n                var environment = environmentMap[key];\n                if(!environment) return;\n                var title = environment.title;\n                if(environment.counter) {\n                    environment.counter.num++;\n                    title += ' ' + environment.counter.num;\n                    elt.id = key + ':' + environment.counter.num;\n                }\n                elt.querySelector('.latex_title').innerHTML = title + '.';\n            });\n        });\n    };\n\n    userCustom.onReady = function () {\n        var style = [\n            '.latex_thm, .latex_lem, .latex_cor, .latex_defn, .latex_prop, .latex_rem, .latex_claim {',\n            '    font-style:italic;',\n            '    display: block;',\n            '    margin:15px 0;',\n            '}',\n            '.latex_prob, .latex_examp, .latex_excs, .latex_proof {',\n            '    font-style:normal;',\n            '    margin: 10px 0;',\n            '    display: block;',\n            '}',\n            '.latex_title {',\n            '    float:left;',\n            '    font-weight:bold;',\n            '    padding-right: 10px;',\n            '}',\n            '.latex_proofend {',\n            '    float:right;',\n            '}',\n        ].join('\\n');\n        $(\"head\").append($('&lt;style type=\"text\/css\"&gt;').html(style));\n    };<\/pre>\n<p>\u53ef\u4ee5\u975e\u5e38\u5bb9\u6613\u7684\u5199\u51fa\u5b9a\u7406\u7b49\u73af\u5883: \u4f8b\u5982<code>\/begin{thm}...\/end{thm}<\/code>, \u53ef\u4ee5\u770b\u5230\u4e0eTeX\u7684\u5199\u6cd5\u7565\u6709\u4e0d\u540c. <\/p>\n<p>\u4e0b\u9762\u6211\u5229\u7528WinEdt\u7684\u6b63\u5219\u8868\u8fbe\u5f0f, \u5c06\u4e0a\u8ff0<code>\/begin{thm}...\/end{thm}<\/code>\u8f6c\u6362\u4e3a\u6807\u51c6\u7684<code>&#92;begin{thm}...&#92;end{thm}<\/code>.<br \/>\n\u8bbe\u7f6e\u5982\u56fe\u6240\u793a, \u7136\u540e\u70b9\u51fbReplace All\u5373\u53ef.<br \/>\n<a href=\"https:\/\/lttt.vanabel.cn\/wp-content\/uploads\/2016\/05\/reg_winedt_stackedit.png\" rel=\"attachment wp-att-4734\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lttt.blog.ustc.edu.cn\/wp-content\/uploads\/2016\/05\/reg_winedt_stackedit-300x296.png\" alt=\"reg_winedt_stackedit\" width=\"300\" height=\"296\" class=\"aligncenter size-medium wp-image-4734\" srcset=\"https:\/\/lttt.vanabel.cn\/wp-content\/uploads\/2016\/05\/reg_winedt_stackedit-300x296.png 300w, https:\/\/lttt.vanabel.cn\/wp-content\/uploads\/2016\/05\/reg_winedt_stackedit.png 513w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n\u9700\u8981\u6ce8\u610f\u7684\u662fWinEdt\u9ed8\u8ba4\u7684\u5c31\u662f\u975e\u8d2a\u5a6a(non-greedy)\u6a21\u5f0f, \u8fd9\u4e0e\u4f20\u7edf\u7684RegEx\u662f\u4e0d\u540c\u7684.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>stackedit\u662f\u4e00\u4e2a\u6bd4\u8f83\u597d\u7684\u5728\u7ebf\u6570\u5b66\u7f16\u8f91\u5668, \u53ef\u4ee5\u968f\u65f6\u5199\u51fa\u6f02\u4eae\u7684\u6570\u5b66\u516c\u5f0f.  &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/lttt.vanabel.cn\/?p=4733\"> <span class=\"screen-reader-text\">stackedit\u8f6c\u4e3aTeX\u8868\u8fbe\u5f0f\u7684\u6b63\u5219\u66ff\u6362\u89c4\u5219<\/span> \u9605\u8bfb\u66f4\u591a &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[631,679],"class_list":["post-4733","post","type-post","status-publish","format-standard","hentry","category-latex","tag-stackedit","tag-winedt"],"_links":{"self":[{"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=\/wp\/v2\/posts\/4733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4733"}],"version-history":[{"count":0,"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=\/wp\/v2\/posts\/4733\/revisions"}],"wp:attachment":[{"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lttt.vanabel.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}