-
-
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
[LaTeX] Revamped styling of all admonitions, with addition of a title row with icon #12508
Conversation
@AA-Turner I tied this to 7.4.0 because it does strengthen a bit the requirements on LaTeX installations, because a package is needed to access the icons. Of course it can be merged earlier. But then all 7.4.0 strings should be updated. (in sphinxpackageboxes.sty there is one location where I wrote 6.4.0 by mistake). |
The mypy linting failures which have surfaced at third commit have nothing to do with this PR. The linting was successful at second commit (on prior day) and the third commit is only a refactoring of LaTeX code. Linting failures from type-docutils 0.21.0.20240704 having been released. See #12510 |
div.hint_title-background-TeXcolor=sphinx-success-title-bgcolor, | ||
div.hint_title-foreground-TeXcolor=sphinx-success-title-fgcolor, | ||
div.tip_title-background-TeXcolor=sphinx-success-title-bgcolor, | ||
div.tip_title-foreground-TeXcolor=sphinx-success-title-fgcolor, | ||
div.seealso_title-background-TeXcolor=sphinx-success-title-bgcolor, | ||
div.seealso_title-foreground-TeXcolor=sphinx-success-title-fgcolor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below lines I really imitated #12486 sphinx13.css which results in grouped choices for foreground and background according to categories "note", "success", "warning", "error". I could not take care of "todo" because the todo extension produces LaTeX markup which amalgamates with "note".
I have modified choices for default associated icons. Also, no warning is emitted if fontawesome5 is not found (because doing so requires adding logic to not emit a warning if the user has made usage of the Here is the new rendering (please make suggestions if you feel so!): Also, at page breaks, the default now adopts a "slice" style for box-decoration-break: and |
Haven't had time to review yet, but like it in principle btw cheers 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at the actual changes, but I remember that I had some issues with fontawesome5. If the package is not available for the texlive distribution, is fontawesome
sufficient?
@picnixz It is only partly sufficient in the current state of this PR: div.note_title-icon = \spx@faIcon{info-circle},
div.hint_title-icon = \spx@faIcon[regular]{lightbulb}, NOT OK
div.tip_title-icon = \spx@faIcon[regular]{lightbulb}, NOT OK
div.seealso_title-icon = \spx@faIcon{share},
div.important_title-icon = \spx@faIcon{pause-circle},
div.caution_title-icon = \spx@faIcon{radiation}, NOT OK
div.warning_title-icon = \spx@faIcon{exclamation-triangle},
div.attention_title-icon = \spx@faIcon{exclamation-triangle},
div.danger_title-icon = \spx@faIcon{radiation}, NOT OK
div.error_title-icon = \spx@faIcon{skull-crossbones}, NOT OK I have marked with NOT OK those names which fontawesome does not recognize and thus in this case there empty output. I guess I should go the extra effort to add a specific "fontawesome but not fontawesome5" handling ;-) I wasn't sure about context because I only work with latest TeXLive and I checked fontawesome5 already was there in TL2019. I will add the extra effort mentioned in previous paragraph... |
Actually, the issues I had were because I was using texlive-2017 and because I was still using an old distribution (so it was an EOL distribution). I could still make it work in general with most packages but if maybe ask for a minimal texlive version distribution (I think 2019 should be sufficient for most users, and if you say that fa5 was present in 2019 then it should be fine). |
@picnixz Thanks a lot for such feedback. I do have Tl2012 to 2019 but not on my current computer (and will be only one for some time) so did not check that far back in time. I will add a complete configuration with fontawesome, but can only test it with the TL2019 version of that package... |
If you think it's too much, maybe we can just ask users to use TL2019+. It would simplify the code base (and your life I think). |
We currently say:
It is not too much here for me to try to support fontawesome as fall-back, although I still have to check if I find some other name for skull-crossbones or if it is really absent and I have to pick another icon, or perhaps in the end use always times-circle as is done in sphinx13.css svg icon. |
Ah yes, we say "can be successfully done on much older LaTeX installations". So maybe add "except for some icons that require TeXLive 2019". I prefer the ❌ if possible because I know people that have some issues with skulls and I think it's better to have neutral icons for them. For the light bulb, it's under |
Would it be acceptable to say that some icons may render differently in earlier TL? Only the radiation is causing me problem at this time.
Ok, I don't have strong opinion so I propose times-circle which is available in both fontawesome and fontawesome5.
Yes, seen.
I was considering |
I think it's definitely fine. I don't think we need to reinvent the wheel for that and if people are really not happy with the default rendering, they can always redefine the corresponding symbol I think.
It's a better one indeed! |
@picnixz I have added fontawesome support. Here is how it renders with fontawesome: With fontawesome5 it renders as: so the sole significant difference is use of "bolt" with fontawesome, as it does not have the fontawesome5 "radiation". If neither is found, the titles will have no icons (and be shifted to start of line). Full customization is possible, see the docs in latex.rst. (ratio of doc time to coding time being circa 10 to 1). In checking this with TeXLive2019 I have hit against an unrelated matter which strangely shifts the title rows downwards in the admonition boxes. I will investigate later. |
I have understood why on testing my code on old LaTeX there was suddenly a gap above the colored title rows, a gap that does not show in above screenshots. With LaTeX of June 2023 (I think) a longstanding issue was fixed about "parskip" vertical glue in minipages. And the gap above is such an instance 1. I did not see it in my testing because I was using recent LaTeX. I will push a commit which will remove the gap seen above when compiling with LaTeX earlier than June 2023. Footnotes
|
- The colours, and also most icons, are emulated from the recent sphinx13.css update (PR sphinx-doc#12486, PR sphinx-doc#12439). - Add iconpackage key to sphinxsetup key of latex_elements fontawesome5 is used if available, else fall-back to fontawesome. If none is available, drop icons and shift titles left. In all cases, div.<type>_title-icon keys allow user to set arbitrary code to be used. - Defaults for padding and border-widths of admonitions have been changed, now that they all acquire a default background colour. The defaults always have horizontal padding plus border-width add up to 12.5pt, so contents of all types align exactly vertically. Or course user can specify arbitrary values. - The code inserting the coloured title-row incorporates a work-around to a feature of TeX vertical lists when they start with for example a colour special. It would not be necessary with LaTeX of 2023-06-01 and newer. cf Improve spacing at top of minipages in https://www.latex-project.org/news/latex2e-news/ltnews37.pdf
squashed and rebased on current master to get mypy linting pass |
Let me describe the logic for icon support:
In all cases, user can employ (I know Use Can one create a build error depending on available packages with the above? Only on purpose. If you do
forcing the loading of both packages, then fontawesome5 crashes the build:
But for normal use, the most probable and unique cause of a crash with this PR user interface will be to set up faulty LaTeX code as the values of the What does this PR do?
Let me conclude by mentioning that since a very long time, since Sphinx 1.5 actually:
all admonitions (except seealso which was added later) have in LaTeX associated environments: sphinxnote, sphinxhint, sphinxdanger, etc... and the user can redefine these environments to do whatever is desired, for example use the package We don't use So far these capacities remained under-exploited, the aim of this PR is to use them as default. |
I like this one and don't want to ever use I have some comments now on the colors being used for the borders. It feels that some of the reds are too extreme (especially for ERROR) or that the borders are a bit too large by default (I think the border could be 50% or 75% of what it is now for the error/warn boxes). Maybe we can ask theme maintainers about what they would suggest (I don't want to ping them yet)? |
@picnixz Reagrding todos, Furo theme, and Alabaster, use a kind of gray and Pydata theme some violet very similar to the choices from sphinx13.css. RTD uses some orange. Not all themes I tried style especially todos, as really distinct from other admonitions. The RTD theme uses white for text, for which there is no config in the present PR for PDF output. Anyhow to my eye (which has problems) this is bit blurry contrast. Not finding yet apart from RTD a yellowish rendering among themes I checked, I do not change the setting but any suggestion is welcome. I changed the border-widths, reverting to previously used Here is how it looks: |
@picnixz I misread your comment thinking a priori you were referring to #12543 but you did mention colors so it is indeed #12508. I added to the discussion some snapshots of various theme renderings for TODOs but did not do similar search for admonitions. |
I like those new colors. A final remark I could say is that Caution/Danger should be redder than Warning/Attention but less red than error (ranked in terms of importance IMO). Is it possible to reduce a bit the red of the error symbol actually? While the contrast is strong (and it should be), I feel it should be a little less. Also, in the other themes, the internal padding seems a bit smaller (symbols are much closer to the margin) so maybe we can also reduce the left padding? I don't know its current value but maybe by we can make it 50% of its current value (or 30% to keep a bit of space still). |
I don't disagree, but the pairs Caution/Warning on one side and Danger/Attention on the other sides were simply copied over from our own sphinx13.css (in doc/_themes/sphinx13/static). Except if I made a mistake.
Absolutely. I completely forgot to update it.
I have no issue with that. In HTML themes some align the text with the symbol as I do in PDF, others align it with the title. I think it is better as it is now. I liked the increased padding but no strong opinion, and it is only a default, theoretically easily overriden as per our docs. |
The rationale for the padding is to avoid a too large discrepancy between on one hand the distance from the symbol to the left margin (aka padding) and the distance from the symbol to the title on its right. I will push a change which reduces both. |
Personally, I like the colors! @AA-Turner do you have some personal comments on this change as well? |
Yeh looks all good to me On a related note, would love to see a more "simple" css-like way to modify stylings of pdfs (as mentioned in the documentation below) Would also be interested if https://typst.app/ (https://github.com/typst/typst) integration with sphinx could make pdf creation not such a horrible experience 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks all!
A
I would too! I think it would be a nice job for an extension to pick up the HTML theme selected by conf.py, analyze all CSS files and extract from it the data which
LaTeX is notoriously complex due to the fact that core functionalities only arise from packages, some of them unmaintained, sometimes conflict exist etc... I know nothing about it but ConTeXt, and now LuaMetaTeX are powerful. Also there is now a lean OpTeX which uses LuaLateX. All of these things suffer certainly from the same situation with LaTeX: very few people actually master (really) the underlying TeX concepts and language. I hope though that producing PDF from Sphinx via LaTeX is not so much horrible since basically the sole setting really needed is perhaps to set latex_engine to 'luatex' or 'xelatex' for Unicode: but then we enter the somewhat horrible world indeed of font loading, as conventions between the two Unicode engines differ about that, and we hit the main core problem being that LaTeX does not have a "fall-back" for fonts. A very good thing about LuaLaTeX is that it does offers fall-back mechanism, but still one has to configure it. Footnotes
|
This fixes sphinx-doc#12594 which emerged because sphinx-doc#12508 had modified seealso and note-like admonitions use background color and other effects, but the ensuing LaTeX can not work in a table cell without extras. This also fixes unreported issues unrelated to the 7.4.0 release: - (now old style "lightbox") admonitions render badly in tabulary, - "heavybox" admonitions (they are all now but warning et al. were already) cause PDF crash if in tabulary and rendered badly if in tabular or longtable. - figure in a table cell is not properly separated from immediately preceding text.
This fixes sphinx-doc#12594 which emerged because sphinx-doc#12508 had modified seealso and note-like admonitions to use background color and other effects, but the ensuing LaTeX can not work in a table cell without extras. This also fixes unreported issues unrelated to the 7.4.0 release: - (now old style "lightbox") admonitions render badly in tabulary, - "heavybox" admonitions (they are all now but warning et al. were already) cause PDF crash if in tabulary and are rendered badly if in tabular or longtable. - figure in a table cell is not properly separated from immediately preceding text.
This closed #10620. |
This closed #8807. |
Subject: The aim is to let Sphinx PDF output via LaTeX use as default for all admonitions (inclusive of seealso) similar styling as used at https://www.sphinx-doc.org/ for HTML output of our own docs.
Feature or Bugfix
Relates
A few on-the-side things need to be mentioned:
xcolor
LaTeX package is now required ; I have trimmed old annoying branches which tried to allow using onlycolor
package. Anyhow we requiredtexlive-latex-recommended
and this includesxcolor
.fontawesome5
LaTeX package is needed. If not available no build error, but a LaTeX warning. On Ubuntutexlive-fonts-extra
must be installed.Examples of output in PDF:
edit beware that the screenshots here are not fully up-to-date anymore as later commits (now squashed) modified some icons, and set the style at page breaks to "slice", whereas here it was still "clone". Also, padding settings changed. But colours have not been modified and are still the ones displayed here. Scroll further down to latest comments to see updated screenshots.
The colours for the titles (background colour and icon colour) should be exactly the same as the ones from sphinx13.css but the colour and widths of the borders were chosen independently.
Note: current implementation of sphinx.ext.todo means we can not yet style the TODO notes especially (they are rendered as "note" admonitions with a modified title that's all). It will be easier to address this in sphinx.ext.todo in a second stage, once this is merged.
First example
Second Example
Third Example with a pagebreak
Fourth Example
Last Example (beware that choices for icons have evolved, scroll down for up-to-date screenshots)