Mohegan SkunkWorks

Fri, 06 Nov 2009 06:32:19 EST

Embedding Equations in a Blog Post

I'm using a home-grown blogging engine which converts pages formatted in markdown to static html pages served from my github account. If I want to include mathematical equations in my blog post my options are to use inline html code or to use one of the online Latex equation editors.

My requirements are simple: I want to be able to use the usual cast of mathematical symbols inlined in my main text as well format large equation blocks. In this post I'll compare and contrast inline html with online editors provided by SITMO, CodeCogs and Textify.

To save you the trouble of having to wade through miles of text, I'll start of with my


Use HTML for inlining symbols and equations. Although those will never look as good in html as in Latex, the overall format of your text will suffer less.

For equation blocks you have the choice between two online editors : SITMO, CodeCogs. When it comes to embedding latex code into your html both editors are comparable. When you're looking for more variety with regard to fonts or markup languages CodeCogs is your only alternative.

If you want to use the url link to embed a large code block you probably would want to use a url shortner. Tiny url is a good option here.As an alternative both editors can generate a png image for you to embed.

Textify has a nice clean interface, but I can't embed the links it generates. My only alternative would appear to be to run my own instance of this service which is obviously not something I need or want to do. Furthermore, although it cleverly provides a shortened url, it uses which unfortunately doesn't handle complex latex url's well..

Read on to find out how I reached these conclusions .


HTML supports special characters as well as subscripts and superscripts. . Let's give it a shot, starting with embedded equations.


Here's an example of the use of HTML to embed equations and symbols. I'll be using the same example through out.

... a classification error εi is the average of all instances of the test data where h t (x i ) ≠ y i . This yields the ratio n N ..... where we integrate ∫ 0 π...

Block Equation

This is the latex of the block equation I'm going to try to render in html :

    D_{t+1} = \frac{D_{t}}{Z_{t}} \times  
                                   & e^{-\alpha_{t} }   \text{ if }  y_{i} = h_{t}(x_{i}) \\  
                                   & e^{\alpha_{t} }   \text{ if }  y_{i} \neq  h_{t}(x_{i})  
                                        = \frac{D_{t}}{Z_{t}} \times e^{(\alpha_{t} y_{i} h_{t}(x_{i}))}  

It's the equation used in the AdaBoost algorithm.
Here's what the equation looks like when I try to render it directly in HTML :

D t+1 = D t Z t × { e t ) if y i = h i (x i ) e (-α t ) if y i ≠ h i (x i ) = D t Z t × e ( α t y i h t (x i ))


For quick inline equations html is certainly good enough. For block equations the html rendered version does not nearly look as good as the Latex one. In the original text the html tags start to overwhelm the content and it becomes hard to see the mathematical trees in the html forest. This makes correcting or updating complicated code blocks difficult.


According to it's web site is a 'quant' company located in Delft, The Netherlands. The company provides an easy to use latex editor which it also makes available as a Google gadget.

You have to option bteween downloading an image or of embedding links to the rendered latex directly into your html.


Typically you can embed the link provided by SITMO straight into your html, like so :


This is what I've done below in order to inline special symbols and simple equations :

... a classification error is the average of all instances of the test data where . This yields a ratio .... where we integrate ...

Block Equation

First I tried to generate a link just as I did for the inline symbols and equations. Here's the url generated by the editor : %20%3D%20\frac 0} 0}%20\times%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20\begin %20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26%20e^ %20 0}%20%20%20\text %20%20y_ %20%3D%20h_ (x_ )%20\%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26%20e^ %20 0}%20%20%20\text %20%20y_ %20\neq%20%20h_ (x_ )%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20\end %20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3D%20\frac 0} 0}%20\times%20e^ %20y_ %20h_ (x_ )) 0}%0A

This obviously needs some serious url-shorting. First up is New York favorite which shortens the url to :

Obviously we've lost some accuracy here.

