PreFigure is a Python package for authoring mathematical diagrams. Following the PreTeXt paradigm, an author writes an XML description of a diagram that PreFigure converts into an image file suitable for including in a text document. By default, PreFigure will create an SVG image that can be included in, say, an HTML document. However, PreFigure prioritizes the creation of accessible diagrams so that annotations can be added that enable a screen reader to easily navigate the diagram. Tactile diagrams can also be created from the same XML source.
PreFigure diagrams can now be authored inside a PreTeXt document. More information, including detailed documentation, is available from the PreFigure homepage.
You may author and compile PreFigure diagrams in either of two environments:
- You may use the Prefigure Playground and download SVG files directly from the playground.
- PreFigure is available in a GitHub Codespace. This is a free, cloud-based platform that takes care of all the installation details and creates a fully configured working environment. Follow the instructions on that page to create your codespace and then get started authoring diagrams.
- PreFigure may be installed locally as a Python package following the instructions in the Local Installation section below.
PreFigure may be installed locally as a Python package in the usual way using pip. However, there are a few additional details that require your attention.
-
PreFigure assumes Python version 3.8.5 or higher. You may check your local Python version with one of the two commands below
python -Vpython3 -V -
You are encouraged to install
liblouis, which enables the creation of non-mathematical braille labels in tactile diagrams. PreFigure can still create diagrams without this package installed though you will see a non-fatal warning message when you compile a tactile diagram and any requested labels will not appear in the diagram.On a linux machine, use your package manager to install
python3-louis. Ubuntu users can useapt get python3-louiswhile on a Mac, you will want
brew install liblouisAlternatively, you can install
liblouisfollowing these instructions.Within a Python interpreter, you should then be able to
import louiswithout an error. -
You are encouraged to install an additional library to support the
pycairopackage. This may not be essential for your local machine, but there is no harm in performing this step. Thepycairopackage is needed to produce labels having plain text (rather than mathematics). If you are not able to installpycairo, you will still be able to build PreFigure diagrams, but any labels with plain text will not appear. -
You are now ready to install PreFigure with
pip install prefig[pycairo]If this fails, it is due to the
pycairodependency so you can instead install PreFigure withoutpycairousingpip install prefig -
You will need a local installation of
nodeandnpmto produce mathematical labels. (Thenodeinstallation includesnpm.) This is a simple process, but you should search to find the instructions for your operating system. On a Ubuntu machine, it's as easy asapt install nodejs -
For building PDF versions of diagrams, you will need to install
rsvg-convert, which PreFigure uses to convert SVGs into PDFs. On Ubuntu, you can sayapt install librsvg2-binwhile Mac users can use
brew install librsvg -
Once installed, the command
prefig initwill install MathJax and the Braille29 font needed to tactile diagrams. If you do not perform this step, MathJax will be automatically installed when you first build a diagram with mathematical labels.
Once PreFigure is installed, help is available with
prefig --help
or, say,
prefig build --help
Details of a requested operation may be obtained using the -v and -vv flags. For instance,
prefig -vv build foo.xml
will print debugging information to the terminal.
Here is a summary of PreFigure commands.
-
PreFigure source files can be compiled into SVG images using one of the following two commands, with the first command creating a regular SVG file while the second produces a tactile version of the diagram.
prefig build foo.xmlprefig build -f tactile foo.xmlBy default, the output appears in
output/foo.svgandoutput/foo.xml, where the XML output contains the annotations used by a screen reader. If PreFigure is called from within a PreTeXt document, then the annotations will appear infoo-annotations.xml. -
To view the resulting diagram, use either
prefig view fooprefig view -i fooThe first command will open the diagram in a browser using the
diagcesslibrary, which enables a reader to explore the annotations interactively. The second command ignores the annotations and simply opens the SVG diagram in a browser. -
Once a diagram has been compiled, you may create a PDF using
prefig pdf fooAdding the
-bswitch will build the diagram from PreFigure source before the PDF is formed. -
Similarly,
prefig png foocreates a PNG. Add the
-bswitch tobuildthe diagram first. -
To validate PreFigure source against the PreFigure XML schema, use
prefig validate foo.xml
You may wish to perform the following steps to set up your authoring environment (these are automatically performed in a codespace):
-
To initialize your local installation, use
prefig initwhich will use
npmto install some MathJax modules. It will also install the Braille29 font needed for tactile diagrams. If the MathJax modules are not installed when you attempt to build a diagram, PreFigure will attempt to install them when you build your first diagram. -
You may install a set of examples for exploration in the current directory using
prefig examples -
You may initialize a new PreFigure project in the current directory using
prefig newThis copies the
diagcesstools and a default publication file into the current directory and creates asourcedirectory in which to author diagrams.
Volker Sorge has provided crucial support for this project as well as access to the diagcess library for navigating an image with a screen reader.
The MathJax module mj-sre-page.js included with this distribution was created by Davide Cervone and Volker Sorge.
Thanks also to the PreTeXt community, and especially Rob Beezer, for support and inspiration. This project was developed with support from the UTMOST Project
PreFigure is distributed with a GPL license.