Skip to content

Commit 7144f49

Browse files
committed
LaTeX: add \sphinxnotetitle et al.
In passing I reverted some deprecation I had added at 6bf4059 to some internals of the sphinxadmonition environment, as it does not look that pressing anyhow and the redundant namings of two colors in particular may nevertheless prove useful to user \renewcommand's, as they avoid to have to refer to \spx@noticetype.
1 parent a7949d4 commit 7144f49

File tree

4 files changed

+101
-41
lines changed

4 files changed

+101
-41
lines changed

CHANGES

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Features added
3535
* LaTeX: a command ``\sphinxbox`` for styling text elements with a (possibly
3636
rounded) box, optional background color and shadow, has been added.
3737
See :ref:`sphinxbox`. (refs: #11224)
38+
* LaTeX: add ``\sphinxnotetitle``, ..., ``\sphinxwarningtitle``, ..., for
39+
an extra layer of mark-up freeing up ``\sphinxstrong`` for other uses.
40+
See :ref:`latex-macros`.
3841
* LaTeX: :dudir:`note`, :dudir:`hint`, :dudir:`important` and :dudir:`tip` can
3942
now each be styled as the other admonitions, i.e. possibly with a background
4043
color, individual border widths and paddings, possibly rounded corners, and
@@ -58,7 +61,7 @@ Bugs fixed
5861
respective to contents (when using rounded corners)
5962
* #11235: LaTeX: added ``\color`` in topic (or admonition) contents may cause color
6063
leak to the shadow and border at a page break
61-
* #11264: LaTeX: missing space before colon after "Voir aussi" for :dudir:`seealso`
64+
* #11264: LaTeX: missing space before colon after "Voir aussi" for :rst:dir:`seealso`
6265
directive in French (refs: #6744)
6366
* #11147: Fix source file/line number info in object description content and in
6467
other uses of ``nested_parse_with_titles``. Patch by Jeremy Maitin-Shepard.

doc/latex.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,16 @@ Macros
14641464
``\sphinxsamedocref``; ``\emph{#1}``
14651465
``\sphinxparam``; ``\emph{#1}``
14661466
``\sphinxoptional``; ``[#1]`` with larger brackets, see source
1467+
``\sphinxnotetitle``; ``\sphinxstrong{#1}<space>``
1468+
``\sphinxhinttitle``; *idem*
1469+
``\sphinximportanttitle``; *idem*
1470+
``\sphinxtiptitle``; *idem*
1471+
``\sphinxwarningtitle``; *idem*
1472+
``\sphinxcautiontitle``; *idem*
1473+
``\sphinxattentiontitle``; *idem*
1474+
``\sphinxdangertitle``; *idem*
1475+
``\sphinxerrortitle``; *idem*
1476+
``\sphinxseealsotitle``; ``\sphinxstrong{#1}\par\nopagebreak``
14671477

14681478
.. versionadded:: 1.4.5
14691479
Use of ``\sphinx`` prefixed macro names to limit possibilities of conflict
@@ -1478,6 +1488,17 @@ Macros
14781488
.. versionadded:: 6.2.0
14791489
``\sphinxparam``, ``\sphinxsamedocref``
14801490

1491+
.. versionadded:: 6.2.0
1492+
``\sphinxnotetitle`` et al. The ``#1`` is the localized name of the
1493+
directive, with a final colon. Wrap it as ``\sphinxremovefinalcolon{#1}``
1494+
if this final colon is to be removed. Example:
1495+
1496+
.. code-block:: latex
1497+
1498+
\renewcommand\sphinxwarningtitle[1]{%
1499+
\underline{\textbf{\sphinxremovefinalcolon{#1}}}\par
1500+
}
1501+
14811502
- More text styling:
14821503

14831504
.. csv-table::

sphinx/texinputs/sphinxlatexadmonitions.sty

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,36 @@
2323
\RequirePackage{framed}% used by sphinxheavybox
2424
%
2525
% Dependencies (they do not need to be defined at time of loading):
26+
%
2627
% - of course the various colour and dimension options handled via sphinx.sty
28+
%
2729
% - \sphinxstrong (for sphinxlightbox and sphinxheavybox)
30+
%
2831
% - dimension register \spx@image@maxheight from sphinxlatexgraphics.sty
32+
%
2933
% - \savenotes/\spewnotes from sphinxpackagefootnote (for sphinxheavybox)
34+
%
35+
% - \sphinxnotetitle, ..., \sphinxwarningtitle, etc... which are used by
36+
% default in the corresponding sphinx<notice> environments to replace at 6.2.0
37+
% formerly hard-coded \sphinxstrong{#1}<space>
38+
% Their definitions are in sphinxlatexstyletext.sty. Also \sphinxseealsotitle
39+
3040

3141
% Provides: (also in sphinxlatexliterals.sty)
3242
\providecommand*\sphinxvspacefixafterfrenchlists{%
3343
\ifvmode\ifdim\lastskip<\z@ \vskip\parskip\fi\else\par\fi
3444
}
3545

3646
% Some are quite plain
37-
\newenvironment{sphinxseealso}[1]{\sphinxstrong{#1}\par\nopagebreak}{}
47+
\newenvironment{sphinxseealso}[1]{\sphinxseealsotitle{#1}}{}
3848

3949
% This \dimen register is a legacy relic from Sphinx 1.5 which is used now
4050
% only for sphinxlightbox. It is set in the sphinxadmonition environment.
4151
\newdimen\spx@notice@border
4252

43-
% 6.2.0: add support for the <type>_TeXcolor options for text color.
44-
% 6.2.0: use directly sphinx<type>BorderColor, not spx@notice@bordercolor,
45-
% as the latter will probably be removed altogether at 7.0.0
4653
\newenvironment{sphinxlightbox}{%
47-
% done in sphinxadmonition but its place should be here
48-
% \spx@notice@border \dimexpr\csname spx@\spx@noticetype @border\endcsname\relax
4954
\par
50-
\noindent{\color{sphinx\spx@noticetype BorderColor}%
55+
\noindent{\color{spx@notice@bordercolor}%
5156
\rule{\linewidth}{\spx@notice@border}}%
5257
\par\nobreak
5358
{\parskip\z@skip\noindent}%
@@ -57,7 +62,7 @@
5762
% (we can't cancel that any earlier \vskip introduced a potential pagebreak)
5863
\sphinxvspacefixafterfrenchlists
5964
\nobreak\vbox{\noindent\kern\@totalleftmargin
60-
{\color{sphinx\spx@noticetype BorderColor}%
65+
{\color{spx@notice@bordercolor}%
6166
\rule[\dimexpr.4\baselineskip-\spx@notice@border\relax]
6267
{\linewidth}{\spx@notice@border}}\hss}\allowbreak
6368
}% end of sphinxlightbox environment definition
@@ -72,33 +77,36 @@
7277
% \newenvironment{sphinxhint}[1]
7378
% {\begin{sphinxlightbox}\sphinxstrong{#1} }{\end{sphinxlightbox}}
7479
%
75-
% It was possible for user to \renewenvironment this to use sphinxheavybox,
76-
% but this had stopped functioning at 5.1.0 which had greatly enhanced the
77-
% sphinxheavybox environment and the needed support macros existed only for
78-
% warning, caution, attention, danger, and error admonitions. At 6.1.0 a
79-
% patch was added to allow the \renewenvironment method to work again for
80-
% note, hint, important, tip to use sphinxheavybox.
81-
%
82-
% Then at 6.2.0, note, hint, important, tip can now access full customization
83-
% of sphinxheavybox: CSS-named alike options (if used) trigger sphinxheavybox.
84-
% The \renewenvironment method still works but then only common border width,
85-
% non-configurable padding, straight corners and no shadow are all implied,
86-
% as long as the related CSS-named options are not used.
80+
% The more complex definition below will branch to sphinxheavybox if a certain
81+
% boolean associated to the notice type is true. This boolean is set to true
82+
% whenever a CSS-named alike options for the notice type has been used in
83+
% sphinxsetup. The old coding as above would still work, with the new options
84+
% being then simply ignored. A user redefinition will probably either use
85+
% directly sphinxlightbox or sphinxheavybox or something else, with no need to
86+
% test the boolean.
87+
%
88+
% 6.2.0 also adds one layer of mark-up via \sphinxnotetitle etc..., because
89+
% the former \sphinxstrong{#1}<space> used a too generic \sphinxstrong. But
90+
% perhaps the #1 should be passed over to sphinx{light,heavy}box as parameter.
91+
% Unfortunately replacing these environments with one-parameter environments
92+
% would be potentially a breaking change. Anyway, sphinxpackageboxes.sty does not
93+
% provide a "titled" box; the caption of code-blocks is handled by extra
94+
% code in sphinxVerbatim.
8795
\newenvironment{sphinxnote}[1]
8896
{\edef\spx@env{sphinx\ifspx@opt@heavynote heavy\else light\fi box}%
89-
\expandafter\begin\expandafter{\spx@env}\sphinxstrong{#1} }
97+
\expandafter\begin\expandafter{\spx@env}\sphinxnotetitle{#1}}
9098
{\expandafter\end\expandafter{\spx@env}}
9199
\newenvironment{sphinxhint}[1]
92100
{\edef\spx@env{sphinx\ifspx@opt@heavyhint heavy\else light\fi box}%
93-
\expandafter\begin\expandafter{\spx@env}\sphinxstrong{#1} }
101+
\expandafter\begin\expandafter{\spx@env}\sphinxhinttitle{#1}}
94102
{\expandafter\end\expandafter{\spx@env}}
95103
\newenvironment{sphinximportant}[1]
96104
{\edef\spx@env{sphinx\ifspx@opt@heavyimportant heavy\else light\fi box}%
97-
\expandafter\begin\expandafter{\spx@env}\sphinxstrong{#1} }
105+
\expandafter\begin\expandafter{\spx@env}\sphinximportanttitle{#1}}
98106
{\expandafter\end\expandafter{\spx@env}}
99107
\newenvironment{sphinxtip}[1]
100108
{\edef\spx@env{sphinx\ifspx@opt@heavytip heavy\else light\fi box}%
101-
\expandafter\begin\expandafter{\spx@env}\sphinxstrong{#1} }
109+
\expandafter\begin\expandafter{\spx@env}\sphinxtiptitle{#1}}
102110
{\expandafter\end\expandafter{\spx@env}}
103111

104112
% warning/caution/attention/danger/error get more distinction
@@ -193,31 +201,35 @@
193201
% - Since 6.2.0, also note/hint/important/tip notices can use these options
194202
% and then they go automatically via sphinxheavybox. If only the legacy options
195203
% are used, they keep using sphinxlightbox.
204+
%
205+
% - Since 6.2.0, \sphinxwarningtitle etc... add one level of mark-up (they
206+
% expand to \sphinxstrong{#1}<space> which was former hard-coded mark-up).
207+
% Example:
208+
% \renewcommand{\sphinxwarningtitle}[1]{\textbf{#1}\par\smallskip
209+
% {\color{sphinxwarningBorderColor}\hrule height1pt}\smallskip}
196210
\newenvironment{sphinxwarning}[1]
197-
{\begin{sphinxheavybox}\sphinxstrong{#1} }{\end{sphinxheavybox}}
211+
{\begin{sphinxheavybox}\sphinxwarningtitle{#1}}{\end{sphinxheavybox}}
198212
\newenvironment{sphinxcaution}[1]
199-
{\begin{sphinxheavybox}\sphinxstrong{#1} }{\end{sphinxheavybox}}
213+
{\begin{sphinxheavybox}\sphinxcautiontitle{#1}}{\end{sphinxheavybox}}
200214
\newenvironment{sphinxattention}[1]
201-
{\begin{sphinxheavybox}\sphinxstrong{#1} }{\end{sphinxheavybox}}
215+
{\begin{sphinxheavybox}\sphinxattentiontitle{#1}}{\end{sphinxheavybox}}
202216
\newenvironment{sphinxdanger}[1]
203-
{\begin{sphinxheavybox}\sphinxstrong{#1} }{\end{sphinxheavybox}}
217+
{\begin{sphinxheavybox}\sphinxdangertitle{#1}}{\end{sphinxheavybox}}
204218
\newenvironment{sphinxerror}[1]
205-
{\begin{sphinxheavybox}\sphinxstrong{#1} }{\end{sphinxheavybox}}
219+
{\begin{sphinxheavybox}\sphinxerrortitle{#1}}{\end{sphinxheavybox}}
206220

207221
% the main dispatch for all types of notices
208222
\newenvironment{sphinxadmonition}[2]{% #1=type, #2=heading
209223
% can't use #1 directly in definition of end part
210224
\def\spx@noticetype {#1}%
211-
% At 6.2.0, these definitions of spx@notice@bordercolor and
212-
% spx@notice@bgcolor serve nothing at all for sphinxheavybox. And the
213-
% sphinxlightbox uses sphinx<type>BorderColor directly. Not removing
214-
% though, in case some people have redefined sphinxlightbox (or even
215-
% sphinxheavybox) and expect these things to exist.
216-
%
217-
% This is marked for removal at 7.0.0.
218-
\sphinxcolorlet{spx@notice@bordercolor}{sphinx#1BorderColor}%
219-
\sphinxcolorlet{spx@notice@bgcolor}{sphinx#1BgColor}%
220-
\spx@notice@border \dimexpr\csname spx@#1@border\endcsname\relax
225+
% those next three are a remnant of legacy code; they are not used at
226+
% all by sphinxheavybox, and their usage could be disposed of by sphinxlightbox
227+
% but we keep for backward compatibility and also because it may be simpler
228+
% for user redefinitions to employ for example "spx@notice@bgcolor" and not
229+
% the more bulky "sphinx\spx@noticetype BgColor".
230+
\sphinxcolorlet{spx@notice@bordercolor}{sphinx#1BorderColor}%
231+
\sphinxcolorlet{spx@notice@bgcolor}{sphinx#1BgColor}%
232+
\spx@notice@border \dimexpr\csname spx@#1@border\endcsname\relax
221233
% trigger the sphinx<type> environment, #2=heading is passed as argument
222234
\begin{sphinx#1}{#2}%
223235
% 6.2.0 support of div.<type>_TeX{color,extras} options

sphinx/texinputs/sphinxlatexstyletext.sty

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
%% TEXT STYLING
22
%
33
% change this info string if making any custom modification
4-
\ProvidesFile{sphinxlatexstyletext.sty}[2022/07/02 text styling]
4+
\ProvidesFile{sphinxlatexstyletext.sty}[2023/03/26 text styling]
55

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

9+
% But those arise rather from the default definitions of the respective
10+
% latex environments done in sphinxlatexadmonitions.sty
11+
\def\sphinxnotetitle#1{\sphinxstrong{#1} }
12+
\let\sphinxhinttitle \sphinxnotetitle % #1 holds the localized notice name
13+
\let\sphinximportanttitle\sphinxnotetitle % followed by a colon
14+
\let\sphinxtiptitle \sphinxnotetitle
15+
\let\sphinxwarningtitle \sphinxnotetitle
16+
\let\sphinxcautiontitle \sphinxnotetitle
17+
\let\sphinxattentiontitle\sphinxnotetitle
18+
\let\sphinxdangertitle \sphinxnotetitle
19+
\let\sphinxerrortitle \sphinxnotetitle
20+
\def\sphinxseealsotitle#1{\sphinxstrong{#1}\par\nopagebreak}
21+
%
22+
% A utility to remove a final colon
23+
% (one must be certain the semi-colon is there)
24+
\protected\def\sphinxremovefinalcolon #1{%
25+
% complications due to : possibly "active"
26+
\begingroup\ifnum\catcode`:=\active
27+
\lccode`~=`:\lowercase{\def\x##1~}{##1}%
28+
\else\def\x##1:{##1}\fi
29+
\expandafter\endgroup\x#1%
30+
}%
31+
% See doc/latex.rst for an example.
32+
933
% Some custom font markup commands.
1034
\protected\def\sphinxstrong#1{\textbf{#1}}
1135
\protected\def\sphinxcode#1{\texttt{#1}}

0 commit comments

Comments
 (0)