Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaTeX: Add math_numsep support to latex builder #12652

Merged
merged 15 commits into from
Aug 18, 2024
Merged
6 changes: 4 additions & 2 deletions sphinx/texinputs/sphinx.sty
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
\DeclareStringOption[-1]{numfigreset}
\DeclareBoolOption[false]{nonumfigreset}
\DeclareBoolOption[false]{mathnumfig}
\DeclareStringOption[.]{mathnumsep}
\define@key{sphinx}{bookmarksdepth}{\AtBeginDocument{\hypersetup{bookmarksdepth=#1}}}
\AtBeginDocument{\define@key{sphinx}{bookmarksdepth}{\hypersetup{bookmarksdepth=#1}}}
% \DeclareBoolOption[false]{usespart}% not used
Expand Down Expand Up @@ -731,7 +732,7 @@
\spx@tempa{div.important_} {important}
\spx@tempa{div.tip_} {tip}

% Add "legacy" hintTeXextras etc...
% Add "legacy" hintTeXextras etc...
\def\spx@tempa#1#2{% #1 = CSS like option prefix, #2 = legacy option prefix
\expandafter\let\csname KV@sphinx@#2TeXextras\expandafter\endcsname
\csname KV@sphinx@#1TeXextras\endcsname
Expand Down Expand Up @@ -807,7 +808,7 @@
% We try to
% - get Sphinx PDF builds to process fine in absence of fontawesome5
% - use fontawesome5 if present, but not if user prefers another package
% - provide an interface for using other LaTeX code for icons
% - provide an interface for using other LaTeX code for icons
% - provide an interface for using some other package than fontawesome5
% Indeed we can't load fontawesome5 unconditionally even if available,
% as it proves incompatible with fontawesome package.
Expand Down Expand Up @@ -898,6 +899,7 @@
\DisableKeyvalOption{sphinx}{numfigreset}
\DisableKeyvalOption{sphinx}{nonumfigreset}
\DisableKeyvalOption{sphinx}{mathnumfig}
\DisableKeyvalOption{sphinx}{mathnumsep}
jfbu marked this conversation as resolved.
Show resolved Hide resolved
\DisableKeyvalOption{sphinx}{booktabs}
\DisableKeyvalOption{sphinx}{borderless}
\DisableKeyvalOption{sphinx}{rowcolors}
Expand Down
20 changes: 10 additions & 10 deletions sphinx/texinputs/sphinxlatexnumfig.sty
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
\ifnum\spx@opt@numfigreset>0
\ltx@ifundefined{c@chapter}
{}
{\g@addto@macro\spx@preAthefigure{\ifnum\c@chapter>\z@\arabic{chapter}.}%
{\g@addto@macro\spx@preAthefigure{\ifnum\c@chapter>\z@\arabic{chapter}}%
\g@addto@macro\spx@preBthefigure{\fi}}%
\fi
\ifnum\spx@opt@numfigreset>1
Expand All @@ -61,7 +61,7 @@
\ifspx@opt@mathnumfig
\@addtoreset{equation}{section}%
\fi%
\g@addto@macro\spx@preAthefigure{\ifnum\c@section>\z@\arabic{section}.}%
\g@addto@macro\spx@preAthefigure{\ifnum\c@section>\z@.\arabic{section}}%
jfbu marked this conversation as resolved.
Show resolved Hide resolved
\g@addto@macro\spx@preBthefigure{\fi}%
\fi
\ifnum\spx@opt@numfigreset>2
Expand All @@ -71,7 +71,7 @@
\ifspx@opt@mathnumfig
\@addtoreset{equation}{subsection}%
\fi%
\g@addto@macro\spx@preAthefigure{\ifnum\c@subsection>\z@\arabic{subsection}.}%
\g@addto@macro\spx@preAthefigure{\ifnum\c@subsection>\z@.\arabic{subsection}}%
\g@addto@macro\spx@preBthefigure{\fi}%
\fi
\ifnum\spx@opt@numfigreset>3
Expand All @@ -81,7 +81,7 @@
\ifspx@opt@mathnumfig
\@addtoreset{equation}{subsubsection}%
\fi%
\g@addto@macro\spx@preAthefigure{\ifnum\c@subsubsection>\z@\arabic{subsubsection}.}%
\g@addto@macro\spx@preAthefigure{\ifnum\c@subsubsection>\z@.\arabic{subsubsection}}%
\g@addto@macro\spx@preBthefigure{\fi}%
\fi
\ifnum\spx@opt@numfigreset>4
Expand All @@ -91,7 +91,7 @@
\ifspx@opt@mathnumfig
\@addtoreset{equation}{paragraph}%
\fi%
\g@addto@macro\spx@preAthefigure{\ifnum\c@subparagraph>\z@\arabic{subparagraph}.}%
\g@addto@macro\spx@preAthefigure{\ifnum\c@subparagraph>\z@.\arabic{subparagraph}}%
\g@addto@macro\spx@preBthefigure{\fi}%
\fi
\ifnum\spx@opt@numfigreset>5
Expand All @@ -101,20 +101,20 @@
\ifspx@opt@mathnumfig
\@addtoreset{equation}{subparagraph}%
\fi%
\g@addto@macro\spx@preAthefigure{\ifnum\c@subsubparagraph>\z@\arabic{subsubparagraph}.}%
\g@addto@macro\spx@preAthefigure{\ifnum\c@subsubparagraph>\z@.\arabic{subsubparagraph}}%
\g@addto@macro\spx@preBthefigure{\fi}%
\fi
\expandafter\g@addto@macro
\expandafter\spx@preAthefigure\expandafter{\spx@preBthefigure}%
\let\thefigure\spx@preAthefigure
\let\thetable\spx@preAthefigure
\let\theliteralblock\spx@preAthefigure
\g@addto@macro\thefigure{\arabic{figure}}%
\g@addto@macro\thetable{\arabic{table}}%
\g@addto@macro\theliteralblock{\arabic{literalblock}}%
\g@addto@macro\thefigure{.\arabic{figure}}%
\g@addto@macro\thetable{.\arabic{table}}%
\g@addto@macro\theliteralblock{.\arabic{literalblock}}%
\ifspx@opt@mathnumfig
\let\theequation\spx@preAthefigure
\g@addto@macro\theequation{\arabic{equation}}%
\g@addto@macro\theequation{\spx@opt@mathnumsep\arabic{equation}}%
jfbu marked this conversation as resolved.
Show resolved Hide resolved
\fi
\fi
}% end of big \AtBeginDocument
Expand Down
5 changes: 4 additions & 1 deletion sphinx/writers/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,10 @@ def __init__(self, document: nodes.document, builder: LaTeXBuilder,
sphinxpkgoptions.append('nonumfigreset')

if self.config.numfig and self.config.math_numfig:
sphinxpkgoptions.append('mathnumfig')
sphinxpkgoptions.extend([
'mathnumfig',
'mathnumsep=%s' % self.config.math_numsep,
jfbu marked this conversation as resolved.
Show resolved Hide resolved
])

if (self.config.language not in {'en', 'ja'} and
'fncychap' not in self.config.latex_elements):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_builders/test_build_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,10 @@ def test_latex_obey_numfig_secnum_depth_is_zero(app, status, warning):
app.build(force_all=True)

result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
assert '\\usepackage[,nonumfigreset,mathnumfig]{sphinx}' in result
assert '\\usepackage[,nonumfigreset,mathnumfig,mathnumsep=.]{sphinx}' in result
jfbu marked this conversation as resolved.
Show resolved Hide resolved

result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
assert '\\usepackage[,nonumfigreset,mathnumfig]{sphinx}' in result
assert '\\usepackage[,nonumfigreset,mathnumfig,mathnumsep=.]{sphinx}' in result


@pytest.mark.sphinx(
Expand All @@ -524,10 +524,10 @@ def test_latex_obey_numfig_secnum_depth_is_two(app, status, warning):
app.build(force_all=True)

result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8')
assert '\\usepackage[,numfigreset=2,mathnumfig]{sphinx}' in result
assert '\\usepackage[,numfigreset=2,mathnumfig,mathnumsep=.]{sphinx}' in result

result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8')
assert '\\usepackage[,numfigreset=3,mathnumfig]{sphinx}' in result
assert '\\usepackage[,numfigreset=3,mathnumfig,mathnumsep=.]{sphinx}' in result


@pytest.mark.sphinx(
Expand Down