在 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 公式就可以正常顯示了。