LaTeX fix attempt #2 (#3276)

* latex fix 2

* fix latex height

* latex

* fix test

* avoid hardcoding
This commit is contained in:
Abubakar Abid 2023-02-22 16:34:38 -06:00 committed by GitHub
parent 06c4cd705f
commit c4f23bf4b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 5 deletions

View File

@ -9,7 +9,7 @@
- Ensure `mirror_webcam` is always respected by [@pngwn](https://github.com/pngwn) in [PR 3245](https://github.com/gradio-app/gradio/pull/3245)
- Fix issue where updated markdown links were not being opened in a new tab by [@gante](https://github.com/gante) in [PR 3236](https://github.com/gradio-app/gradio/pull/3236)
- Added a timeout to queue messages as some demos were experiencing infinitely growing queues from active jobs waiting forever for clients to respond by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3196](https://github.com/gradio-app/gradio/pull/3196)
- Fixes the height of rendered LaTeX images so that they match the height of surrounding text by [@abidlabs](https://github.com/abidlabs) in [PR 3258](https://github.com/gradio-app/gradio/pull/3258)
- Fixes the height of rendered LaTeX images so that they match the height of surrounding text by [@abidlabs](https://github.com/abidlabs) in [PR 3258](https://github.com/gradio-app/gradio/pull/3258) and in [PR 3276](https://github.com/gradio-app/gradio/pull/3276)
- Fix bug where matplotlib images where always too small on the front end by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3274](https://github.com/gradio-app/gradio/pull/3274)
## Documentation Changes:

View File

@ -886,8 +886,12 @@ def tex2svg(formula, *args):
svg_start = xml_code.index("<svg ")
svg_code = xml_code[svg_start:]
svg_code = re.sub(r"<metadata>.*<\/metadata>", "", svg_code, flags=re.DOTALL)
svg_code = re.sub(r' width="[^"]+"', "", svg_code)
svg_code = re.sub(r' height="[^"]+"', "", svg_code)
svg_code = re.sub(r' width="[^"]+"', '', svg_code)
height_match = re.search(r'height="([\d.]+)pt"', svg_code)
if height_match:
height = float(height_match.group(1))
new_height = height / FONTSIZE # conversion from pt to em
svg_code = re.sub(r'height="[\d.]+pt"', f'height="{new_height}em"', svg_code)
copy_code = f"<span style='font-size: 0px'>{formula}</span>"
return f"{copy_code}{svg_code}"

View File

@ -1784,7 +1784,7 @@ class TestMarkdown:
def test_component_functions(self):
markdown_component = gr.Markdown("# Let's learn about $x$", label="Markdown")
assert markdown_component.get_config()["value"].startswith(
"""<h1>Lets learn about <span class="math inline"><span style=\'font-size: 0px\'>x</span><svg xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 11.6 19.35625" xmlns="http://www.w3.org/2000/svg" version="1.1">\n \n <defs>\n <style type="text/css">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id="figure_1">\n <g id="patch_1">\n <path d="M 0 19.35625"""
"""<h1>Lets learn about <span class="math inline"><span style=\'font-size: 0px\'>x</span><svg xmlns:xlink="http://www.w3.org/1999/xlink" height="0.9678125em" viewBox="0 0 11.6 19.35625" xmlns="http://www.w3.org/2000/svg" version="1.1">\n \n <defs>\n <style type="text/css">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id="figure_1">\n <g id="patch_1">"""
)
def test_in_interface(self):

View File

@ -35,7 +35,6 @@
div :global(.math.inline svg) {
display: inline;
margin-bottom: 0.22em;
height: 1em;
}
div {