jxxcarlson/meenylatex/7.0.3

NOTE: the latest version is 15.2.0

MiniLatex.MiniLatex

This library exposes functions for rendering MiniLaTeX text into HTML. Most users will need only (1) the functions exposed in the MiniLatex module and (2) EditRecord, which is exposed in the Differ module.

See MiniLatex Live for a no-login demo of the MiniLatex technology. Source code

See this Hackernoon article for an explanation of the theory behind the MiniLatex package.

API

render : String -> String -> Html msg

The function call render macros sourceTest produces an HTML element or Html msg value corresponding to the MiniLatex source text sourceText. The macro definitions in macros are prepended to this string and are used by MathJax to render purely mathematical text. The macros string may be empty.

renderWithSeed : Int -> String -> String -> Html msg

Like render, but used the seed to define the ids for each paragraph.

initializeEditRecord : Int -> String -> EditRecord (Html msg)

Create an EditRecord from a string of MiniLaTeX text. The seed is used for creating id's for rendered paragraphs in order to help Elm's runtime optimize diffing for rendering text.

editRecord = MiniLatex.initialize source

    { paragraphs =
        [ "\\italic{Test:}\n\n"
        , "$$a^2 + b^2 = c^2$$\n\n"
        , "\\strong{Q.E.D.}\n\n"
        ]
    , renderedParagraphs = ((an Html msg value representing))
        [ "  <span class=italic>Test:</span>"
        , " $$a^2 + b^2 = c^2$$"
        , "  <span class=\"strong\">Q.E.D.</span> "
        ]
    , latexState =
        { counters =
            Dict.fromList
                [ ( "eqno", 0 )
                , ( "s1", 0 )
                , ( "s2", 0 )
                , ( "s3", 0 )
                , ( "tno", 0 )
                ]
        , crossReferences = Dict.fromList []
        }
    , idList = []
    , idListStart = 0
    } : MiniLatex.Differ.EditRecord
getRenderedText : EditRecord (Html msg) -> List (Html msg)

Using the renderedParagraph list of the editRecord, return an HTML element represeing the paragraph list of the editRecord.

parse : String -> List (List LatexExpression)

Parse the given text and return an AST represeting it.

updateEditRecord : Int -> EditRecord (Html msg) -> String -> EditRecord (Html msg)

Update the given edit record with modified text. Thus, if

source2 = "\italic{Test:}\n\n$$a^3 + b^3 = c^3$$\n\n\strong{Q.E.D.}"

then we can say

editRecord2 = updateEditRecord 0 source2 editRecord

The updateEditRecord function attempts to re-render only the (logical) paragraphs which have been changed. It will always update the text correctly, but its efficiency depends on the nature of the edit. This is because the "differ" used to detect changes is rather crude.

emptyStringRecord : EditRecord (Html msg)

Return an empty EditRecord

    { paragraphs = []
    , renderedParagraphs = []
    , latexState =
        { counters =
            Dict.fromList
                [ ( "eqno", 0 )
                , ( "s1", 0 )
                , ( "s2", 0 )
                , ( "s3", 0 )
                , ( "tno", 0 )
                ]
        , crossReferences = Dict.fromList []
        }
    , idList = []
    , idListStart = 0
    }