【问题标题】:How to combine Marked and MathJax如何结合 Marked 和 MathJax
【发布时间】:2020-10-08 11:42:52
【问题描述】:

我知道的

使用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)$

应该像这样渲染:

(source)

我怎样才能做到这一点?


(这里是 JS 新手)

【问题讨论】:

    标签: javascript html rendering


    【解决方案1】:

    一个快速的解决方法是使用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”。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-19
      • 2015-03-09
      • 2018-01-27
      • 2016-07-13
      • 1970-01-01
      • 2015-06-01
      • 2011-07-04
      相关资源
      最近更新 更多