Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imgmath: Allow embedding images in HTML as base64 #10816

Merged
merged 16 commits into from Sep 23, 2022

Conversation

jschueller
Copy link
Contributor

@jschueller jschueller commented Sep 12, 2022

A new flag imgmath_embed allows to include LaTeX output images as inline base64 into the HTML instead of separate png/svg files, using:
<img class="math" src="data:image/svg+xml;base64,ocmVmPScjZzEtNzMnL...>
This allows to avoid uploading many small files for continuous integration artifacts.
The latex output file is removed after encoding.

inspired from https://github.com/sphinx-contrib/imageembed

@jschueller jschueller force-pushed the math_embed branch 2 times, most recently from be0c5b2 to c06244a Compare September 12, 2022 12:08
sphinx/ext/imgmath.py Outdated Show resolved Hide resolved
@AA-Turner
Copy link
Member

@jschueller please don't force-push, I'll squash on merge.

A

@AA-Turner AA-Turner added type:enhancement enhance or introduce a new feature builder labels Sep 12, 2022
@AA-Turner AA-Turner added this to the 5.2.0 milestone Sep 12, 2022
@jschueller
Copy link
Contributor Author

oh, ok

@AA-Turner
Copy link
Member

Please may you add some tests for the new behaviour, and an entry in CHANGES?

A

@AA-Turner AA-Turner changed the title imgmath: Allow to embed images as base64 HTML imgmath: Allow embedding images in HTML as base64 Sep 12, 2022
@AA-Turner
Copy link
Member

As a design point, I'd suggest splitting render_math() into two functions, at the # Move generated image on tempdir to build dir line.

We would always call the function that creates the temporary image, but the flag would control if we called the move_rendered_image_from_temp_dir_to_build_dir() function or the read_rendered_image_and_return_base_64_encoded_string() function (names to be improved!).

This then means we always know the mime type and don't have to use the guess functions, and don't need to remove any images, as they're in temp directories anyway.

A

@jschueller
Copy link
Contributor Author

@AA-Turner the move is now in a separate function get_img_src, but I dont have as many functions as suggested,
could you give more details on how to split the functions if its not ok for you ?

# Conflicts:
#	CHANGES
@AA-Turner AA-Turner merged commit ef01c5b into sphinx-doc:5.x Sep 23, 2022
@AA-Turner
Copy link
Member

Thanks Julien!

A

@jschueller jschueller deleted the math_embed branch September 23, 2022 19:52
@jschueller
Copy link
Contributor Author

thanks!

@jschueller
Copy link
Contributor Author

jschueller commented Sep 26, 2022

@AA-Turner it seems it does not work in parallel (using -j4 flag), any idea why ?

File "/usr/lib/python3.10/site-packages/sphinx/util/parallel.py", line 125, in _join_one
    raise SphinxParallelError(*result)
sphinx.errors.SphinxParallelError: FileNotFoundError: [Errno 2] No such file or directory: '/home/devel/project/build/python/src/sphinx_build/html/_images/math/dd25924f1cd0f37c1985116c759fb5c0dbfae2bb.svg'

@AA-Turner
Copy link
Member

Could you open a new issue please, or a PR adding a failing test for parallel building?

A

@jschueller
Copy link
Contributor Author

ok, see #10869

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
builder type:enhancement enhance or introduce a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants