Skip to content

Commit

Permalink
[LaTeX] Re-style all admonitions to default to having icon + title
Browse files Browse the repository at this point in the history
The colours, and also most icons, are emulated from the recent
sphinx13.css update (PR sphinx-doc#12486, PR sphinx-doc#12439).
  • Loading branch information
jfbu committed Jul 3, 2024
1 parent 086a791 commit bb56be7
Show file tree
Hide file tree
Showing 7 changed files with 607 additions and 501 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ Release 7.4.0 (in development)
Dependencies
------------

* LaTeX: the ``xcolor`` package is now required.

Incompatible changes
--------------------

Deprecated
----------

* LaTeX: the ``sphinxlightbox`` environment is not used anymore, all types
of admonitions use ``sphinxheavybox``.

Features added
--------------

Expand Down
688 changes: 368 additions & 320 deletions sphinx/texinputs/sphinx.sty

Large diffs are not rendered by default.

271 changes: 200 additions & 71 deletions sphinx/texinputs/sphinxlatexadmonitions.sty

Large diffs are not rendered by default.

25 changes: 9 additions & 16 deletions sphinx/texinputs/sphinxlatexliterals.sty
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% LITERAL BLOCKS
%
% change this info string if making any custom modification
\ProvidesFile{sphinxlatexliterals.sty}[2023/04/01 code-blocks and parsed literals]
\ProvidesFile{sphinxlatexliterals.sty}[2024/07/01 v7.4.0 code-blocks and parsed literals]

% Provides support for this output mark-up from Sphinx latex writer:
%
Expand Down Expand Up @@ -34,6 +34,7 @@
% - needspace
% - sphinxpackageboxes
\RequirePackage{sphinxpackageboxes}
% 7.4.0 removes unneeded usage of \spx@boxes@border

% also in sphinxlatexadmonitions.sty:
% This is a workaround to a "feature" of French lists, when literal block
Expand Down Expand Up @@ -224,7 +225,6 @@
\spx@boxes@border@right\z@
\spx@boxes@border@bottom\z@
\spx@boxes@border@left\z@
\spx@boxes@border\z@
% MEMO: rounded corners still make sense in presence of a background
% color, so we do not force the fcolorbox@rectangle here
\fi
Expand Down Expand Up @@ -670,25 +670,18 @@
\def\sphinxVerbatim@Before
{\sphinxVerbatim@Title\nointerlineskip
\kern\dimexpr-\dp\strutbox+\sphinxbelowcaptionspace
% if no frame (code-blocks inside table cells), remove
% the top padding (better visually)
\ifspx@opt@verbatimwithframe\else
% but we must now check if there is a background color
% MEMO: "fcolorbox@setup" will have been done by time of use
\ifspx@boxes@withbackgroundcolor\else-\spx@boxes@padding@top\fi
\fi
% MEMO: prior to 7.4.0 a test was done for presence or
% not of a frame and if not top padding was removed if
% no background color. A background color is now always
% assumed, so this got removed.
% caption package adds \abovecaptionskip vspace, remove it
\spx@ifcaptionpackage{-\abovecaptionskip}{}\relax}%
\spx@ifcaptionpackage{-\abovecaptionskip}{}\relax}%
\else
\vskip\sphinxverbatimsmallskipamount
\def\sphinxVerbatim@After
{\nointerlineskip\kern\dimexpr\dp\strutbox
\ifspx@opt@verbatimwithframe\else
% but we must now check if there is a background color
% MEMO: "fcolorbox@setup" will have been done by time of use
\ifspx@boxes@withbackgroundcolor\else-\spx@boxes@padding@bottom\fi
\fi
\spx@ifcaptionpackage{-\abovecaptionskip}{}\relax
% MEMO: 7.4.0 removes here too an optional removal of bottom padding
\spx@ifcaptionpackage{-\abovecaptionskip}{}\relax
\sphinxVerbatim@Title}%
\fi
\def\@captype{literalblock}%
Expand Down
42 changes: 4 additions & 38 deletions sphinx/texinputs/sphinxlatexstyletext.sty
Original file line number Diff line number Diff line change
@@ -1,45 +1,11 @@
%% TEXT STYLING
%
% change this info string if making any custom modification
\ProvidesFile{sphinxlatexstyletext.sty}[2023/07/23 text styling]
\ProvidesFile{sphinxlatexstyletext.sty}[2024/07/01 v7.4.0 text styling]

% Basically everything here consists of macros which are part of the latex
% markup produced by the Sphinx latex writer

% But those arise rather from the default definitions of the respective
% latex environments done in sphinxlatexadmonitions.sty
\def\sphinxstylenotetitle #1{\sphinxstrong{#1} }
\let\sphinxstylehinttitle \sphinxstylenotetitle % #1 holds the localized notice name
\let\sphinxstyleimportanttitle\sphinxstylenotetitle % followed by a colon
\let\sphinxstyletiptitle \sphinxstylenotetitle
\let\sphinxstylewarningtitle \sphinxstylenotetitle
\let\sphinxstylecautiontitle \sphinxstylenotetitle
\let\sphinxstyleattentiontitle\sphinxstylenotetitle
\let\sphinxstyledangertitle \sphinxstylenotetitle
\let\sphinxstyleerrortitle \sphinxstylenotetitle
\def\sphinxstyleseealsotitle#1{\sphinxstrong{#1}\par\nopagebreak}
%
% A utility to remove a final colon. Removing last token is not easy in
% LaTeX, and there are additional complications:
% - some languages will make the : "active" in document body,
% - the generic admonition ends up using "note", so for \sphinxnotetitle to
% use it safely, the utility has to allow an input not having any final colon.
% - a bit far-fetched but maybe there is more than one colon inside the input
% (possible from a generic admonition title).
% Hence the scary code.
\def\sphinxremovefinalcolon#1{% #1 is the "active" : TeX token
\protected\def\sphinxremovefinalcolon ##1{%
% complications due to : possibly "active"
\begingroup\ifnum\catcode`:=\active
\def\x####1#1\relax{####1}%
\else\def\x####1:\relax{####1}\fi
\expandafter\endgroup\x##1\relax
% trick to let \x work also if input ##1 has no ending colon
\@gobblefour#1\relax:\relax\relax\relax
}%
}% end of wrapper to inject active :
\begingroup\catcode`:\active\expandafter\endgroup\sphinxremovefinalcolon:
% See doc/latex.rst for an example.
% 7.4.0 has moved all that is related to admonitions to sphinxlatexadmonitions.sty
% Most verything left here consists of macros which are part of the latex markup
% produced by the Sphinx LaTeX writer.

% Some custom font markup commands.
\protected\def\sphinxstrong#1{\textbf{#1}}
Expand Down
20 changes: 6 additions & 14 deletions sphinx/texinputs/sphinxlatextables.sty
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% TABLES (WITH SUPPORT FOR MERGED CELLS OF GENERAL CONTENTS)
%
% change this info string if making any custom modification
\ProvidesFile{sphinxlatextables.sty}[2022/08/15 tables]%
\ProvidesFile{sphinxlatextables.sty}[2024/07/01 v7.4.0 tables]%

% Provides support for this output mark-up from Sphinx latex writer
% and table templates:
Expand Down Expand Up @@ -42,6 +42,11 @@
% - \sphinxthistablewithnocolorrowsstyle
% - \sphinxthistablewithvlinesstyle
% - \sphinxthistablewithnovlinesstyle
%
% Also provides user command (see docs)
% - \sphixncolorblend
% (Sphinx 7.4.0 now requires xcolor, so \sphinxcolorblend does not check
% its availability anymore)
%
% Executes \RequirePackage for:
%
Expand Down Expand Up @@ -513,19 +518,6 @@
\fi
}
\def\sphinxcolorblend#1{\gdef\spx@colorblendparam{{#1}}\spx@table@hackCT@colorblend}
% Either xcolor.sty exists on user system and has been loaded by sphinx.sty,
% or it does not exist, so we can use \@ifpackageloaded without delaying.
\@ifpackageloaded{xcolor}%
{}%
{\def\sphinxcolorblend#1{%
\PackageWarning{sphinx}{This table uses \string\sphinxcolorblend\space
but xcolor is not in\MessageBreak
the TeX/LaTeX installation, the command will be\MessageBreak
ignored in this and the next tables}%
\global\let\sphinxcolorblend\@gobble
\sphinxbuildwarning{colorblend}%
}%
}
%%%%%%%%%%%%%%%%%%
Expand Down
57 changes: 15 additions & 42 deletions sphinx/texinputs/sphinxpackageboxes.sty
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
%% COLOURED BOXES
%
% change this info string if making any custom modification
\ProvidesPackage{sphinxpackageboxes}[2023/03/19 v6.2.0 advanced colored boxes]
\ProvidesPackage{sphinxpackageboxes}[2024/07/01 v7.4.0 advanced colored boxes]
% 7.4.0 removes usage of some booleans "...withbackgroundcolor" and
% "...withbordercolor" as well as \spx@boxes@border dimen which was
% actually really needed nowhere. This was done in sync with changes in
% sphinx.sty, sphinxlatexadmonitions.sty and sphinxlatexliterals.sty.
%
% Optionally executes \RequirePackage for:
%
% - pict2e. Ideally we would like to use the v0.4a 2020/08/16 release of this
Expand Down Expand Up @@ -78,15 +83,13 @@
%%%%%%%%%%%%%%%%
% Internal registers, conditionals, colors to be configured by each caller
% via a preliminary "setup" call
%
\newif\ifspx@boxes@withshadow
\newif\ifspx@boxes@insetshadow
\newif\ifspx@boxes@withbackgroundcolor
%%% \newif\ifspx@boxes@withbackgroundcolor % removed at 7.4.0
\newif\ifspx@boxes@withshadowcolor
\newif\ifspx@boxes@withbordercolor
%%% \newif\ifspx@boxes@withbordercolor % removed at 7.4.0
\newif\ifspx@boxes@shadowinbbox
%
\newdimen\spx@boxes@border
\newdimen\spx@boxes@border@top
\newdimen\spx@boxes@border@right
\newdimen\spx@boxes@border@bottom
Expand Down Expand Up @@ -150,7 +153,6 @@
\spx@boxes@border@right \dimexpr\@nameuse{spx@#1@border@right}\relax
\spx@boxes@border@bottom\dimexpr\@nameuse{spx@#1@border@bottom}\relax
\spx@boxes@border@left \dimexpr\@nameuse{spx@#1@border@left}\relax
\spx@boxes@border \dimexpr\@nameuse{spx@#1@border}\relax
%
\spx@boxes@padding@top \dimexpr\@nameuse{spx@#1@padding@top}\relax
\spx@boxes@padding@right \dimexpr\@nameuse{spx@#1@padding@right}\relax
Expand Down Expand Up @@ -200,19 +202,9 @@
\spx@boxes@insetshadowfalse
\fi
%
\@nameuse{ifspx@#1@withbordercolor}%
\spx@boxes@withbordercolortrue
\sphinxcolorlet{spx@boxes@bordercolor}{sphinx#1BorderColor}%
\else
\spx@boxes@withbordercolorfalse
\fi
%
\@nameuse{ifspx@#1@withbackgroundcolor}%
\spx@boxes@withbackgroundcolortrue
\sphinxcolorlet{spx@boxes@backgroundcolor}{sphinx#1BgColor}%
\else
\spx@boxes@withbackgroundcolorfalse
\fi
%
\@nameuse{ifspx@#1@withshadowcolor}%
\spx@boxes@withshadowcolortrue
Expand Down Expand Up @@ -447,14 +439,12 @@
\fi
% BACKGROUND
% draw background and move back to reference point
\ifspx@boxes@withbackgroundcolor
{\color{spx@boxes@backgroundcolor}%
\vrule\@height\ht\spx@tempboxa
\@depth\dp\spx@tempboxa
\@width\wd\spx@tempboxa
\kern-\wd\spx@tempboxa
}%
\fi
% BOX SHADOW
% draw shadow and move back to reference point
\ifspx@boxes@withshadow
Expand Down Expand Up @@ -494,13 +484,8 @@
}% end of \vbox
\fi % end of shadow drawing, and we are back to horizontal reference point
% BOX BORDER
\vbox{\ifspx@boxes@withbordercolor
\color{spx@boxes@bordercolor}%
\else
% 6.2.0: guard against a \color command in contents whose effect
% could leak to border at a pagebreak
\normalcolor
\fi
% 7.4.0 requires a set border color
\vbox{\color{spx@boxes@bordercolor}%
\hrule\@height\spx@boxes@border@top
\kern-\spx@boxes@border@top
\setbox\spx@tempboxb\hb@xt@\wd\spx@tempboxa
Expand Down Expand Up @@ -540,14 +525,13 @@
\def\spx@boxes@fcolorbox@insetshadow{%
% BACKGROUND
% draw background and move back to reference point
\ifspx@boxes@withbackgroundcolor
% 6.4.0 always assumes a background color
{\color{spx@boxes@backgroundcolor}%
\vrule\@height\ht\spx@tempboxa
\@depth\dp\spx@tempboxa
\@width\wd\spx@tempboxa
\kern-\wd\spx@tempboxa
}%
\fi
% BOX SHADOW
% draw shadow and move back to reference point
\ifspx@boxes@withshadow
Expand Down Expand Up @@ -589,13 +573,8 @@
}% end of \hbox, attention its depth is only |yoffset| if yoffset<0
\fi % end of inset shadow drawing, and we are back to horizontal reference point
% BOX BORDER
\vbox{\ifspx@boxes@withbordercolor
\color{spx@boxes@bordercolor}%
\else
% 6.2.0: guard against a \color command in contents whose effect
% could leak to border at a pagebreak
\normalcolor
\fi
% 7.4.0 requires a set border color
\vbox{\color{spx@boxes@bordercolor}%
\hrule\@height\spx@boxes@border@top
\kern-\spx@boxes@border@top
\setbox\spx@tempboxb\hb@xt@\wd\spx@tempboxa
Expand Down Expand Up @@ -807,17 +786,11 @@
\fi
\spx@boxes@border@defpath% must be redone after each \fillpath! (even if
% was in a \put)
\ifspx@boxes@withbordercolor
% 7.4.0 requires a set border color
\color{spx@boxes@bordercolor}%
\else
\normalcolor
\fi
\fillpath
\ifspx@boxes@withbackgroundcolor
% and backgroundcolor command
\color{spx@boxes@backgroundcolor}%
\else
\color{white}%
\fi
\edef\spx@width{\number\dimexpr\spx@width-\spx@boxes@border@left
-\spx@boxes@border@right sp}%
\edef\spx@height{\number\dimexpr\spx@height-\spx@boxes@border@top
Expand Down

0 comments on commit bb56be7

Please sign in to comment.