Creating an Exporter
How to create your own exporter.
The steps to create an Exporter are:
- Create a new library
- Add a reference to the Export library in the new library
- Create the function to do the export. This function should have typeThis
is the function that will be called when the exporter is used. The typical way to do this
involves one function for each notation that the exporter will support. The LaTeX
exporter provides an example:
The last clause in ToLaTeXText invokes the standard export for any notation that isn't handled explicitly already.
- Add the clauses that will convert an expression to a list of text objects. The text
objects are converted directly to text after your function runs.
- It may be appropriate to do this by copying an existing exporter and modifying the RHS of each clause
- It isn't necessary to write a clause to export every object. If an existing exporter will export some or most of the expressions in the form that you want, you can call that exporter at the end of your function.
- When you are editing the right-hand side of the export clauses, the text autocomplete will allow you to select from the list of predefined characters.
- The last two clauses in the LaTeX exporter process any remaining expressions, including these two clauses guarantees that the exporter will return a Text expression for every term in the original expression. The first of these two clauses handles expressions with parameters. The second clause just takes any term which is just a name and moves it to the Text namespace.
- Add the your exporter to the context menu. This involves created an extension for the
GetExporters function in your new library.
The first parameter of the menu item is just the name that will appear in the context menu. The second parameter is the function you created in step 3.
- Reference this new library in the document(s) that will use the export.
In most cases, you will want to create a unit test library to go with the exporter. This makes testing the exporter much easier. There is a unit test library called LaTeX unit tests.eql that shows you examples of expressions being exported.