Small HTML fixes and documentation updates.
[docutils.git] / docutils / docutils / utils / math / __init__.py
blobd9d19570bbd6645a36aa903a1b827d7f0ba7332b
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 :tex2mathml_extern: Wrapper for TeX -> MathML command line converters
23 """
25 # helpers for Docutils math support
26 # =================================
28 def pick_math_environment(code, numbered=False):
29 """Return the right math environment to display `code`.
31 The test simply looks for line-breaks (``\\``) outside environments.
32 Multi-line formulae are set with ``align``, one-liners with
33 ``equation``.
35 If `numbered` evaluates to ``False``, the "starred" versions are used
36 to suppress numbering.
37 """
38 # cut out environment content:
39 chunks = code.split(r'\begin{')
40 toplevel_code = ''.join([chunk.split(r'\end{')[-1]
41 for chunk in chunks])
42 if toplevel_code.find(r'\\') >= 0:
43 env = 'align'
44 else:
45 env = 'equation'
46 if not numbered:
47 env += '*'
48 return env