From 94d85db7fe7abf6161dbba6fbe2fd4c61a327533 Mon Sep 17 00:00:00 2001 From: Tseing Date: Mon, 14 Oct 2024 18:36:59 +0800 Subject: [PATCH] feat: add docsify-latex and MathJax to support formulas --- docs/tutorials/README.md | 10 ++++++++++ index.html | 1 + resources/js/docsify-latex.js | 9 +++++++++ 3 files changed, 20 insertions(+) create mode 100644 resources/js/docsify-latex.js diff --git a/docs/tutorials/README.md b/docs/tutorials/README.md index 17ee8cf..f079e9e 100644 --- a/docs/tutorials/README.md +++ b/docs/tutorials/README.md @@ -17,3 +17,13 @@ Chinese : 更新为自己使用的镜像 你好,我不会说中文,所以随便复制粘贴了一些东西。 `日本語は話せません` + +## $\mathrm{Hello,}\ \LaTeX\mathrm{!}$ in title + +Make some $\LaTeX$ formulas here: + +$$\Re{z} =\frac{n\pi \dfrac{\theta +\psi}{2}}{ +\left(\dfrac{\theta +\psi}{2}\right)^2 + \left( \dfrac{1}{2} +\log \left\lvert\dfrac{B}{A}\right\rvert\right)^2}$$ + +And I can insert some inline formulas in articles like $2^k-\binom{k}{1}2^{k-1}+\binom{k}{2}2^{k-2}$ and $\frac{1}{\sqrt{\pi}}$. \ No newline at end of file diff --git a/index.html b/index.html index 2a2060e..c9267fe 100644 --- a/index.html +++ b/index.html @@ -27,6 +27,7 @@ + diff --git a/resources/js/docsify-latex.js b/resources/js/docsify-latex.js new file mode 100644 index 0000000..07dc607 --- /dev/null +++ b/resources/js/docsify-latex.js @@ -0,0 +1,9 @@ +/*! + * docsify-latex + * v0.5.2 + * https://scruel.github.io/docsify-latex/ + * (c) 2022 Scruel Tao + * MIT license + */ +!function(){"use strict";function t(){t=function(){return e};var e={},n=Object.prototype,r=n.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,n){return t[e]=n}}function l(t,e,n,r){var o=e&&e.prototype instanceof h?e:h,a=Object.create(o.prototype),i=new E(r||[]);return a._invoke=function(t,e,n){var r="suspendedStart";return function(o,a){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw a;return O()}for(n.method=o,n.arg=a;;){var i=n.delegate;if(i){var c=b(i,n);if(c){if(c===s)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var u=f(t,e,n);if("normal"===u.type){if(r=n.done?"completed":"suspendedYield",u.arg===s)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r="completed",n.method="throw",n.arg=u.arg)}}}(t,n,i),a}function f(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=l;var s={};function h(){}function p(){}function d(){}var v={};u(v,a,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(L([])));g&&g!==n&&r.call(g,a)&&(v=g);var m=d.prototype=h.prototype=Object.create(v);function x(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){function n(o,a,i,c){var u=f(t[o],t,a);if("throw"!==u.type){var l=u.arg,s=l.value;return s&&"object"==typeof s&&r.call(s,"__await")?e.resolve(s.__await).then((function(t){n("next",t,i,c)}),(function(t){n("throw",t,i,c)})):e.resolve(s).then((function(t){l.value=t,i(l)}),(function(t){return n("throw",t,i,c)}))}c(u.arg)}var o;this._invoke=function(t,r){function a(){return new e((function(e,o){n(t,r,e,o)}))}return o=o?o.then(a,a):a()}}function b(t,e){var n=t.iterator[e.method];if(void 0===n){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,b(t,e),"throw"===e.method))return s;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var r=f(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,s;var o=r.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,s):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,s)}function M(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function k(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(M,this),this.reset(!0)}function L(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),k(n),s}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;k(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:L(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),s}},e}function e(t,e,n,r,o,a,i){try{var c=t[a](i),u=c.value}catch(t){return void n(t)}c.done?e(u):Promise.resolve(u).then(r,o)}function n(t){return function(){var n=this,r=arguments;return new Promise((function(o,a){var i=t.apply(n,r);function c(t){e(i,o,a,c,u,"next",t)}function u(t){e(i,o,a,c,u,"throw",t)}c(void 0)}))}}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,c=!0,u=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return c=t.done,t},e:function(t){u=!0,i=t},f:function(){try{c||null==n.return||n.return()}finally{if(u)throw i}}}}function a(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function i(t,e){Object.keys(t).forEach((function(n){Object.prototype.hasOwnProperty.call(e,n)&&"[object Object]"===Object.prototype.toString.call(t[n])?i(t[n],e[n]):e[n]=t[n]}))}var c={inlineMath:[["$","$"],["\\(","\\)"]],displayMath:[["$$","$$"]],overflowScroll:!0,beforeInitFunc:function(){},customOptions:{}};window&&(window.$docsify=window.$docsify||{},window.$docsify.latex=window.$docsify.latex||{},i(window.$docsify.latex,c),window.$docsify.latex.version="0.5.2");var u="docsify-latex",l="docsify-latex-back",f="display",s="#0B87DA";function h(t){var e=t.querySelectorAll("".concat(u," a[href]"));if(null!==e&&0!==e.length){var n,r=o(e);try{var a=function(){var t=n.value;Object.prototype.hasOwnProperty.call(t.style,"color")&&t.style.color||(t.style.color=s);var e=t.getAttribute("href"),r=decodeURIComponent(e).substring(1);e.startsWith("#")&&(t.title="Jump to equation",t.onclick=function(){var e=document.getElementById(r);if(null===e)return!0;for(var n=e.parentElement;null!==n&&n.tagName!==u.toUpperCase();)n=n.parentElement;var o=n.querySelector(l);null===o&&(o=document.createElement(l),n.append(o),o.innerHTML=''.concat("Back To Reference",""),o.style.color=s,o.style.float="right");var a=document.documentElement.scrollTop;return o.style.display="",o.onclick=function(){return o.style.display="none",window.scrollTo(0,a),!1},window.scrollTo(0,n.offsetTop-t.getBoundingClientRect().top),!1})};for(r.s();!(n=r.n()).done;)a()}catch(t){r.e(t)}finally{r.f()}}}var p=Object;if(p.prepareContent=function(t,e){return t},p.prepareRender=function(){},p.renderElement=function(t,e){},p.afterRender=function(){},c.beforeInitFunc(),"undefined"!=typeof MathJax&&MathJax){if("3"===MathJax.version[0])i(c.customOptions,MathJax.config),MathJax.config.tex.inlineMath=c.inlineMath,MathJax.config.tex.displayMath=c.displayMath,MathJax.startup.getComponents(),p.prepareRender=function(){MathJax.startup.getComponents();var t=MathJax.startup.output;void 0!==t.clearCache?t.clearCache():void 0!==t.clearFontCache&&t.clearFontCache()},p.renderElement=function(){var e=n(t().mark((function e(n,r){return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,MathJax.typesetPromise([n]);case 2:case"end":return t.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),p.afterRender=function(){if(h(document),c.overflowScroll){var t,e=o(document.querySelectorAll(u));try{for(e.s();!(t=e.n()).done;){var n=t.value,r=n.querySelector("mjx-math");if(null!==r){r.style.width="";var a=r.getBoundingClientRect().width,i=0,l=n.querySelector("mjx-assistive-mml");null!==r&&(i=l.getBoundingClientRect().width),n.style.width=Math.max(a,i)+"px"}}}catch(t){e.e(t)}finally{e.f()}}};else if("2"===MathJax.version[0]){var d={skipStartupTypeset:!0,messageStyle:"none"};i(c.customOptions,d),i({tex2jax:{inlineMath:c.inlineMath,displayMath:c.displayMath}},d),MathJax.Hub.Config(d),MathJax.Hub.processSectionDelay=0,MathJax.Hub.processUpdateDelay=0,p.prepareRender=function(){void 0!==MathJax.InputJax.TeX&&MathJax.Hub.Queue(["PreProcess",MathJax.Hub],["resetEquationNumbers",MathJax.InputJax.TeX]),MathJax.Hub.Queue(["PreProcess",MathJax.Hub],["Reprocess",MathJax.Hub])},p.renderElement=function(t,e){MathJax.Hub.Queue(["Typeset",MathJax.Hub,t],[h,t])}}}else if("undefined"!=typeof katex&&katex){var v={throwOnError:!1,trust:function(t){return["\\htmlId","\\href"].includes(t.command)},macros:{"\\eqref":"\\href{##ktx-#1}{(\\text{#1})}","\\ref":"\\href{##ktx-#1}{\\text{#1}}","\\label":"\\htmlId{ktx-#1}{}"}};i(c.customOptions,v),p.prepareContent=function(t,e){return e},p.renderElement=function(t,e){v.displayMode=e,t.innerHTML=katex.renderToString(t.innerHTML.replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/&/g,"&"),v),h(t)}}var y="latex:replace",g="latex:delete";function m(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return"\x3c!-- ".concat(y," ").concat(e," ").concat(t," --\x3e")}function x(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return new RegExp("\x3c!-- ".concat(y," ").concat(t," (.*?) --\x3e"))}function w(t,e,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return r&&(t=a(t),e=a(e)),new RegExp("(?:^|[^\\\\])((".concat(t,")((?:[^\\\\").concat(n?"":"\n","]|\\\\.)+?)").concat(e,")"))}function b(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=w(e[0],e[1],n);return M(t,r,n)}function M(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=t.match(e);if(r){var o={};return o.displayMode=n,o.content=r[1],o.innerContent=r[3],o.index=r.index+r[0].length-o.content.length,o.endIndex=o.index+o.content.length,o.regex=e,o}return null}var k="CODE",E={codeTagMarkup:w("","",!0),codeBlockMarkup:w("`{3,}","\\2",!0,!1),codeInlineMarkup:w("`{1,}","\\2",!1,!1),commentDeleteReplaceMarkup:/^(>?[ ]*)