javascript - 在网页中使用 MathJax 时如何在非数学上下文中使用 "$"

标签 javascript html mathjax

<分区>

如何在非数学设置中绕过 MathJax 将美元符号识别为内联定界符?

我在我的博客中使用 MathJax 来显示数学方程式,但并不是我所有的帖子都与数学相关,所以每次我使用“$”符号时,MathJax 都会被触发并使我的帖子被解释为数学文本。

我尝试使用以下技巧在不直接输入的情况下呈现“$”符号。

Dollar HexCode = &#x24;
Dollar HTMLcode = &#36;
DollarHTMLentity = &dollar;
but MathJax still catches me.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type='text/javascript'>
  window.MathJax = {
    TeX: {
      extensions: ['AMSsymbols.js', '[a11y]/accessibility-menu.js']
    },
    menuSettings: {
      collapsible: false,
      autocollapse: false
    },
    messageStyle: 'none',
    tex2jax: {
      inlineMath: [
        ['$', '$'],
        ["\\(", "\\)"]
      ],
      processEscapes: true
    }
  };
</script>
<!--MATHJAX SCRIPT ENDS-->
<script async='async' src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-MML-AM_CHTML'></script>

<div class="post-body">
  This is the regular post<br> $100 The Whole Part Between These Two Dollar Signs Gets Caught By MathJax$100 This Part Doesn't Get Caught And Is Safely Displayed On The Page$200 This Part Gets Caught, $00 And This Part Doesn't $300 This Part Should Have
  Been Caught But It Bypasses Because The Closing Dollar Sign Is Missing.
</div>
<br><br>
<div class="post-body">
  Here I use "&amp;#x24;"<br> &#x24;100 The Whole Part Between These Two Dollar Signs Gets Caught By MathJax&#x24;100 This Part Doesn't Get Caught And Is Safely Displayed On The Page&#x24;200 This Part Gets Caught, &#x24;200 And This Part Doesn't &#x24;300
  This Part Should Have Been Caught But It Bypasses Because The Closing Dollar Sign Is Missing.
</div>
<br>
<div class="post-body">
  Here I'll use "&amp;#36;" &#36;100 The Whole Part Between These Two Dollar Signs Gets Caught By MathJax &#36;100 This Part Doesn't Get Caught And Is Safely Displayed On The Page &#36;200 This Part Gets Caught, &#36;200 And This Part Doesn't &#36;300 This
  Part Should Have Been Caught But It Bypasses Because The Closing Dollar Sign Is Missing.
</div>
<br>
<div class="post-body">
  Here I use "&amp;dollar;" &dollar;100 The Whole Part Between These Two Dollar Signs Gets Caught By MathJax &dollar;100 This Part Doesn't Get Caught And Is Safely Displayed On The Page &dollar;200 This Part Gets Caught, &dollar;200 And This Part Doesn't
  &dollar;300 This Part Should Have Been Caught But It Bypasses Because The Closing Dollar Sign Is Missing.
</div>

对于冗长的代码,我深表歉意,但我认为代码描述了我的意思...我需要使用“$”符号,但我不能从我的整个博客中跳过 MathJax。

最佳答案

因为您有 processEscapes: true,您可以使用 \$ 来表示 $ 而无需将其用作 MathJax 分隔符。

http://docs.mathjax.org/en/latest/options/preprocessors/tex2jax.html#configure-tex2jax

关于javascript - 在网页中使用 MathJax 时如何在非数学上下文中使用 "$",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54366977/

相关文章:

html - Safari 错误边距 - 在 Chrome 和 FF 中工作正常

javascript - 从 jQuery 第二次调用 Mathjax 排版函数不起作用

javascript - 将日期字符串转换为 ISO 8601 格式字符串并最终转换为日期对象

html - 具有 100% 高度行和 Internet Explorer 9 的表格

javascript - 在 Firefox 中禁用滚轮更改数字和日期输入

jquery - 将元素拉伸(stretch)到填充的流体父级的全宽

doxygen - 在 Doxygen markdown 中包含数学符号/方程?

MathJax 尝试渲染\begin{itemize}

javascript - 在 GridView 中显示没有绑定(bind)数据且未检索到结果的不同消息

javascript - openJSCAD 包含文件