sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.41k stars 2.09k forks source link

pre_border-radius not translating to latexpdf for .. warning #12016

Closed Torxed closed 6 months ago

Torxed commented 6 months ago

Describe the bug

Following https://www.sphinx-doc.org/en/master/latex.html#the-sphinxsetup-configuration-setting, setting, I expected rounded corners on .. warning and other boxes:

% Rounded boxes are new at 5.1.0

The following however generates a square warning box.

How to Reproduce

.. raw:: latex

   \begingroup
   \sphinxsetup{%
      TitleColor={named}{DarkGoldenrod},
      % pre_border-width is 5.1.0 alias for verbatimborder
      pre_border-width=2pt,
      pre_border-right-width=8pt,
      % pre_padding is a 5.1.0 alias for verbatimsep
      pre_padding=5pt,
      % Rounded boxes are new at 5.1.0
      pre_border-radius=5pt,
      % TeXcolor reminds that syntax must be as for LaTeX \definecolor
      pre_background-TeXcolor={named}{OldLace},
      % ... and since 5.3.0 also xcolor \colorlet syntax is accepted and we
      %     can thus drop the {named}{...} thing if xcolor is available!
      pre_border-TeXcolor=Gold,
      % ... and even take more advantage of xcolor syntax:
      pre_border-TeXcolor=Gold!90,
      % add a shadow to code-blocks
      pre_box-shadow=6pt 6pt,
      pre_box-shadow-TeXcolor=gray!20,
      %
      % This 5.1.0 CSS-named option is alias for warningborder
      div.warning_border-width=3pt,
      % Prior to 5.1.0, padding for admonitions was not customizable
      div.warning_padding=6pt,
      div.warning_padding-right=18pt,
      div.warning_padding-bottom=18pt,
      % Assume xcolor has been loaded with its svgnames option
      div.warning_border-TeXcolor=DarkCyan,
      div.warning_background-TeXcolor=LightCyan,
      % This one is the only option with space separated input:
      div.warning_box-shadow=-12pt -12pt inset,
      div.warning_box-shadow-TeXcolor=Cyan,
      %
      % The 5.1.0 new name would be div.attention_border-width
      attentionborder=3pt,
      % The 5.1.0 name here would be div.attention_border-TeXcolor
      attentionBorderColor=Crimson,
      % The 5.1.0 name would be div.attention_background-TeXcolor
      attentionBgColor=FloralWhite,
      %
      % For note/hint/important/tip, the CSS syntax was added at 6.2.0
      % Legacy syntax still works
      noteborder=1pt,
      noteBorderColor=Olive,
      % But setting a background color via the new noteBgColor means that
      % it will be rendered using the same interface as warning type
      noteBgColor=Olive!10,
      % We can customize separately the four border-widths, and mimic
      % the legacy "light" rendering, but now with a background color:
      % div.note_border-left-width=0pt,
      % div.note_border-right-width=0pt,
      % Let's rather for variety use lateral borders:
      div.note_border-top-width=0pt,
      div.note_border-bottom-width=0pt,
      %
      % As long as only border width and border color are set, *and* using
      % for this the old interface, the rendering will be the "light" one
      hintBorderColor=LightCoral,
      % but if we had used div.hint_border-TeXcolor or *any* CSS-named
      % option we would have triggered the more complex "heavybox" code.
   }

Test
====

.. warning::

   A test

.. raw:: latex

   \endgroup

Environment Information

Platform:              linux; (Linux-6.7.6-arch1-1-x86_64-with-glibc2.39)
Python version:        3.11.7 (main, Jan 29 2024, 16:03:57) [GCC 13.2.1 20230801])
Python implementation: CPython
Sphinx version:        7.2.6
Docutils version:      0.20.1
Jinja2 version:        3.1.3
Pygments version:      2.17.2

Sphinx extensions

extensions = []

Additional context

