-
Notifications
You must be signed in to change notification settings - Fork 0
Home
You will find here some documentation on the use of the Mathex package(s).
Mathex is useful to write LaTeX mathematical formula easily and in a more readable language (Smalltalk).
Mathex is built on top of Pharo wich is a Smalltalk implementation. If you don't know Pharo or Smalltalk, please have a look at Pharo's books to understand the syntax.
Mathex defines some objects to represents 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 got a Mathex object, you can call messages on him to create a formula. For example:
(1 asMathex + 2 asMathex) equal: 3 asMathex.
(($a power: 2) + ($b power: 2)) equal: (c power: 2).
As you can see, for the second line I didn't convert integer into Mathex object. This expression works only because you didn't call mathex messages directly on these integers. If you create a formula that looks like this:
$a power: (2 times: $x).
You will get an exception because you called #times message on an integer and it does not understand this message. The right way to write this formula is:
$a power: (2 asMathex times: $x).
You can get a list of available message to send to Mathex object by evaluating:
Mathex allUsableSubclasses collect: #selector
Which will return a collection containing symbols of the selectors you can use as message on a Mathex object.
Mathex allow you to add custom command 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 power: Gamma)) ]
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.