jxxcarlson / meenylatex

Experimental version of MiniLatex package
https://demo.minilatex.app/
BSD 3-Clause "New" or "Revised" License
9 stars 6 forks source link

Cannot render latex #2

Closed wjdhamilton closed 4 years ago

wjdhamilton commented 4 years ago

Hi,

Thanks very much for taking the time to write this library.

I cannot get the library to render latex. Using the very simple example provided in the README, as follows:

module Main exposing (..)

import Browser
import Html exposing (Html, div, h1, img, text)
import Html.Attributes exposing (src)
import MiniLatex
import MiniLatex.Render exposing (MathJaxRenderOption(..))

---- MODEL ----

type alias Model =
    {}

init : ( Model, Cmd Msg )
init =
    ( {}, Cmd.none )

---- UPDATE ----

type Msg
    = NoOp

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    ( model, Cmd.none )

---- VIEW ----

view : Model -> Html Msg
view model =
    div []
        [ img [ src "/logo.svg" ] []
        , h1 [] [ text "Your Elm App is working!" ]
        , MiniLatex.render NoDelay "" "Pythagoras says: $a^2 + b^2 = c^2$"
        ]

---- PROGRAM ----

main : Program () Model Msg
main =
    Browser.element
        { view = view
        , init = \_ -> init
        , update = update
        , subscriptions = always Sub.none
        }

The output I get is:

Pythagoras says: $a^2 + b^2 = c^2$ ythagoras says: $a^2 + b^2 = c^2$ thagoras says: $a^2 + b^2 = c^2$ ...

^
Expecting '$$' for displayed math

Pythagoras says: $a^2 + b^2 = c^2$ ythagoras says: $a^2 + b^2 = c^2$ thagoras says: $a^2 + b^2 = c^2$ ...

^
Expecting '$$' for displayed math

As you can see, the error appears to be repeating itself but getting shorter and shorter each time.

Any suggestions as to how I can fix this would be most appreciated.

wjdhamilton commented 4 years ago

Would you mind giving me your thoughts? I have a live project I want to use this in and it's nearing completion so it would be great to make this work.

jxxcarlson commented 4 years ago

So sorry I didn't see this till today. I will respond in a couple hours. Thanks

wjdhamilton commented 4 years ago

Not at all! It's difficult to "poke" someone politely online. I appreciate your help

jxxcarlson commented 4 years ago

It's my bad! Below is a fix. The problem is that you need to supply a true dummy set of macros, as below. But this is not good programming practice. I'll update the package in the near future -- check the README when the version changes.

Sorry about this — I know how frustrating it is when something doesn't work as it should.

---- VIEW ----

macros = "\\newcommand{\\bra}{\\langle}"

sourceText = "Pythagoras says: $a^2 + b^2 = c^2$"

view : Model -> Html Msg
view model =
    div []
        [ img [ src "/logo.svg" ] []
        , h1 [] [ text "Your Elm App is working!" ]
        , div [style "font-size" "18px"] [MiniLatex.render NoDelay macros sourceText]
        ]

``

jxxcarlson commented 4 years ago

I should mention that macros are not working at the moment because of the transition to MathJax3 -- hope to have a fix soon.

wjdhamilton commented 4 years ago

Not at all - I know how much of one's free time these things can absorb. Thanks again!

jxxcarlson commented 4 years ago

I'd be interested to know where you are going with this. You can also reach me at jxxcarlson@gmail.com

wjdhamilton commented 4 years ago

I was trying to develop my understanding of the TF-IDF function, and so I wrote a blog post with an elm app in it that allows you to chart the function according to its different parameters and then see how moving the other parameters alters the output:

https://principledigital.com/tfidf/

But I also thought that being able to display the function and show the parameters changing within it was a good idea, so that was what I want to use this package for.