More robust code for getting saved "depth" of svg inline math snippet

This commit is contained in:
jfbu 2019-04-24 11:17:27 +02:00
parent 1adf12bfa7
commit 505ff622c2
2 changed files with 15 additions and 14 deletions

View File

@ -95,20 +95,17 @@ built:
.. confval:: imgmath_use_preview .. confval:: imgmath_use_preview
``dvipng`` has the ability to determine the "depth" of the rendered text: for ``dvipng`` and ``dvisvgm`` have the ability to collect from LaTeX the
example, when typesetting a fraction inline, the baseline of surrounding text "depth" of the rendered text: an inline image should use this "depth" in a
should not be flush with the bottom of the image, rather the image should ``vertical-align`` style to be correctly aligned with surrounding text.
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.
Unfortunately, this only works when the `preview-latex package`_ is This mechanism requires the `LaTeX preview package`_ (available as
installed (on Ubuntu xenial, it is available as `preview-latex-style`_). ``preview-latex-style`` on Ubuntu xenial). Therefore, the default for this
Therefore, the default for this option is ``False``. 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 .. confval:: imgmath_add_tooltips
@ -222,5 +219,4 @@ package jsMath_. It provides this config value:
.. _dvisvgm: https://dvisvgm.de/ .. _dvisvgm: https://dvisvgm.de/
.. _MathJax: https://www.mathjax.org/ .. _MathJax: https://www.mathjax.org/
.. _jsMath: http://www.math.union.edu/~dpvc/jsmath/ .. _jsMath: http://www.math.union.edu/~dpvc/jsmath/
.. _preview-latex package: https://www.gnu.org/software/auctex/preview-latex.html .. _LaTeX preview package: https://www.gnu.org/software/auctex/preview-latex.html
.. _preview-latex-style: https://packages.ubuntu.com/xenial/preview-latex-style

View File

@ -88,6 +88,7 @@ DOC_BODY_PREVIEW = r'''
depth_re = re.compile(br'\[\d+ depth=(-?\d+)\]') depth_re = re.compile(br'\[\d+ depth=(-?\d+)\]')
depthsvg_re = re.compile(br'.*, depth=(.*)pt') depthsvg_re = re.compile(br'.*, depth=(.*)pt')
depthsvgcomment_re = re.compile(r'<!-- DEPTH=(-?\d+) -->')
def read_svg_depth(filename): def read_svg_depth(filename):
@ -97,7 +98,11 @@ def read_svg_depth(filename):
with open(filename, 'r') as f: with open(filename, 'r') as f:
for line in f: for line in f:
pass 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): def write_svg_depth(filename, depth):