无法在Blogdown中逃脱LaTeX美元符号`$` [英] Can't escape LaTeX dollar sign `$` in blogdown

查看:108
本文介绍了无法在Blogdown中逃脱LaTeX美元符号`$`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

请在Blogdown .Rmd文件中包含以上代码块,并确保您的Hugo主题支持LaTeX方程式.然后保存并使用blogdown::serve_site()为您的网站提供服务.当我这样做时,上面显示的三个选项都不能正确地逃避LaTeX的美元符号 $ .

Please include the code chunk above in a blogdown .Rmd file, and make sure your Hugo theme supports LaTeX equations. Then Save and serve your site with blogdown::serve_site(). When I do this none of the three options shown above properly escape LaTeX's dollar sign $.

这就是我的情况(是的,在尝试此操作之前,我确实使用 update.packages(ask = FALSE,checkBuilt = TRUE)更新所有软件包).以下这三个结果来自以上相同的三个尝试:

Here's what happens to me (and yes I did update all packages with update.packages(ask = FALSE, checkBuilt = TRUE) prior to trying this). These three results below are from the same three attempts above:

  1. 此语句中的以LaTeX样式设置格式,而其他所有内容都设置为普通"格式.
  2. 此语句中的以LaTeX样式设置格式,而其他所有内容都设置为普通"格式.(换句话说,结果与数字1完全相同).
  3. LaTeX $ 被转义,但句子现在显示为"介于$ 5到\ $ 10之间的金额.".每个美元符号前加一个斜线.
  1. The and in this statement is formatted in LaTeX style while everything else is formatted "normal".
  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).
  3. The LaTeX $ is escaped but the sentence now displays as "An amount between \$5 and \$10." with one slash before each dollar sign.

如何正确保留这句话中的美元符号" 5至10美元之间的金额.".带有接受LaTeX输入的Hugo主题?

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?

我应该提到,如果我用 Ctrl + Shift + K 编织相同的.Rmd文件,美元符号的确会正确地"转义.如果我使用示例2中所示的解决方案.该问题仅在 blogdown :: serve_site()为我的网站提供服务时出现,使我相信问题出在Hugo主题接受LaTeX输入.

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. The issue only appears when blogdown::serve_site() serve my site, leading me to believe the issue is with Hugo themes accepting LaTeX input.

推荐答案

一个简单的技巧是在$和数字之间放置一个空格.

A simple trick is to put in a space between the $ and the number.

4. An amount between $ 5 and $ 10. 

MathJax仅在(第一个)后跟非空格字符时才应触发并激活数学模式,并应以$开头,并以非空格开头.

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.

它并不总是能正常工作,但是我在我的Blogdown设置上尝试了它,这似乎还可以.

It doesn't always work quite right but I tried it on my blogdown setup and that seemed okay.

也...(我不知道这是否可能是原因)...但是您正在加载哪个版本的MathJax?我在页面中包含了以下代码,这也使您的第三个示例也可以.

Also ... (and I have no idea if this could be the reason) ... but which version of MathJax are you loading? 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>

这篇关于无法在Blogdown中逃脱LaTeX美元符号`$`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