From 9cdf4fe00f31cefe9bc4fa4c4f03d16622e6013b Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 11 Oct 2016 18:57:46 +0200 Subject: [PATCH 1/3] (latex) separate loading of hyperref from sphinx.sty new 'hyperref' key in ``latex_elements``. --- doc/config.rst | 19 +++++++++++++++---- sphinx/templates/latex/content.tex_t | 1 + sphinx/texinputs/sphinx.sty | 13 ------------- sphinx/writers/latex.py | 12 ++++++++++++ 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index 8fbbf606a..cdf7eae1a 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1692,6 +1692,10 @@ These options influence LaTeX output. See further :doc:`latex`. to use ``'47363sp'``. To obtain ``72px=1in``, use ``'1bp'``. .. versionadded:: 1.5 + ``'passoptionstopackages'`` + "PassOptionsToPackage" call, default empty. + + .. versionadded:: 1.4 ``'geometry'`` "geometry" package inclusion, the default definition is: @@ -1716,10 +1720,6 @@ These options influence LaTeX output. See further :doc:`latex`. the "Bjarne" style uses numbers spelled out in English). Other "fncychap" styles you can try are "Lenny", "Glenn", "Conny", "Rejne" and "Bjornstrup". You can also set this to ``''`` to disable fncychap. - ``'passoptionstopackages'`` - "PassOptionsToPackage" call, default empty. - - .. versionadded:: 1.4 ``'preamble'`` Additional preamble content, default empty. See :doc:`latex`. ``'postamble'`` @@ -1754,6 +1754,17 @@ These options influence LaTeX output. See further :doc:`latex`. .. versionadded:: 1.2 ``'fontenc'`` "fontenc" package inclusion, default ``'\\usepackage[T1]{fontenc}'``. + ``'hyperref'`` + "hyperref" package inclusion; also loads package "hypcap" and issues + ``\urlstyle{same}``. This is done after :file:`sphinx.sty` file is + loaded and before executing the contents of ``'preamble'`` key. + + .. attention:: + + Loading of packages "hyperref" and "hypcap" is mandatory. + + .. versionadded:: 1.5 + Previously this was done from inside :file:`sphinx.sty`. ``'maketitle'`` "maketitle" call, default ``'\\maketitle'`` (but it has been redefined by the Sphinx ``manual`` and ``howto`` classes.) Override diff --git a/sphinx/templates/latex/content.tex_t b/sphinx/templates/latex/content.tex_t index 9361961c5..1e0028503 100644 --- a/sphinx/templates/latex/content.tex_t +++ b/sphinx/templates/latex/content.tex_t @@ -20,6 +20,7 @@ \usepackage{multirow} \usepackage{eqparbox} <%= usepackages %> +<%= hyperref %> <%= contentsname %> <%= numfig_format %> <%= pageautorefname %> diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index c184f8bb5..bb2da9f1f 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -853,19 +853,6 @@ \fi \fi -% Include hyperref last. -\RequirePackage[colorlinks,breaklinks, - linkcolor=InnerLinkColor,filecolor=OuterLinkColor, - menucolor=OuterLinkColor,urlcolor=OuterLinkColor, - citecolor=InnerLinkColor]{hyperref} -% Fix anchor placement for figures with captions. -% (Note: we don't use a package option here; instead, we give an explicit -% \capstart for figures that actually have a caption.) -\RequirePackage{hypcap} - -% Set up styles of URL: it should be placed after hyperref -\urlstyle{same} - % From docutils.writers.latex2e % inline markup (custom roles) % \DUrole{#1}{#2} tries \DUrole#1{#2} diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 29def59af..a47864443 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -278,6 +278,18 @@ class LaTeXTranslator(nodes.NodeVisitor): 'fontpkg': '\\usepackage{times}', 'fncychap': '\\usepackage[Bjarne]{fncychap}', 'longtable': '\\usepackage{longtable}', + 'hyperref': ('% Include hyperref last.\n' + '\\usepackage[colorlinks,breaklinks,%\n' + ' ' + 'linkcolor=InnerLinkColor,filecolor=OuterLinkColor,%\n' + ' ' + 'menucolor=OuterLinkColor,urlcolor=OuterLinkColor,%\n' + ' ' + 'citecolor=InnerLinkColor]{hyperref}\n' + '% Fix anchor placement for figures with captions.\n' + '\\usepackage{hypcap}% it must be loaded after hyperref.\n' + '% Set up styles of URL: it should be placed after hyperref.\n' + '\\urlstyle{same}'), 'usepackages': '', 'numfig_format': '', 'contentsname': '', From 9972d729abb076441d9cfe24b637a19e471bab50 Mon Sep 17 00:00:00 2001 From: jfbu Date: Thu, 13 Oct 2016 22:41:37 +0200 Subject: [PATCH 2/3] new ``'packages'`` key to ``latex_elements`` serves to load packages after ``sphinx.sty`` itself and before hyperref. --- doc/config.rst | 7 ++++++- sphinx/templates/latex/content.tex_t | 1 + sphinx/writers/latex.py | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/config.rst b/doc/config.rst index cdf7eae1a..adc1892cb 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1720,8 +1720,13 @@ These options influence LaTeX output. See further :doc:`latex`. the "Bjarne" style uses numbers spelled out in English). Other "fncychap" styles you can try are "Lenny", "Glenn", "Conny", "Rejne" and "Bjornstrup". You can also set this to ``''`` to disable fncychap. + ``'packages'`` + Extra user specified ``\\usepackage{}`` commands, default empty, + executed *after* the loading of :file:`sphinx.sty` and *before* the + loading of "hyperref". ``'preamble'`` - Additional preamble content, default empty. See :doc:`latex`. + Additional preamble content, default empty. Executed *after* + the loading of "hyperref" package. See :doc:`latex`. ``'postamble'`` Additional postamble content (before the indices), default empty. ``'figure_align'`` diff --git a/sphinx/templates/latex/content.tex_t b/sphinx/templates/latex/content.tex_t index 1e0028503..6a3fb444d 100644 --- a/sphinx/templates/latex/content.tex_t +++ b/sphinx/templates/latex/content.tex_t @@ -20,6 +20,7 @@ \usepackage{multirow} \usepackage{eqparbox} <%= usepackages %> +<%= packages %> <%= hyperref %> <%= contentsname %> <%= numfig_format %> diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index a47864443..e46285300 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -278,6 +278,7 @@ class LaTeXTranslator(nodes.NodeVisitor): 'fontpkg': '\\usepackage{times}', 'fncychap': '\\usepackage[Bjarne]{fncychap}', 'longtable': '\\usepackage{longtable}', + 'packages': '', 'hyperref': ('% Include hyperref last.\n' '\\usepackage[colorlinks,breaklinks,%\n' ' ' From 536d52063f33a4c90860e7a6d26a9059a90363e6 Mon Sep 17 00:00:00 2001 From: jfbu Date: Fri, 14 Oct 2016 09:04:45 +0200 Subject: [PATCH 3/3] Revert "new ``'packages'`` key to ``latex_elements``" This reverts commit 9972d729abb076441d9cfe24b637a19e471bab50. --- doc/config.rst | 7 +------ sphinx/templates/latex/content.tex_t | 1 - sphinx/writers/latex.py | 1 - 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index adc1892cb..cdf7eae1a 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1720,13 +1720,8 @@ These options influence LaTeX output. See further :doc:`latex`. the "Bjarne" style uses numbers spelled out in English). Other "fncychap" styles you can try are "Lenny", "Glenn", "Conny", "Rejne" and "Bjornstrup". You can also set this to ``''`` to disable fncychap. - ``'packages'`` - Extra user specified ``\\usepackage{}`` commands, default empty, - executed *after* the loading of :file:`sphinx.sty` and *before* the - loading of "hyperref". ``'preamble'`` - Additional preamble content, default empty. Executed *after* - the loading of "hyperref" package. See :doc:`latex`. + Additional preamble content, default empty. See :doc:`latex`. ``'postamble'`` Additional postamble content (before the indices), default empty. ``'figure_align'`` diff --git a/sphinx/templates/latex/content.tex_t b/sphinx/templates/latex/content.tex_t index 6a3fb444d..1e0028503 100644 --- a/sphinx/templates/latex/content.tex_t +++ b/sphinx/templates/latex/content.tex_t @@ -20,7 +20,6 @@ \usepackage{multirow} \usepackage{eqparbox} <%= usepackages %> -<%= packages %> <%= hyperref %> <%= contentsname %> <%= numfig_format %> diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index e46285300..a47864443 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -278,7 +278,6 @@ class LaTeXTranslator(nodes.NodeVisitor): 'fontpkg': '\\usepackage{times}', 'fncychap': '\\usepackage[Bjarne]{fncychap}', 'longtable': '\\usepackage{longtable}', - 'packages': '', 'hyperref': ('% Include hyperref last.\n' '\\usepackage[colorlinks,breaklinks,%\n' ' '