我有一个HTML文档的动态内容,包括数学公式。我想使用KaTeX呈现动态生成的数学。根据网上的各种建议,我目前的设置是:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<style>
/* LaTeX display environment will effect the LaTeX characters but not the layout on the page */
span.katex-display {
display: inherit; /* You may comment this out if you want the default behavior */
}
body {
background-color: black;
color: white;
}
</style>
<title>QUESTIONS</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></script>
<script src="main.js"></script>
<title></title>
</head>
<body>
<div id="myapp"></div>
<script>
var app = Elm.Main.init({
node: document.getElementById('myapp'),
flags: Date.now()
});
</script>
<script>
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.body, {
// customised options
// • auto-render specific keys, e.g.:
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
{left: '\\(', right: '\\)', display: false},
{left: '\\[', right: '\\]', display: true}
],
// • rendering keys, e.g.:
throwOnError : false
});
});
</script>
</body>
</html>其中main.js是ELM生成的javascript。脚本生成的初始内容有一些数学公式,并正确显示。不幸的是,与页面交互后生成的数学公式没有呈现出来。
如有任何帮助/建议,将不胜感激。
发布于 2022-09-01 07:45:14
您只在页面加载、DOMContentLoaded事件处理程序和脚本加载时呈现数学。
确定其他合适的事件,并在那里运行代码(或者相反)。理想情况下,其他事件将是首先导致页面内容更改的更新。在最坏的情况下,您可以使用一些计时器事件,但这感觉不如。
https://stackoverflow.com/questions/73556855
复制相似问题