From 78e14fb6ba92f1aa9723aee6346fd7f763b3d978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20B?= <2589111+jfbu@users.noreply.github.com> Date: Tue, 14 Mar 2023 23:42:38 +0100 Subject: [PATCH] LaTeX: add boolean option addstrut to \sphinxbox/\sphinxboxsetup --- doc/latex.rst | 13 +++++++++++-- sphinx/texinputs/sphinx.sty | 8 ++++++++ sphinx/texinputs/sphinxpackageboxes.sty | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/doc/latex.rst b/doc/latex.rst index 2e1e05090..485613233 100644 --- a/doc/latex.rst +++ b/doc/latex.rst @@ -1536,9 +1536,18 @@ Here is the complete list of keys: - ``border-top-left-radius``, ``border-top-right-radius``, ``border-bottom-right-radius``, ``border-bottom-left-radius``, - ``box-shadow``, -- ``border-TeXcolor``, ``background-TeXcolor``, ``box-shadow-TeXcolor``. +- ``border-TeXcolor``, ``background-TeXcolor``, ``box-shadow-TeXcolor``, +- and ``addstrut`` which is a boolean key, i.e. to be used as ``addstrut=true``, + or ``addstrut`` alone where ``=true`` is omitted, or ``addstrut=false``. -Refer to :ref:`additionalcss` for important syntax information. The default +This last key is specific to ``\sphinxbox`` and it means to add a ``\strut`` +so that heights and depths are equalized across various instances, +independently of text content. The combination ``addstrut, +padding-bottom=0pt, padding-top=1pt`` is often satisfactory. The default is +``addstrut=false``.e + +Refer to :ref:`additionalcss` for important syntax information regarding the +other keys. The default configuration uses no shadow, a border-width of ``\fboxrule``, a padding of ``\fboxsep``, rounded corners (with radius ``\fboxsep``) and background and border colors as for the default rendering of code-blocks. One can modify diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index 9b7b4e2ec..7586c84e8 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -698,6 +698,13 @@ will be set to white}% \spx@tempa{div.important_} {important} \spx@tempa{div.tip_} {tip} +\newif\ifspx@opt@box@addstrut +\expandafter\def\csname KV@sphinx@box_addstrut\endcsname#1{% + \csname spx@opt@box@addstrut#1\endcsname +} +\expandafter\def\csname KV@sphinx@box_addstrut@default\endcsname{% + \spx@opt@box@addstruttrue +} \DeclareDefaultOption{\@unknownoptionerror} \ProcessKeyvalOptions* @@ -818,6 +825,7 @@ will be set to white}% {border-bottom-right-radius}{border-bottom-left-radius}% {box-shadow}% {border-TeXcolor}{background-TeXcolor}{box-shadow-TeXcolor}% + {addstrut}{addstrut@default}% \do{\expandafter\let\csname KV@sphinxbox@\x\expandafter\endcsname \csname KV@sphinx@box_\x\endcsname} \newcommand\sphinxboxsetup{\setkeys{sphinxbox}} diff --git a/sphinx/texinputs/sphinxpackageboxes.sty b/sphinx/texinputs/sphinxpackageboxes.sty index f9e09b581..c0df4d88d 100644 --- a/sphinx/texinputs/sphinxpackageboxes.sty +++ b/sphinx/texinputs/sphinxpackageboxes.sty @@ -258,7 +258,8 @@ \setbox0\hbox\bgroup\aftergroup\spx@boxes@sphinxbox@a \let\next=% } -\def\spx@boxes@sphinxbox@a{\spx@boxes@fcolorbox{\box\z@}\endgroup} +\def\spx@boxes@sphinxbox@a{\spx@boxes@fcolorbox{% + \ifspx@opt@box@addstrut\strut\fi\box\z@}\endgroup} \newcommand\newsphinxbox[2][]{% \newcommand#2[1][]{\sphinxbox[#1,##1]}%