使用pandoc ruby​​将HTML和内联Mathjax数学转换为LaTeX [英] Convert HTML and inline Mathjax math to LaTeX with pandoc ruby

查看:119
本文介绍了使用pandoc ruby​​将HTML和内联Mathjax数学转换为LaTeX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Rails应用程序,并且正在寻找一种将数据库条目与html和内联MathJax数学(TeX)转换为LaTeX以创建PDF的方法。



我发现了类似于我的问题:



,我在这里看到两个选项:


  1. 创建一个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:

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?

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