在网页中使用MathJax时如何在非Math上下文中使用“ $”

时间:2019-01-25 14:11:35

标签: javascript html mathjax

在非数学设置中,如何绕开MathJax识别美元符号作为行内定界符?

我正在使用MathJax在博客中显示数学方程式,但是并非我的所有帖子都与Math相关,因此每次我使用'$'符号时,都会触发MathJax并将我的帖子解释为Math文本。

我尝试使用以下技巧来呈现“ $”符号而不直接输入。

Dollar HexCode = $
Dollar HTMLcode = $
DollarHTMLentity = $
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。

1 个答案:

答案 0 :(得分:1)

由于拥有processEscapes: true,因此可以使用\$来表示$,而不必将其用作MathJax分隔符。

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