[教學] 在 Mathjax 環境中打出 \xRightarrow, \xLeftarrow 箭頭

在 VScode 裡打 Markdown 檔案太方便

移到部落格裡才發現原來不是所有套件都可以在網頁顯示 Latex 的 Mathjax 套件中執行

例如 \xRightarrow\xLeftarrow\xLeftrightarrow

以下就介紹如何在 Mathjax 套件環境中打出

  • \(\require{extpfeil}\Newextarrow{\xLeftrightarrow} {5,5}{0x21D4}\xLeftrightarrow[\text{text below}]{\text{text above}}\)

  • \(\require{extpfeil}\Newextarrow{\xRightarrow} {5,5}{0x21D2}\xRightarrow[\text{text below}]{\text{text above}}\)

  • \(\require{extpfeil}\Newextarrow{\xLeftarrow} {5,5}{0x21D0}\xLeftarrow[\text{text below}]{\text{text above}}\)

第零步:呼叫 Mathjax 套件

感謝 peter 大大無私分享:在Blogger中使用LaTeX 表達數學式
在 HTML 的編輯環境下輸入

<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"> </script>

就可以使用 Mathjax 套件了

第一步:引入 extpfeil 套件

在 Mathjax 環境下要引入套件用:

\require{extpfeil}

第二步:尋找適當箭頭 Unicode

Mathjax 文件中定義

\Newextarrow{\cs}{lspace,rspace}{unicode-char}

  • \cs :new control sequence name to be defined (名稱)
  • lspace, rspace:the amount of space (空格)
  • unicode-char:unicode character position in either decimal or hexadecimal notation

其中 unicode-char 可在此網頁對照

這裡用到的 

\(\Leftarrow\)  對應到 0x21D0

\(\Rightarrow\)  對應到 0x21D2

\(\Leftrightarrow\)  對應到 0x21D4


第三步:呼叫箭頭

Mathjax 打出 \xRightarrow\xLeftarrow\xLeftrightarrow

  • \[\require{extpfeil}\Newextarrow{\xLeftrightarrow} {5,5}{0x21D4}\xLeftrightarrow[\text{text below}]{\text{text above}}\]
\require{extpfeil} \Newextarrow{\xLeftrightarrow} {5,5}{0x21D4} \xLeftrightarrow[\text{text below}]{\text{text above}}
  • \[\require{extpfeil}\Newextarrow{\xRightarrow} {5,5}{0x21D2}\xRightarrow[\text{text below}]{\text{text above}}\]
\require{extpfeil} \Newextarrow{\xRightarrow} {5,5}{0x21D2} \xRightarrow[\text{text below}]{\text{text above}}
  • \[\require{extpfeil}\Newextarrow{\xLeftarrow} {5,5}{0x21D0}\xLeftarrow[\text{text below}]{\text{text above}}\]
\require{extpfeil} \Newextarrow{\xLeftarrow} {5,5}{0x21D0} \xLeftarrow[\text{text below}]{\text{text above}}

另一種表達箭頭的方法:mhchem

雖然這個套件主要是表達化學式
但因為我也用到了一個 \xrightleftharpoons
但是在 Mathjax 環境中也無法顯示出來
所以順便分享這個套件的用法

同樣也是引入套件

\require{mhchem}

接著定義箭頭

\ce{<=>[\text{text above}][\text{text below}]

成果

\require{mhchem} \ce{<=>[\text{text above}][\text{text below}]

\[\require{mhchem} \ce{<=>[\text{text above}][\text{text below}]}\]


參考文件:How to typeset longer ⇒ with text under it using MathJax?

留言

這個網誌中的熱門文章