Drop support for Python 2.3.
[docutils.git] / docutils / math / __init__.py
blob4c38a1e86acb5357710bfadd82323830af7c91a5
1 # :Id: $Id$
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
12 """
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
22 """
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
32 ``equation``.
34 If `numbered` evaluates to ``False``, the "starred" versions are used
35 to suppress numbering.
36 """
37 # cut out environment content:
38 chunks = code.split(r'\begin{')
39 toplevel_code = ''.join([chunk.split(r'\end{')[-1]
40 for chunk in chunks])
41 if toplevel_code.find(r'\\') >= 0:
42 env = 'align'
43 else:
44 env = 'equation'
45 if not numbered:
46 env += '*'
47 return env