README

Path: README
Last Update: Thu Sep 15 17:29:12 EDT 2005
Author:William Morgan (mailto: wmorgan-ritex@masanjin.net)
Copyright:Copyright 2005 William Morgan
License:GNU GPL version 2

Introduction

Ritex converts expressions from WebTeX into MathML. WebTeX is an adaptation of TeX math syntax for web display.

Ritex makes inserting math into HTML pages easy. It supports most TeX math syntax as well as macros.

For example, Ritex turns

  \alpha^\beta

into

  <math xmlns="http://www.w3.org/1998/Math/MathML">
    <msup>
      <mi>&alpha;</mi>
      <mi>&beta;</mi>
    </msup>
  </math>

Ritex is based heavily on itex2mml (pear.math.pitt.edu/mathzilla/itex2mmlItex.html), a popular TeX math to MathML convertor—so much so that the default correct answer to unit tests is to do whatever itex2mml does!

Ritex features several advantages over itex2mml:

  • It’s written in Ruby (hey, I consider that an advantage).
  • It supports macros.
  • It handles unary minus better.
  • It’s easier to extend.

Where to get Ritex

Use RubyGems. gem install ritex

For CVS access, see the Rubyforge page: rubyforge.org/projects/ritex.

Synopsis

  require 'rubygems'
  require 'ritex'
  p = Ritex::Parser.new
  ARGF.each { |l| puts p.parse(l) }

  ## or ...

  ARGF.each do |l|
    begin
      puts p.parse(l)
    rescue Racc::ParseError
      $stderr.puts "invalid input"
    end
  end

Using Ritex

Calling Ritex from Ruby is very simple. If the synopsis above isn’t enough, see the documentation for Ritex::Parser for the gory details.

Creating MathML with Ritex

Ritex parses WebTeX. WebTeX is an adapation of the TeX math syntax which is designed for web page display. The WebTeX documentation can be found at stuff.mit.edu/afs/athena/software/webeq/currenthome/docs/webtex/toc.html.

If you’re familiar with TeX math syntax, you’ll feel right at home. But there are several important differences between it and WebTeX. Most notably:

  • arrays: different \array syntax; no \eqnarray or \align
  • macro definitions: \define; no \newcommand or \def
  • \left and \right no longer need "invisible" delimiters

These differences are explained in the WebTeX documentation.

Ritex is based heavily on Itex2mml. Itex2mml accepts what it calls "Itex", an extension of WebTeX which adds a few aliases (like \infinity for \infty) and markups (like \underoverset). Ritex supports these extensions. Regardless, I’ve chosen to say that Ritex parses WebTeX rather than Itex, mainly because the former includes macros and is better documented.

Itex is described at pear.math.pitt.edu/mathzilla/itex2mmlItex.html.

See the ReleaseNotes for features in WebTeX that are currently unimplemented in Ritex.

Differences between Ritex and itex2mml

If you’re familiar with itex2mml, there are a few subtle differences between the two:

  • A sequence of letters like "abc" is treated as three separate variables and not as one variable. I believe that’s the TeX Way (tm).
  • \ (backslash space) is a medium space, not an undefined character.
  • Sequences like "x—3" will correctly mark the second operator as a unary minus.
  • And of course, macros.

[Validate]