Skip to content

latex issure #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Wongboo opened this issue Apr 13, 2021 · 6 comments
Closed

latex issure #72

Wongboo opened this issue Apr 13, 2021 · 6 comments
Labels
Milestone

Comments

@Wongboo
Copy link

Wongboo commented Apr 13, 2021

version:2.0.0-beta8

let header = [ "$x_0$"; "迭代次数"; "数值结果"; "数值误差" ]

The thing is that I can't produce LaTeX output out of line, which can be produced under Plotly on python, MATLAB

@kMutagene
Copy link
Collaborator

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.

@kMutagene kMutagene added this to the Backlog milestone Apr 13, 2021
@Wongboo
Copy link
Author

Wongboo commented Apr 13, 2021

@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?

@kMutagene
Copy link
Collaborator

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`

@Wongboo
Copy link
Author

Wongboo commented Apr 13, 2021

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!

@kMutagene
Copy link
Collaborator

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

@kMutagene
Copy link
Collaborator

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants