Convert HTML and inline Mathjax math to LaTeX with pandoc ruby

半世苍凉 提交于 2019-12-06 07:59:23

问题


I'm building a Rails app and I'm looking for a way to convert database entries with html and inline MathJax math (TeX) to LaTeX for pdf creation.

I found similar questions like mine:

  • Convert html mathjax to markdown with pandoc
  • How to convert HTML with mathjax into latex using pandoc?

and I see two options here:

  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)

So my question is: what should the regex look like to split the string by \(math\).

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

And for the sake of completeness, how should the Haskell script be written to leave \(math\) alone when converting to LaTeX and the ruby method is not a possible solution?


回答1:


Get the very latest version of pandoc (1.12.2). Then you can do

pandoc -f html+tex_math_dollars+tex_math_single_backslash -t latex


来源:https://stackoverflow.com/questions/20492982/convert-html-and-inline-mathjax-math-to-latex-with-pandoc-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!