From 9f9aac2fb11f2c227c9cb5500ce7af7fcf94ffdd Mon Sep 17 00:00:00 2001 From: grubert Date: Mon, 12 Nov 2007 13:34:59 +0000 Subject: [PATCH] latex2e writer : Move usepackage hyperref after stylesheet inclusion. git-svn-id: https://docutils.svn.sourceforge.net/svnroot/docutils/trunk@5462 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/HISTORY.txt | 1 + docutils/docutils/writers/latex2e/__init__.py | 9 +++++++-- docutils/test/functional/expected/latex_docinfo.tex | 4 +++- docutils/test/functional/expected/standalone_rst_latex.tex | 4 +++- docutils/test/test_writers/test_latex2e.py | 4 +++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 599f76f5a..a205c4088 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -116,6 +116,7 @@ Changes Since 0.4 * docutils/writers/latex2e/__init__.py: + - Move usepackage hyperref after stylesheet inclusion. - Fix: scrartcl does not have chapter but scrreprt. - Add newline after ``\end{verbatim}``. - Merge smaller differences from latex2e_adaptive_preamble. diff --git a/docutils/docutils/writers/latex2e/__init__.py b/docutils/docutils/writers/latex2e/__init__.py index dc865c653..2c6ff6e63 100644 --- a/docutils/docutils/writers/latex2e/__init__.py +++ b/docutils/docutils/writers/latex2e/__init__.py @@ -569,7 +569,9 @@ class LaTeXTranslator(nodes.NodeVisitor): # --------- latex_head = '\\documentclass[%s]{%s}\n' - linking = '\\usepackage[colorlinks=%s,linkcolor=%s,urlcolor=%s]{hyperref}\n' + linking = "\\ifthenelse{\\isundefined{\\hypersetup}}{\n" \ + +"\\usepackage[colorlinks=%s,linkcolor=%s,urlcolor=%s]{hyperref}\n" \ + +"}{}\n" stylesheet = '\\input{%s}\n' # add a generated on day , machine by user using docutils version. generator = '% generated by Docutils \n' @@ -693,7 +695,6 @@ class LaTeXTranslator(nodes.NodeVisitor): '\\usepackage{color}\n', '\\usepackage{multirow}\n', '\\usepackage{ifthen}\n', # before hyperref! - self.linking % (self.colorlinks, self.hyperlink_color, self.hyperlink_color), self.typearea, self.generator, # latex lengths @@ -717,6 +718,10 @@ class LaTeXTranslator(nodes.NodeVisitor): if stylesheet: settings.record_dependencies.add(stylesheet) self.head_prefix.append(self.stylesheet % (stylesheet)) + # hyperref after stylesheet + # TODO conditionally if no hyperref is used dont include + self.head_prefix.append( self.linking % ( + self.colorlinks, self.hyperlink_color, self.hyperlink_color)) if self.linking: # and maybe check for pdf self.pdfinfo = [ ] diff --git a/docutils/test/functional/expected/latex_docinfo.tex b/docutils/test/functional/expected/latex_docinfo.tex index b1a9a1962..a093c7965 100644 --- a/docutils/test/functional/expected/latex_docinfo.tex +++ b/docutils/test/functional/expected/latex_docinfo.tex @@ -12,7 +12,6 @@ \usepackage{color} \usepackage{multirow} \usepackage{ifthen} -\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} \usepackage[DIV12]{typearea} % generated by Docutils \newlength{\admonitionwidth} @@ -55,6 +54,9 @@ \newcommand{\rubric}[1]{\subsection*{~\hfill {\it #1} \hfill ~}} \newcommand{\titlereference}[1]{\textsl{#1}} % end of "some commands" +\ifthenelse{\isundefined{\hypersetup}}{ +\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} +}{} \title{} \author{Foo Fred~\\ Food Foomatics {\&} Friends~\\ diff --git a/docutils/test/functional/expected/standalone_rst_latex.tex b/docutils/test/functional/expected/standalone_rst_latex.tex index 15393fbed..a4c9c9f6a 100644 --- a/docutils/test/functional/expected/standalone_rst_latex.tex +++ b/docutils/test/functional/expected/standalone_rst_latex.tex @@ -12,7 +12,6 @@ \usepackage{color} \usepackage{multirow} \usepackage{ifthen} -\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} \usepackage[DIV12]{typearea} % generated by Docutils \newlength{\admonitionwidth} @@ -55,6 +54,9 @@ \newcommand{\rubric}[1]{\subsection*{~\hfill {\it #1} \hfill ~}} \newcommand{\titlereference}[1]{\textsl{#1}} % end of "some commands" +\ifthenelse{\isundefined{\hypersetup}}{ +\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} +}{} \title{reStructuredText Test Document\\ \large{Examples of Syntax Constructs} } diff --git a/docutils/test/test_writers/test_latex2e.py b/docutils/test/test_writers/test_latex2e.py index ea7a81f2e..84e263f59 100755 --- a/docutils/test/test_writers/test_latex2e.py +++ b/docutils/test/test_writers/test_latex2e.py @@ -36,7 +36,6 @@ latex_head = """\ \\usepackage{color} \\usepackage{multirow} \\usepackage{ifthen} -\\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} \\usepackage[DIV12]{typearea} % generated by Docutils \\newlength{\\admonitionwidth} @@ -79,6 +78,9 @@ latex_head = """\ \\newcommand{\\rubric}[1]{\\subsection*{~\\hfill {\\it #1} \\hfill ~}} \\newcommand{\\titlereference}[1]{\\textsl{#1}} % end of "some commands" +\\ifthenelse{\\isundefined{\\hypersetup}}{ +\\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} +}{} """ totest = {} -- 2.11.4.GIT