# MathJax, or otherwise, LaTeX-rendered SVG's into Cytoscape nodes/edge labels?

Hi,
I’ve been down several rabbit holes trying to figure out how to do this most naturally.

For example dash-latex. Had an issue.
PyLaTeX heavy reliance on ActiveState, and wouldn’t run client-side. And it’s broken. I installed perl etc and it still doesn’t work.

Our best bet is still MathJax!

Has anyone got this to work? I am able to render mathjax to SVG with:

<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=default"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js"],
jax: ["input/TeX", "output/SVG"],
})
</script>
<body>
<div>$$a = b + c$$</div>
</svg>
</body>
</html>


It fills out the SVG in place. But you can’t view it with “View source” in your browser. “Inspect” works in chrome.

Just wondering how then to tie this SVG element to a node label.

Also, how do I include MathJax.js locally or remotely into a Dash app header?

The documentations have an /assets/ folder with a custom-script.js that somehow magically loads itself.

However, copying the entire MathJax/ folder hierarchy into /assets/ does not seem like a good idea intuitively.

Then, also, how would connect to a remote MathJax CDN like the one in the static html above?

It seems like you have two questions; one related to MathJax and one to Cytoscape. I’ll start the the former.

You should only use the static folder for your own css files. For libraries such as MathJax, it is better to use a CDN as in your example. In Dash, an MWE could look like this

import dash
import dash_html_components as html

# Create app.
external_stylesheets = ['https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
# Make some LaTeX content.
app.layout = html.Div(id='main', children='$$\LaTeX$$')
# Run app.
if __name__ == '__main__':
app.run_server(debug=True)


where the MathJax configuration should be tailored to the application content for performance considerations. While this solution works, there is (at least) one caveat; only static content is rendered. I am not sure if this is a deal breaker for your use case (it is possible to pre render all possible labels)?
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 1, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.32352593541145325, "perplexity": 5320.4760583474}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2023-14/segments/1679296949506.62/warc/CC-MAIN-20230330225648-20230331015648-00435.warc.gz"}