一千萬個為什麽

搜索

使用pandoc ruby​​將HTML和內聯Mathjax數學轉換為LaTeX

我正在構建一個Rails應用程序,我正在尋找一種方法將數據庫條目與html和內聯MathJax數學(TeX)轉換為用於創建PDF的LaTeX。

我發現了類似我的問題:

我在這裏看到兩個選項:

  1. Create a Haskell executable which leaves stuff like \(y=f(x)\) alone when converting html to LaTeX
  2. Write a ruby method which does the following things:
    • Take the string and split it into an array with a regex (string.split(regex))
    • loop through the created array and if content matches regex convert the parts to LaTeX which do not include inline math with PandocRuby.html(string).to_latex
    • concatenate everything back together (array.join)

I would prefer the ruby method solution because I'm hosting my application on Heroku and I don't like to checkin binaries into git.
Note: the pandoc binary is implemented this way http://www.petekeen.net/introduction-to-heroku-buildpacks)

所以我的問題是: regex 應該如何通過 \(math \)拆分 string

E.g. string can look like this: text \(y=f(x) \iff \log_{10}(b)\) and \(a+b=c\) text

並且為了完整起見,當轉換為LaTeX時,如何編寫Haskell腳本以保留 \(math \),並且ruby方法不是可行的解決方案?

最佳答案

獲取最新版本的pandoc(1.12.2)。那你可以做

pandoc -f html+tex_math_dollars+tex_math_single_backslash -t latex

轉載註明原文: 使用pandoc ruby​​將HTML和內聯Mathjax數學轉換為LaTeX