使用pandoc ruby将HTML和内联Mathjax数学转换为LaTeX [英] Convert HTML and inline Mathjax math to LaTeX with pandoc ruby
问题描述
我正在构建一个Rails应用程序,并且正在寻找一种将数据库条目与html和内联MathJax数学(TeX)转换为LaTeX以创建PDF的方法。
我发现了类似于我的问题:
,我在这里看到两个选项:
- 创建一个Haskell可执行文件,其内容像<$当将html转换为LaTeX时,单独使用c $ c> \(y = f(x)\)编写一个ruby方法,它执行以下操作:
- 取
字符串
并将其分成数组
用正则表达式( string.split(regex)
)
- 循环遍历所创建的
数组
,如果内容匹配regex
,则将零件转换为不包含内联的LaTeX数学与PandocRuby.html(字符串).to_latex
- 将所有内容连接在一起(
array.join
)
- 循环遍历所创建的
- 取
我更喜欢ruby方法解决方案,因为我'在Heroku上托管我的应用程序,我不喜欢将二进制文件检入到git中。
注意: pandoc
二进制文件是实现的way http://www.petekeen.net/introduction-to-heroku-buildpacks)
所以我的问题是: regex
看起来像分割<
$ b $ 例如 string
可以是这样的: text \(y = f(x)\iff \log_ {10}(b )\)和\(a + b = c\)text
为了完整起见,Haskell当转换为LaTeX并且ruby方法不是一个可行的解决方案时,脚本被编写为仅保留 \(math \)
>
获取最新版本的pandoc(1.12.2)。然后你可以做到:
pre $ p $ c $ pandoc -f html + tex_math_dollars + tex_math_single_backslash -t latex
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:
- Create a Haskell executable which leaves stuff like
\(y=f(x)\)
alone when converting html to LaTeX - Write a ruby method which does the following things:
- Take the
string
and split it into anarray
with a regex (string.split(regex)
) - loop through the created
array
and if content matchesregex
convert the parts to LaTeX which do not include inline math withPandocRuby.html(string).to_latex
- concatenate everything back together (
array.join
)
- Take the
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?
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
这篇关于使用pandoc ruby将HTML和内联Mathjax数学转换为LaTeX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!