KaTeX is a new method for publishing LaTeX-based math on the Web. It's faster than MathJax, but not as robust (yet).

The post KaTeX – a new way to display math on the Web appeared first on squareCircleZ.

]]>It’s a direct competitor to MathJax, which I’ve been using on IntMath for some time now.

You can see immediately that KaTeX produces math much faster than MathJax. This is because KaTex "renders its math synchronously and doesn’t need to reflow the page", according to their short blurb on Github.

There is obviously much less time required for processing. KaTeX doesn’t suffer from the page reflow jumps that MathJax has after each equation is created. (To be fair, there are ways around those instabilities in MathJax.)

I wrote a page so you can see the same input as processed by both methods. See

There’s a rough "time to process page" at the top. It’s not a fair comparison in the sense that KaTeX doesn’t handle several of the equations (yet), and MathJax handles them all.

The difference is stark on a mobile phone – around 1 second for KaTeX and around 30 seconds for MathJax.

It claims to "supports all major browsers, including Chrome, Safari, Firefox, Opera, and IE 8 – IE 11". So does MathJax, and it also copes with the vagaries of earlier IE versions.

So far the only differences I’ve noted are some font weight issues. In Chrome, the rendering seems "thin" to me. Sometimes it’s too much so, and the "equal" signs almost look like minuses, and some minus signs almost disappear.

But that is not such an issue in Firefox or IE. Here are some screen shot comparisons.

Using KaTeX in Chrome, where "=" and “−” are thin :

Using MathJax in Chrome is bolder, and easier to read:

Here’s how KaTeX looks in Firefox (somewhere between the first 2, and most pleasing to me):

KaTeX in Internet Explorer looks almost identical to the above FF rendering, but has some alignment issues. (Note where the *u* and *v* are in relation to the fraciton line.

It’s no surprise that IE falls over here and there. It almost always does. Here are 2 instances that I’ve spotted so far:

The right hand side should have been: (*a*^{2} + *b*^{2} + *c*^{2})^{3}

This surd also has obvious problems in IE:

As mentioned earlier, KaTeX doesn’t do everything yet (it chokes on anything starting with \begin, \align or \choose, and many symbols don’t work yet.

You can see what currently works on the Demo page.

This list on the GitHub KaTeX wiki shows what functions are currently available.

The setup for KaTeX is similar to what you have to do with MathJax, but there is no CDN version of KaTeX yet.

First, download the KaTeX zip.

Extract the zip amd upload it all to your server. (This is much smaller than MathJax, as there is no image fallback with KaTeX, so there aren’t thousands of images to upload.)

Next, in the head of your page, point towards the KaTeX javascript and css, something like this:

<link rel="stylesheet" type="text/css" href="/path/to/katex/katex.min.css">

<script type="text/javascript" src="/path/to/katex/katex.min.js"></script>

If you have only a few equations on your page, you can proceed as follows:

<p><span id="mykatex1">...</span></p>

<script> katex.render("f(a,b,c) = (a^2+b^2+c^2)^3", mykatex1); </script>

This will place the equation into your Web page, as properly rendered math.

A second equation would need a new id on the span, and in the script, like this:

<p><span id="mykatex2">...</span></p>

<script> katex.render("f(a,b,c) = (a^2+b^2+c^2)^3", mykatex2); </script>

If you want to present a lot of LaTeX on your page, it would be better to proceed as follows.

You would use the same class name for the DIVs (or spans) containing math. Your HTML would look something like:

<div class="math"> f(x) = \sqrt{1+x} \quad (x \ge -1) </div>

<p>Some other text here. </p>

<div class="math"> f(x) = \sqrt{1+x}, \quad x \ge -1 </div>

Next, we use javascript to iterate over all the DIVs with class "math" (they can be <p>, <span> or <td> too, as long as the class is "math" and it contains LaTeX only.

I’m using jQuery to do this, but there are pure javascript methods as well.

The following code just means:

- Iterate over all the objects with class name "math"
- Get the text from the object (this is the LaTeX that we want to convert)
- Get the type of element. If it’s a DIV, then add "\displaystyle" so it will be presented as math centered on the page.
- Try to convert it to math using katex.render.
- If it fails, output an error message.

(function(){ $(".math").each(function() { var texTxt = $(this).text(); el = $(this).get(0); if(el.tagName == "DIV"){ addDisp = "\\displaystyle"; } else { addDisp = ""; } try { katex.render(addDisp+texTxt, el); } catch(err) { $(this).html("<span class='err'>"+err); } }); })();

There’s also an option to generate HTML on the server, so "you can pre-render expressions using Node.js and send them as plain HTML."

To do this you use "katex.renderToString".

This is where the math will appear:

<p><span class="katex">...</span></p>

This is the script you use:

var html = katex.renderToString("c = \\pm\\sqrt{a^2 + b^2}");

Apparently Khan Academy will be using both KaTeX (for speed) and MathJax (for more complicated equations) in the near term. Hopefully they will continue to develop KaTeX, but there’s a long way to go to catch up with MathJax’s flexibility.

MathJax has promised :significant speed improvements” in their next version.

Interesting times.

The developers answer some issues here, including “Why is it so fast?” (because it uses CSS for positioning and does a lot fewer things than MathJax), and some of their plans for future development (including matrices – yay!)

The post KaTeX – a new way to display math on the Web appeared first on squareCircleZ.

]]>The Carnival of Mathematics is a collection of recent math blog articles covering visual math, various rants and some math history, by various authors.

The post Carnival of Mathematics 114 appeared first on squareCircleZ.

]]>Helix Bridge and Flyer, Singapore

114 is a **sphenic **number (the product of 3 distinct prime numbers):

114 = 2 × 3 × 19

It’s also a **repdigit**: 114 = 222_{7} (the digits repeat in the base 7 representation)

It’s the 19th number in the **Padovan** sequence, given by the recurrence relation *P*(*n*) = *P*(*n* − 2) + *P*(*n* − 3), and where the first 3 terms are 1.

114 is an **abundant number **(where the sum of its proper divisors is greater than itself):

114 < 1 + 2 + 3 + 6 + 19 + 38 + 57

That’s appropriate, as we have abundant posts for this, the 114th Carnival of Mathematics!

On with the show.

Now here are some animations that could be the basis for some interesting class discussion. See |

Andrea Hawksley gives us a nice roundup of the recent meeting on Origami, Science Math and Educaion. She features some of her own work, as well as other gems that were presented. See: |

6th meeting on Origami, Science, Math, and Education (6OSME)

While you’re there, mouse over Andrea’s name in the header of her blog. It’s cute.

That’s logical, as it’s the name of his blog! See

See:

BBC Sport’s Anti-Smartness Bias

In a similar vein, Gilead of “Tycho’s Nose” rants about inaccuracies (or part-truths) in background equations as seen in the new Doctor Who series. See: |

Here’s a rant of a different nature. Stephen Cavadino of "cavmaths" questions whether stem-and-leaf plots are a necessary part of the math curriculum. See: |

Mark Dominus provides us with a neat exploration of numbers that are permutations of each other. His first example is the decimal expansion of |

See:

When do n and 2n have the same digits?

Richard Elwes introduces us to an interesting knotty problem. It turns out this generally accepted picture is wrong… See how at: |

Jeremy Kun of "Math ∩ Programming" explores optimal greedy algorithms and matroids.

See:

When Greedy Algorithms are Perfect: the Matroid

This post, right here on "squareCircleZ", was inspired by a reader’s question. He makes solar cookers for use in Africa and wanted to know how to construct the spiral length around his cookers. It’s some "real-world" math that involves sustainable, cheap energy.

See:

Arc length of a spiral around a paraboloid

0 |
In a lot to do about nothing, Evelyn Lamb of the Scientific American blog, recounts her journey of discovery with her students, which involved decipering Plimpton, the 4000 year-old Babylonian tablet. |

So how did the Babylonians work in base 60, without 0 as a place holder?

See:

See:

How The Ancient Egyptians (Should Have) Built The Pyramids

α β γ δ ε ζ |
Here’s a summary of the Greek alphabet by SixWingedSeraph of Gyre&Gimble. We should spend more time on this topic in class, so students are more comfortable with this foreign script. See |

This post is a plug for an experimental MOOC (Massive Open Online Course). The blurb says:

"Citizen Maths is an online resource anyone can use — to discover how maths can be a powerful tool for solving those problems that come up at work and in your life."

See:

