-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
%20 is not escaped in image file names/URLs for LaTeX #13189
Comments
I observe that using .. image:: https://raster.shields.io/badge/doc-CC--BY\ 4.0-green.png "works": the LATEX build directory contains a fetched copy of the image file with an underscore replacing the space and correctly refers to it: \noindent\sphinxincludegraphics{{doc-CC--BY_4.0-green}.png} while the HTML file contains non escaped space character <img alt="https://raster.shields.io/badge/doc-CC--BY 4.0-green.png" src="https://raster.shields.io/badge/doc-CC--BY 4.0-green.png" /> and Firefox displays correctly. I am not HTML-savvy enough to see if this is mark-up is generally accepted by browsers. If one control-clicks (macOS mouse) on the image and selects "Copy image link" Firefox reconstructs Trying the same .. image:: /images/doc-CC--BY\ 4.0-green.png leads to another kind of behavior: the HTML will be with the <img alt="_images/doc-CC--BY%204.0-green.png" src="_images/doc-CC--BY%204.0-green.png" /> On the other hand the LATEX file will be with an unescaped space but this is fine as the image file is copied to the LATEX build directory with no change of filename and the mark-up is \noindent\sphinxincludegraphics{{doc-CC--BY 4.0-green}.png} and is ok for the PDF build. Using .. image:: /images/doc-CC--BY%204.0-green.png does not work even for HTML builds. As per what is presumably related to your use case: .. image:: https://raster.shields.io/badge/doc-CC--BY%204.0-green.png the distant file is correctly fetched and is copied to the LATEX build directory but with filename being
refers to the correct file but fails similarly as you reported due to Note that this does not involve Trying to reproduce your problem led me to the above which does not involve If we use the URL without image directive this kind of TEX is produced: A link \sphinxhref{https://raster.shields.io/badge/doc-CC--BY\%204.0-green.png}{https://raster.shields.io/badge/doc\sphinxhyphen{}CC\textendash{}BY\%204.0\sphinxhyphen{}green.png} which produces a correct PDF (which does not have the image but only the link to the image). I see how to let Simpler would be for Sphinx when fetching the distant image file and copying it in the LATEX build directory to not keep the original But then do we also have to take care of all |
Any characters in a URLs can be escaped in hex (here: space = dec 32 = hex 0x20). Escaping is done with a percent character. In form data (after the Using I might consider this as a work around until Sphinx has a fix to handle URLs with escaped hex-characters. My ReST has 2 images, one for HTML in SVG format and one in PNG format for LaTeX. So I can specify different URLs if needed. |
Or you properly escape the percent sign when generating the LaTeX code. This works:
Note the space after \pcnt. Found the workaround here: https://tex.stackexchange.com/questions/351123/percentage-sign-and-space-in-image-filename |
And before you ask, here's how to escape curly braces:
|
Describe the bug
When a shield from Shields.io is embedded in the documentation, the URL might contain
%20
for a space (or other escaped characters). This URL is used as filename without escaping/rewriting the percent-sign by Sphinx. When translating the document afterwards with LaTeX (xelatex), the document structure is broken, due to a comment sign (%
).Suggestion:
%
, or%
to_
.How to Reproduce
Example URL: https://raster.shields.io/badge/doc-CC--BY%204.0-green.png
This generates a shield with
CC-BY 4.0
as text.%20
is the space character:Generated LaTeX Code:
Produced LaTeX Error message:
Environment Information
Sphinx extensions
Additional context
LaTeX environment: MikTeX (all updated)
LaTeX processor: xelatex
The text was updated successfully, but these errors were encountered: