在 Asciidoc 文档中使用 Latex

在 Asciidoc 文档中使用 Latex

本文基于 asciidoctor 1.5.7.13,其通过 mathjax 实现 LaTex 字体的显示,方法和 markdown 差不多,区别是 markdown(不同差距实现方法不同)使用 $$ 或者 $``$ 包围 LaTex 语法,而 asciidoctor 使用 stem:[] 包围 LaTex 语法。

单个符号对照表

渲染后

源码

stem:[\cdot]

stem:[\cdot]

stem:[\times]

stem:[\times]

stem:[a^{prime} a]

stem:[a^{prime} a]

stem:[a’’]

stem:[a’’]

stem:[a’’’]

stem:[a’’’]

stem:[\pm]

stem:[\pm]

stem:[\mp]

stem:[\mp]

stem:[!]

stem:[!]

stem:[\dots]

stem:[\dots]

stem:[\ldots]

stem:[\ldots]

stem:[\cdots]

stem:[\cdots]

stem:[\vdots]

stem:[\vdots]

stem:[\ddots]

stem:[\ddots]

行列式

渲染后

源码

15\\ 7 \end{array}right)
\vec{a} =
\left[\begin{array}{rrrr}  
  15\\
  7
\end{array}\right)         
[latexmath]
++++
\begin{cases}
 \ u_{tt}(x,t)= b(t)\triangle u(x,t-4)&\\
\ \hspace{42pt}- q(x,t)f[u(x,t-3)]+te^{-t}\sin^2 x,  &  t \neq t_k; \\
 \ u(x,t_k^+) - u(x,t_k^-) = c_k u(x,t_k), & k=1,2,3\ldots ;\\
 \ u_{t}(x,t_k^+) - u_{t}(x,t_k^-) =c_k u_{t}(x,t_k), &
 k=1,2,3\ldots\ .
\end{cases}
]
++++
q(x,t)=
\begin{cases}(t-k+1)x^2,\quad \ \ &
  t\in\big(k-1,k-\dfrac{1}{2}\big],\\
  (k-t)x^2, \quad \ \ & t\in\big(k-\dfrac{1}{2},k\big],
\end{cases}

hexo中集成asciidoctor后渲染latex的bug

hexo, asciidoctor, latex 三者在一起组成了一个很小众的东西。实际上使用 ruby 安装的 asciidoctor 在使用起来完全没有问题,但是 hexo 中因为使用的是 nodejs 中的一个 hexo-renderer-asciidoc 插件对 hexo 增强了 asciidoctor 的功能,并且该插件会对 { } 进行 转义,因此会导致莫名其妙的 问题出现。

另外 hexo 的 theme\next 主题中有 mathjax 的配置,将其设置为 true 后所有的页面都会引用 mathjax 的 js。

themes/next/_config.yml.

mathjax:
  enable: true
  per_page: false
  cdn: //cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML

因此开启此项配置后,结合插件,页面上的 LaTex 公式就可以正常显示了。