Git Product home page Git Product logo

Comments (6)

Wongboo avatar Wongboo commented on May 14, 2024 1

So temporarily solution is to change the HTML directly through adding these lines.
In the long term, wait for the API change in MathJAX.
Thanks for your help!

from plotly.net.

kMutagene avatar kMutagene commented on May 14, 2024 1

@Wongboo Watch out for the next release, you will be able to use Chart.WithMathTex:

[
    Chart.Line([(1.,2.)],@"$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$")
    Chart.Line([(1.,2.)],@"$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$")
]
|> Chart.Combine
|> Chart.withTitle @"$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$"
|> Chart.WithMathTex(true)

image

from plotly.net.

kMutagene avatar kMutagene commented on May 14, 2024

Hi @Wongboo

I would really appreciate a full code example, but i managed latex output to work in principle.

The problem is MathJax (the tex rendering engine used in plotly tex examples) not being referenced in our HTML scaffold. For a workaround until this is properly implemented, add these script tags to the html:

<script type="text/x-mathjax-config;executed=true">MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']], processEscapes: true}});</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML%2CSafe.js&ver=4.1"></script>

Additionally, as tex uses a lot of \ characters, your tex strings should be escaped using @:

[
    Chart.Line([(1.,2.)],@"$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$")
    Chart.Line([(1.,2.)],@"$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$")
]
|> Chart.Combine
|> Chart.Show

Which will then look like this:

image

From our side it is most likely the best to set this on the Config level of GenericChart, providing a Chart.withMathTex function indicating that the mathtex script should be contained in the html scaffold.

from plotly.net.

Wongboo avatar Wongboo commented on May 14, 2024

@kMutagene
I kind of understand, so this generally means that until the official support is established, We have to change the source code of Plotly.NET or manually add

<script type="text/x-mathjax-config;executed=true">MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']], processEscapes: true}});</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML%2CSafe.js&ver=4.1"></script>

to the chart which might be too complicated since no API in GenericChart supports directly adding these script tags. Am I right?

from plotly.net.

kMutagene avatar kMutagene commented on May 14, 2024

or manually add [script tags]
to the chart which might be too complicated since no API in GenericChart supports directly adding these script tags. Am I right?

I can think of two workarounds that might work for you in the meantime:

  • The output of Chart.Show is a html text file like any other, so you can open the files programmatically and add those lines.

  • The GenericChart.toChartHTML returns the contents of that file as a string, so you can add these lines there and then write the content to a file like this:

     [
     Chart.Line([(1.,2.)],@"$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$")
     Chart.Line([(1.,2.)],@"$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$")
     ]
     |> Chart.Combine
     |> Chart.toChartHTML
     |> `add the missing lines`
     |> `write to a .html file`

from plotly.net.

kMutagene avatar kMutagene commented on May 14, 2024

Exactly, i don't imagine this feature taking too long to implement though

from plotly.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.