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

在学习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,在以后也会单独写点浅显的学习心得与经验。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值