November 09, 2005

Equations in blogs

We've just added support for LateX markup in blogs. This means that if you write this:-
[latex]
\Large\varepsilon=\sum_{i=1}^{n-1} \frac1{\Delta x}\int_{x_i}^{x_{i+1}}\left\{\frac1{\Delta x}\big[ (x_{i+1}-x)y_i^\ast+(x-x_i)y_{i+1}^\ast\big]-f(x)\right\}^2dx
[/latex]

then it will appear like this:-


\Large\varepsilon=\sum_{i=1}^{n-1}    \frac1{\Delta x}\int_{x_i}^{x_{i+1}}\left\{\frac1{\Delta x}\big[    (x_{i+1}-x)y_i^\ast+(x-x_i)y_{i+1}^\ast\big]-f(x)\right\}^2dx

Hope this is useful for some people. Comments as always very welcome. In fact in this particular case, we have to hold our hands up and say that we're not mathematicians; our solutions to Fermat's theorem don't fit in the margin, we don't know whether all perfect numbers are even, we don't have the faintest idea what the above equation means, if it means anything. All of which is to say that we'd welcome more expert opinion than ours on whether this service does what a mathematician might reasonably expect and/or find useful.

Update 14/11/05: Note that we've now changed from angle brackets to square brackets


- 27 comments by 4 or more people Not publicly viewable

[Skip to the latest comment]
  1. If you'd like to help me set up Latex on my pc, then feel free :D

    09 Nov 2005, 12:28

  2. I'd be interested in knowing the server load of the implementation because a forum I frequent is considering putting this in.

    09 Nov 2005, 12:39

  3. Not a clue yet I'm afraid. But I would have thought it is going to be pretty small considering the amount of use it will get and the size of server we have. However if there is a maths forums website with a weedy server where it'll be used loads…it might be a problem.

    09 Nov 2005, 13:53

  4. There's several variables you have to consider. I help to run a science forum for which I have coded a small LaTeX module to render these sorts of equations. My code is geared towards a higher quality output, so the DVI files generated by LaTeX are resampled, adding to the server load. You could grab a copy of LatexRender for PHP, which is what we used before, which doesn't do this – you don't get the same kind of quality, but it still looks good.

    In general, it hasn't slowed the forums down too much. The rendering itself is quite slow, but that's because we're hosted on a virtual server (VPS) as opposed to a proper dedicated server. The images generated are cached, so that they don't have to be re-generated every single time you load the page. But mainly it's just down to how much power you have behind the website.

    Another option is what you see on this page. It looks like you guys are using MimeTeX, which runs as a CGI on the server. The difference is that it renders the text itself as opposed to sending it off to LaTeX and dvips, hence making it quite a bit faster. It also doesn't store the images on the server. There are three downsides for myself; the code you input isn't proper LaTeX, you can't use external packages (for instance, using mhchem to typeset chemical equations) and the image quality isn't particularly brilliant.

    Reading back through this seems like I'm criticising everything you've done here, but that's really not the case :-) I think having the ability to render equations on here is a great idea – especially for the mathematicians/physicists/etc amongst us. My only comment is that I would personally use something like LatexRender. It might be slower, but it means you can use proper LaTeX, and with all the academics here that are already familiar with this syntax, it might just make life a little easier.

    Anyway, I'll stop rambling now ;-) This'll make a great addition to the blogs.

    09 Nov 2005, 14:28

  5. Whilst I doubt many people will use it (hardly a shocking suggestion), I'm sure those that do will find it fun or useful. Maybe even both. Everyone loves equations, right?

    09 Nov 2005, 15:10

  6. Thanks guys!

    09 Nov 2005, 19:44

  7. John Dale

    David, thanks for your thoughtful response. You're quite right that there are better looking and more functionally rich implementations than the one we chose, but we were thinking about cost-benefit when we made our selection. MimeTeX is so simple to get working, with no dependencies at all, that it took only a couple of days to get it added to blogs. So even if only a dozen people have a use for it, it's still a reasonable investment. If it later turns out that there are hundreds of people who want better-looking equations or richer markup, we can invest more time in a more sophisticated system. But if there aren't, we haven't lost a lot of time on something that's not in fact that valuable.

    One thing I don't quite understand, though; you say "the code you input isn't proper LaTeX", but I'm not sure why that is; it's a sub-set of LaTeX, sure, but in what way is it not proper?

    09 Nov 2005, 21:51

  8. John, I think David is right, in that there does seem to be a cosmetic difference between the version you are using and a standard LaTeX distribution. For example, when I typeset your formula I get this. Note the differences in the position of the integral limits, the italicness of the capital delta and the size of the curly brackets. I think there is a slight difference in the spacing around binary operations as well. But, of course, none of this is important. Thanks for getting it working.

    10 Nov 2005, 11:48

  9. John Dale

    Oh, absolutely, I get that there's a difference in the quality and to some extent the positioning of various elements in the resulting image. But what I understood David to be suggesting is that in some sense what you write between the latex tags in Blogs is not the same as standard LaTeX, that it's somehow a different syntax:-

    it means you can use proper LaTeX, and with all the academics here that are already familiar with this syntax, it might just make life a little easier.

    What I'm keen to understand is the ways in which the MimeTeX syntax diverges from proper LaTeX syntax.

    10 Nov 2005, 12:04

  10. Chris May

    To hark back to the question about performance, if it turned out that generating the images was slow, there's nothing at all stopping you from puttiing a squid cache (or even apache with mod_proxy cacheing) between the mimetex cgi and the requests (on the assumption that most images will get more than one view). You could even pre-render them in the background to feed the cache.

    10 Nov 2005, 12:59

  11. Sorry, I don't think I typed what I actually meant :-) What I had meant to say is that (in my experience) you have to fiddle about with mimeTeX quite a bit in terms of things like font size to get the output that you want. I'm somewhat of a perfectionist when it comes to this (mainly because I like it to look pretty), so I guess it's another personal preference.

    Of course it's very reasonable that you shouldn't implement a complicated system that may take quite some time to perfect, and have nobody use it. Just thought I'd contribute my 2 cents to the comments. As I said before, I think it'll make a great addition to the blogs, and my thanks for it.

    10 Nov 2005, 21:37

  12. Nathan Sircombe

    \left( \frac{\partial2}{\partial t2} - c_S2 \nabla2 \right) \delta n = \frac{\epsilon_0}{4m_i}\nabla2 |\bar{\mathbf{E}}2|

    11 Nov 2005, 14:42

  13. Nathan Sircombe

    hummmm. That didn't even nearly work. What am I doing wrong here? i put teh tag before and after.

    …its a fantastic idea though!

    11 Nov 2005, 14:44

  14. I am having some problems with LaTeX rendering.

    1. the latex tag often seems to prompt an unwanted new line

    2. It doesn't seem to handle brackets well (see link)

    11 Nov 2005, 14:58

  15. John Dale

    Couple of things: Nathan, I think we may have forgotten to make the equation markup work correctly in comments. I think it currently works in entries but not comments. We'll look into getting that fixed.

    Trevor, for the benefit of people for whom maths is just like greek, could you explain in words what the problem with handling brackets is?

    Finally, we may change from using angle brackets to using square brackets like this – [latex] – in a future release. With hindsight, angle brackets are a little bit more fiddly for us to manage.

    11 Nov 2005, 16:59

  16. Nathan Sircombe

    will this latex thing work in sitebuilder pages?
    If not, are there any plans to add this functionality to sitebuilder?
    That would be very, very useful.

    14 Nov 2005, 13:24

  17. John Dale

    We do indeed plan to add LaTeX support to SiteBuilder. It'll arrive, most likely, as part of support for Textile more generally in SiteBuilder pages.

    In other news, we've fixed a couple of minor bugs; LaTeX should now work in comments, and we've changed it to use square brackets like these [ latex ] instead of angle brackets.

    14 Nov 2005, 17:15

  18. Nathan Sircombe

    
