question

chintanr11-MSFT avatar image
0 Votes"
chintanr11-MSFT asked KranthiPakala-MSFT commented

LaTex display for mathematical equations in Synapse Analytics

I am using Azure Synapse Analytics to analyse my output data using a notebook running on a Spark pool in Synapse. In the process, I have a CSV loaded (as model output) from the ADLS Gen2. One of these columns is a list of model parameters and I want to programmatically build the equation string in LaTex and print it as a part of code cell output. I tried the following way (considering it to be an example for now):

import IPython.display as disp
fr=2 
disp.display(disp.Latex("$f_r = %i$ GHz"%(fr)))


As expected, the output should be the visualisation of the LaTex string. However, I receive the following output from the code cell: <IPython.core.display.Latex object>.

I am looking for some pointers to achieve the same.

Regards,
Chintan Rajvir

azure-synapse-analytics
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @chintanr11-MSFT,

Thanks for reaching out. We are reaching out to internal team on this requirement and will get back to as soon as we have an update.

Thank you for your patience.

1 Vote 1 ·

1 Answer

KranthiPakala-MSFT avatar image
1 Vote"
KranthiPakala-MSFT answered KranthiPakala-MSFT commented

Hi @chintanr11-MSFT,

After having conversation with internal team, it is confirmed that outputting LaTeX is not directly supported in the Notebook code cell in Synapse Studio.

As of now, however, you may try with displayHTML function and to render the LaTeX expression via HTML output. This may need some HTML boilerplate like the one provided by MathJax: https://www.mathjax.org/#gettingstarted. And you may need to enable “Preview Features” on the notebook toolbar in order to properly consume external scripts in the HTML output.

An example of the HTML snippet is here: 78097-htmlsnippet.txt

And the outcome is as follows:

78131-image.png

If you have any feedback/suggestion regarding the product improvements, I would recommend you to please share your feedback in Azure Synapse Analytics user voice forum: https://feedback.azure.com/forums/307516-azure-synapse-analytics .

Please do share the feedback link one it is posted so that other users with similar idea can up-vote and/or comment on your suggestion.

Hope this info helps.



Please don’t forget to Accept Answer and Up-Vote wherever the information provided helps you, this can be beneficial to other community members.



htmlsnippet.txt (342 B)
image.png (71.2 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This is good workaround @KranthiPakala-MSFT! Thanks a lot! I have added the feedback post here.

Meanwhile, I also tried using matplotlib text plot to display the LaTex string as plots. Adding a small snippet to the Python function here:

def show_model_info(info):
    ax = plt.axes([0, 0, 0.05, 0.1])
    ax.set_xticks([])
    ax.set_yticks([])
    ax.axis('off')
    i = 0
    for text in info.split("\n"):
        plt.text(0.4, 0.4+i, '$' + text + '$', size=10, color="green")
        i -= 0.5
    plt.show()


The function also considers wrapping with the split at \n character. It follows the same MathJax syntax to create visualizations for formulas. However, I liked the HTML workaround, as we can mix across common text and equations.


0 Votes 0 ·

Glad to know that the above workaround was helpful. Appreciate much for sharing your additional inputs here.

Thank you

1 Vote 1 ·