Next up is the link generated by venerable tinyurl which shortens the url to a manageable :

No complaints here.

The SITMO editor can also be used to generate a png image, which you then can embed yourself. Here's the result :


Take a look at the embedded symbols and equations for this section. If you're a stickler for consistent layout using image links to inline equations creates a few challenges. You need to handle the integration with your background color as well as the alignment within the main text. I found the use of embedded links more cumbersome than using inlined html because these embedded links don't integrate well with the overall layout without tweaking. On the other hand the rendered latex is looks better than the embedded html, and using both html (for inline equations) and latex (for blocks) in your post may create it's own formatting discontinuities.

The block equation is rendered beautifully by the Lates editor. The challenge is dealing with the ungodly long url if you want to embed the link generated by the SITMO editor. Clearly, not all bit shortners are able to handle this. The alternative is to embed an image in your document.


This editor is provided by CodeCogs engineering. Please consult the install page for more information. This editor seems to be quite popular on the web. CodeCogs provides an equation editor which generates a url on their website you can embed or a gif image you can host yourself. CodeCogs provides a variety of formats like html snippets, a url and code to embed into wiki pages, among other things.
Here's an example of an html snippit :


Embedding the url provided by CodeCogs into your html is straightforward :


This generates a default image size of 110 dpi. When you compare this to the SITMO url you'll notice that it doesn't have a size tag. CodeCogs does allow you to vary the size through a drop box . This adds a dpi tag to the url :


Here's how the embedded equations are rendered, using image url's :

... a classification error is the average of all instances of the test data where . This yields a ratio .... where we integrate ...

Block Equation

I would have liked to have been able to test the HTML snippet generated by the CodeCogs editor. However, as I mentioned in the intor, my blog engine runs pages through a mark down transformer and chokes on the html generated by CodeCogs.

As an alternative I've run the url through two bit shortners. Here's the rendering using the url generated by bitly '' :

Again, something obviously got lost in translation.

Here's the the rendering from the link generated by tinyurl : ''

CodeCogs can also be used to generate an image file. You can choose between several image formats, like png, gif, pdf and others and several fonts. By the way, this applies to the url as well. The image below is generated in comic sans serif at 150 dpi :


I found the CodeCogs editor easy to use. It allows equations to be saved in a wide variety of image formats, sizes and fonts and provides code to embed them in a variety of markup formats.

My observations about inlining symbols when discussing the SITM editor apply here as well.

I was unable to test the html snippet generated for the block equation, due to limitations (bugs !) in my blog engine. Nevertheless, running the url provided by the editor through a bit shortner provides a good alternative. In addition, you can save an image of the equation ins a variety of formats.


Textify is a product designed by John Forkosh Associates, Inc. Textify does not provide a Latex editor so it assumes at least some Latex proficiency on the user's part. In fact, it's web page can best be described as no-frills, which I happen to think of as a complement.

Ok, so let's get to it.


Textify provides results that can be used in web pages, email or forums. Whereas the previous two services provide a web based api, Textify generates an html snippet around a gif, which can be embedded in your web page :


There are two alternative sizes for the image provided on the page. You don't have the ability to customize the size or font the image.
Let's see how it works out :

... a classification error \epsilon_{i} is the average of all instances of the test data where ..........

Ok, ooopsee.. As an alternative, I tried to use the other image files that were generated :

... a classification error is the average of all instances of the test data where This yields a ratio ... where we integrate ...

Clearly not very useful for my purposes, but it does allow you to use links in emails or google docs.

Block Equation

Textify automatically generates shortened url for use in twitter. Unfortunately, it's using which proves problematic :

The shortened url used here is '' and it exhibits the same pathologies I mentioned above for SITMO and CodeCogs.


I like the clean look of Textify. Unfortunatly, I can't use it as use of the server is restricted. In addition, providing shortened urls for equations is clearly a smart thing, but seems doesn't seem to handle the latex formatting urls properly.