Skip to content

latex issure #72

Closed
Closed

Description

@wang-jinbo

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

Activity

  1. kMutagene commented on Apr 13, 2021

    @kMutagene
    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.

  2. added this to the Backlog milestone on Apr 13, 2021
  3. wang-jinbo commented on Apr 13, 2021

    @wang-jinbo
    Author

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

  4. kMutagene commented on Apr 13, 2021

    @kMutagene
    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`
  5. wang-jinbo commented on Apr 13, 2021

    @wang-jinbo
    Author

    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!

  6. kMutagene commented on Apr 13, 2021

    @kMutagene
    Collaborator

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

  7. added a commit that references this issue on Apr 13, 2021
  8. kMutagene commented on Apr 14, 2021

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions