From: Vladimír Vondruš Date: Mon, 29 Jan 2018 20:28:58 +0000 (+0100) Subject: doxygen: support math formulas in custom environment. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=bb2181c452e113831af5d44dd92b9eb7e260aa99;p=blog.git doxygen: support math formulas in custom environment. And also be more generous with spacing. --- diff --git a/doxygen/dox2html5.py b/doxygen/dox2html5.py index 86479cbf..9c72cc5b 100755 --- a/doxygen/dox2html5.py +++ b/doxygen/dox2html5.py @@ -248,12 +248,11 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET. # can be both, depending on what's inside elif i.tag == 'formula': - if i.text.startswith('\[ ') and i.text.endswith(' \]'): + if i.text.startswith('$') and i.text.endswith('$'): + formula_block = False + else: end_previous_paragraph = True formula_block = True - else: - assert i.text.startswith('$ ') and i.text.endswith(' $') - formula_block = False # is autodetected to be either block or inline elif i.tag == 'programlisting': @@ -731,17 +730,18 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET. logging.debug("{}: rendering math: {}".format(state.current, i.text)) + # Assume that Doxygen wrapped the formula properly to distinguish + # between inline, block or special environment + rendered = latex2svg.latex2svg('{}'.format(i.text), params=m.math.latex2svg_params) + # We should have decided about block/inline above assert formula_block is not None if formula_block: has_block_elements = True - rendered = latex2svg.latex2svg('$${}$$'.format(i.text[3:-3]), params=m.math.latex2svg_params) out.parsed += '
{}
'.format( ' ' + add_css_class if add_css_class else '', m.math._patch(i.text, rendered, '')) else: - rendered = latex2svg.latex2svg('${}$'.format(i.text[2:-2]), params=m.math.latex2svg_params) - # CSS classes and styling for proper vertical alignment. Depth is relative # to font size, describes how below the line the text is. Scaling it back # to 12pt font, scaled by 125% as set above in the config. diff --git a/doxygen/test/contents_math/index.html b/doxygen/test/contents_math/index.html index b6795619..a171f715 100644 --- a/doxygen/test/contents_math/index.html +++ b/doxygen/test/contents_math/index.html @@ -100,7 +100,7 @@ $ \hat q $

LaTeX Math -$ c^2 $ +$c^2$ @@ -110,7 +110,55 @@ $ c^2 $ - should be part of a new paragraph, not stuck out of it.

+ should be part of a new paragraph, not stuck out of it. The following formula has a custom environment:

+LaTeX Math + +\begin{eqnarray*} g &=& \frac{Gm_2}{r^2} \\ &=& 9.82066032\,\mbox{m/s}^2 \end{eqnarray*} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/doxygen/test/contents_math/input.dox b/doxygen/test/contents_math/input.dox index 4eb2b0a1..b335ca6d 100644 --- a/doxygen/test/contents_math/input.dox +++ b/doxygen/test/contents_math/input.dox @@ -12,6 +12,12 @@ And @f$ \hat q @f$ is how quaternion is denoted. a^2 + b^2 = c^2 @f] -@f$ c^2 @f$ should be part of a new paragraph, not stuck out of it. +@f$c^2@f$ should be part of a new paragraph, not stuck out of it. The following +formula has a custom environment: + +\f{eqnarray*}{ + g &=& \frac{Gm_2}{r^2} \\ + &=& 9.82066032\,\mbox{m/s}^2 +\f} */