PHP-based LaTeX parser — where to begin?

前端 未结 6 1346
情话喂你
情话喂你 2020-12-30 13:31

The project: I want to build a LaTeX-to-MathML translator in PHP. Why? Because I\'m a mathematician, and I want to publish math on my Drupal site. It doesn\'t have to tra

相关标签:
6条回答
  • 2020-12-30 14:10

    I actually had a go at this last year. I got something working, though I wouldn't claim it had any elegance or charm to it, nor was it fully functional.

    If you want to convert equations to MathML, rather than full LaTeX conversion, then you could use itex2MML. If you can load extensions into your PHP, it's possible to compile itex2MML with PHP-bindings and use it natively in scripts. The Makefile might need a bit of hacking to get all the configurations right.

    Links:

    • PHPLaTeX
    • itex2MML with PHP-bindings
    0 讨论(0)
  • 2020-12-30 14:20

    If you are okay with converting formulas to pictures, there are tons of solutions. If you want MathML specifically, there are several of those as well. However, you might consider jsMath which uses javascript to render (a subset of) LaTeX in the browser. It's used by Sage and works well there.

    0 讨论(0)
  • 2020-12-30 14:26

    uh:

    http://drupal.org/project/drutex

    http://drupal.org/project/jsmath

    http://www.forkosh.com/mimetex.html

    http://www.codecogs.com/

    what is wrong with any of these?

    0 讨论(0)
  • 2020-12-30 14:35

    Don't write the parser yourself unless you want to do that as a learning experience. Just call existing LaTeX toolchains from PHP.

    LaTeX2HTML is about as good as you're going to get, and here's an (old) description of a LaTeX to MathML convertor from the maintainer of LaTeX2HTML.

    0 讨论(0)
  • 2020-12-30 14:35

    Alright this answer was a mess.

    Here's a cleaned up version:

    Since regex's clearly won't cut it for a translator for this type of thing, you have two options, based on your goals:

    1. You just want to be able to display LATEX on your site one way or another.
      • If this is what you want, there is a simple solution somewhere out there for you that is easier than picking up an advanced book on compiler theory. Either some way to include latex on your site, an existing translator, or something.

    2. You are a keener, and want to learn about compiler theory.
      • If this is the case, I cannot recommend the PDB highly enough. It's a fascinating book, and you'll learn a lot from it; After the first two chapters, you will have learned enough about lexical analysis to complete this project. Best money I've spent on an educational resource to date!
    0 讨论(0)
  • 2020-12-30 14:35

    Wikipedia is using a LaTeX to HTML(or image) translator written in OCaml. You can borrow some code there, or just use it as is.

    0 讨论(0)
提交回复
热议问题