> Selection_037.png
>
>
>
> to look like:
>
> Selection_038.png
>
>
> (Observe that "Note:" has disappeared and the "See Also: is unaffected.)
>
> Explicitly, my conf.py currently contains:
>
> latex_elements = {
> 'preamble':
> r'''
> \definecolor{Admonition}{RGB}{221,233,239}
>
> \makeatletter
> \newenvironment{admonitionbox}{
> \begin{lrbox}{\@tempboxa}\begin{minipage}{\columnwidth}
> }{
> \end{minipage}\end{lrbox}
> \colorbox{Admonition}{\usebox{\@tempboxa}}
> }
>
> \renewenvironment{sphinxadmonition}[2]{
> \begin{admonitionbox}
> }{
> \end{admonitionbox}
> }
> \makeatother
>
>
>
> Ideally, I could have different colors for different admonitions, but I understand that that may not be possible.
>
> Thank you
Hi, since Sphinx 1.5 one can customize each admonition type.
http://www.sphinx-doc.org/en/master/latex.html#environments
For example "note" uses this :
% may be renewenvironment'd by user for complete customization
\newenvironment{sphinxnote}[1]
{\begin{sphinxlightbox}\sphinxstrong{#1} }{\end{sphinxlightbox}}
It thus looks as if your customization could do something like this
latex_elements = {
'preamble': r"""
\newsavebox\mytempbox
\definecolor{sphinxnoteBgColor}{RGB}{221,233,239}
\renewenvironment{sphinxnote}[1]
{\begin{lrbox}{\mytempbox}\begin{minipage}{\columnwidth}%
\begin{sphinxlightbox}\sphinxstrong{#1} }
{\end{sphinxlightbox}\end{minipage}\end{lrbox}%
\colorbox{sphinxnoteBgColor}{\usebox{\mytempbox}}}
""",
}
Here we kept the "sphinxlightbox" thing whose aim is to insert
horizontal rules.
If you want to insert a background color and still allow pagebreak
then it is more appropriate to use the "sphinxheavybox". Simply
imitate the way things are set-up in sphinx.sty for warning, etc...
Notice that sphinxnoteBgColor will be applied automatically
(the heavybox uses a color named according to the admonition type)
but we need to define it this way, there is no interface in "sphinxsetup"
latex_elements = {
'preamble': r"""
\definecolor{sphinxnoteBgColor}{RGB}{221,233,239}
\renewenvironment{sphinxnote}[1]
{\begin{sphinxheavybox}\sphinxstrong{#1} }{\end{sphinxheavybox}}
""",
'sphinxsetup': 'noteborder=1.5pt',
}
I have also shown above how to modify the width of the frame using "sphinxsetup".
Unfortunately if you want only a border on top and bottom but not
on the side, this means an environment analogous to but not the
same as sphinxheavybox should be used. But this is arduous LaTeX coding.
So we can go back to your lrbox approach (dropping possibility of pagebreak)
and do something like this:
latex_elements = {
'preamble': r"""
\newsavebox\mytempbox
\definecolor{sphinxnoteBgColor}{RGB}{221,233,239}
\makeatletter
\renewenvironment{sphinxnote}[1]
{\begin{lrbox}{\mytempbox}\begin{minipage}{\columnwidth}%
\sphinxstrong{#1} }
{\end{minipage}\end{lrbox}%
\smallskip
\hrule height \spx@opt@noteborder\relax
\hbox{\colorbox{sphinxnoteBgColor}{\usebox{\mytempbox}}}%
\hrule height \spx@opt@noteborder\relax
\smallskip
}
\makeatother
""",
'sphinxsetup': 'noteborder=1.5pt',
}
This is a bit complicated LaTeX but less so than doing a variant of sphinxheavybox
Here we ignore the noteBorderColor parameter. Here is code
using it:
latex_elements = {
'preamble': r"""
\newsavebox\mytempbox
\definecolor{sphinxnoteBgColor}{RGB}{221,233,239}
\makeatletter
\renewenvironment{sphinxnote}[1]
{\begin{lrbox}{\mytempbox}\begin{minipage}{\columnwidth}%
\sphinxstrong{#1} }
{\end{minipage}\end{lrbox}%
\color{sphinxnoteBorderColor}
\hrule height \spx@opt@noteborder\relax
\normalcolor
\hbox{\colorbox{sphinxnoteBgColor}{\usebox{\mytempbox}}}%
\color{sphinxnoteBorderColor}
\hrule height \spx@opt@noteborder\relax
\normalcolor
}
\makeatother
""",
'sphinxsetup': 'noteborder=1.5pt, noteBorderColor={named}{magenta}',
}
For sphinxnoteBgColor, there is no "noteBgColor" key to 'sphinxsetup',
contrarily to "warningBgColor" etc..., because the "sphinxlightbox"
has no use of a background color. This interface should arguably be
added for cases such as this one.
In code above the handling of noteborder parameter is a bit complicated
because we must use the internal form.
Besides the above uses TeX primitives rather than LaTeX syntax,
but I don't know immediately how to do these effects in LaTeX
(and ultimately it all boils down to core TeX, so for the next
few years before LaTeX3 makes impossible using the TeX primitives
directly let's enjoy our current freedom).
(the color package does not seem to provide a \fcolorbox
for only horizontal borders, perhaps some other package
does, then you can use it in place of my code above)
Hope this helps,
Jean-François