Showing posts with label blogging. Show all posts
Showing posts with label blogging. Show all posts

November 25, 2011

Just Testing Mathematics Setting with MathJax


I decided it would be a good idea to test out the instructions from my last post, where I explain how to put mathematics in your blog. This is fast becoming addictive, so I am going to have to sit on my hands for a while after this post.

A Cross Product Formula

\[\mathbf{V}_1 \times \mathbf{V}_2 =  \begin{vmatrix}
\mathbf{i} & \mathbf{j} & \mathbf{k} \\
\frac{\partial X}{\partial u} &  \frac{\partial Y}{\partial u} & 0 \\
\frac{\partial X}{\partial v} &  \frac{\partial Y}{\partial v} & 0
\end{vmatrix}  \]
That seemed to work, but I did notice a couple of glitches. So here are a few hints.
  1. After you paste in the HTML, consider typing a couple of characters ("xx" or similar) as a placemarker so that you can be sure where your blog text is being inserted in relation to the script calls (the scripts should be right at the start). It's usually a good idea to lay down a marker like this when switching between “compose” and “HTML” editing modes.
  2. If you want to put a formula in-line just write it with a dollar sign before and after. So
    and therefore $x^2$ cannot be zero
    will come out as:
    and therefore $x^2$ cannot be zero
  3. When TeX inputs are copied from the web, to avoid formatting confusion it is often better to either paste into the HTML edit mode, or paste into a text window and re-copy to lose the formatting before pasting into the compose edit mode.
  4. If at first you don't succeed, look for help among the TeX community. It is large, and many of its members are professional educators.
Just to test the application a little more throughly here are a few random examples lifted from the web. Did I mention I love the web?

Simple equations
\begin{equation}\label{eq1}
\sum_{i=0}^{i=10} \phi_i(3)
\end{equation}

\begin{equation}\label{eq2}
\int_{0}^{10} \phi_i(x)dx = 3
\end{equation}

\[
z \left( 1 \ +\ \sqrt{\omega_{i+1} + \zeta -\frac{x+1}{\Theta +1} y + 1}
\ \right)
\ \ \ =\ \ \ 1
\]

Multi-line equation

\[
\begin{align}
(a+b)^3 &= (a+b)^2(a+b)\\
&=(a^2+2ab+b^2)(a+b)\\
&=(a^3+2a^2b+ab^2) + (a^2b+2ab^2+b^3)\\
&=a^3+3a^2b+3ab^2+b^3
\end{align}
\]

The derivative is defined as

\begin{equation}
\frac{dy}{dx} = \lim_{\Delta x \to 0} \frac{\Delta y}
{\Delta x}
\end{equation}
\begin{equation}
f(x) \to y \quad \mbox{as} \quad x \to
x_{0}
\end{equation}
\begin{equation}
f(x) \mathop {\longrightarrow}
\limits_{x \to x_0} y
\end{equation}

Math with font-size set to 250%
\[
g\frac{d^2u}{dx^2} + L\sin u = 0
\]

While my testing can hardly be called exhaustive, I think I have provided as good a start as anyone could expect in the world of mathematical blogging. Good luck with yours!

Blogging Mathematics

I just wanted to see if I could get some simple mathematics into this blog. Not so much for my own needs, but because my brother (who is a far better mathematician than I am, but rather less adventurous when it comes to using computers) has been wanting to do so for a while, but hasn't been able to find a suitable system.

If you want to write about mathematics you need some way to describe the formulae, as the “mathematical keyboard” does not yet appear to have been invented. The most commonly-used mathematical typesetting system is probably Donald Knuth's TEX, which provides a very versatile language for describing mathematical expressions in relatively plain text. I started my search on the assumption that there has to be some way of integrating TEX with the popular Blogger platform that I and many others use. There are other languages for describing mathematics, including a markup (HTML-like) language called MathML, and this solution can be adapted (by reading applications documentation) to handle some others.

Ideally the author should just be able to type TEX-style input and have wonderful formulae appear automatically. In other words when you want to talk about the probability of getting \(k\) heads when flipping \(n\) coins you should be able to write

\[P(E) = {n \choose k} p^k (1-p)^{n-k}\]

and have it appear as

\[P(E) = {n \choose k} p^k (1-p)^{n-k}\]

(EDIT: Formula corrected Nov 25, 2011)
Note that the \(k\) and \(n\) in the paragraph above the formula, as well as those in this one, are properly represented in mathematical notation, and therefore identifiable as mathematical symbols, because they are so flagged in the body of the text—you can write simple or complex formulae inline as well as in separate expressions like the one above. I achieved this result using the MathJax system, which uses Javascript to render complex mathematics in the browser. The really nice part is that there's nothing to install, because MathJax is downloaded by the reader's browser. I'd welcome similar instructions for other blogging platforms in the comments if readers want to help users of those other platforms.

I realize that these instructions are detailed and therefore somewhat tedious, but I wanted them to be as useful and as simple as possible. Unfortunately the authors of MathJax make a very common mistake of software authors - they assume that their readers know enough to already understand how MathJax is used on the web. The people who really need to know this stuff are working mathematicians, scientists and engineers. While they are often as smart as all get-up they mostly don't have the time to develop great insight into web technologies, and I am hoping this proves they don't need to.

As usual, however, the assumption is that users will be happy to pick up whatever skills they need to get the job done. The MathJax site has examples in it, but nothing that really shows you exactly how to get that mathematics into your pages. I hope to provide those missing steps here. Please note, however, that I know very little about TEX, and cannot help you to find representations for specific formulae. As a working computer scientist I often have to learn enough about a “foreign” system to be able to demonstrate a concept. This blog post is intended to provide no more than a simple proof-of-concept, and I will not be responsible for any limitations of or problems with MathJax, Blogger or these instructions.

The first thing to do is to make sure your post includes a couple of pieces of information. You have to insert configuration data for MathJax (there are various options you can explore once you understand its principles). You must also include a request to load the actual code of MathJax, which is conveniently stored at multiple locations on the internet under a single name—a “content delivery network” determines your closest location and sends the code from there.

There are two different ways to inject this code. The simpler way, which I have used for this post and describe here, inserts these instructions in each individual post. If you want mathematics in every post then you should consider moving the configuration data and code request into your blog template, so you do not need to repeat the insertion for each post. This more advanced method is beyond the scope of this article, but I mention it for those bloggers who know enough to be able to use it.

So, create a new post for your blog, and then switch to the HTML input mode. Copy the text from the area immediately below and paste it in at the start of your HTML input window:



(You might want to follow the final ">" with an x that you use to set the cursor after the code, which should begin the post). Then go back into standard compose mode and, as an example, enter the following text:


A Cross Product Formula

\[\mathbf{V}_1 \times \mathbf{V}_2 =  \begin{vmatrix}
\mathbf{i} & \mathbf{j} & \mathbf{k} \\
\frac{\partial X}{\partial u} &  \frac{\partial Y}{\partial u} & 0 \\
\frac{\partial X}{\partial v} &  \frac{\partial Y}{\partial v} & 0
\end{vmatrix}  \]



Hopefully, if all has gone well, you can now see this when you preview your blog page:

A Cross Product Formula

\[\mathbf{V}_1 \times \mathbf{V}_2 =  \begin{vmatrix}
\mathbf{i} & \mathbf{j} & \mathbf{k} \\
\frac{\partial X}{\partial u} &  \frac{\partial Y}{\partial u} & 0 \\
\frac{\partial X}{\partial v} &  \frac{\partial Y}{\partial v} & 0
\end{vmatrix}  \]

As I believe I mentioned, this is largely a proof-of-concept post. I can't imagine why the MathJax guys haven't published this already. It's possible they already have an application note about about this, but if not then they are free to link to this article to help their users (hello, MathJax users).

So there you have it. This could make it much easier to talk about mathematics on the web. Please let me know if anything isn't clear, and I will try to correct it until it is. Otherwise, just have fun blogging mathematics!

February 12, 2009

Seven Year Itch?

Today is the seventh anniversary of this blog. I don't know how many people were blogging back then, but there sure are a hell of a lot more now!

April 7, 2008

Just Because I Can?

Seth Godin as usual makes some interesting points in a blog entry today, including two very salient ones for me:

a) blogging doesn't have to be perfect, so blog and move on rather than waiting for the perfect way to express a transient thought;
b) you don't express any ideas at all by not writing, so writing a little and often may well be more useful than producing large well-crafted essays every six months.

The first is a message that has started to get through to me anyway as a result of my work at Python Magazine; the second is a variation on the theme that nobody knows what history will make of them, so there's little point trying for a particular effect.

Thanks for getting me started again Seth!

September 18, 2007

Blogger Behind the Curve?

I am sure I wasn't the only one who greeted Blogger's acquisition by Google with enthusiasm. At last, I thought, I will be free of the editor applet, which has become rather tedious to use.

Alas not, though. While much has changed, and the AJAX-based layout editor is a great improvement, we are still left with a content editor that creates horrible HTML and whose toggle buttons easily lose synchronization with the editor's state.

A recent post by Paddy also highlights the fact that there is inadequate support for posting code. I realise this probably isn't a majority interest, but in this day and age you would think the the world's leading web company could do better.

February 11, 2007

Five Years as a Blogger Tomorrow

I just read via Unofficial Planet Python fuzzyman wishing his Voidsapce blog a happy fourth birthday - congratulations, fuzz. This caused me to dig back into my own archives and realise that "... for Some Value of Magic" will be five years old tomorrow. So if four years is "practically ancient" I suppose this blog must go back into pre-history.

Why couldn't this wait until tomorrow? Because that'll be my last full day in the UK for some time - we are moving back to Virginia and I very much doubt I'll have the time to be writing blog entries as we have to get the cats to the airport and various other mundane but necessary tasks. I'm not looking forward to the joys of a 5:50 am flight out on Tuesday, but can't help being excited at the prospect of this return.

February 4, 2007

The Purpose of Advertising

A recent Seth Godin post about changes in the way advertising has been changing over the last quarter-century ends with an interesting quote:
"The winners, I think, are the agencies and the pundits and those that would like advertising to be more than it actually is."
He makes the point that advertisers are more interested in creating a short little movie that spreads - which if you think about it is exactly what everyone on YouTube is trying to create.

Bloggers are trying to create compelling writing that holds the interest of a (probably quite select) group of readers. Is this the same thing? Not really, in my view. Most bloggers aren't doing it for the money, but to promote their opinions and share their knowledge, but there's still the desire to promote a particular point of view - even if successful promotion doesn't result in the reader buying something.

While there's always a chance that a successful blog will attract enough readership to make advertising a money-earning proposition most blogs aren't going to be popular enough to attract advertisers. Yet still their dedicated authors keep pushing out the material. Just like I do, I suppose.

For some reason a number of posts were stuck in the blog as drafts. This one is from February 2007.