diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2012-10-18 23:13:45 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2012-10-18 23:13:45 +0000 |
| commit | 553ed8e60f9d35b4584e2edeaba4647a04140f37 (patch) | |
| tree | 835bdb71fc03088e48fba409dceadff0b4f9b78d | |
| parent | 9d4623c13eb5b71b30f3ce70f6eef0d94bafb190 (diff) | |
| download | docutils-553ed8e60f9d35b4584e2edeaba4647a04140f37.tar.gz | |
Customizable MathJax URL (based on patch by Dmitry Shachnev).
Also: No line break after opening inline math tag.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7532 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
| -rw-r--r-- | HISTORY.txt | 2 | ||||
| -rw-r--r-- | docs/user/config.txt | 8 | ||||
| -rw-r--r-- | docutils/writers/html4css1/__init__.py | 28 | ||||
| -rw-r--r-- | test/functional/expected/math_output_html.html | 48 | ||||
| -rw-r--r-- | test/functional/expected/math_output_latex.html | 48 | ||||
| -rw-r--r-- | test/functional/expected/math_output_mathjax.html | 48 | ||||
| -rw-r--r-- | test/functional/expected/standalone_rst_html4css1.html | 3 |
7 files changed, 75 insertions, 110 deletions
diff --git a/HISTORY.txt b/HISTORY.txt index 53a4b5fc5..c114ec3d3 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -46,6 +46,8 @@ Changes Since 0.9.1 - Use ``<code>`` tag for inline "code", do not drop nested inline nodes (syntax highlight tokens). + - Customizable MathJax URL (based on patch by Dmitry Shachnev). + - No line break after opening inline math tag. * docutils/writers/manpage.py diff --git a/docs/user/config.txt b/docs/user/config.txt index a31634f89..2bbb9b74a 100644 --- a/docs/user/config.txt +++ b/docs/user/config.txt @@ -797,6 +797,14 @@ _`math_output` fonts for high-quality typesetting that is scalable and prints at full resolution. + A custom URL can be appended after whitespace, + for example a local install + ``MathJax file:/usr/share/javascript/mathjax/MathJax.js`` or + `access the MathJax CDN using a https secure connection`__ + ``mathjax https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=config=TeX-AMS-MML_HTMLorMML``. + + __ http://www.mathjax.org/resources/faqs/#problem-https + Pro: Works 'out of the box' across multiple browsers and platforms. diff --git a/docutils/writers/html4css1/__init__.py b/docutils/writers/html4css1/__init__.py index 569c5a211..acc11aa1d 100644 --- a/docutils/writers/html4css1/__init__.py +++ b/docutils/writers/html4css1/__init__.py @@ -263,12 +263,7 @@ class HTMLTranslator(nodes.NodeVisitor): # __http://www.mathjax.org/download/mathjax-cdn-terms-of-service/ mathjax_url = ('http://cdn.mathjax.org/mathjax/latest/MathJax.js?' 'config=TeX-AMS-MML_HTMLorMML') - # TODO: make this configurable: - # - # a) as extra option or - # b) appended to math-output="MathJax"? - # - # If b), which delimiter/delimter-set (':', ',', ' ')? + # may be overwritten by custom URL appended to "mathjax" stylesheet_link = '<link rel="stylesheet" href="%s" type="text/css" />\n' embedded_stylesheet = '<style type="text/css">\n\n%s\n</style>\n' @@ -302,8 +297,14 @@ class HTMLTranslator(nodes.NodeVisitor): self.body_suffix = ['</body>\n</html>\n'] self.section_level = 0 self.initial_header_level = int(settings.initial_header_level) - - self.math_output = settings.math_output.lower() + + self.math_output = settings.math_output.split(None, 1) + if len(self.math_output) == 2: + self.math_output_option = self.math_output[1] + else: + self.math_output_option = None + self.math_output = self.math_output[0].lower() + # A heterogenous stack used in conjunction with the tree traversal. # Make sure that the pops correspond to the pushes: self.context = [] @@ -1168,7 +1169,7 @@ class HTMLTranslator(nodes.NodeVisitor): def visit_math(self, node, math_env=''): # If the method is called from visit_math_block(), math_env != ''. - + # As there is no native HTML math support, we provide alternatives: # LaTeX and MathJax math_output modes simply wrap the content, # HTML and MathML math_output modes also convert the math_code. @@ -1176,7 +1177,7 @@ class HTMLTranslator(nodes.NodeVisitor): self.document.reporter.error( 'math-output format "%s" not supported ' 'falling back to "latex"'% self.math_output) - self.math_output = 'latex' + self.math_output = 'latex' # # HTML container tags = {# math_output: (block, inline, class-arguments) @@ -1205,7 +1206,8 @@ class HTMLTranslator(nodes.NodeVisitor): if self.math_output in ('latex', 'mathjax'): math_code = self.encode(math_code) if self.math_output == 'mathjax': - self.math_header = self.mathjax_script % self.mathjax_url + self.math_header = self.mathjax_script % ( + self.math_output_option or self.mathjax_url) elif self.math_output == 'html': math_code = math2html(math_code) elif self.math_output == 'mathml': @@ -1228,7 +1230,9 @@ class HTMLTranslator(nodes.NodeVisitor): raise nodes.SkipNode # append to document body if tag: - self.body.append(self.starttag(node, tag, CLASS=clsarg)) + self.body.append(self.starttag(node, tag, + suffix='\n'*bool(math_env), + CLASS=clsarg)) self.body.append(math_code) if math_env: self.body.append('\n') diff --git a/test/functional/expected/math_output_html.html b/test/functional/expected/math_output_html.html index 25f4f4e19..c77336787 100644 --- a/test/functional/expected/math_output_html.html +++ b/test/functional/expected/math_output_html.html @@ -13,10 +13,8 @@ <h1 class="title">Mathematics</h1> <p>Docutils supports inline math with the prefix or postfix <tt class="docutils literal">:math:</tt> -role specificator, <span class="formula"> -<i>n</i>! + sin(<i>x</i><span class="scripts"><sup class="script">2</sup><sub class="script"><i>n</i></sub></span>)</span> - and <span class="formula"> -<i>A</i><sub><span class="text">c</span></sub> = <span class="fraction"><span class="ignored">(</span><span class="numerator"><i>π</i></span><span class="ignored">)/(</span><span class="denominator">4</span><span class="ignored">)</span></span><i>d</i><sup>2</sup></span> +role specificator, <span class="formula"><i>n</i>! + sin(<i>x</i><span class="scripts"><sup class="script">2</sup><sub class="script"><i>n</i></sub></span>)</span> + and <span class="formula"><i>A</i><sub><span class="text">c</span></sub> = <span class="fraction"><span class="ignored">(</span><span class="numerator"><i>π</i></span><span class="ignored">)/(</span><span class="denominator">4</span><span class="ignored">)</span></span><i>d</i><sup>2</sup></span> , as well as displayed math via the <cite>math</cite> directive:</p> <div class="formula"> @@ -59,8 +57,7 @@ See <a class="reference internal" href="#eq-m">eq:M</a> and <a class="reference </span> </span><span class="array"><span class="arrayrow"><span class="bracket align-right">⎞</span></span><span class="arrayrow"><span class="bracket align-right">⎟</span></span><span class="arrayrow"><span class="bracket align-right">⎠</span></span></span> </div> -<p>is <span class="formula"> -|<b>M</b>| = <i>ad</i> − <i>bc</i></span> +<p>is <span class="formula">|<b>M</b>| = <i>ad</i> − <i>bc</i></span> .</p> <p>More than one display math block can be put in one math directive. For example, the following sum and integral with limits:</p> @@ -76,8 +73,7 @@ directives:</p> <div class="formula" id="eq-schrodinger"> <i>i</i>ℏ<span class="fraction"><span class="ignored">(</span><span class="numerator">∂</span><span class="ignored">)/(</span><span class="denominator">∂<i>t</i></span><span class="ignored">)</span></span>Ψ = <i>Ĥ</i>Ψ, </div> -<p>with the <em>wave function</em> <span class="formula"> -Ψ</span> +<p>with the <em>wave function</em> <span class="formula">Ψ</span> , describes how the quantum state of a physical system changes in time.</p> <dl class="docutils"> @@ -89,44 +85,32 @@ physical system changes in time.</p> <col width="33%" /> </colgroup> <tbody valign="top"> -<tr><td><span class="formula"> -<i>á</i></span> +<tr><td><span class="formula"><i>á</i></span> <tt class="docutils literal">\acute{a}</tt></td> -<td><span class="formula"> -<i>ṫ</i></span> +<td><span class="formula"><i>ṫ</i></span> <tt class="docutils literal">\dot{t}</tt></td> -<td><span class="formula"> -<i>γ̂</i></span> +<td><span class="formula"><i>γ̂</i></span> <tt class="docutils literal"><span class="pre">\hat{\gamma}</span></tt></td> </tr> -<tr><td><span class="formula"> -<i>à</i></span> +<tr><td><span class="formula"><i>à</i></span> <tt class="docutils literal">\grave{a}</tt></td> -<td><span class="formula"> -<i>ẗ</i></span> +<td><span class="formula"><i>ẗ</i></span> <tt class="docutils literal">\ddot{t}</tt></td> -<td><span class="formula"> -<i>α̃</i></span> +<td><span class="formula"><i>α̃</i></span> <tt class="docutils literal"><span class="pre">\tilde{\alpha}</span></tt></td> </tr> -<tr><td><span class="formula"> -<i>x̆</i></span> +<tr><td><span class="formula"><i>x̆</i></span> <tt class="docutils literal">\breve{x}</tt></td> -<td><span class="formula"> -<i>t⃛</i></span> +<td><span class="formula"><i>t⃛</i></span> <tt class="docutils literal">\dddot{t}</tt></td> -<td><span class="formula"> -<i>ı⃗</i></span> +<td><span class="formula"><i>ı⃗</i></span> <tt class="docutils literal"><span class="pre">\vec{\imath}</span></tt></td> </tr> -<tr><td><span class="formula"> -<i>ǎ</i></span> +<tr><td><span class="formula"><i>ǎ</i></span> <tt class="docutils literal">\check{a}</tt></td> -<td><span class="formula"> -<span class="bar"><i>a</i></span></span> +<td><span class="formula"><span class="bar"><i>a</i></span></span> <tt class="docutils literal">\bar{a}</tt></td> -<td><span class="formula"> -<i>R⃗</i></span> +<td><span class="formula"><i>R⃗</i></span> <tt class="docutils literal">\vec{R}</tt></td> </tr> </tbody> diff --git a/test/functional/expected/math_output_latex.html b/test/functional/expected/math_output_latex.html index c8605bab8..6a0d5cef1 100644 --- a/test/functional/expected/math_output_latex.html +++ b/test/functional/expected/math_output_latex.html @@ -12,10 +12,8 @@ <h1 class="title">Mathematics</h1> <p>Docutils supports inline math with the prefix or postfix <tt class="docutils literal">:math:</tt> -role specificator, <tt class="math"> -n! + \sin(x_n^2)</tt> - and <tt class="math"> -A_\text{c} = +role specificator, <tt class="math">n! + \sin(x_n^2)</tt> + and <tt class="math">A_\text{c} = \frac{\pi}{4} d^2</tt> , as well as displayed math via the <cite>math</cite> directive:</p> @@ -32,8 +30,7 @@ See <a class="reference internal" href="#eq-m">eq:M</a> and <a class="reference <pre class="math" id="eq-m"> \mathbf{M} = \left(\begin{matrix}a&b\\c&d\end{matrix}\right) </pre> -<p>is <tt class="math"> -|\mathbf{M}| = ad - bc</tt> +<p>is <tt class="math">|\mathbf{M}| = ad - bc</tt> .</p> <p>More than one display math block can be put in one math directive. For example, the following sum and integral with limits:</p> @@ -49,8 +46,7 @@ directives:</p> <pre class="math" id="eq-schrodinger"> i\hbar \frac{\partial }{\partial t}\Psi = \hat{H}\Psi , </pre> -<p>with the <em>wave function</em> <tt class="math"> -\Psi </tt> +<p>with the <em>wave function</em> <tt class="math">\Psi </tt> , describes how the quantum state of a physical system changes in time.</p> <dl class="docutils"> @@ -62,44 +58,32 @@ physical system changes in time.</p> <col width="33%" /> </colgroup> <tbody valign="top"> -<tr><td><tt class="math"> -\acute{a}</tt> +<tr><td><tt class="math">\acute{a}</tt> <tt class="docutils literal">\acute{a}</tt></td> -<td><tt class="math"> -\dot{t}</tt> +<td><tt class="math">\dot{t}</tt> <tt class="docutils literal">\dot{t}</tt></td> -<td><tt class="math"> -\hat{\gamma}</tt> +<td><tt class="math">\hat{\gamma}</tt> <tt class="docutils literal"><span class="pre">\hat{\gamma}</span></tt></td> </tr> -<tr><td><tt class="math"> -\grave{a}</tt> +<tr><td><tt class="math">\grave{a}</tt> <tt class="docutils literal">\grave{a}</tt></td> -<td><tt class="math"> -\ddot{t}</tt> +<td><tt class="math">\ddot{t}</tt> <tt class="docutils literal">\ddot{t}</tt></td> -<td><tt class="math"> -\tilde{\alpha}</tt> +<td><tt class="math">\tilde{\alpha}</tt> <tt class="docutils literal"><span class="pre">\tilde{\alpha}</span></tt></td> </tr> -<tr><td><tt class="math"> -\breve{x}</tt> +<tr><td><tt class="math">\breve{x}</tt> <tt class="docutils literal">\breve{x}</tt></td> -<td><tt class="math"> -\dddot{t}</tt> +<td><tt class="math">\dddot{t}</tt> <tt class="docutils literal">\dddot{t}</tt></td> -<td><tt class="math"> -\vec{\imath}</tt> +<td><tt class="math">\vec{\imath}</tt> <tt class="docutils literal"><span class="pre">\vec{\imath}</span></tt></td> </tr> -<tr><td><tt class="math"> -\check{a}</tt> +<tr><td><tt class="math">\check{a}</tt> <tt class="docutils literal">\check{a}</tt></td> -<td><tt class="math"> -\bar{a}</tt> +<td><tt class="math">\bar{a}</tt> <tt class="docutils literal">\bar{a}</tt></td> -<td><tt class="math"> -\vec{R}</tt> +<td><tt class="math">\vec{R}</tt> <tt class="docutils literal">\vec{R}</tt></td> </tr> </tbody> diff --git a/test/functional/expected/math_output_mathjax.html b/test/functional/expected/math_output_mathjax.html index 2d8fb52f1..cf79bb3a3 100644 --- a/test/functional/expected/math_output_mathjax.html +++ b/test/functional/expected/math_output_mathjax.html @@ -13,10 +13,8 @@ <h1 class="title">Mathematics</h1> <p>Docutils supports inline math with the prefix or postfix <tt class="docutils literal">:math:</tt> -role specificator, <span class="math"> -\(n! + \sin(x_n^2)\)</span> - and <span class="math"> -\(A_\text{c} = +role specificator, <span class="math">\(n! + \sin(x_n^2)\)</span> + and <span class="math">\(A_\text{c} = \frac{\pi}{4} d^2\)</span> , as well as displayed math via the <cite>math</cite> directive:</p> @@ -39,8 +37,7 @@ See <a class="reference internal" href="#eq-m">eq:M</a> and <a class="reference \mathbf{M} = \left(\begin{matrix}a&b\\c&d\end{matrix}\right) \end{equation*} </div> -<p>is <span class="math"> -\(|\mathbf{M}| = ad - bc\)</span> +<p>is <span class="math">\(|\mathbf{M}| = ad - bc\)</span> .</p> <p>More than one display math block can be put in one math directive. For example, the following sum and integral with limits:</p> @@ -62,8 +59,7 @@ directives:</p> i\hbar \frac{\partial }{\partial t}\Psi = \hat{H}\Psi , \end{equation*} </div> -<p>with the <em>wave function</em> <span class="math"> -\(\Psi \)</span> +<p>with the <em>wave function</em> <span class="math">\(\Psi \)</span> , describes how the quantum state of a physical system changes in time.</p> <dl class="docutils"> @@ -75,44 +71,32 @@ physical system changes in time.</p> <col width="33%" /> </colgroup> <tbody valign="top"> -<tr><td><span class="math"> -\(\acute{a}\)</span> +<tr><td><span class="math">\(\acute{a}\)</span> <tt class="docutils literal">\acute{a}</tt></td> -<td><span class="math"> -\(\dot{t}\)</span> +<td><span class="math">\(\dot{t}\)</span> <tt class="docutils literal">\dot{t}</tt></td> -<td><span class="math"> -\(\hat{\gamma}\)</span> +<td><span class="math">\(\hat{\gamma}\)</span> <tt class="docutils literal"><span class="pre">\hat{\gamma}</span></tt></td> </tr> -<tr><td><span class="math"> -\(\grave{a}\)</span> +<tr><td><span class="math">\(\grave{a}\)</span> <tt class="docutils literal">\grave{a}</tt></td> -<td><span class="math"> -\(\ddot{t}\)</span> +<td><span class="math">\(\ddot{t}\)</span> <tt class="docutils literal">\ddot{t}</tt></td> -<td><span class="math"> -\(\tilde{\alpha}\)</span> +<td><span class="math">\(\tilde{\alpha}\)</span> <tt class="docutils literal"><span class="pre">\tilde{\alpha}</span></tt></td> </tr> -<tr><td><span class="math"> -\(\breve{x}\)</span> +<tr><td><span class="math">\(\breve{x}\)</span> <tt class="docutils literal">\breve{x}</tt></td> -<td><span class="math"> -\(\dddot{t}\)</span> +<td><span class="math">\(\dddot{t}\)</span> <tt class="docutils literal">\dddot{t}</tt></td> -<td><span class="math"> -\(\vec{\imath}\)</span> +<td><span class="math">\(\vec{\imath}\)</span> <tt class="docutils literal"><span class="pre">\vec{\imath}</span></tt></td> </tr> -<tr><td><span class="math"> -\(\check{a}\)</span> +<tr><td><span class="math">\(\check{a}\)</span> <tt class="docutils literal">\check{a}</tt></td> -<td><span class="math"> -\(\bar{a}\)</span> +<td><span class="math">\(\bar{a}\)</span> <tt class="docutils literal">\bar{a}</tt></td> -<td><span class="math"> -\(\vec{R}\)</span> +<td><span class="math">\(\vec{R}\)</span> <tt class="docutils literal">\vec{R}</tt></td> </tr> </tbody> diff --git a/test/functional/expected/standalone_rst_html4css1.html b/test/functional/expected/standalone_rst_html4css1.html index 9e08674cc..87a5e91be 100644 --- a/test/functional/expected/standalone_rst_html4css1.html +++ b/test/functional/expected/standalone_rst_html4css1.html @@ -862,8 +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="math">\(\alpha = f(x)\)</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> |