So, what is mathematics? Shecky Riemann of "Math-Frolic" has a quote from *How Mathematicians Think*, by William Byers, which ponders that math is a series of situations where we are led to observe,

I hope you’ve enjoyed Mathematics Carnival #114, coming to you from Singapore.

The next carnival will be at MathTuition88, slated for October 2014. See where and how to submit.

*Singapore Helix and Flyer* by ensogo, accessed from http://www.ensogo.com.ph/escapes/singapore-flyer-cruise-09092012.html

*BBC Sport logo*, by BBC, accessed from http://www.bbc.com/sport/0/

*Stem & leaf plot* by ck-12.org, accessed from http://www.ck12.org/book/Basic-Probability-and-Statistics-A-Full-Course/r4/section/7.2/

*Reflection*, by Marcia Birken, accessed from http://alumnae.mtholyoke.edu/blog/light-motifs-marcia-birkens-images-meld-math-and-art/

All other images are from the posts to which they link. If you have any objections to their use in this manner, let me know and I’ll remove them.

The post Carnival of Mathematics 114 appeared first on squareCircleZ.

]]>IntMath will be hosting the next Carnival of Mathematics, a collection of recent blog posts about math.

The post Carnival of Maths is coming to IntMath appeared first on squareCircleZ.

]]>To submit an article, go to:

As it says on the submission form:

The Carnival of Mathematics accepts any mathematics-related blog posts: explanations of serious mathematics, puzzles, writing about mathematics education, mathematical anecdotes, refutations of bad mathematics, applications, reviews, etc. Sufficiently mathematized portions of other disciplines are also acceptable. We also accept YouTube videos, and non-blog based content, as long as it’s new and has been recently posted online.

The most recent carnival was hosted by Mike at Walking Randomly. It covered the full gamut from limits to Ninjas and 3D printed geometry to mathematically-related underwear. See

All the previous carnivals can be found on Aperiodical. See:

See you back here in mid-September for edition #114!

The post Carnival of Maths is coming to IntMath appeared first on squareCircleZ.

]]>The post Context Free math-based art appeared first on squareCircleZ.

]]>Context Free is software that you can use to generate fascinating art work. You give instructions using code called a "grammar". It’s quite a neat way to bring together math, art and programming, which are key STEM skills.

The Context Free Art site provides downloads of the (free) software (Mac, Windows and Linux), and also a gallery of around 1000 works of art generated using the program.

Everything is released using a Creative Commons non-commercial license, so you can use the images in your own work. You can modify other people’s code to create your own materpieces (but give credit to the original, of course).

Here are some of the output images from the gallery:

Drawing these images involves some interesting math topics, including:

- Trigonometry
- Logarithms
- Matrices
- Vectors
- Geometry
- Number theory
- Complex numbers

This one is called the Lorenz Attractor, by thijs:

To give you an idea what is involved, this is the code thijs wrote to produce the above shape:

startshape Lorenz_Attractor //1600*900 CF::Background = [b -0.9 sat 0.2] CF::Size=[s 60 33.75] CF::ColorDepth = 16 CF::MinimumSize= 0.3 CF::Impure = 1 A=10 B=8/3 C=28 d=0.002 vector3 D(vector3 V) =V[0]+d*( A*(V[1]-V[0]) ) ,V[1]+d*( V[0]*(C-V[2])-V[1] ) ,V[2]+d*( V[0]*V[1]-B*V[2] ) vector3 M(vector3 V1,vector3 V2) =(V1[0]+V2[0])/2 ,(V1[1]+V2[1])/2 ,(V1[2]+V2[2])/2 //------------------------------------ shape Lorenz_Attractor { V0=(-12.5, -17.4, 26) Next(0,V0)[r 100] } shape Next (i,vector3 Vi) { if (i<320000) { Vn=M(Vi,D(D(Vi))) Plot (i,Vi,Vn) [] Next (i+1 ,Vn) [] } } shape Plot(i,vector3 V0,vector3 V1) { P=V0[0,2] Q=V1[0,2] Z=V0[2] H=45+15*sin(i/3) Line(0.05,P,Q) [z Z b 1 h H sat .4] Line(0.15,P,Q) [z Z b -1 a -.950] Line(1.50,P,Q) [z Z b -1 a -.999] } path Line(S,vector2 P,vector2 Q) { MOVETO(P) LINETO(Q) STROKE(S,CF::RoundCap)[]

