gpt4 book ai didi

javascript - 如何结合 Marked 和 MathJax

转载 作者:行者123 更新时间:2023-12-04 17:24:27 26 4
gpt4 key购买 nike

我知道的
使用 Marked Documentation ,我能够创建正确呈现 Markdown 语法的代码:

<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Marked in the browser</title>
</head>
<body>
<div id="content"></div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
document.getElementById('content').innerHTML =
marked('# Marked in browser\n\nRendered by **marked**.');
</script>
</body>
</html>
具有上述示例的真实网页是 here
我还可以使用 this answer 使 mathJax 内联渲染工作:
<!from: https://tex.stackexchange.com/questions/27633/mathjax-inline-mode-not-rendering>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true
}
});
</script>
效果很好( real-world example )。
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

<!from: https://www.mathjax.org/#gettingstarted>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

<!from: https://stackoverflow.com/a/46511456/8565438>

<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.6/marked.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


This is an example of MathJax inline rendering: $\dot{u}=\alpha \nabla^2 u$.

问题
如何结合 Marked 和 MathJax? 我希望能够使用类似于 math.stackexchange.com 的语法:markdown 和 MathJax 相结合。

预期产出
例如,这段文字(被一些 JS 魔法包围):
Problem
-------

I am having trouble with finding a solution which satisfies the boundary and initial conditions to this PDE:

$$\frac{\partial u}{\partial t} = \frac{\partial ^2 u}{\partial^2x}$$
where $u=u(x,t)$, $0 \leq x \leq L$
with boundary & initial conditions:

BC1: $u(x=0,t>0)=T_f$;
BC2: $u(x=L,t>0)=T_i$;
IC: $u(x,t=0)=f(x)$
应该呈现这样的东西:
enter image description here
( source )
我怎样才能做到这一点?

(JS新手在这里)

最佳答案

一个快速的解决方法是使用 https://stackedit.io/app
写完文本后,您可以将内容发布为 HTML(到云驱动器),结果正是您想要的,例如http://hangtarolo.hu/math.html
结果可以通过stackedit.js嵌入:https://openbase.io/js/stackedit/documentation
另一方面,这里有组合使用的建议:https://hiltmon.com/blog/2017/01/28/mathjax-in-markdown – 但对我来说它没有用。也许 markdown2 可以,但它只适用于 Mac。
或者第三种可能性:
您可以在同一个文件中使用这两种表示法,但不能在同一行中使用,就像在 https://hangtarolo.hu/math.php 中一样
(php代码在这里:https://hangtarolo.hu/math.txt——php任务只是将换行符替换为“\n”。)

关于javascript - 如何结合 Marked 和 MathJax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64261805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com