-
Notifications
You must be signed in to change notification settings - Fork 0
Add a LaTeX command
This page explains you how to extend Mathex with more LaTeX command
Mathex let you extends it by creating subclasses inheriting from one of these classes:
- MObject
- MCommand
- MEnvironment
- MBinaryOperator
- MBinaryOperatorCommand
- MSpecialBinaryOperator
- MDelimiters
according to your needs, you will have to choose the right object from which will inherit your object.
This is the most abstract object of the package. Inheriting from this object implies that your new class will implements #mathexOn: message, class-side messages: #allUsableSubclasses, #isUsable , #selector and will be able to receive messages representing already defined mathex objects.
#mathexOn: message defines how your object has to be printed on the stream given in parameter. If you look at MConcatenate>>#mathexOn: implementation, you will see this:
mathexOn: aPRStream
| canvas |
canvas := PRLaTeXCanvas on: aPRStream.
self parameters doWithIndex: [ :param :i |
param mathexOn: aPRStream.
(i ~= self parameters size) ifTrue: [ canvas raw: ' '; flush ] ]
So, basically, MConcatenate just prints objects you gave him by calling its #parameter: message with whitespaces between them. It is your job to define how you want your object to look in LaTeX!
Because your object inherits from MObject, you can send him messages that represents others mathex objects (these messages are not hard-coded, MObject>>#doesNotUnderstand: permit to do a look-up for the message you try to send in usable subclasses).
For example, if your myObject variable contains one of your object,
myObject concatenate: ' something'.
will concatenate myObject LaTeX representation with LaTeX representation of ' something' string.
If you want your object to be used when MObject>>#doesNotUnderstand: look for a message that represent your object, you need to implements the following methods:
isUsable
^true
allUsableSubclasses
self shouldNotImplement
And #selector message that returns a symbol representing the selector of the message called to invoke your object. For example, MConcatenate class>>#selector returns #concatenate: .
If you subclass MCommand, it means you want you new object to looks like
\acommandname[optParam]{param}{param}
in LaTeX.
MCommand is easier to subclass than MObject, all you need to do is to implements the following class-side messages:
- #commandName that returns a string representing the LaTeX command name without the '', for example MFrac that represent \frac returns 'frac'.
- #isUsable that must return true if your class is not abstract.
- #optParameterCount that is the number of optional parameters, in LaTeX those are the parameters between '[]'. For example, MFrac returns 0.
- #parameterCount that is the number of parameters, in LaTeX those are the parameters between '{}'. For example, MFrac returns 2.
- #selector that returns a symbol representing the selector of the message called to invoke your object. For example, MFrac returns #frac:.
This class represents LaTeX environment like math environment for example. To subclass this, you need to implement the following class-side messages:
- #environmentName that returns a string representing the name of the environment.
- #isUsable that must return true if your class is not abstract.
- #selector that returns a symbol representing the selector of the message called to invoke your object.
This class represents LaTeX commands that needs their parameters to be on the right and on the left of the operator. Have a look to MMinus for example. You only have to implement 2 class-side messages:
- #isUsable that must return true if your class is not abstract.
- #operator that is the operator to use. For example, MMinus>>#operator returns '-'.
This class do the same thing as MBinaryOperator and is to subclass the same way except that #operator message must returns a latex command that will start by a ''. For example, it could returns 'cup' to represents the \cup LaTeX command.
This class represents "special" operators like '_' (see MIndex) or '^' (see MPower) in LaTeX, if you want to subclass this, you need to implement class-side messages:
- #isUsable that must return true if your class is not abstract.
- #operator that is the operator to use. For example, MIndex>#operator returns '_'.
- #selector that returns a symbol representing the selector of the message called to invoke your object.
This class represents delimiters like parentheses, brackets, etc... To subclass this, you need to implement the following class-side message:
- #isUsable that must return true if your class is not abstract.
- #selector that returns a symbol representing the selector of the message called to invoke your object.
- #leftDelimiter that returns a string representing the left delimiter. For example, MPipes returns '|'.
- #rightDelimiter that is the same than #leftDelimiter but for the right delimiter.