Skip to content

Commit

Permalink
Merge pull request #8790 from jfbu/latex_refactor_style_files
Browse files Browse the repository at this point in the history
Refactor LaTeX style files
  • Loading branch information
jfbu committed Jan 31, 2021
2 parents e77378d + 54078e8 commit 4a85cae
Show file tree
Hide file tree
Showing 19 changed files with 812 additions and 605 deletions.
301 changes: 248 additions & 53 deletions sphinx/texinputs/sphinx.sty
Original file line number Diff line number Diff line change
Expand Up @@ -31,105 +31,300 @@
}}


%% PACKAGES
%% OPTION HANDLING
%
% we delay handling of options to after having loaded packages, because
% of the need to use \definecolor.
\input{sphinxlatexrequirepackages.sty}

% We first handle options then load packages, but we need \definecolor from
% xcolor/color.

%% PYGMENTS
% stylesheet for highlighting with pygments
\RequirePackage{sphinxhighlight}
% fix baseline increase from Pygments latex formatter in case of error tokens
% and keep \fboxsep's scope local via added braces
\def\PYG@tok@err{%
\def\PYG@bc##1{{\setlength{\fboxsep}{-\fboxrule}%
\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}%
% FIXME: we should \RequirePackage{xcolor} always now
% The xcolor package draws better fcolorboxes around verbatim code
\IfFileExists{xcolor.sty}{
\RequirePackage{xcolor}
}{
\RequirePackage{color}
}
\def\PYG@tok@cs{%
\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}%
\def\PYG@bc##1{{\setlength{\fboxsep}{0pt}%
\colorbox[rgb]{1.00,0.94,0.94}{\strut ##1}}}%
}%


%% OPTION HANDLING
% Handle options via "kvoptions" (later loaded by hyperref anyhow)
\RequirePackage{kvoptions}
\SetupKeyvalOptions{prefix=spx@opt@} % use \spx@opt@ prefix

% Sphinx legacy text layout: 1in margins on all four sides
\ifx\@jsc@uplatextrue\@undefined
\DeclareStringOption[1in]{hmargin}
\DeclareStringOption[1in]{vmargin}
\DeclareStringOption[.5in]{marginpar}
\else
% Japanese standard document classes handle \mag in a special way
\DeclareStringOption[\inv@mag in]{hmargin}
\DeclareStringOption[\inv@mag in]{vmargin}
\DeclareStringOption[.5\dimexpr\inv@mag in\relax]{marginpar}
\fi

\DeclareStringOption[0]{maxlistdepth}% \newcommand*\spx@opt@maxlistdepth{0}
\DeclareStringOption[-1]{numfigreset}
\DeclareBoolOption[false]{nonumfigreset}
\DeclareBoolOption[false]{mathnumfig}
% \DeclareBoolOption[false]{usespart}% not used
% dimensions, we declare the \dimen registers here.
\newdimen\sphinxverbatimsep
\newdimen\sphinxverbatimborder
\newdimen\sphinxshadowsep
\newdimen\sphinxshadowsize
\newdimen\sphinxshadowrule
% \DeclareStringOption is not convenient for the handling of these dimensions
% because we want to assign the values to the corresponding registers. Even if
% we added the code to the key handler it would be too late for the initial
% set-up and we would need to do initial assignments explicitely. We end up
% using \define@key directly.
% verbatim
\sphinxverbatimsep=\fboxsep
\define@key{sphinx}{verbatimsep}{\sphinxverbatimsep\dimexpr #1\relax}
\sphinxverbatimborder=\fboxrule
\define@key{sphinx}{verbatimborder}{\sphinxverbatimborder\dimexpr #1\relax}
% topic boxes
\sphinxshadowsep =5pt
\define@key{sphinx}{shadowsep}{\sphinxshadowsep\dimexpr #1\relax}
\sphinxshadowsize=4pt
\define@key{sphinx}{shadowsize}{\sphinxshadowsize\dimexpr #1\relax}
\sphinxshadowrule=\fboxrule
\define@key{sphinx}{shadowrule}{\sphinxshadowrule\dimexpr #1\relax}
% verbatim
\DeclareBoolOption[true]{verbatimwithframe}
\DeclareBoolOption[true]{verbatimwrapslines}
\DeclareBoolOption[true]{verbatimhintsturnover}
\DeclareBoolOption[true]{inlineliteralwraps}
\DeclareStringOption[t]{literalblockcappos}
\DeclareStringOption[r]{verbatimcontinuedalign}
\DeclareStringOption[r]{verbatimcontinuesalign}
% parsed literal
\DeclareBoolOption[true]{parsedliteralwraps}
% \textvisiblespace for compatibility with fontspec+XeTeX/LuaTeX
\DeclareStringOption[\textcolor{red}{\textvisiblespace}]{verbatimvisiblespace}
\DeclareStringOption % must use braces to hide the brackets
[{\makebox[2\fontcharwd\font`\x][r]{\textcolor{red}{\tiny$\m@th\hookrightarrow$}}}]%
{verbatimcontinued}
% notices/admonitions
% the dimensions for notices/admonitions are kept as macros and assigned to
% \spx@notice@border at time of use, hence \DeclareStringOption is ok for this
\newdimen\spx@notice@border
\DeclareStringOption[0.5pt]{noteborder}
\DeclareStringOption[0.5pt]{hintborder}
\DeclareStringOption[0.5pt]{importantborder}
\DeclareStringOption[0.5pt]{tipborder}
\DeclareStringOption[1pt]{warningborder}
\DeclareStringOption[1pt]{cautionborder}
\DeclareStringOption[1pt]{attentionborder}
\DeclareStringOption[1pt]{dangerborder}
\DeclareStringOption[1pt]{errorborder}
% footnotes
\DeclareStringOption[\mbox{ }]{AtStartFootnote}
% we need a public macro name for direct use in latex file
\newcommand*{\sphinxAtStartFootnote}{\spx@opt@AtStartFootnote}
% no such need for this one, as it is used inside other macros
\DeclareStringOption[\leavevmode\unskip]{BeforeFootnote}
% some font styling.
\DeclareStringOption[\sffamily\bfseries]{HeaderFamily}
% colours
% same problems as for dimensions: we want the key handler to use \definecolor.
% first, some colours with no prefix, for backwards compatibility
\newcommand*{\sphinxDeclareColorOption}[2]{%
\definecolor{#1}#2%
\define@key{sphinx}{#1}{\definecolor{#1}##1}%
}%
\sphinxDeclareColorOption{TitleColor}{{rgb}{0.126,0.263,0.361}}
\sphinxDeclareColorOption{InnerLinkColor}{{rgb}{0.208,0.374,0.486}}
\sphinxDeclareColorOption{OuterLinkColor}{{rgb}{0.216,0.439,0.388}}
\sphinxDeclareColorOption{VerbatimColor}{{rgb}{1,1,1}}
\sphinxDeclareColorOption{VerbatimBorderColor}{{rgb}{0,0,0}}
% now the colours defined with "sphinx" prefix in their names
\newcommand*{\sphinxDeclareSphinxColorOption}[2]{%
% set the initial default
\definecolor{sphinx#1}#2%
% set the key handler. The "value" ##1 must be acceptable by \definecolor.
\define@key{sphinx}{#1}{\definecolor{sphinx#1}##1}%
}%
% Default color chosen to be as in minted.sty LaTeX package!
\sphinxDeclareSphinxColorOption{VerbatimHighlightColor}{{rgb}{0.878,1,1}}
% admonition boxes, "light" style
\sphinxDeclareSphinxColorOption{noteBorderColor}{{rgb}{0,0,0}}
\sphinxDeclareSphinxColorOption{hintBorderColor}{{rgb}{0,0,0}}
\sphinxDeclareSphinxColorOption{importantBorderColor}{{rgb}{0,0,0}}
\sphinxDeclareSphinxColorOption{tipBorderColor}{{rgb}{0,0,0}}
% admonition boxes, "heavy" style
\sphinxDeclareSphinxColorOption{warningBorderColor}{{rgb}{0,0,0}}
\sphinxDeclareSphinxColorOption{cautionBorderColor}{{rgb}{0,0,0}}
\sphinxDeclareSphinxColorOption{attentionBorderColor}{{rgb}{0,0,0}}
\sphinxDeclareSphinxColorOption{dangerBorderColor}{{rgb}{0,0,0}}
\sphinxDeclareSphinxColorOption{errorBorderColor}{{rgb}{0,0,0}}
\sphinxDeclareSphinxColorOption{warningBgColor}{{rgb}{1,1,1}}
\sphinxDeclareSphinxColorOption{cautionBgColor}{{rgb}{1,1,1}}
\sphinxDeclareSphinxColorOption{attentionBgColor}{{rgb}{1,1,1}}
\sphinxDeclareSphinxColorOption{dangerBgColor}{{rgb}{1,1,1}}
\sphinxDeclareSphinxColorOption{errorBgColor}{{rgb}{1,1,1}}

\DeclareDefaultOption{\@unknownoptionerror}
\ProcessKeyvalOptions*
% don't allow use of maxlistdepth via \sphinxsetup.
\DisableKeyvalOption{sphinx}{maxlistdepth}
\DisableKeyvalOption{sphinx}{numfigreset}
\DisableKeyvalOption{sphinx}{nonumfigreset}
\DisableKeyvalOption{sphinx}{mathnumfig}
% FIXME: this is unrelated to an option, move this elsewhere
% To allow hyphenation of first word in narrow contexts; no option,
% customization to be done via 'preamble' key
\newcommand*\sphinxAtStartPar{\nobreak\hskip\z@skip}
% No need for the \hspace{0pt} trick (\hskip\z@skip) with luatex
\ifdefined\directlua\let\sphinxAtStartPar\@empty\fi
% user interface: options can be changed midway in a document!
\newcommand\sphinxsetup[1]{\setkeys{sphinx}{#1}}


%% MISCELLANEOUS CONTEXT
%
\input{sphinxlatexoptionhandling.sty}


%% LISTS
% flag to be set in a framed environment
% (defined here as currently needed by three sphinxlatex....sty files and
% even if not needed if such files are replaced, the definition does no harm)
\newif\ifspx@inframed
%
\input{sphinxlatexmisclists.sty}


%% INDEX, BIBLIOGRAPHY, APPENDIX, TABLE OF CONTENTS
% \spx@ifcaptionpackage (defined at begin document)
% is needed currently in macros from:
% sphinxlatexliterals.sty (sphinxVerbatim)
% sphinxlatextables.sty (for some macros used in the table templates)
%
\input{sphinxlatexenvindbibtoc.sty}

% \sphinxcaption is mark-up injected by the tabular and tabulary templates
% it is defined in sphinxlatextables.sty
%
% store the original \caption macro for usage with figures inside longtable
% and tabulary cells. Make sure we get the final \caption in presence of
% caption package, whether the latter was loaded before or after sphinx.
\AtBeginDocument{%
\let\spx@originalcaption\caption
\@ifpackageloaded{caption}
{\let\spx@ifcaptionpackage\@firstoftwo
\caption@AtBeginDocument*{\let\spx@originalcaption\caption}%
% in presence of caption package, drop our own \sphinxcaption whose aim was to
% ensure same width of caption to all kinds of tables (tabular(y), longtable),
% because caption package has its own width (or margin) option
\def\sphinxcaption{\caption}%
}%
{\let\spx@ifcaptionpackage\@secondoftwo}%
}

%% FIXME STUFF
%% PASS OPTIONS
%
\input{sphinxlatexmiscfixme.sty}
% pass options to hyperref; it must not have been loaded already
\input{sphinxoptionshyperref.sty}
% pass options to geometry; it must not have been loaded already
\input{sphinxoptionsgeometry.sty}


%% PAGE STYLING
%% COLOR (general)
%
\input{sphinxlatexstylepage.sty}
% FIXME: these two should be deprecated
%
% FIXME: \normalcolor should be used and \py@NormalColor never defined
\def\py@NormalColor{\color{black}}
% FIXME: \color{TitleColor} should be used directly and \py@TitleColor
% should never get defined.
\def\py@TitleColor{\color{TitleColor}}


%% TITLES
%% PACKAGES
%
\input{sphinxlatexstyleheadings.sty}
% as will be indicated below, secondary style files load some more packages
%
% For \text macro (sphinx.util.texescape)
% also for usage of \firstchoice@true(false) in sphinxlatexgraphics.sty
\RequirePackage{amstext}
% It was passed "warn" option from latex template in case it is already loaded
% via some other package before \usepackage{sphinx} in preamble
\RequirePackage{textcomp}
% For the H specifier. Do not \restylefloat{figure}, it breaks Sphinx code
% for allowing figures in tables.
\RequirePackage{float}
% For floating figures in the text. Better to load after float.
\RequirePackage{wrapfig}
% Provides \captionof, used once by latex writer (\captionof{figure})
\RequirePackage{capt-of}
% Support hlist directive
\RequirePackage{multicol}


%% GRAPHICS
%
% It will always be needed, so let's load it here
\RequirePackage{graphicx}
\input{sphinxlatexgraphics.sty}


%% CITATIONS
%% FRAMED ENVIRONMENTS
%
\protected\def\sphinxcite{\cite}
\input{sphinxlatexadmonitions.sty}
\input{sphinxlatexliterals.sty}
\input{sphinxlatexshadowbox.sty}


%% FOOTNOTES
%% PYGMENTS
% stylesheet for highlighting with pygments
\RequirePackage{sphinxhighlight}
% fix baseline increase from Pygments latex formatter in case of error tokens
% and keep \fboxsep's scope local via added braces
\def\PYG@tok@err{%
\def\PYG@bc##1{{\setlength{\fboxsep}{-\fboxrule}%
\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}%
}
\def\PYG@tok@cs{%
\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}%
\def\PYG@bc##1{{\setlength{\fboxsep}{0pt}%
\colorbox[rgb]{1.00,0.94,0.94}{\strut ##1}}}%
}%


%% TABLES
%
% Support large numbered footnotes in minipage
% But now obsolete due to systematic use of \savenotes/\spewnotes
% when minipages are in use in the various macro definitions next.
\def\thempfootnote{\arabic{mpfootnote}}
\input{sphinxlatextables.sty}


%% NUMBERING OF FIGURES, TABLES, AND LITERAL BLOCKS
%
\input{sphinxlatexmiscnumbering.sty}
\input{sphinxlatexnumfig.sty}


%% LITERAL BLOCKS
%% LISTS
%
\input{sphinxlatexenvliteral.sty}
\input{sphinxlatexlists.sty}


%% TOPIC AND CONTENTS BOXES
%% FOOTNOTES
%
\input{sphinxlatexenvshadowbox.sty}
% support large numbered footnotes in minipage; but this is now obsolete
% from systematic use of savenotes environment around minipages
\def\thempfootnote{\arabic{mpfootnote}}
% This package is needed to support hyperlinked footnotes in tables and
% framed contents, and to allow code-blocks in footnotes.
\RequirePackage{sphinxpackagefootnote}


%% NOTICES AND ADMONITIONS
%% INDEX, BIBLIOGRAPHY, APPENDIX, TABLE OF CONTENTS
%
\input{sphinxlatexenvadmonitions.sty}
\input{sphinxlatexindbibtoc.sty}


%% PYTHON DOCS MACROS AND ENVIRONMENTS
%% STYLING
%
\input{sphinxlatexenvdocs.sty}
\input{sphinxlatexstylepage.sty}
\input{sphinxlatexstyleheadings.sty}
\input{sphinxlatexstyletext.sty}


%% TEXT STYLING
%% MODULE RELEASE DATA AND OBJECT DESCRIPTIONS
%
\input{sphinxlatexstyletext.sty}
\input{sphinxlatexobjects.sty}


% FIXME: this line should be dropped, as "9" is default anyhow.
\ifdefined\pdfcompresslevel\pdfcompresslevel = 9 \fi


\endinput
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
%% NOTICES AND ADMONITIONS
%
% change this info string if making any custom modification
\ProvidesFile{sphinxlatexenvadmonitions.sty}[2021/01/27 admonitions]
\ProvidesFile{sphinxlatexadmonitions.sty}[2021/01/27 admonitions]

% Provides support for this output mark-up from Sphinx latex writer:
%
% - sphinxadmonition (environment)
% This is a dispatch supporting
%
% - note, hint, important, tip (via sphinxlightbox)
% - warning, caution, attention, danger, error (via sphinxheavybox)
%
% Each sphinx<notice name> environment can be redefined by user.
% The defaults are customizable via various colour and dimension
% settings, cf sphinx docs (latex customization).
%
% Requires:
\RequirePackage{framed}% used by sphinxheavybox
%
% Dependencies (they do not need to be defined at time of loading):
% - of course the various colour and dimension options handled via sphinx.sty
% - \sphinxstrong (for sphinxlightbox and sphinxheavybox)
% - dimension register \spx@image@maxheight from sphinxlatexgraphics.sty
% - \savenotes/\spewnotes from sphinxpackagefootnote (for sphinxheavybox)

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

% Some are quite plain
% the spx@notice@bordercolor etc are set in the sphinxadmonition environment
Expand Down Expand Up @@ -119,4 +145,4 @@
% workaround some LaTeX "feature" of \end command
{\edef\spx@temp{\noexpand\end{sphinx\spx@noticetype}}\spx@temp}

\endinput
\endinput
Loading

0 comments on commit 4a85cae

Please sign in to comment.