简体   繁体   English

在博客中无法逃脱 LaTeX 美元符号“$”

[英]Can't escape LaTeX dollar sign `$` in blogdown

1. An amount between $5 and $10.  
2. An amount between \$5 and \$10.  
3. An amount between \\$5 and \\$10.  

Please include the code chunk above in a blogdown.Rmd file, and make sure your Hugo theme supports LaTeX equations.请在 blogdown.Rmd 文件中包含上面的代码块,并确保您的 Hugo 主题支持 LaTeX 方程。 Then Save and serve your site with blogdown::serve_site() .然后使用blogdown::serve_site() Save并提供您的网站。 When I do this none of the three options shown above properly escape LaTeX's dollar sign $ .当我这样做时,上面显示的三个选项都没有正确逃脱 LaTeX 的美元符号$

Here's what happens to me (and yes I did update all packages with update.packages(ask = FALSE, checkBuilt = TRUE) prior to trying this).这是发生在我身上的事情(是的,在尝试此操作之前,我确实使用update.packages(ask = FALSE, checkBuilt = TRUE)更新了所有包)。 These three results below are from the same three attempts above:以下这三个结果来自上述相同的三个尝试:

  1. The and in this statement is formatted in LaTeX style while everything else is formatted "normal".此语句中的and格式为 LaTeX 样式,而其他所有内容的格式为“正常”。
  2. The and in this statement is formatted in LaTeX style while everything else is formatted "normal" (in other words the results are exactly identical to number 1).此语句中的and格式为 LaTeX 样式,而其他所有内容的格式为“正常”(换句话说,结果与数字 1 完全相同)。
  3. The LaTeX $ is escaped but the sentence now displays as " An amount between \$5 and \$10. " with one slash before each dollar sign. LaTeX $被转义,但句子现在显示为“ An amount between \$5 and \$10. ”,每个美元符号前有一个斜杠。

How can I properly esacpe the dollar signs in this sentence " An amount between $5 and $10. " with a Hugo theme that accepts LaTeX input?如何使用接受 LaTeX 输入的 Hugo 主题正确避开这句话“ An amount between $5 and $10. ”中的美元符号?

I should mention that if I knit the same.Rmd file with Ctrl+Shift+K the dollar sign does get escaped "properly" if I utilize the solution shown in example #2.我应该提到,如果我使用Ctrl+Shift+K编织相同的.Rmd 文件,如果我使用示例 #2 中显示的解决方案,美元符号确实会“正确”转义。 The issue only appears when blogdown::serve_site() serve my site, leading me to believe the issue is with Hugo themes accepting LaTeX input.该问题仅在blogdown::serve_site()为我的网站提供服务时出现,让我相信问题出在 Hugo 主题接受 LaTeX 输入。

A simple trick is to put in a space between the $ and the number.一个简单的技巧是在 $ 和数字之间放置一个空格。

4. An amount between $ 5 and $ 10. 

MathJax should only triggered and activate math mode when it is (first) followed by a non-whitespace character and should end at a $ preceded by something that isn't white space. MathJax 仅应在(首先)后跟非空白字符时触发并激活数学模式,并且应以 $ 结尾,前面有非空白字符。

It doesn't always work quite right but I tried it on my blogdown setup and that seemed okay.它并不总是工作得很好,但我在我的 blogdown 设置上试过了,这似乎没问题。

Also... (and I have no idea if this could be the reason)... but which version of MathJax are you loading?另外...(我不知道这是否是原因)...但是您正在加载哪个版本的 MathJax? I'm including the following code in my pages, and that renders your third example okay too.我在我的页面中包含以下代码,这也使您的第三个示例也可以。

  <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
      processEscapes: true
    }
    });
  </script>
  <script type="text/javascript"
      src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
  </script>

In MathJax.Hub.Config set processEscapes: true在 MathJax.Hub.Config 中设置 processEscapes: true

Then, use \\\$ to display the dollar sign - triple backslash....然后,使用\\\$显示美元符号 - 三重反斜杠....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM