Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 7 additions & 29 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ ipywidgets = "*"
kaleido = ">=0.2.1,!=0.2.1.post1"
langchain-openai = {version = ">=0.1.8", optional = true}
langdetect = "*"
latex2mathml = ">=3.77.0"
llvmlite = {version = "*", python = ">=3.8,<=3.11"}
matplotlib = "*"
mistune = "^3.0.2"
Expand Down
2 changes: 1 addition & 1 deletion validmind/html_templates/content_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
</script>
"""

# FIXME: this is a bit too hacky
# have to dynamically load mathjax
math_jax_snippet = """
<script>
window.MathJax = {
Expand Down
15 changes: 7 additions & 8 deletions validmind/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from IPython.core import getipython
from IPython.display import HTML
from IPython.display import display as ipy_display
from latex2mathml.converter import convert
from matplotlib.axes._axes import _log as matplotlib_axes_logger
from numpy import ndarray
from sklearn.exceptions import UndefinedMetricWarning
Expand Down Expand Up @@ -491,7 +490,7 @@ def display(widget_or_html, syntax_highlighting=True, mathjax=True):
ipy_display(HTML(widget_or_html))
# if html we can auto-detect if we actually need syntax highlighting or MathJax
syntax_highlighting = 'class="language-' in widget_or_html
mathjax = "$$" in widget_or_html
mathjax = "math/tex" in widget_or_html
else:
ipy_display(widget_or_html)

Expand All @@ -510,20 +509,20 @@ def md_to_html(md: str, mathml=False) -> str:
)(md)

if not mathml:
# return the html as is (with latex that will be rendered by MathJax)
return html

# convert the latex to MathML which CKeditor can render
# convert the latex to mathjax
math_block_pattern = re.compile(r'<div class="math">\$\$([\s\S]*?)\$\$</div>')
html = math_block_pattern.sub(
lambda match: "<p>{}</p>".format(convert(match.group(1), display="block")), html
lambda match: '<script type="math/tex; mode=display">{}</script>'.format(
match.group(1)
),
html,
)

inline_math_pattern = re.compile(r'<span class="math">\\\((.*?)\\\)</span>')
html = inline_math_pattern.sub(
lambda match: "<span>{}</span>".format(
convert(match.group(1), display="inline")
),
lambda match: '<script type="math/tex">{}</script>'.format(match.group(1)),
html,
)

Expand Down
Loading