diff --git a/doc/usage/extensions/math.rst b/doc/usage/extensions/math.rst index 1c64c5d17..52d0c54c3 100644 --- a/doc/usage/extensions/math.rst +++ b/doc/usage/extensions/math.rst @@ -95,20 +95,17 @@ built: .. confval:: imgmath_use_preview - ``dvipng`` has the ability to determine the "depth" of the rendered text: for - example, when typesetting a fraction inline, the baseline of surrounding text - should not be flush with the bottom of the image, rather the image should - extend a bit below the baseline. This is what TeX calls "depth". When this - is enabled, the images put into the HTML document will get a - ``vertical-align`` style that correctly aligns the baselines. + ``dvipng`` and ``dvisvgm`` have the ability to collect from LaTeX the + "depth" of the rendered text: an inline image should use this "depth" in a + ``vertical-align`` style to be correctly aligned with surrounding text. - Unfortunately, this only works when the `preview-latex package`_ is - installed (on Ubuntu xenial, it is available as `preview-latex-style`_). - Therefore, the default for this option is ``False``. + This mechanism requires the `LaTeX preview package`_ (available as + ``preview-latex-style`` on Ubuntu xenial). Therefore, the default for this + option is ``False`` but it is strongly recommended to set it to ``True``. - .. versionchanged:: 2.1.0 + .. versionchanged:: 2.1 - This option can also be used with ``imgmath_image_format`` set to ``'svg'``. + This option can be used with the ``'svg'`` :confval:`imgmath_image_format`. .. confval:: imgmath_add_tooltips @@ -222,5 +219,4 @@ package jsMath_. It provides this config value: .. _dvisvgm: https://dvisvgm.de/ .. _MathJax: https://www.mathjax.org/ .. _jsMath: http://www.math.union.edu/~dpvc/jsmath/ -.. _preview-latex package: https://www.gnu.org/software/auctex/preview-latex.html -.. _preview-latex-style: https://packages.ubuntu.com/xenial/preview-latex-style +.. _LaTeX preview package: https://www.gnu.org/software/auctex/preview-latex.html diff --git a/sphinx/ext/imgmath.py b/sphinx/ext/imgmath.py index 6d007407a..51ebbeff4 100644 --- a/sphinx/ext/imgmath.py +++ b/sphinx/ext/imgmath.py @@ -88,6 +88,7 @@ DOC_BODY_PREVIEW = r''' depth_re = re.compile(br'\[\d+ depth=(-?\d+)\]') depthsvg_re = re.compile(br'.*, depth=(.*)pt') +depthsvgcomment_re = re.compile(r'') def read_svg_depth(filename): @@ -97,7 +98,11 @@ def read_svg_depth(filename): with open(filename, 'r') as f: for line in f: pass - return int(line[11:-4]) + # Only last line is checked + matched = depthsvgcomment_re.match(line) + if matched: + return int(matched.group(1)) + return None def write_svg_depth(filename, depth):