sphinx-doc / sphinx-doc/sphinx

For "math into SVG" conversion, run latex+dvisvgm only once for all equations at once

Open
#6,281 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extensions:mathematics type:enhancement
Dominant language
Python
Stars
8k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

As far as I understand from quick look sphinx.ext.imgmath, it executes latex and dvisvgm for each math equation when configured to produce SVG output.

It appears to be possible to execute latex only once and then dvisvgm once on the multipage document. This is made easier with standalone class on latex side.

I used for testing this latex file:

\documentclass[12pt, multi=sphinxmathenv, border=12pt]{standalone}
\begin{document}
\begin{sphinxmathenv}
  $F^{\mu\nu} = \partial^\mu A^\nu - \partial^\nu A^\mu$
\end{sphinxmathenv}
\begin{sphinxmathenv}
  \huge$F^{\mu\nu} = \partial^\mu A^\nu - \partial^\nu A^\mu$
\end{sphinxmathenv}
\end{document}

then

$ dvisvgm -p "1-" --font-format=woff temp.dvi
pre-processing DVI file (format version 2)
processing page 1
  graphic size: 102.482353pt x 9.333332pt (36.018428mm x 3.280291mm)
  output written to temp-1.svg
processing page 2
  graphic size: 218.927669pt x 20.031837pt (76.944275mm x 7.040386mm)
  output written to temp-2.svg
2 of 2 pages converted in 0.363326 seconds

This example shows that the two figures get their respective dimensions.

tested with dvisvgm 2.6.2.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in sphinx.ext.imgmath and reproduce the supplied standalone LaTeX document with dvisvgm. Trace how SVG output is currently generated per equation; done means processing all equations through one LaTeX run and one multipage dvisvgm run while preserving each figure's dimensions.

Written by the indexing model from the issue text.

Assessment

Tech stack
latex, python
Domain
documentation
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.