Skip to content
Julien Delplanque edited this page Oct 18, 2015 · 6 revisions

Welcome to the Mathex wiki!

You will find here some documentation on the use of the Mathex package(s).

Introduction

Mathex is useful to write LaTeX mathematical formulas easily and in a more readable language (Smalltalk).

Mathex is built on top of Pharo which is a Smalltalk implementation. If you don't know Pharo or Smalltalk, please have a look at Pharo's books to understand the syntax.

Basic uses

Mathex defines some objects to represent Smalltalk basic objects as LaTeX code. You can find those in Mathex package in MathexObjects tag.

This allows you to convert numbers, character and strings as Mathex objects using #asMathex message on them:

1 asMathex.
(1/2) asMathex.
0.5 asMathex.
$c asMathex.
'hello' asMathex.

Once you have a Mathex object, you can send messages to him to create a formula. For example:

(1 asMathex + 2 asMathex) equals: 3 asMathex.
(($a power: 2) + ($b power: 2)) equals: (c power: 2).

As you can see, for the second line I didn't converted the Integer into a Mathex object. This expression works only because you didn't sent mathex messages directly to these integers. If you create a formula which looks like this:

$a power: (2 times: $x).

You will get an exception because you sent #times: message to an Integer and it does not understand it. The right way to write this formula is:

$a power: (2 asMathex times: $x).

You can get a list of available messages sendable to Mathex object by evaluating:

Mathex allUsableSubclasses collect: #selector

Which will returns a collection containing symbols representing selectors you can use as message on a Mathex object.

Advanced uses

Mathex allows you to add custom commands by creating a new class (see this page) or by using blocks if your new command is a composition of already existing Mathex objects.

For example, if you want to create a message that, for a receiver x, generate the LaTeX code:

x^{\lambda^{\gamma}}

You would execute the following code that will register your new command action and its selector:

Mathex
	register: [ :x | (x power: (#alpha asMathex power: #gamma asMathex)) ]
	asCommandNamed: #powerLambdaGamma.

And now you can use #powerLambdaGamma on any Mathex object:

$x asMathex powerLambdaGamma.
1 asMathex powerLambdaGamma.
($x asMathex + $y asMathex) powerLambdaGamma.

It is possible to list registered commands using:

Mathex registeredCommands.

And to unregister a command or all commands using:

Mathex unregisterCommandNamed: #powerLambdaGamma.
Mathex unregisterAllCommands.

Clone this wiki locally