2 # :Author: Guenter Milde.
3 # :License: Released under the terms of the `2-Clause BSD license`_, in short:
5 # Copying and distribution of this file, with or without modification,
6 # are permitted in any medium without royalty provided the copyright
7 # notice and this notice are preserved.
8 # This file is offered as-is, without any warranty.
10 # .. _2-Clause BSD license: http://www.spdx.org/licenses/BSD-2-Clause
13 This is the Docutils (Python Documentation Utilities) "math" sub-package.
15 It contains various modules for conversion between different math formats
16 (LaTeX, MathML, HTML).
18 :math2html: LaTeX math -> HTML conversion from eLyXer
19 :latex2mathml: LaTeX math -> presentational MathML
20 :unichar2tex: Unicode character to LaTeX math translation table
21 :tex2unichar: LaTeX math to Unicode character translation dictionaries
24 # helpers for Docutils math support
25 # =================================
27 def pick_math_environment(code
, numbered
=False):
28 """Return the right math environment to display `code`.
30 The test simply looks for line-breaks (``\\``) outside environments.
31 Multi-line formulae are set with ``align``, one-liners with
34 If `numbered` evaluates to ``False``, the "starred" versions are used
35 to suppress numbering.
37 # cut out environment content:
38 chunks
= code
.split(r
'\begin{')
39 toplevel_code
= ''.join([chunk
.split(r
'\end{')[-1]
41 if toplevel_code
.find(r
'\\') >= 0: