基於php的LaTeX解析器——從哪里開始?

[英]PHP-based LaTeX parser — where to begin?


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 translate all of LaTeX, since the basic document-level stuff is ably handled by the CMS and wouldn't be written in LaTeX to begin with; it just has to translate math written in LaTeX into math written in MathML. Although I feel as though I've done my due diligence, this doesn't seem to exist already. Maybe I'm wrong---if you know of something that would serve this purpose, by all means let me know, and thank you in advance. But assuming it doesn't exist, I guess I have to go write it myself.

項目:我想在PHP中構建一個latexto - mathml轉換器。為什么?因為我是數學家,我想在Drupal上發布數學。它不需要翻譯所有的乳膠,因為基本的文檔級的東西是由CMS處理的,並且不會以乳膠的形式開始寫;它只需要把用乳膠編寫的數學轉換成用MathML編寫的數學。雖然我覺得我已經做了盡職調查,但這似乎還不存在。也許我錯了——如果你知道有什么事可以達到這個目的的話,請讓我知道,並提前謝謝你。但是假設它不存在,我想我必須自己去寫。

Here's the thing, though: I've never done anything this ambitious. I don't really know where to begin. I've used PHP for years, but just to do the standard "build a CMS with PHP and MySQL"-type of stuff. I've never attempted anything as seemingly sophisticated as translation from one language to another.

事情是這樣的:我從未做過如此雄心勃勃的事。我真的不知道從哪里開始。我已經使用PHP很多年了,但是僅僅是做標准的“用PHP和MySQL構建一個CMS”之類的事情。我從來沒有嘗試過從一種語言到另一種語言的翻譯這么復雜的東西。

I'm just dumb enough to consider doing it with regex---after all, LaTeX is a much more formal language, and it doesn't allow for nearly the kinds of pathological edge-cases, as say, HTML. But on the other hand, I'm just smart enough to realize this is probably a terrible idea: now I have two problems, and I sure don't want to end up like this guy.

畢竟,LaTeX是一種更為正式的語言,而且它幾乎不允許出現病態的邊緣情況,比如HTML。但另一方面,我很聰明地意識到這可能是個糟糕的想法:現在我有兩個問題,我肯定不想以這個人的方式結束。

So if that's not the way to go (right?), what is? How should I start thinking about this problem? Am I essentially writing a LaTeX compiler in PHP, and if so, what do I need to know to do that (like, should I just go read the Purple Dragon book first?)?

如果這不是正確的方法(對吧?)我該如何開始思考這個問題呢?我實際上是在用PHP編寫一個乳膠編譯器嗎?如果是的話,我需要知道什么才能做到這一點(比如,我應該先去讀《紫龍》這本書嗎?)

I'm both really excited and pretty intimidated by the prospect of this project, but hey, this is how we all learn to be programmers, right? If something we need doesn't exist, we go and build it, necessity is the mother of... you get the point. Tremendous thanks to everyone in advance for any and all guidance you can offer.

我對這個項目的前景既興奮又害怕,但嘿,這就是我們學習成為程序員的方式,對吧?如果我們需要的東西不存在,我們就去建造它,需要是……你明白了吧。非常感謝各位在此之前所給予的一切指導。

6 个解决方案

#1


3  

uh:

哦:

http://drupal.org/project/drutex

http://drupal.org/project/drutex

http://drupal.org/project/jsmath

http://drupal.org/project/jsmath

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

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

http://www.codecogs.com/

http://www.codecogs.com/

what is wrong with any of these?

這些有什么問題嗎?

#2


2  

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

不要自己編寫解析器,除非您希望將其作為學習經驗。只需從PHP調用現有的LaTeX工具鏈。

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.

LaTeX2HTML差不多就是您所能得到的最好的,下面是LaTeX2HTML的維護者對MathML轉換器的(舊的)描述。

#3


2  

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.

如果您想將方程轉換為MathML,而不是全乳膠轉換,那么您可以使用itex2MML。如果可以將擴展加載到PHP中,那么可以使用PHP綁定編譯itex2MML並在腳本中使用它。Makefile可能需要一些黑客技術才能正確配置所有配置。

Links:

鏈接:

#4


0  

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:

由於regex顯然不會為這種類型的東西提供翻譯,基於您的目標,您有兩個選擇:

  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.

    • 如果這是你想要的,那么有一個簡單的解決方案,比閱讀一本關於編譯理論的高級書籍更容易。要么是在你的站點上包含latex,要么是現有的轉換器,要么是其他東西。
  2. 您只是希望能夠以這樣或那樣的方式在站點上顯示乳膠。如果這是你想要的,那么有一個簡單的解決方案,比閱讀一本關於編譯理論的高級書籍更容易。要么是在你的站點上包含latex,要么是現有的轉換器,要么是其他東西。
  3. 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!
    • 如果是這種情況,我無法充分推薦PDB。這是一本迷人的書,你會從中學到很多;在前兩章之后,您將學習足夠的詞匯分析知識來完成這個項目。到目前為止,我花在教育資源上的最好的錢!
  4. 你是個熱心的人,想學習編譯理論。如果是這種情況,我無法充分推薦PDB。這是一本迷人的書,你會從中學到很多;在前兩章之后,您將學習足夠的詞匯分析知識來完成這個項目。到目前為止,我花在教育資源上的最好的錢!

#5


0  

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.

如果你可以把公式轉換成圖,有很多的解。如果您特別想要MathML,也可以使用其中的幾個。但是,您可以考慮使用javascript在瀏覽器中呈現(乳膠的一個子集)的jsMath。Sage使用的很好。

#6


0  

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.

維基百科正在使用OCaml編寫的乳膠(或圖像)翻譯程序。你可以在那里借用一些代碼,或者直接使用。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/03/11/2faad35e9b0605b139acc78cb5ea1485.html



 
  © 2014-2022 ITdaan.com 联系我们: