Merge pull request #4332 from jfbu/latex_math_numfig

Let LaTeX obey :confval:`math_numfig` for equation numbering
This commit is contained in:
Jean-François B 2017-12-21 19:32:10 +01:00 committed by GitHub
commit f5dfdfcfe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 10 deletions

View File

@ -46,11 +46,10 @@ or use Python raw strings (``r"raw"``).
.. confval:: math_numfig .. confval:: math_numfig
If ``True``, displayed math equations are numbered across pages in html and If ``True``, displayed math equations are numbered across pages when
related (epub, ...) output when :confval:`numfig` is enabled. :confval:`numfig` is enabled. The :confval:`numfig_secnum_depth` setting
:confval:`numfig_secnum_depth` is respected. The :rst:role:`eq` role must is respected. The :rst:role:`eq`, not :rst:role:`numref`, role
be used to reference equation numbers, not the :rst:role:`numref` role. must be used to reference equation numbers. Default is ``True``.
Default is ``True``.
.. versionadded:: 1.7 .. versionadded:: 1.7

View File

@ -249,6 +249,7 @@
\DeclareStringOption[0]{maxlistdepth}% \newcommand*\spx@opt@maxlistdepth{0} \DeclareStringOption[0]{maxlistdepth}% \newcommand*\spx@opt@maxlistdepth{0}
\DeclareStringOption[-1]{numfigreset} \DeclareStringOption[-1]{numfigreset}
\DeclareBoolOption[false]{nonumfigreset} \DeclareBoolOption[false]{nonumfigreset}
\DeclareBoolOption[false]{mathnumfig}
% \DeclareBoolOption[false]{usespart}% not used % \DeclareBoolOption[false]{usespart}% not used
% dimensions, we declare the \dimen registers here. % dimensions, we declare the \dimen registers here.
\newdimen\sphinxverbatimsep \newdimen\sphinxverbatimsep
@ -353,6 +354,7 @@
\DisableKeyvalOption{sphinx}{maxlistdepth} \DisableKeyvalOption{sphinx}{maxlistdepth}
\DisableKeyvalOption{sphinx}{numfigreset} \DisableKeyvalOption{sphinx}{numfigreset}
\DisableKeyvalOption{sphinx}{nonumfigreset} \DisableKeyvalOption{sphinx}{nonumfigreset}
\DisableKeyvalOption{sphinx}{mathnumfig}
% user interface: options can be changed midway in a document! % user interface: options can be changed midway in a document!
\newcommand\sphinxsetup[1]{\setkeys{sphinx}{#1}} \newcommand\sphinxsetup[1]{\setkeys{sphinx}{#1}}
@ -682,11 +684,16 @@
\@removefromreset{figure}{chapter}% \@removefromreset{figure}{chapter}%
\@removefromreset{table}{chapter}% \@removefromreset{table}{chapter}%
\@removefromreset{literalblock}{chapter}% \@removefromreset{literalblock}{chapter}%
\ifspx@opt@mathnumfig
\@removefromreset{equation}{chapter}%
\fi
}% }%
\def\thefigure{\arabic{figure}}% \def\thefigure{\arabic{figure}}%
\def\thetable {\arabic{table}}% \def\thetable {\arabic{table}}%
\def\theliteralblock{\arabic{literalblock}}% \def\theliteralblock{\arabic{literalblock}}%
%\let\theHliteralblock\theliteralblock \ifspx@opt@mathnumfig
\def\theequation{\arabic{equation}}%
\fi
\else \else
\let\spx@preAthefigure\@empty \let\spx@preAthefigure\@empty
\let\spx@preBthefigure\@empty \let\spx@preBthefigure\@empty
@ -709,6 +716,9 @@
\@addtoreset{figure}{section}% \@addtoreset{figure}{section}%
\@addtoreset{table}{section}% \@addtoreset{table}{section}%
\@addtoreset{literalblock}{section}% \@addtoreset{literalblock}{section}%
\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}.}%
\g@addto@macro\spx@preBthefigure{\fi}% \g@addto@macro\spx@preBthefigure{\fi}%
\fi \fi
@ -716,6 +726,9 @@
\@addtoreset{figure}{subsection}% \@addtoreset{figure}{subsection}%
\@addtoreset{table}{subsection}% \@addtoreset{table}{subsection}%
\@addtoreset{literalblock}{subsection}% \@addtoreset{literalblock}{subsection}%
\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}% \g@addto@macro\spx@preBthefigure{\fi}%
\fi \fi
@ -723,6 +736,9 @@
\@addtoreset{figure}{subsubsection}% \@addtoreset{figure}{subsubsection}%
\@addtoreset{table}{subsubsection}% \@addtoreset{table}{subsubsection}%
\@addtoreset{literalblock}{subsubsection}% \@addtoreset{literalblock}{subsubsection}%
\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}% \g@addto@macro\spx@preBthefigure{\fi}%
\fi \fi
@ -730,6 +746,9 @@
\@addtoreset{figure}{paragraph}% \@addtoreset{figure}{paragraph}%
\@addtoreset{table}{paragraph}% \@addtoreset{table}{paragraph}%
\@addtoreset{literalblock}{paragraph}% \@addtoreset{literalblock}{paragraph}%
\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}% \g@addto@macro\spx@preBthefigure{\fi}%
\fi \fi
@ -737,6 +756,9 @@
\@addtoreset{figure}{subparagraph}% \@addtoreset{figure}{subparagraph}%
\@addtoreset{table}{subparagraph}% \@addtoreset{table}{subparagraph}%
\@addtoreset{literalblock}{subparagraph}% \@addtoreset{literalblock}{subparagraph}%
\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}% \g@addto@macro\spx@preBthefigure{\fi}%
\fi \fi
@ -748,6 +770,10 @@
\g@addto@macro\thefigure{\arabic{figure}}% \g@addto@macro\thefigure{\arabic{figure}}%
\g@addto@macro\thetable{\arabic{table}}% \g@addto@macro\thetable{\arabic{table}}%
\g@addto@macro\theliteralblock{\arabic{literalblock}}% \g@addto@macro\theliteralblock{\arabic{literalblock}}%
\ifspx@opt@mathnumfig
\let\theequation\spx@preAthefigure
\g@addto@macro\theequation{\arabic{equation}}%
\fi
\fi \fi

View File

@ -601,6 +601,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
(',numfigreset=%s' % self.numfig_secnum_depth) (',numfigreset=%s' % self.numfig_secnum_depth)
else: else:
self.elements['sphinxpkgoptions'] += ',nonumfigreset' self.elements['sphinxpkgoptions'] += ',nonumfigreset'
try:
if builder.config.math_numfig:
self.elements['sphinxpkgoptions'] += ',mathnumfig'
except AttributeError:
pass
if builder.config.latex_logo: if builder.config.latex_logo:
# no need for \\noindent here, used in flushright # no need for \\noindent here, used in flushright

View File

@ -2,6 +2,8 @@
master_doc = 'index' master_doc = 'index'
extensions = ['sphinx.ext.imgmath'] # for math_numfig
latex_documents = [ latex_documents = [
('indexmanual', 'SphinxManual.tex', 'Test numfig manual', ('indexmanual', 'SphinxManual.tex', 'Test numfig manual',
'Sphinx', 'manual'), 'Sphinx', 'manual'),

View File

@ -353,10 +353,10 @@ def test_latex_obey_numfig_secnum_depth_is_zero(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'SphinxManual.tex').text(encoding='utf8') result = (app.outdir / 'SphinxManual.tex').text(encoding='utf8')
assert '\\usepackage[,nonumfigreset]{sphinx}' in result assert '\\usepackage[,nonumfigreset,mathnumfig]{sphinx}' in result
result = (app.outdir / 'SphinxHowTo.tex').text(encoding='utf8') result = (app.outdir / 'SphinxHowTo.tex').text(encoding='utf8')
assert '\\usepackage[,nonumfigreset]{sphinx}' in result assert '\\usepackage[,nonumfigreset,mathnumfig]{sphinx}' in result
@pytest.mark.sphinx( @pytest.mark.sphinx(
@ -366,10 +366,23 @@ def test_latex_obey_numfig_secnum_depth_is_two(app, status, warning):
app.builder.build_all() app.builder.build_all()
result = (app.outdir / 'SphinxManual.tex').text(encoding='utf8') result = (app.outdir / 'SphinxManual.tex').text(encoding='utf8')
assert '\\usepackage[,numfigreset=2]{sphinx}' in result assert '\\usepackage[,numfigreset=2,mathnumfig]{sphinx}' in result
result = (app.outdir / 'SphinxHowTo.tex').text(encoding='utf8') result = (app.outdir / 'SphinxHowTo.tex').text(encoding='utf8')
assert '\\usepackage[,numfigreset=3]{sphinx}' in result assert '\\usepackage[,numfigreset=3,mathnumfig]{sphinx}' in result
@pytest.mark.sphinx(
'latex', testroot='latex-numfig',
confoverrides={'numfig': True, 'math_numfig': False})
def test_latex_obey_numfig_but_math_numfig_false(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'SphinxManual.tex').text(encoding='utf8')
assert '\\usepackage[,numfigreset=1]{sphinx}' in result
result = (app.outdir / 'SphinxHowTo.tex').text(encoding='utf8')
assert '\\usepackage[,numfigreset=2]{sphinx}' in result
@pytest.mark.sphinx('latex') @pytest.mark.sphinx('latex')