【工具】【Mathjax-2】Mathjax-config的初步学习,以及in-line$...$输入模式的开启

本文探讨了MathJax中遇到的公式显示难题,特别是inline模式无法正常工作的问题,并提供了解决方案,包括配置调整及使用不同输入语法。

在学习Mathjax时,碰到一个问题,因为据教程所讲,Mathjax具有两种输入模式:

1. 开源输入模式(inline),“$...$”

2. 封闭输入模式(enclose), “$$...$$”

但是在使用开源输入模式时出现了困扰比如

$\alpha+\beta=\gamma$ 无法转化成公式

但是经过试验如果将其改写为封闭输入模式就能成功。

$$\alpha+\beta=\gamma$$

为了解决这个问题,查阅了一篇mizuho豆瓣上的帖子:https://www.douban.com/note/534786000/?type=rec

指出$...$是默认关闭的,需要手动打开。

于是我修改了Mathjax-config的参数,如下代码:

<!DOCTYPE html>
<html>
<head>
<title>MathJax TeX Test Page</title>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({tex2jax: {inlineMath: ['$','$'], ['\\(','\\)']}});
</script>
<script type="text/javascript" async
  src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML">
</script>
</head>
<body>

</body>
</html>

遗憾的是,Mathjax的inline依然not working.

终于,在前段时间,在闲逛时发现了这个博客,博主Dean的文章:https://codepen.io/josdea/pen/rLOJxL

代码如下:

<div class="container">
<h2>
Inline MathJax
</h2>

<p>$x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}$</p>
<p>
The scripts in this file allow math formulas to be written anywhere within the HTML code.  To start a formula you use either a dollar sign \$ or you can use a slash an an open parentheses "/(".  To end the inline math, you have another dollar sign or a back slash and a closing parentheses.  Enclosing in double dollar signs put the math on its own line.  Or you can use the backslash and a hard bracket "\[".
</p>

<p>
If you need to actually use a regular dollar sign in the text, then you need to 'escape' it so the page doesn't think its the start of math.  In order to escape it you use a backslash before the dollar sign.  "\\$"
</p>

<h3>
Examples
</h3>
<ol>
<li>Dollar Signs: $y=mx+1$</li>
<li>Parenthesis: \(y=mx+2\)</li>
<li>Double Dollar Signs: $$y=mx+3$$</li>
<li>Hard Bracket: \[y=mx+5\]</li>
  <li>$\lim_{x \to \infty} \exp(‐x) = 0$</li>
  <li>$\cos (2\theta) = \cos^2 \theta ‐ \sin^2 \theta$</li>
  <li>$a \bmod b$</li>
  <li>$x \equiv a \pmod b$</li>
</ol>

<h4>
In a sentence
</h4>
<p>
When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
</p>
</div>

在这里,他引入了两种Mathjax的Inline代码,才发现如:\(ax^2 + bx + c = 0\)可以实现的。

终于找到了不支持Inline mode的原因,我怀疑是我电脑里某个扩展或者代码无法识别单个dollar ($)。

而是用

\(\)符号可以代替$$

并且,Mathjax针对目前主要浏览器都可以自动调用,不需要自己重新调用,除非,想更改字体或者其他参数就要用得上Mathjax-config。

我准备先熟悉Mathjax的主要代码,在以后会继续更新一些自己常用的代码。

关于Mathjax-config,在以后也会单独写点浅显的学习心得与经验。

processing file: SangerRead_Report_ab1.Rmd |................................................. | 95% [unnamed-chunk-9]INFO [2025-08-11 17:21:31] * Making basecall !! INFO [2025-08-11 17:21:31] * Updating slots in 'SangerRead' instance !! output file: SangerRead_Report_ab1.knit.md "C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS SangerRead_Report_ab1.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output pandoc237871d63756.html --lua-filter "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\RMARKD~1\lua\PAGEBR~1.LUA" --lua-filter "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\RMARKD~1\lua\LATEX-~1.LUA" --lua-filter "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\RMARKD~1\lua\TABLE-~1.LUA" --embed-resources --standalone --variable bs3=TRUE --section-divs --table-of-contents --toc-depth 3 --variable toc_float=1 --variable toc_selectors=h1,h2,h3 --variable toc_collapsed=1 --variable toc_smooth_scroll=1 --variable toc_print=1 --template "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\rmd\h\DEFAUL~1.HTM" --no-highlight --variable highlightjs=1 --variable theme=bootstrap --mathjax --variable "mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --include-in-header "C:\Users\ADMINI~1\AppData\Local\Temp\RtmpYBVwty\rmarkdown-str237857086851.html" [WARNING] Div at SangerRead_Report_ab1.knit.md line 153 column 1 unclosed at SangerRead_Report_ab1.knit.md line 232 column 1, closing implicitly. [WARNING] Div at SangerRead_Report_ab1.knit.md line 147 column 1 unclosed at SangerRead_Report_ab1.knit.md line 232 column 1, closing implicitly. Output created: C:/Users/Administrator/AppData/Local/Temp/RtmpYBVwty/013-G2/SangerRead_Report_ab1.html Error: 分析失败: $ operator is invalid for atomic vectors Execution halted
08-12
Rscript sangeranalyseR2.R -i 013-G2.ab1 -r GJB2.fasta -q -p -m 0.1 Bioconductor version '3.20' is out-of-date; the current release version '3.21' is available with R version '4.5'; see https://bioconductor.org/install INFO [2025-08-11 17:21:28] ------------------------------------------------ INFO [2025-08-11 17:21:28] -------- Creating 'SangerRead' instance -------- INFO [2025-08-11 17:21:28] ------------------------------------------------ INFO [2025-08-11 17:21:28] >> Forward Read: Creating abif & sangerseq ... INFO [2025-08-11 17:21:28] >> Creating Forward Read raw abif ... INFO [2025-08-11 17:21:28] >> Creating Forward Read raw sangerseq ... INFO [2025-08-11 17:21:28] * Making basecall !! INFO [2025-08-11 17:21:28] * Updating slots in 'SangerRead' instance !! SUCCESS [2025-08-11 17:21:29] -------------------------------------------------------- SUCCESS [2025-08-11 17:21:29] -------- 'SangerRead' S4 instance is created !! -------- SUCCESS [2025-08-11 17:21:29] -------------------------------------------------------- SUCCESS [2025-08-11 17:21:29] >> '013-G2.ab1' is created (Forward Read; ABIF). INFO [2025-08-11 17:21:29] >> Read is trimmed by 'M1 - Mott’s trimming algorithm'. DEBUG [2025-08-11 17:21:29] >> For more information, please run 'object'. DEBUG [2025-08-11 17:21:29] >> Run 'object@objectResults@readResultTable' to check the result of the Sanger read INFO [2025-08-11 17:21:29] Your input is 'SangerRead' S4 instance INFO [2025-08-11 17:21:29] >>> outputDir : C:\Users\Administrator\AppData\Local\Temp\RtmpYBVwty processing file: SangerRead_Report_ab1.Rmd |................................................. | 95% [unnamed-chunk-9]INFO [2025-08-11 17:21:31] * Making basecall !! INFO [2025-08-11 17:21:31] * Updating slots in 'SangerRead' instance !! output file: SangerRead_Report_ab1.knit.md "C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS SangerRead_Report_ab1.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output pandoc237871d63756.html --lua-filter "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\RMARKD~1\lua\PAGEBR~1.LUA" --lua-filter "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\RMARKD~1\lua\LATEX-~1.LUA" --lua-filter "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\RMARKD~1\lua\TABLE-~1.LUA" --embed-resources --standalone --variable bs3=TRUE --section-divs --table-of-contents --toc-depth 3 --variable toc_float=1 --variable toc_selectors=h1,h2,h3 --variable toc_collapsed=1 --variable toc_smooth_scroll=1 --variable toc_print=1 --template "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\rmd\h\DEFAUL~1.HTM" --no-highlight --variable highlightjs=1 --variable theme=bootstrap --mathjax --variable "mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --include-in-header "C:\Users\ADMINI~1\AppData\Local\Temp\RtmpYBVwty\rmarkdown-str237857086851.html" [WARNING] Div at SangerRead_Report_ab1.knit.md line 153 column 1 unclosed at SangerRead_Report_ab1.knit.md line 232 column 1, closing implicitly. [WARNING] Div at SangerRead_Report_ab1.knit.md line 147 column 1 unclosed at SangerRead_Report_ab1.knit.md line 232 column 1, closing implicitly.
08-12
正在分析单端Sanger测序文件: 013-G2.ab1 INFO [2025-08-11 17:36:10] ------------------------------------------------ INFO [2025-08-11 17:36:10] -------- Creating 'SangerRead' instance -------- INFO [2025-08-11 17:36:10] ------------------------------------------------ INFO [2025-08-11 17:36:10] >> Forward Read: Creating abif & sangerseq ... INFO [2025-08-11 17:36:10] >> Creating Forward Read raw abif ... INFO [2025-08-11 17:36:10] >> Creating Forward Read raw sangerseq ... INFO [2025-08-11 17:36:10] * Making basecall !! INFO [2025-08-11 17:36:10] * Updating slots in 'SangerRead' instance !! SUCCESS [2025-08-11 17:36:11] -------------------------------------------------------- SUCCESS [2025-08-11 17:36:11] -------- 'SangerRead' S4 instance is created !! -------- SUCCESS [2025-08-11 17:36:11] -------------------------------------------------------- SUCCESS [2025-08-11 17:36:11] >> '013-G2.ab1' is created (Forward Read; ABIF). INFO [2025-08-11 17:36:11] >> Read is trimmed by 'M1 - Mott’s trimming algorithm'. DEBUG [2025-08-11 17:36:11] >> For more information, please run 'object'. DEBUG [2025-08-11 17:36:11] >> Run 'object@objectResults@readResultTable' to check the result of the Sanger read 生成质量报告... INFO [2025-08-11 17:36:11] Your input is 'SangerRead' S4 instance INFO [2025-08-11 17:36:11] >>> outputDir : C:\Users\Administrator\AppData\Local\Temp\Rtmp6Pr8wB processing file: SangerRead_Report_ab1.Rmd |................................................. | 95% [unnamed-chunk-9]INFO [2025-08-11 17:36:12] * Making basecall !! INFO [2025-08-11 17:36:12] * Updating slots in 'SangerRead' instance !! output file: SangerRead_Report_ab1.knit.md "C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS SangerRead_Report_ab1.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output pandoc1d4c20606dbd.html --lua-filter "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\RMARKD~1\lua\PAGEBR~1.LUA" --lua-filter "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\RMARKD~1\lua\LATEX-~1.LUA" --lua-filter "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\RMARKD~1\lua\TABLE-~1.LUA" --embed-resources --standalone --variable bs3=TRUE --section-divs --table-of-contents --toc-depth 3 --variable toc_float=1 --variable toc_selectors=h1,h2,h3 --variable toc_collapsed=1 --variable toc_smooth_scroll=1 --variable toc_print=1 --template "C:\PROGRA~1\R\R-44~1.3\library\RMARKD~1\rmd\h\DEFAUL~1.HTM" --no-highlight --variable highlightjs=1 --variable theme=bootstrap --mathjax --variable "mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --include-in-header "C:\Users\ADMINI~1\AppData\Local\Temp\Rtmp6Pr8wB\rmarkdown-str1d4cef82398.html" [WARNING] Div at SangerRead_Report_ab1.knit.md line 153 column 1 unclosed at SangerRead_Report_ab1.knit.md line 232 column 1, closing implicitly. [WARNING] Div at SangerRead_Report_ab1.knit.md line 147 column 1 unclosed at SangerRead_Report_ab1.knit.md line 232 column 1, closing implicitly. [WARNING] Could not fetch resource https://pro.fontawesome.com/releases/v5.10.0/webfonts/fa-duotone-900.ttf: HttpExceptionRequest Request { host = "pro.fontawesome.com" port = 443 secure = True requestHeaders = [] path = "/releases/v5.10.0/webfonts/fa-duotone-900.ttf" queryString = "" method = "GET" proxy = Nothing rawBody = False redirectCount = 10 responseTimeout = ResponseTimeoutDefault requestVersion = HTTP/1.1 proxySecureMode = ProxySecureWithConnect } (InternalException (HostCannotConnect "pro.fontawesome.com" [Network.Socket.connect: <socket: 852>: failed (Connection timed out (WSAETIMEDOUT)),Network.Socket.connect: <socket: 852>: failed (Connection timed out (WSAETIMEDOUT))])) Output created: C:/Users/Administrator/AppData/Local/Temp/Rtmp6Pr8wB/013-G2/SangerRead_Report_ab1.html Error: 分析失败: $ operator is invalid for atomic vectors Execution halted
08-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值