\epsilon(\omega,k) = 1 - \frac{1}{2k^2\lambda_d^2}\int_{-\infty}^{\infty}\frac{\partial_v f(v)}{v-\omega/(k v_T)}dv

    14 Nov 2005, 22:57

  19. Nathan Sircombe

    excellent, I like it. I look forward to its appearance in SiteBuilder!

    14 Nov 2005, 22:58

  20. John Dale

    In fact it can be made to work right now, with a bit of fiddling. Here's an example. Basically, create a blog entry with the equation you want, publish it, copy and paste the source code for the equation into SiteBuilder's HTML view and your equation will appear there.

    15 Nov 2005, 09:45

  21. There is a problem with how the LaTeX images are displayed in RSS feeds, or at least how they are displayed in my RSS reader (Safari 2.0.2).

    I think this might be because you don't use the full address of the cgi file in the html source. Safari is looking for something at the address:

    feed://blogs.warwick.ac.uk/cgi-bin/mimetex.cgi?...
    rather than
    http://blogs.warwick.ac.uk/cgi-bin/mimetex.cgi?...
    But you'll know more about this than me.

    16 Nov 2005, 10:06

  22. A comment and a question

    1. Have a look at the follow-up link which shows some strange behaviour with the LaTeX rendering engine (or is it my browser?). BTW and totally tangential, I noticed in passing that when you edit the title of a blog, the change does not show up in the URL, which I found a bit confusing.

    2. How can I display the code in a box (as above) so that it doesn't get rendered?

    16 Nov 2005, 12:24

  23. Matthew: We were only using a relative path to the mimetex.cgi, it is now an absolute reference and should be working as expected.

    16 Nov 2005, 14:24

  24. Trevor:
    1) See my comment on your entry…and the url doesn't change because it would break links if changing the title changed the url once it was created.

    2) Use the three backslashes escaping to get it work not render the markup. See the Textile FAQ

    16 Nov 2005, 14:30

  25. Kieron: the behaviour is now very odd indeed. Whilst Safari is clearly finding the cgi file, it seems to be compiling the code as if every "\" has been replaced by a "/". Screenshot here. Any ideas why?

    16 Nov 2005, 15:28

  26. The problem (see comment 22) I was having (which no-one could see) was browser based. I have now edited my blog (link) with a screegrab that shows the problem

    16 Nov 2005, 16:25

  27. In fact it can be made to work right now, with a bit of fiddling. Here's an example. Basically, create a blog entry with the equation you want, publish it, copy and paste the source code for the equation into SiteBuilder's HTML view and your equation will appear there.

    Hey! I've seen that somewhere before ;)

    17 Nov 2005, 20:39


Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.

Search this blog

Tags

Most recent comments

  • Hi, Do you have a list of keyboard shortcuts? I can see Ctrl+b for Bold and Ctrl+i for italics works… by Mike Downes on this entry
  • I don't know what I have done and I have 2 blogs… definitely practise by on this entry
  • I am aiming to achieve better organisation and planning skills and focus on how to deal with disrupt… by on this entry
  • N.B. we responded directly to Sian when this query was asked via another channel. For reference, Fee… by Simon Harper on this entry
  • I was pleased to see this change: "We've modified the Atom API to allow setting of arbitrary permiss… by Sian Prosser on this entry
Not signed in
Sign in

Powered by BlogBuilder
© MMXXIV