Here's a useful list of resources by Mikael Hvidtfeldt Christensen: Generative Art Links, containing links to some interesting software for creating several different types of math art, including 3D fractals, and there's also some interesting blogs.

The post Context Free math-based art appeared first on squareCircleZ.

]]>The updated applets on the Graphs of tan, cot, sec and csc page now run on mobile devices, albeit rather slowly. One of the most popular pages on IntMath.

The post Updated Graphs of tan, cot, sec and csc appeared first on squareCircleZ.

]]>To make the page more mobile-device friendly, I updated it so now the interactive graphs use JSXGraph, rather than Flash.

The page explains how to sketch these trigonometric curves, mostly by considering the denominator (the bottom) of the function expression.

Each of the curves tan *θ*, cot *θ*, sec *θ* and csc *θ* has a discontinuity, or "gap" in the curve. For example, tan *θ* is defined by:

Since cos *θ* has value 0 at *θ* = … −3π/2 −π/2, π/2, 3π/2, 5π/2,…, it means tan *θ* will not exist for those values of *θ*. The result is there will be "gaps" in the curve at those points.

Either side of those gaps, the curve heads off to plus or minus infinity. Here is the graph of *y = *tan *θ*:

The page has animations that demonstrate where the values of the curves come from.

Here’s a screen shot of one of the animations:

On a tablet, the animations may run a little slow. After all, we’re asking the processor to perform a lot of calculations! Alo, the screen gets re-drawn multiple times during the animation, which also slows things down.

As a result, you can only animate one of the graphs at a time.

The link again:

Graphs of tan, cot, sec and csc

The post Updated Graphs of tan, cot, sec and csc appeared first on squareCircleZ.

]]>Here's some background on the new Riemann Sums applet I added to IntMath. You can see how we find areas under curves using rectangles.

The post New Riemann Sums applet appeared first on squareCircleZ.

]]>I recently added a new Riemann Sums Applet to IntMath which demonstrates some of the ways it can be done, without calculus.

Here is some background to the concept.

For centuries, mathematicians tried to find efficient ways of calculating rates of change. They needed to solve a wide range of practical problems, including building faster ships, developing more accurate weapons and predicting the positions of the stars and planets for better navigation.

They were also interested in the reverse problem. That is, they may have known the rate of change, but they wanted to know the fundamental relationship between two changing quantities. For example, they may have known the velocity of an object at different times, and they wanted to know the position of the object in space during those times.

Since the age of the ancient Greeks, there were good approximation methods for such problems.

A Riemann Sum is an approximation of the area under a curve (that is, between a curve and an axis). It’s named after Bernhard Riemann, the German mathematician who worked on this problem in the mid-19th century.

The principle behind Riemann Sums is simple, and was known since the time of Archimedes. (See Archimedes and the area of a parabolic segment.)

We just divide the area into smaller pieces using simple geometric shapes for which we can easily find the area, like rectangles.

If we find the area of each rectangle, and add those areas, we’ll get a good approximation for the area under the curve. If we take more rectangles, the error will reduce, and we’ll get a better approximation.

We can place the rectangles in different ways (just above the curve, just below, or mid-way like in the above image).

I recently added a new applet that allows you to explore this concept. You can change the placement of the rectangles, and you can even see how trapezoids and parabolas are used as very good approximations.

You’ll find the new applet here: Riemann Sums Applet

The post New Riemann Sums applet appeared first on squareCircleZ.

]]>What is the length of a spiral around a paraboloid? This is an interesting application of integral calculus, involving an environmentally friendly cooker design.

The post Arc length of a spiral around a paraboloid appeared first on squareCircleZ.

]]>A reader from Africa, Magnar, recently asked about running a string in a spiral around a parabolic dish, as illustrated in the following image:

Magnar wanted to know how to calculate the length of such a spiral.

There’s an interesting story behind Magnar’s question. He builds parabolic dish cookers in Africa. In this photo, he’s helping to install one of his dishes in a village. The dish concentrates the heat of the sun and the cook pot is placed at the focus of the parabola.

Image source (used with permission)

This is a great use of sustainable energy, it keeps the air cleaner (by avoiding open fires inside huts), and saves women from the backbreaking and time-consuming task of gathering firewood every day.

Let’s look at some of the math behind this problem.

