Wednesday, April 20, 2011

Using LaTeX for Math Formulas on the Web

I love the idea of using R+LaTeX+Sweave for reproducible research. This is even easier now that R has a jazzy new IDE that supports Sweave syntax highlighting and automatic PDF generation.

I know I'm going to take some flak for saying this, but let's be honest here... If you're working in the biomedical sciences, chances are, your collaborators have never heard of Sweave. Physicians only use LaTeX during surgery. Lots of folks you work with probably think real applied statistics can only be done in SAS (if you're one of them, please see http://www.r-project.org/). Most biomedical journals will only accept MS Word .doc files during manuscript submission. NIH grant applications use a standardized MS Word template.

These are a few of the reasons I don't routinely incorporate LaTeX+Sweave in my analysis workflow.

That said, one of the things LaTeX is really good for is mathematical typesetting. Writing out math formulae using LaTeX is fast, intuitive, and your plain-text code is portable. If you're ever posting a question on stats.stackexchange, editing Wikipedia, or if you're like me and keep your lab notebook online in a private blog online, using LaTeX conventions for typesetting formulae can be extremely handy.

Codecogs.com's Online LaTeX Equation Editor makes it very simple to use HTML to add formulae to your blog or anywhere on the web. The idea's simple - you type in the LaTeX code for the formula you want, e.g.

SS_{err}=\sum_i({y_i-\hat{y}_i})^2

And you'll get this HTML code:

<img src="http://latex.codecogs.com/gif.latex?SS_{err}=\sum_i({y_i-\hat{y}_i})^2" title="SS_{err}=\sum_i({y_i-\hat{y}_i})^2" />

This HTML code generates a hosted image that you can copy and paste anywhere on the web you like. Paste this into the compose window in Blogger, and it looks like this:



Online LaTeX Equation Editor

6 comments:

  1. I have been looking for a "translator" such as this for a long time. I'm a biostatistics graduate student and was not able to do equations on my blog until now. Thank you so much!

    ReplyDelete
  2. I haven't used this myself, but the jsMath software (http://www.math.union.edu/~dpvc/jsMath/) uses div(s) with class "math" to render LaTeX using fonts and/or images.

    ReplyDelete
  3. That's indeed very useful. Thanks

    ReplyDelete
  4. You can also take a look at MathJax. It renders LaTeX using JavaScript, but feels much more compatible than jsMath..

    ReplyDelete
  5. http://cameron.bracken.bz/on-the-fly-latex

    ReplyDelete

Creative Commons License
Getting Genetics Done by Stephen Turner is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.