texlive-basic 2023.66594-20
texlive-bibtexextra 2023.66594-20
texlive-bin 2023.66984-19
texlive-binextra 2023.66594-20
texlive-context 2023.66594-20
texlive-fontsextra 2023.66594-20
texlive-fontsrecommended 2023.66594-20
texlive-fontutils 2023.66594-20
texlive-formatsextra 2023.66594-20
texlive-games 2023.66594-20
texlive-humanities 2023.66594-20
texlive-latex 2023.66594-20
texlive-latexextra 2023.66594-20
texlive-latexrecommended 2023.66594-20
texlive-luatex 2023.66594-20
texlive-mathscience 2023.66594-20
texlive-metapost 2023.66594-20
texlive-music 2023.66594-20
texlive-pictures 2023.66594-20
texlive-plaingeneric 2023.66594-20
texlive-pstricks 2023.66594-20
texlive-publishers 2023.66594-20
texlive-xetex 2023.66594-20
Torxed commented 6 months ago

I might misunderstand what the border radius note actually means. And if so, is the intended usage to renewenvironment for sphinxheavybox?

It feels a bit complex, and if so perhaps a workaround is to use tcolorbox, but that means we would have to rely on .. raw:: latex to build the warning boxes instead of rest .. warning::?

picnixz commented 6 months ago

IIRC, using tcolorbox means using tikz and this comes at some cost we want to avoid.

@jfbu can you perhaps clarify the usage?

jfbu commented 6 months ago

A priori you should use the latex_elements['sphinxsetup'] key like this in conf.py for example

latex_elements = {
     'sphinxsetup': r"""
     div.warning_border-width=3pt,
     div.warning_border-radius=5pt,
     div.warning_padding=10pt,
     """,
}

and the your example gives this

Capture d’écran 2024-02-26 à 22 32 19

It is also possible to use \sphinxsetup inside raw latex for exceptional decorations to one particular warning.

It all works. Did you try as proposed here?

@picnixz I will wait to see if really this question is about using tcolorbox which is an option for people knowledgeable in LaTeX; they only need indeed to renewenvironment sphinxheavybox appropriately.

Torxed commented 6 months ago

@jfbu div.warning_border-radius=3pt, works like a charm and is in my case the preferred solution.

Any reason border-radius isn't mentioned in https://www.sphinx-doc.org/en/master/latex.html#additional-css-like-sphinxsetup-keys?

<prefix>_border-top-width, <prefix>_border-right-width, <prefix>_border-bottom-width, <prefix>_border-left-width, <prefix>_border-width. The latter can (currently) be only a single dimension which then sets all four others.

With some guessing game I should probably have figured out the syntax, but perhaps either mention it in the above linked section or https://www.sphinx-doc.org/en/master/latex.html#the-sphinxsetup-configuration-setting to avoid confusion with pre_border-radius (which I now understand is the <pre> tag?)

Also thank you for the help and clarification, this helped a lot!

picnixz commented 6 months ago

Actually, the border-radius is mentioned three sections below since it's not part of the customization of border's widths. But as you can see, I didn't even know that we could do that in Sphinx.

jfbu commented 6 months ago

@Torxed As pointed out by @picnixz it was mentioned indeed

But writing good documentation is hard! I realize perhaps I am confusing people in providing raw latex examples which in practice are only to allow advanced users achieve special effects. As for example Sphinx-doc maintainers obtain in the PDF docs of Sphinx itself a special rendering in PDF output for that chapter of the documentation devoted to LaTeX+PDF...

Torxed commented 6 months ago

Damn, yepp it sure is mentioned! I don't know how the heck my ctrl-f didn't pick up radius, I must have searched for radious or something super silly. Completely my fault and I apologize for the noise. This could have been a StackOverflow post for sure.

perhaps I am confusing people in providing raw latex examples

I think I might be a unique schmuck here hehe, the docs are well written. I'm pretty practical and tend to favor examples and that's on me. If anything, perhaps in the example comments found in the example of https://www.sphinx-doc.org/en/master/latex.html#the-sphinxsetup-configuration-setting - in the top perhaps mention the <prefix>_ style/information as that was a bit of a "ofcourse!" moment. But it's very well mentioned and explained in https://www.sphinx-doc.org/en/master/latex.html#additional-css-like-sphinxsetup-keys so with some digging and actually following the manual users will find it eventually.

I'll go ahead and close this issue tho, as it was a user error on my part.