From: <mi...@us...> - 2012-10-18 23:13:52
|
Revision: 7532 http://docutils.svn.sourceforge.net/docutils/?rev=7532&view=rev Author: milde Date: 2012-10-18 23:13:45 +0000 (Thu, 18 Oct 2012) Log Message: ----------- Customizable MathJax URL (based on patch by Dmitry Shachnev). Also: No line break after opening inline math tag. Modified Paths: -------------- trunk/docutils/HISTORY.txt trunk/docutils/docs/user/config.txt trunk/docutils/docutils/writers/html4css1/__init__.py trunk/docutils/test/functional/expected/math_output_html.html trunk/docutils/test/functional/expected/math_output_latex.html trunk/docutils/test/functional/expected/math_output_mathjax.html trunk/docutils/test/functional/expected/standalone_rst_html4css1.html Modified: trunk/docutils/HISTORY.txt =================================================================== --- trunk/docutils/HISTORY.txt 2012-10-18 22:26:11 UTC (rev 7531) +++ trunk/docutils/HISTORY.txt 2012-10-18 23:13:45 UTC (rev 7532) @@ -46,6 +46,8 @@ - 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 Modified: trunk/docutils/docs/user/config.txt =================================================================== --- trunk/docutils/docs/user/config.txt 2012-10-18 22:26:11 UTC (rev 7531) +++ trunk/docutils/docs/user/config.txt 2012-10-18 23:13:45 UTC (rev 7532) @@ -797,6 +797,14 @@ 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. Modified: trunk/docutils/docutils/writers/html4css1/__init__.py =================================================================== --- trunk/docutils/docutils/writers/html4css1/__init__.py 2012-10-18 22:26:11 UTC (rev 7531) +++ trunk/docutils/docutils/writers/html4css1/__init__.py 2012-10-18 23:13:45 UTC (rev 7532) @@ -263,12 +263,7 @@ # __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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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') Modified: trunk/docutils/test/functional/expected/math_output_html.html =================================================================== --- trunk/docutils/test/functional/expected/math_output_html.html 2012-10-18 22:26:11 UTC (rev 7531) +++ trunk/docutils/test/functional/expected/math_output_html.html 2012-10-18 23:13:45 UTC (rev 7532) @@ -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 @@ </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 @@ <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 @@ <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> Modified: trunk/docutils/test/functional/expected/math_output_latex.html =================================================================== --- trunk/docutils/test/functional/expected/math_output_latex.html 2012-10-18 22:26:11 UTC (rev 7531) +++ trunk/docutils/test/functional/expected/math_output_latex.html 2012-10-18 23:13:45 UTC (rev 7532) @@ -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 @@ <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 @@ <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 @@ <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> Modified: trunk/docutils/test/functional/expected/math_output_mathjax.html =================================================================== --- trunk/docutils/test/functional/expected/math_output_mathjax.html 2012-10-18 22:26:11 UTC (rev 7531) +++ trunk/docutils/test/functional/expected/math_output_mathjax.html 2012-10-18 23:13:45 UTC (rev 7532) @@ -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 @@ \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 @@ 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 @@ <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> Modified: trunk/docutils/test/functional/expected/standalone_rst_html4css1.html =================================================================== --- trunk/docutils/test/functional/expected/standalone_rst_html4css1.html 2012-10-18 22:26:11 UTC (rev 7531) +++ trunk/docutils/test/functional/expected/standalone_rst_html4css1.html 2012-10-18 23:13:45 UTC (rev 7532) @@ -862,8 +862,7 @@ 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> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |