summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2013-03-04 21:17:09 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2013-03-04 21:17:09 +0000
commit610e75d12dccf4a107ad298d896519640b631a93 (patch)
tree976cd2d942bbc364956381ed2944d001367895a2
parentfe41d1da98b77895d0885962ffa62baa6948360d (diff)
downloaddocutils-610e75d12dccf4a107ad298d896519640b631a93.tar.gz
New default for `math-output` setting: "HTML math.css".
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7623 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r--HISTORY.txt3
-rw-r--r--RELEASE-NOTES.txt18
-rw-r--r--docs/user/config.txt20
-rw-r--r--docutils/writers/html4css1/__init__.py21
-rw-r--r--test/functional/expected/standalone_rst_html4css1.html4
-rw-r--r--test/functional/tests/standalone_rst_html4css1.py5
-rwxr-xr-xtest/test_writers/test_html4css1_misc.py23
7 files changed, 62 insertions, 32 deletions
diff --git a/HISTORY.txt b/HISTORY.txt
index eb9bb8f60..7f7babaf3 100644
--- a/HISTORY.txt
+++ b/HISTORY.txt
@@ -43,6 +43,9 @@ Changes Since 0.10
- New setting `stylesheet_dirs`: Comma-separated list of directories
where stylesheets are found. Used by `stylesheet_path` when expanding
relative path arguments.
+ - New default for math-output_: ``HTML math.css``.
+
+.. _math-output: docs/user/config.html#math-output
* docutils/writers/latex2e/__init__.py
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 0f49f7b99..1ea4bd102 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -43,23 +43,27 @@ Changes Since 0.10
* docutils/writers/html4css1/__init__.py
- New setting `stylesheet_dirs` (see above).
-
+
Now, it is easy to add a custom stylesheet to Docutils' default
stylesheet with, e.g., ``--stylesheet_path='html4css1.css, mystyle.css'``
-
- Changed behaviour of the default settings:
+
+ Changed behaviour of the default settings:
if there is a file ``html4css1.css`` in the working directory of the
process at launch, it is used instead of the one provided by Docutils
in the writer source directory.
+ - New default for `math-output` setting: "HTML math.css".
+ Secure and self-contained alternative to the old default
+ ("MathJax" requiring JavaScript from the MathJax server network).
+
Release 0.10 (2012-12-16)
=========================
-.. Note::
+.. Note::
Docutils 0.9.x is the last version supporting Python 2.3.
-
+
Docutils 0.10 is compatible with Python versions from 2.4 to 3.2
(cf. `Python 3 compatibility`_).
@@ -70,7 +74,7 @@ Release 0.10 (2012-12-16)
- ``docutils/math``, ``docutils/error_reporting.py``, and
``docutils/urischemes.py`` moved to the utils package.
Code importing these modules needs to adapt, e.g.::
-
+
try:
import docutils.math as math
except ImportError:
@@ -80,7 +84,7 @@ Release 0.10 (2012-12-16)
* docutils/io.py
- - FileInput/FileOutput: no system-exit on IOError.
+ - FileInput/FileOutput: no system-exit on IOError.
The `handle_io_errors` option is ignored.
.. _Python 3 compatibility: README.html#python-3-compatibility
diff --git a/docs/user/config.txt b/docs/user/config.txt
index 2a06bc843..a10502c9b 100644
--- a/docs/user/config.txt
+++ b/docs/user/config.txt
@@ -922,6 +922,16 @@ math_output
The format of mathematical content (`math directive`_ and role) in
the output document. Supported values are (case insensitive):
+:HTML:
+ Format math in standard HTML enhanced by CSS rules.
+ Requires the ``math.css`` stylesheet (in the system
+ `stylesheet directory <stylesheet_dirs [html4css1 writer]_>`_
+
+ A `stylesheet_path <stylesheet_path [html4css1 writer]_>`_
+ can be appended after whitespace, the specified
+ stylesheet(s) will only be referenced or embedded, if required
+ (i.e. if there is mathematical content in the document).
+
:MathJax:
Format math for display with MathJax_, a JavaScript-based math
rendering engine that uses HTML/CSS, JavaScript, and unicode
@@ -950,12 +960,6 @@ the output document. Supported values are (case insensitive):
__ http://www.mathjax.org/resources/faqs/#problem-https
-:HTML:
- Format math in standard HTML enhanced by CSS rules
-
- Requires the ``math.css`` stylesheet (in the system
- `stylesheet directory <stylesheet_dirs [html4css1 writer]_>`_
-
:MathML:
Embed math content as presentational MathML_.
@@ -978,7 +982,7 @@ the output document. Supported values are (case insensitive):
The failsave fallback.
-Default: MathJax. Option: ``--math-output``.
+Default: "HTML math.css". Option: ``--math-output``.
New in Docutils 0.8.
@@ -1390,7 +1394,7 @@ A comma-separated list of style files. Relative paths are expanded if a
matching file is found in the stylesheet_dirs__.
If embed_stylesheet__ is False, paths are rewritten relative to the
output file path. Run ``latex`` from the directory containing
-the output file.
+the output file.
The stylesheet__ option is preferred for files in the `TeX input path`_.
diff --git a/docutils/writers/html4css1/__init__.py b/docutils/writers/html4css1/__init__.py
index 3dd2d1108..0afa5f323 100644
--- a/docutils/writers/html4css1/__init__.py
+++ b/docutils/writers/html4css1/__init__.py
@@ -140,9 +140,9 @@ class Writer(writers.Writer):
['--table-style'],
{'default': ''}),
('Math output format, one of "MathML", "HTML", "MathJax" '
- 'or "LaTeX". Default: "MathJax"',
+ 'or "LaTeX". Default: "HTML math.css"',
['--math-output'],
- {'default': 'MathJax'}),
+ {'default': 'HTML math.css'}),
('Omit the XML declaration. Use with caution.',
['--no-xml-declaration'],
{'dest': 'xml_declaration', 'default': 1, 'action': 'store_false',
@@ -328,7 +328,7 @@ class HTMLTranslator(nodes.NodeVisitor):
self.in_document_title = 0 # len(self.body) or 0
self.in_mailto = False
self.author_in_authors = False
- self.math_header = ''
+ self.math_header = []
def astext(self):
return ''.join(self.head_prefix + self.head
@@ -773,7 +773,10 @@ class HTMLTranslator(nodes.NodeVisitor):
self.meta.insert(0, self.content_type % self.settings.output_encoding)
self.head.insert(0, self.content_type % self.settings.output_encoding)
if self.math_header:
- self.head.append(self.math_header)
+ if self.math_output == 'mathjax':
+ self.head.extend(self.math_header)
+ else:
+ self.stylesheet.extend(self.math_header)
# skip content-type meta tag with interpolated charset value:
self.html_head.extend(self.head[1:])
self.body_prefix.append(self.starttag(node, 'div', CLASS='document'))
@@ -1207,13 +1210,17 @@ class HTMLTranslator(nodes.NodeVisitor):
# settings and conversion
if self.math_output in ('latex', 'mathjax'):
math_code = self.encode(math_code)
- if self.math_output == 'mathjax':
+ if self.math_output == 'mathjax' and not self.math_header:
if self.math_output_options:
self.mathjax_url = self.math_output_options[0]
- self.math_header = self.mathjax_script % self.mathjax_url
+ self.math_header = [self.mathjax_script % self.mathjax_url]
elif self.math_output == 'html':
+ if self.math_output_options and not self.math_header:
+ self.math_header = [self.stylesheet_call(
+ utils.find_file_in_dirs(s, self.settings.stylesheet_dirs))
+ for s in self.math_output_options[0].split(',')]
# TODO: fix display mode in matrices and fractions
- # math2html.DocumentParameters.displaymode = (math_env != '')
+ math2html.DocumentParameters.displaymode = (math_env != '')
math_code = math2html.math2html(math_code)
elif self.math_output == 'mathml':
self.doctype = self.doctype_mathml
diff --git a/test/functional/expected/standalone_rst_html4css1.html b/test/functional/expected/standalone_rst_html4css1.html
index cd0f7c282..427f9a202 100644
--- a/test/functional/expected/standalone_rst_html4css1.html
+++ b/test/functional/expected/standalone_rst_html4css1.html
@@ -12,8 +12,8 @@
<meta name="copyright" content="This document has been placed in the public domain. You may do with it as you wish. You may copy, modify, redistribute, reattribute, sell, buy, rent, lease, destroy, or improve it, quote it at length, excerpt, incorporate, collate, fold, staple, or mutilate it, or do anything else to it that your or anyone else's heart desires." />
<meta content="reStructuredText, test, parser" name="keywords" />
<meta content="A test document, containing at least one example of each reStructuredText construct." lang="en" name="description" />
-<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="stylesheet" href="../input/data/html4css1.css" type="text/css" />
+<link rel="stylesheet" href="../input/data/math.css" type="text/css" />
</head>
<body>
<div class="header">
@@ -862,7 +862,7 @@ directly (the code will not be parsed/tagged, as the language is not known)
or as base for special code roles, e.g. the LaTeX code in the next
paragraph.</p>
<p>Docutils uses LaTeX syntax for math directives and roles:
-<code class="tex">\alpha = f(x)</code> prints <span class="math">\(\alpha = f(x)\)</span>
+<code class="tex">\alpha = f(x)</code> prints <span class="formula"><i>α</i> = <i>f</i>(<i>x</i>)</span>
.</p>
<p>The <tt class="docutils literal">:code:</tt> option of the <cite>include</cite> directive sets the included content
as a code block, here the rst file <tt class="docutils literal">header_footer.txt</tt> with line numbers:</p>
diff --git a/test/functional/tests/standalone_rst_html4css1.py b/test/functional/tests/standalone_rst_html4css1.py
index a3ac8975f..4298736c5 100644
--- a/test/functional/tests/standalone_rst_html4css1.py
+++ b/test/functional/tests/standalone_rst_html4css1.py
@@ -8,7 +8,6 @@ test_destination = "standalone_rst_html4css1.html"
writer_name = "html4css1"
# Settings:
-# local copy of default stylesheet:
+# local copy of stylesheets:
# (Test runs in ``docutils/test/``, we need relative path from there.)
-settings_overrides['stylesheet_path'] = (
- 'functional/input/data/html4css1.css')
+settings_overrides['stylesheet_dirs'] = ('.', 'functional/input/data')
diff --git a/test/test_writers/test_html4css1_misc.py b/test/test_writers/test_html4css1_misc.py
index b011a1566..0741b9cee 100755
--- a/test/test_writers/test_html4css1_misc.py
+++ b/test/test_writers/test_html4css1_misc.py
@@ -94,11 +94,11 @@ class MathTestCase(DocutilsTestSupport.StandardTestCase):
data = ':math:`42`'
def test_math_output_default(self):
- # Currently MathJax with default URL. Likely to change to HTML!
+ # HTML with math.css stylesheet (since 0.11)
mysettings = {'_disable_config': True,}
- head = core.publish_parts(self.data, writer_name='html4css1',
- settings_overrides=mysettings)['head']
- self.assertIn(self.mathjax_script % self.default_mathjax_url, head)
+ styles = core.publish_parts(self.data, writer_name='html4css1',
+ settings_overrides=mysettings)['stylesheet']
+ self.assertIn('convert LaTeX equations to HTML output.', styles)
def test_math_output_mathjax(self):
# Explicitly specifying math_output=MathJax, case insensitively
@@ -119,13 +119,26 @@ class MathTestCase(DocutilsTestSupport.StandardTestCase):
self.assertIn(self.mathjax_script % self.custom_mathjax_url, head)
def test_math_output_html(self):
- # There should be no MathJax script when math_output is not MathJax
mysettings = {'_disable_config': True,
'math_output': 'HTML'}
head = core.publish_parts(self.data, writer_name='html4css1',
settings_overrides=mysettings)['head']
+ # There should be no MathJax script when math_output is not MathJax
self.assertNotIn('MathJax.js', head)
+ def test_math_output_html_stylesheet(self):
+ mysettings = {'_disable_config': True,
+ 'math_output': 'HTML math.css,custom/style.css',
+ 'stylesheet_dirs': ('.', 'functional/input/data'),
+ 'embed_stylesheet': False}
+ styles = core.publish_parts(self.data, writer_name='html4css1',
+ settings_overrides=mysettings)['stylesheet']
+ self.assertEqual(u"""\
+<link rel="stylesheet" href="functional/input/data/html4css1.css" type="text/css" />
+<link rel="stylesheet" href="functional/input/data/math.css" type="text/css" />
+<link rel="stylesheet" href="custom/style.css" type="text/css" />
+""", styles)
+
def test_math_output_mathjax_no_math(self):
mysettings = {'_disable_config': True,
'math_output': 'MathJax'}