Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PreFigure

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.

Using PreFigure

You may author and compile PreFigure diagrams in either of two environments:

  1. You may use the Prefigure Playground and download SVG files directly from the playground.
  2. 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.
  3. PreFigure may be installed locally as a Python package following the instructions in the Local Installation section below.

Local Installation

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.

  1. PreFigure assumes Python version 3.8.5 or higher. You may check your local Python version with one of the two commands below

    python -V
    
    python3 -V
    
  2. 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 use

    apt install python3-louis
    

    while on a Mac, you will want

    brew install liblouis
    

    Alternatively, you can install liblouis following these instructions.

    Within a Python interpreter, you should then be able to import louis without an error.

  3. You are encouraged to install an additional library to support the pycairo package. This may not be essential for your local machine, but there is no harm in performing this step. The pycairo package is needed to produce labels having plain text (rather than mathematics). If you are not able to install pycairo, you will still be able to build PreFigure diagrams, but any labels with plain text will not appear.

  4. You are now ready to install PreFigure with

    pip install prefig[pycairo]
    

    If this fails, it is due to the pycairo dependency so you can instead install PreFigure without pycairo using

    pip install prefig
    
  5. You will need a local installation of node and npm to produce mathematical labels. (The node installation includes npm.) 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 as

    apt install nodejs
    
  6. 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 say

    apt install librsvg2-bin
    

    Mac users can use

    brew install librsvg
    

    On Windows, download rsvg-convert and add the location to your path.

  7. Once installed, the command prefig init will 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.

Usage

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.

  1. 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.xml
    
    prefig build -f tactile foo.xml
    

    By default, the output appears in output/foo.svg and output/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 in foo-annotations.xml.

  2. To view the resulting diagram, use either

    prefig view foo
    
    prefig view -i foo
    

    The first command will open the diagram in a browser using the diagcess library, which enables a reader to explore the annotations interactively. The second command ignores the annotations and simply opens the SVG diagram in a browser.

  3. Once a diagram has been compiled, you may create a PDF using

    prefig pdf foo
    

    Adding the -b switch will build the diagram from PreFigure source before the PDF is formed.

  4. Similarly,

    prefig png foo
    

    creates a PNG. Add the -b switch to build the diagram first.

  5. 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):

  1. To initialize your local installation, use

    prefig init
    

    which will use npm to 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.

  2. You may install a set of examples for exploration in the current directory using

    prefig examples
    
  3. You may initialize a new PreFigure project in the current directory using

    prefig new
    

    This copies the diagcess tools and a default publication file into the current directory and creates a source directory in which to author diagrams.

Acknowledgements

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

License

PreFigure is distributed with a GPL license.

Metadata

Release files for prefig 0.7.9.dev20261001113959

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prefig 0.7.9.dev20261001113959
File Size Uploaded
prefig-0.7.9.dev20261001113959.tar.gz 155.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prefig 0.7.9.dev20261001113959
File Interpreter ABI Platform
prefig-0.7.9.dev20261001113959-py3-none-any.whl Python 3 none any Details

Total release size: 338.4 kB

Release files / prefig-0.7.9.dev20261001113959.tar.gz

Download URL prefig-0.7.9.dev20261001113959.tar.gz
Size 155.7 kB
Tags Source
SHA-256 checksum
How to use checksums
511c0c0c15027f8a7c3ebc63059d3c765e8bd97b493644a5a7b17611d8395daf
BLAKE2b-256 checksum
How to use checksums
a0f76de806f4a620fc2b87648a822e5c83bbbe2a4abe566c10daaaa7130b6da8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.21 Linux/6.17.0-1022-azure

Release files / prefig-0.7.9.dev20261001113959-py3-none-any.whl

Download URL prefig-0.7.9.dev20261001113959-py3-none-any.whl
Size 182.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a954a24718be5d01ddbffbb700a8ad4cad35bdf018d1725757794b1aa2ee8d3b
BLAKE2b-256 checksum
How to use checksums
58f28eebd4a239d819d4ca6f8954e9c7b294cecb9d9118c96b4a914d4841bf69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.21 Linux/6.17.0-1022-azure

Release history Release notifications | RSS feed

0.7.9

2 release files

This release

0.7.8

2 release files

0.7.7

2 release files

0.7.6

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.7

2 release files

0.6.6

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.15

2 release files

0.5.13

2 release files

0.5.12

2 release files

0.5.11

2 release files

0.5.9

2 release files

0.5.8

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.16

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page