A paraboloid is the 3D surface resulting from the rotation of a parabola around an axis. The equation of a simple paraboloid is given by the folmula:

*z* = *x*^{2} + *y*^{2}

The surface generated by that equation looks like this, if we take values of both *x * and *y* from −5 to 5:

Some typical points on this curve are (0,0,0), (1,1,2), (-2,3,13) and (3,4,25). That last point is on the top lip of the surface in the 3-D graph given above, at the front, facing us. (In this graph, the *x*- and *y*-axes axes are equally scaled, but the *z*-axis is not.)

We can also represent this paraboloid using parametric equations with variables *t* and *r*, as follows:

*x = r *cos(*t*)

*y = r *sin(*t*)

*z* = *r*^{2}

We could write this as an ordered triple, like this:

(*r *cos(*t*), *r *sin(*t*), *r*^{2})

We only need to let *t* take values from 0 to 2π (otherwise we just "paint" the surface more than necessary) and *r* takes values from 0 to 5 if our aim is to create the same curved surface as shown in the above graph.

Let’s get back to the original problem. We want to create a spiral around the surface of the paraboloid. We modify the earlier parametric equations to get a curve rather than a surface, like this.

*x = t *cos(*t*)

*y = t *sin(*t*)

*z* = *t*^{2}

Once again, we could write this as an ordered triple, as follows:

(*t *cos(*t*), *t *sin(*t*), *t*^{2})

We no longer create a surface with this expression. Instead, it will be a curve.

As the variable *t* takes various values starting from *t* = 0, it generates a spiral around the 3-D surface.

Let’s see how, starting with a simple case.

Let’s consider the case where we fix the curve so it is in the *x-z* plane only (it’s not actually spiralling in this case, to make things simple.) We write this as:

(*t*, 0, *t*^{2})

The graph of this is part of a parabola, starting at (0,0,0) and extending to (20,0,400), as shown.

What is the length of this simple curve?

We use a result from calculus, which is based on the Pythagorean Theorem.

The arc (or curved) length is given by:

(See Arc Length of a Curve and Arc Length of a Curve in Parametric or Polar Coordinates for background on these formulas.)

In this example where *x* = *t* and *z* = *t*^{2},

and

Also, in this example we have the end point *t*_{1} = 20.

Substituting gives:

(I used a computer algebra system to find this integral.)

This seems quite a low firgure for the length, since the *z*-value at the end of the curve is 400, and going around the curve should add more than just over 1 unit to the length.

However, the above graph does not have equally-scaled axes, whereas the following one does.

We see that a parabola is "almost" straight, and a curve length of just over 400 for this curve is reasonable.

Let’s now see the effect of those trigonometric terms we saw before.

We now plot (*t *cos(*t*), *t *sin(*t*),* t*^{2}) for *t* = 0 to *t* = 20. (Of course, *t* is in radians.)

The start of the curve, when *t* = 0, is at the point (0,0,0). The point where the curve finishes, when *t* = 20, is:

(20 cos(20), 20 sin(20), 20^{2}) = (8.162, 18.259, 400).

For interest, looking from above (down along the *z*-axis), the above spiral looks like this:

The arms cut the *x*-axis evenly at 2π = 6.28, 4π = 12.57, and 6π = 18.85.

You can see the curve ends near (8, 18) as we claimed before.

We extend the 2-dimensional case above now that we are working in 3 dimensions. In general, the length of an arc when using the parametric terms ((*x*(*t*), *y*(*t*),* z*(*t*)) is given by:

Substituting in our expressions for * x*, *y* and *z*, we have:

Now to examine the solar cooker problem.

Considering one of Magnar’s cooker designs, the parabola has a cross-section which is quite flat compared to the paraboloid we drew above. (Like most parabolic dishes, they are using flat panels to approximate the curved surface.)

In fact, the top lip passes through the point (25,45) in that design. The general form of a parabola can be written:

*z = cx*^{2}

Substituting (25,45) gives us .

We now plot the curve

from *t* = 0 to *t* = 45.

The curve starts at (0,0,0) and the top point is (23.6, 38.3, 45). We see there are about 7 spirals.

Here it is from the side:

And next the view from the top shows we finish near *x* = 24 and *y* = 38:

We have around 7 turns in the above spiral, but we may need more or less. If we want to achieve more spirals within the same *x-, y-, *and *z-*constraints, we need to multiply the variable within the trigonometric terms by a number.

Here is the case when we multiply the variables in the trig terms by 5. That is:

We get around 35 spirals this time:

Here it is from the side.

The length of this spiral is:

Similarly, if we multiply those variables by a number less than 1, we get less spirals. Here is the case when we multiply by 0.3:

This time we have just over 2 spirals (which is similar to the situation we had in Magnar’s first diagram at the top) and our length is:

This has been an interesting application of math where 3-D geometry and integral calculus are being used to examine a good use of solar power. We need to make more use of the huge amount of energy available from the sun, and solar cook pots are a great way to do so.

The post Arc length of a spiral around a paraboloid appeared first on squareCircleZ.

]]>The post From brain injury to math genius: Jason Padgett appeared first on squareCircleZ.

]]>Jason Padgett was attacked by 2 men one night and savagely beaten. He ended up with severe concussion and an amazing new ability to "see the world through the lens of geometry".

He began to create intricate geometric art, like this image:

See the full story at Discovery.com: Brain Injury Turns Man Into Math Genius. Don’t miss the gallery of his art while you’re there.

Padgett’s story reminded me of the work of Alan Snyder, the Sydney-based researcher who is able to temporarily "turn on" savant-like mathematical abilities in test subjects. (See Switching on your inner Rainman: Enhancing Creativity).

Snyder uses magnetic pulses through the brain to release what he believes are math and creative abilities inherent in all of us.

Padgett wouldn’t change his new abilities if he could.

"It’s so good, I can’t even describe it," he said.

It’s fascinating that Padgett has discovered the joys of math patterns, but it’s very sad it took a violent event to bring it about.

The post From brain injury to math genius: Jason Padgett appeared first on squareCircleZ.

]]>Google tries hard to provide super-fast Web pages, and uses calculus in the process.

The post Google uses integration to speed up the Web appeared first on squareCircleZ.

]]>Google’s success as a company was built on **optimization**. They’ve put a lot of effort into making everything they do super fast.

Google wants all pages to be fast, so they provide a free Web page speed test facility, WebPageTest.org. You can test any page there and see why it is so slow (or fast). It’s great for those of us who are keen on speeding up our sites.

Of course, there are many things that will slow down a page, including slow Net connections, a slow server, size of the page (in kb), slow download speeds and slow browser processing speeds.

WebPageTest provides various test result measures, including connection time, download times and a metric called **Speed Index**.

Speed Index is an indication of how quickly the page elements appear on a page. In some cases, we see just a small part of the page and then see the browser "spinner" indicating more is to come (we are likely to leave in such cases). On other pages, we may see most of the page quickly, but the spinner indicates some more is coming.

Obviously the second cane is a better user experience, so it should get a better Speed Index score.

The Speed Index documentation explains how they calculate the score. It involves finding the **area under a curve**, which is a concept we learn when first meeting integral calculus.

They give a formula:

where

*T* is the "visually complete" time (total time to load and process the page); and

*VC*/100 is the "percent visually complete".

The areas are calculated at 0.1 s intervals (or similar) and added to produce the final index.

The area represented by the integral is the darker blue area in this chart, which represents a fast Web page (most of the content is visible quickly and the last 10% or so appears later).

[Image credit: WebPageTest]

So in fact, we are finding the **area between 2 curves,** the top one is the constant value 1 (or 100%), and the other is the VC curve.

Some closing ironies:

- The documentation page referred to above took around 27 seconds to "visually complete" status when I opened it today. They haven’t even optimized images on that page to reduce the download time.
- Google is not always quick. Gmail has many elements and takes a long time to load when first opened.

The post Google uses integration to speed up the Web appeared first on squareCircleZ.

]]>The post Friday math movie: 5 Quick Math Tricks for Filmmakers appeared first on squareCircleZ.

]]>Here are some math-related tips for better movies.

He discusses the f-stop scale, what an appropriate shutter angle is, the 180-degree Rule and Rule of Thirds, and how to read a histogram.

Actually, there are plenty of potential interesting math lessons arising from this. How about get students to make relevant videos about the math they are using, while making videos!

The post Friday math movie: 5 Quick Math Tricks for Filmmakers appeared first on squareCircleZ.

]]>