配置 mathjax 以坚持某些 div

发布于 2025-01-05 05:38:02 字数 476 浏览 0 评论 0原文

我最近创建了一个博客,在其中讨论编程、阅读、科学和数学。现在,对于编程部分,我已经安装了 SyntaxHighlighter,但我对应该用于数学的内容感到相当困惑。我正在考虑使用 MathJax,因为我已经习惯了它并且它非常好。问题是,MathJax 会干扰其他东西。例如,它可能会干扰我在编程帖子中使用的任何 PHP 代码(其中有很多美元符号)。

现在我想保留内联/块美元符号,但我不希望它破坏其他东西。我正在考虑将 MathJax 与某个 CSS 类关联起来,这样我就可以将广泛使用数学的所有部分与这些标签括起来。我的意思是,我仍然可以在这些 div 中正常输入(无需进行数学化),但我可以使用美元符号并获取数学代码。在 div 之外,任何美元符号都将被保留。

有谁知道可以让我执行此操作的配置选项?我了解 JS,但我在文档中找不到任何选项。我想在研究代码之前我应该​​在这里问一下。

I have recently started a blog, in which I talk about programming, reading, science, and math. Now, for the programming part, I have installed SyntaxHighlighter, but I am rather confused with what I should use for math. I'm thinking about using MathJax, since I'm used to it and it's pretty good. The issue is, MathJax will interfere with other stuff. For example, it can interfere with any PHP code (which has lots of dollar signs) that I use on a programming post.

Now I want to keep the inline/block dollar signs, but I don't want it to blow up other stuff. I was thinking about associating MathJax with a certain CSS class, so that I can enclose all sections which use math extensively with those tags. By this, I mean that I can still type normally within those divs (without having it math-ified), but I can use the dollar signs and get math code. Outside the divs, any dollar signs will be left alone.

Does anyone know a configuration option that lets me do this? I know JS, but I can't find any options in the documentation. Thought I'd ask here before plowing through the code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

娇纵 2025-01-12 05:38:02

class="tex2jax_ignore" 添加到文档 标记,然后在部件的容器上使用 class="tex2jax_process"您要在其中包含数学的页面。正如其他人所指出的,您可以配置用于这些功能的类名称。例如

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  tex2jax: {
    inlineMath: [['

,那么您的页面将是

<html>
<head>
  ...
</head>
<body class="no-mathjax">
  ...
  <div class="mathjax">
  ... (math goes here) ...
  </div>
  ...
</body>
</html>

希望有帮助。

达维德

,'

,那么您的页面将是


希望有帮助。

达维德

],['\\(','\\)']], processClass: "mathjax", ignoreClass: "no-mathjax" } }); </script>

,那么您的页面将是

希望有帮助。

达维德

add class="tex2jax_ignore" to your document <body> tag, and then use class="tex2jax_process" on the containers for the parts of your page where you want to include mathematics. As others have pointed out, you can configure the class names to use for these features. E.g.

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  tex2jax: {
    inlineMath: [['

Then your page would be

<html>
<head>
  ...
</head>
<body class="no-mathjax">
  ...
  <div class="mathjax">
  ... (math goes here) ...
  </div>
  ...
</body>
</html>

Hope that helps.

Davide

,'

Then your page would be


Hope that helps.

Davide

],['\\(','\\)']], processClass: "mathjax", ignoreClass: "no-mathjax" } }); </script>

Then your page would be

Hope that helps.

Davide

贪恋 2025-01-12 05:38:02

图片来源:@MarkS.Everitt

http://www.mathjax.org/docs/1.1 /options/tex2jax.html

有一个配置选项,processClass: "tex2jax_process"
最终配置变为:

tex2jax: {

inlineMath: [['
,'
], ['\\(','\\)']],'

ignoreClass: "[a-zA-Z1-9]*",

processClass: "math"

}
});

Credit: @MarkS.Everitt

http://www.mathjax.org/docs/1.1/options/tex2jax.html

There is a configuration option, processClass: "tex2jax_process"
The final configuration becomes:

tex2jax: {

inlineMath: [['
,'
], ['\\(','\\)']],'

ignoreClass: "[a-zA-Z1-9]*",

processClass: "math"

}
});
南风起 2025-01-12 05:38:02

IMO 现有的答案不是真正的解决方案,因为它们涉及修改您的 HTML。有时这甚至是不可能的,但即使是这样,谁愿意用无意义的 CSS 类来弄脏他们的标记只是为了让 MathJax 工作?

在导入 MathJax 的

<script type="text/x-mathjax-config">
    MathJax.Hub.Config(
        {
            elements: mathElements
        }
    );
</script>

其中 mathElements 包含要处理的 DOM 元素列表,例如类似于 var mathElements = document.querySelectorAll("article") 。

The existing answers are IMO not real solutions because they involve modifying your HTML. Sometimes this isn't even possible, but even when it is, who wants to dirty their markup with meaningless CSS classes just to get MathJax working?

Insert the following tag before the <script> tag that imports MathJax:

<script type="text/x-mathjax-config">
    MathJax.Hub.Config(
        {
            elements: mathElements
        }
    );
</script>

where mathElements contains a list of DOM elements to be processed, for example something like var mathElements = document.querySelectorAll("article").

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文