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.
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.EditRecordUsing the renderedParagraph list of the editRecord, return an HTML element represeing the paragraph list of the editRecord.
Parse the given text and return an AST represeting it.
Example:
import MiniLatex.MiniLatex exposing(parse) parse "This \strong{is a test!}" [[LXString ("This "),Macro "strong" [][LatexList [LXString ("is a test!")]]][LXString ("This "),Macro "strong" [] [LatexList [LXString ("is a test!")]]]][[LXString ("This "),Macro "strong" [] [LatexList [LXString ("is a test!")]]]]
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) aragraphs
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.
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
}
The function call
render macros sourceTestproduces an HTML element corresponding to the MiniLatex source textsourceText. The macro definitions inmacrosare prepended to this string and are used by MathJax to render purely mathematical text. Themacrosstring may be empty. Thus, ifmacros = "" source = "\italic{Test:}\n\n$$a^2 + b^2 = c^2$$\n\n\strong{Q.E.D.}"
then
render macros sourceyields an HTML msg value representing the HTML text