From 081337bb81db5fc54aedbe2b5ede2547aa774cc6 Mon Sep 17 00:00:00 2001 From: milde Date: Wed, 28 May 2014 16:02:56 +0000 Subject: [PATCH] Do not add newline after inline math (produces unwanted whitespace). Thanks to Yury G. Kudryashov for the patch. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@7749 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/HISTORY.txt | 11 +++-- docutils/docutils/writers/html4css1/__init__.py | 6 ++- .../test/functional/expected/math_output_html.html | 46 +++++++-------------- .../functional/expected/math_output_latex.html | 48 ++++++++-------------- .../functional/expected/math_output_mathjax.html | 48 ++++++++-------------- .../expected/standalone_rst_html4css1.html | 3 +- 6 files changed, 60 insertions(+), 102 deletions(-) diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 7820573f6..95c60f630 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -25,11 +25,16 @@ Changes Since 0.11 - Improve error report when a non-ASCII character is specified as delimiter, quote or escape character under Python 2. Fixes [ 249 ] and [ 250 ]. - + +* docutils/writers/html4css1/__init__.py + + - Don't add newline after inline math. + Thanks to Yury G. Kudryashov for the patch. + * docutils/writers/latex2e/__init__.py - Fix [ 239 ] Latex writer glues paragraphs with figure floats. - - Apply [ 116 ] by Kirill Smelkov. Don't hardcode \large for subtitle. + - Apply [ 116 ] by Kirill Smelkov. Don't hardcode \large for subtitle. * docutils/writers/odf_odt/__init__.py @@ -42,7 +47,7 @@ Changes Since 0.11 * test/test_nodes.py - Apply [ 115 ] respect fixed 2to3 string literal conversion behavior. - + Release 0.11 (2013-07-22) ========================= diff --git a/docutils/docutils/writers/html4css1/__init__.py b/docutils/docutils/writers/html4css1/__init__.py index f91a24983..15b649710 100644 --- a/docutils/docutils/writers/html4css1/__init__.py +++ b/docutils/docutils/writers/html4css1/__init__.py @@ -1245,10 +1245,12 @@ class HTMLTranslator(nodes.NodeVisitor): suffix='\n'*bool(math_env), CLASS=clsarg)) self.body.append(math_code) - if math_env: + if math_env: # block mode (equation, display) self.body.append('\n') if tag: - self.body.append('\n' % tag) + self.body.append('' % tag) + if math_env: + self.body.append('\n') # Content already processed: raise nodes.SkipNode diff --git a/docutils/test/functional/expected/math_output_html.html b/docutils/test/functional/expected/math_output_html.html index b0db72258..5e32481a9 100644 --- a/docutils/test/functional/expected/math_output_html.html +++ b/docutils/test/functional/expected/math_output_html.html @@ -13,9 +13,7 @@

Mathematics

Docutils supports inline math with the prefix or postfix :math: -role specificator, n! + sin(x2n) - and Ac = (π)/(4)d2 -, as well as displayed math via the +role specificator, n! + sin(x2n) and Ac = (π)/(4)d2, as well as displayed math via the math directive:

f(ϵ) = (1)/(1 + exp(ε)/(kBT)) @@ -57,8 +55,7 @@ See eq:M and
-

is |M| = ad − bc -.

+

is |M| = ad − bc.

More than one display math block can be put in one math directive. For example, the following sum and integral with limits:

@@ -73,8 +70,7 @@ directives:

i()/(t)Ψ = Ψ, 
-

with the wave function Ψ -, describes how the quantum state of a +

with the wave function Ψ, describes how the quantum state of a physical system changes in time.

Math-Accents:
@@ -85,33 +81,21 @@ physical system changes in time.

- - \acute{a} - - \dot{t} -γ̂ - \hat{\gamma} + \acute{a} + \dot{t} +γ̂ \hat{\gamma} - - \grave{a} - - \ddot{t} -α̃ - \tilde{\alpha} + \grave{a} + \ddot{t} +α̃ \tilde{\alpha} - - \breve{x} -t⃛ - \dddot{t} -ı⃗ - \vec{\imath} + \breve{x} +t⃛ \dddot{t} +ı⃗ \vec{\imath} - - \check{a} -a - \bar{a} -R⃗ - \vec{R} + \check{a} +a \bar{a} +R⃗ \vec{R} diff --git a/docutils/test/functional/expected/math_output_latex.html b/docutils/test/functional/expected/math_output_latex.html index 8ef54b806..b4712f5e2 100644 --- a/docutils/test/functional/expected/math_output_latex.html +++ b/docutils/test/functional/expected/math_output_latex.html @@ -12,10 +12,8 @@

Mathematics

Docutils supports inline math with the prefix or postfix :math: -role specificator, n! + \sin(x_n^2) - and A_\text{c} = -\frac{\pi}{4} d^2 -, as well as displayed math via the +role specificator, n! + \sin(x_n^2) and A_\text{c} = +\frac{\pi}{4} d^2, as well as displayed math via the math directive:

 f(\epsilon) = \frac{1}{1 + \exp\left(\frac{\varepsilon}{k_\text{B}T}\right)}
@@ -30,8 +28,7 @@ See eq:M and 
 \mathbf{M} = \left(\begin{matrix}a&b\\c&d\end{matrix}\right)
 
-

is |\mathbf{M}| = ad - bc -.

+

is |\mathbf{M}| = ad - bc.

More than one display math block can be put in one math directive. For example, the following sum and integral with limits:

@@ -46,8 +43,7 @@ directives:

 i\hbar \frac{\partial }{\partial t}\Psi  = \hat{H}\Psi ,
 
-

with the wave function \Psi -, describes how the quantum state of a +

with the wave function \Psi , describes how the quantum state of a physical system changes in time.

Math-Accents:
@@ -58,33 +54,21 @@ physical system changes in time.

-\acute{a} - \acute{a} -\dot{t} - \dot{t} -\hat{\gamma} - \hat{\gamma} +\acute{a} \acute{a} +\dot{t} \dot{t} +\hat{\gamma} \hat{\gamma} -\grave{a} - \grave{a} -\ddot{t} - \ddot{t} -\tilde{\alpha} - \tilde{\alpha} +\grave{a} \grave{a} +\ddot{t} \ddot{t} +\tilde{\alpha} \tilde{\alpha} -\breve{x} - \breve{x} -\dddot{t} - \dddot{t} -\vec{\imath} - \vec{\imath} +\breve{x} \breve{x} +\dddot{t} \dddot{t} +\vec{\imath} \vec{\imath} -\check{a} - \check{a} -\bar{a} - \bar{a} -\vec{R} - \vec{R} +\check{a} \check{a} +\bar{a} \bar{a} +\vec{R} \vec{R} diff --git a/docutils/test/functional/expected/math_output_mathjax.html b/docutils/test/functional/expected/math_output_mathjax.html index b2bd3d74e..27af59567 100644 --- a/docutils/test/functional/expected/math_output_mathjax.html +++ b/docutils/test/functional/expected/math_output_mathjax.html @@ -13,10 +13,8 @@

Mathematics

Docutils supports inline math with the prefix or postfix :math: -role specificator, \(n! + \sin(x_n^2)\) - and \(A_\text{c} = -\frac{\pi}{4} d^2\) -, as well as displayed math via the +role specificator, \(n! + \sin(x_n^2)\) and \(A_\text{c} = +\frac{\pi}{4} d^2\), as well as displayed math via the math directive:

\begin{equation*} @@ -37,8 +35,7 @@ See eq:M and \(|\mathbf{M}| = ad - bc\) -.

+

is \(|\mathbf{M}| = ad - bc\).

More than one display math block can be put in one math directive. For example, the following sum and integral with limits:

@@ -59,8 +56,7 @@ directives:

i\hbar \frac{\partial }{\partial t}\Psi = \hat{H}\Psi , \end{equation*}
-

with the wave function \(\Psi \) -, describes how the quantum state of a +

with the wave function \(\Psi \), describes how the quantum state of a physical system changes in time.

Math-Accents:
@@ -71,33 +67,21 @@ physical system changes in time.

-\(\acute{a}\) - \acute{a} -\(\dot{t}\) - \dot{t} -\(\hat{\gamma}\) - \hat{\gamma} +\(\acute{a}\) \acute{a} +\(\dot{t}\) \dot{t} +\(\hat{\gamma}\) \hat{\gamma} -\(\grave{a}\) - \grave{a} -\(\ddot{t}\) - \ddot{t} -\(\tilde{\alpha}\) - \tilde{\alpha} +\(\grave{a}\) \grave{a} +\(\ddot{t}\) \ddot{t} +\(\tilde{\alpha}\) \tilde{\alpha} -\(\breve{x}\) - \breve{x} -\(\dddot{t}\) - \dddot{t} -\(\vec{\imath}\) - \vec{\imath} +\(\breve{x}\) \breve{x} +\(\dddot{t}\) \dddot{t} +\(\vec{\imath}\) \vec{\imath} -\(\check{a}\) - \check{a} -\(\bar{a}\) - \bar{a} -\(\vec{R}\) - \vec{R} +\(\check{a}\) \check{a} +\(\bar{a}\) \bar{a} +\(\vec{R}\) \vec{R} diff --git a/docutils/test/functional/expected/standalone_rst_html4css1.html b/docutils/test/functional/expected/standalone_rst_html4css1.html index db9d0fbfd..680b00120 100644 --- a/docutils/test/functional/expected/standalone_rst_html4css1.html +++ b/docutils/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.

Docutils uses LaTeX syntax for math directives and roles: -\alpha = f(x) prints α = f(x) -.

+\alpha = f(x) prints α = f(x).

The :code: option of the include directive sets the included content as a code block, here the rst file header_footer.txt with line numbers:

-- 
2.11.4.GIT