Javascript and skeletons Monday, Feb 9 2009 

Here’s an analogy (and I don’t know how useful it is). It’s about writing JavaScript for web pages.

A beetle, for example, has a hard external skeleton, to which everything else is attached. A cat, for example, has a hard internal skeleton, to which everything else is attached. A cat is soft outside (although with teeth and claws) while a beetle is soft inside.

So what’s this got to do with JavaScript and HTML? Well, a simple HTML page spruced up with some JavaScript for say form entry is a bit like a beetle, where the HTML is the hard external skeleton.

But a complex web page, constructed mostly from JavaScript and Ajax supplied data is something else. It’s too big and complex to be supported just by HTML and the DOM. It needs some sort of skeleton. And so perhaps should be built more like a cat.
(more…)

TUG board election Saturday, Jan 31 2009 

I’m standing for the board of the TeX Users Group. You’re invited to make comments on my election statement below.

I work for the Open University (the UK’s leading provider of distance education) as a TeX expert for print media. I’m also halfway
through a two-year project on putting mathematics on web pages.

In 2006–7 I set up MathTran, which now provides typesetting of
TeX-notation formulas to images as a public web service, serving
about a million images a month.

MathTran shows the value of TeX as a web service, which I’d like to
extend to whole documents. Installing and configuring TeX can be
slow and difficult. Using TeX through a web browser will help
beginners.

Part of my math-on-web project is a page where students can
interactively create a TeX-notation formula, say for putting on a web
page or in a word-processor document.

I have a doctorate in Mathematics and although not my career I still
have research interests. I have been using TeX for over 20 years,
and joined TUG in 1989. For the past two years I’ve been Chair of the
UK TeX Users Group, and have recently been re-elected for another
two years.

The past three years have seen UK TUG come out of a long period of
inactivity and decline. The credit for this of course belongs to the
Committee and the members, and not simply myself. We’ve organised
three successful meetings, adopted a new constitution, and set up a
website with links to UK TeX resources.

As a board member I would bring to TUG a focus on a key core
community, namely those who write material with lots of mathematics.
I have a particular interest in providing help and support,
particularly through web pages.

TUG, by virtue of TeX being a typesetting program, rightly has a
focus on print media. But to flourish we must also use new media
effectively. The Open University faces the same challenge, and my
experience there will help TUG.

TUG has a special responsibility, to publicise TeX and related
fonts, programs, documentation and other resources.

I’d like TUG to offer more to institutional members. In particular,
we should help them share user support experience and resources.
Supporting TeX can be daunting without outside help.

When I joined TUG there were over 150 institutional members. There are
now just 27. The loss I feel the most is the Library of Congress.

Implementing super in JavaScript Sunday, Sep 21 2008 

The problem

JavaScript has objects and what is called prototypal inheritance, but it does not have built-in support for many features provided by other languages. In particular, it does not have built-in support for classes and instances. Nor does it have built-in support for methods of one class to call super-class methods.

Here is an example. Class C is a subclass of class B, and both have an init method. We would like the init method of Class C to be able to call the init method of class B. In other words, when writing init for class C, we wish to call the super-class init method. Note that class B might in fact be a subclass of class A, and that B might inherit init from A, and not have an init method of its own.

This post of focussed in the single topic of providing access to super-class. It does not for instance cover how to provide support for class hierarchies and how to manage instance creation.

Motivation

Over the past few days I’ve been trying to understand John Resig’s post on Simple JavaScript Inheritance, on both the technical and the practical levels. John’s goal was to extract the soul of the implementations of classical inheritance in base2 and Prototype, and to present them as a stand-alone package.

Well, I’ve not succeeded, but I do understand the problem better. In particular, I couldn’t get a clear understanding of what his _super method did. So to help me understand I set out to write my own. And this is what I came up with.

I hope in a later post to compare the two approaches. Be warned that this post is unavoidable quite technical, and that if you’re a JavaScript novice you’ll learn a lot if you manage to understand it all.

(more…)

Data objects in JavaScript Saturday, Sep 20 2008 

The Problem

Suppose we want to count the words in a document, or the identifiers in a computer program. We’ll need to keep a dictionary (aka hash or mapping) whose keys are the words and whose values are their frequencies. When we come across a new word (or identifier) we add it to the dictionary as a key, with value equal to one. When we meet a word already in the dictionary, we increase the value by one.

The starting point, of course, is an empty dictionary (or mapping or hash or whatever you want to call it). In JavaScript creating one of these requires some thought, and seems not to have been done before. Here’s the problem. In JavaScript we have to store the data (key-value pairs) in an object, and every object comes with some builtin methods. Here’s some command-line JavaScript:

js> data = {};  // Create empty data object, we hope.
js> data.foo === undefined; // true
js> data['foo'] === undefined;  // true
js> data['constructor'] === undefined; // false - not what we want.

(more…)

Learning jQuery Sunday, Apr 27 2008 

Learning from mistakes

This post is about my experience of learning jQuery. I’m developing some JavaScript for use with MathTran, and from past experience I know that I need a library. Elsewhere I explain why I’ve chosen jQuery. On Friday I started learning jQuery, mostly from the two Packt books, and yesterday and today (Saturday and Sunday) I’ve started with some coding.

I’m fairly new to JavaScript programming, and it’s easy for me to trip up on some of the language features. For example, it’s my Python habit to write ’self’ when I really should be saying ‘this’. I addition, I’m not used to the widespread dynamic creation of functions, to be attached to DOM elements to handle events. So in addition to learning how to think jQuery, I’ve also been learning how to think JavaScript and DOM.

(more…)

Using MathTran in blogs and wikis Wednesday, Feb 27 2008 

This post is mainly for system administrators and developers who want to add mathematics capabilities to a blog or wiki that they host or develop. We hope that in a year or so some of the ideas we describe here will be available to ordinary users who have a blog, say on WordPress.

After an Introduction, we discuss Light-, Medium- and Heavy- weight installation of MathTran. Then we discuss how to print mathematics using MathTran. Finally, we revisit the examples in the introduction, and state conclusions.

(more…)

Microsoft loves Yahoo … Saturday, Feb 9 2008 

… but will they be happy together?

Microsoft loves Yahoo, but will they be happy together? To find out visit the LoveGraph page for this match.

LoveGraph uses a special algorithm to generate data about the potential of the match, which it then graphs. Do pay particular attention to the “Spheres of Interest Overlap” chart.

LoveGraph uses charts and graphs generated by Google Charts.

(more…)

Django and the MathTran website – AJAX and templates Saturday, Feb 2 2008 

Introduction

In my previous post I spoke about ReST. It’s not able to do what I want, which is a nuisance. But most of the post of about coding forms such as that on the MathTran home page using Django templates. In the course of the post I come to the conclusion that providing such forms is a matter just for the template, and has nothing much to do with the view! Finally, I make some remarks about AJAX, which is used (along with some rather improper dynamic HTML) in the present implementation.

(more…)

Django and the MathTran website – ReST Saturday, Jan 26 2008 

This weekend I’m doing some work on the MathTran website. The main goal is to move it to Django, and to clean up and improve the content while I’m at it. I’m not much of a web-wizard. I know about HTML and JavaScript of course, and to get dynamic baseline alignment of bitmap mathematics I even did a bit of Ajax programming. But I’ve not developed on a website that has a database backend yet, although that is one of my ambitions for the MathTran site.

(more…)

Google Charts, MathTran and editable PNG files Monday, Jan 14 2008 

This post is about putting charts and formulas in your web pages, creating editable and scalable PNG files, and the need for a standard for embedded application data in image files.

Earlier today I looked at Google Charts, which allows you to ‘dynamically generate charts’. Send a Google a suitable GET request and you will get a pie chart, a bar chart or whatever, as specified in your query string. Their example is

http://chart.apis.google.com/chart?cht=p3&chd=s:hW&chs=250x100&chl=Hello|World

which will produce the chart
Hello world pie chart

This is rather similar to MathTran, where are URL such as

http://www.mathtran.org/cgi-bin/mathtran?D=3;tex=1%20%2B%201%2F2%20%2B%201%2F4%20%2B%20%5Cldots%20%2B%201%2F2%5En

produces the image
1 + 1/2 + 1/4 + \ldots + 1/2^n

Google Charts allows you to dynamically create graphs, and MathTran allows you to dynamically create rendered mathematical formulas. The Google API is rather better than MathTran’s, and it is certainly better documents. But MathTran has something that Google Charts doesn’t have … yet. The PNG’s returned by MathTran can be edited.

(more…)

Next Page »