Scripta.API provides the functions you will need for an application that compiles source text in L0, microLaTeX, or XMarkdown to HTML.
compile : DisplaySettings -> Scripta.Language.Language -> String -> List (Element Render.Msg.MarkupMsg)
Compile source text in the given language using the given display settings.
{ windowWidth : Basics.Int
, longEquationLimit : Basics.Float
, counter : Basics.Int
, selectedId : String
, selectedSlug : Maybe String
, scale : Basics.Float
}
windowWidth: set this to agree with the width of the window in pixels in which the rendered text is displayed.
counter: This is updated on each edit. For technical reasons (virtual Dom) this is needed for the text to display properly.
selectedId and selectedSlug: useful for interactive editing.
scale: a fudge factor
compile (displaySettings 0) "Pythagorean formula: $a^2 + b^2 = c^2$"
where
we define
displaySettings : Int -> Scripta.API.DisplaySettings
displaySettings counter =
{ windowWidth = 500
, counter = counter
, selectedId = "--"
, selectedSlug = Nothing
, scale = 0.8
}
The counter field must be updated on each edit.
This is needed for the rendered text to be
properly updated. See the demo app in
folder Example1
.
Compilation can be sped up by keeping track of which blocks
of source text have changed and ony reparsing those blocks.
An EditRecord
is used to keep track of what has changed
and what has not. In this setup, the EditRecord
is
initialized with the source text using the init
function.
On each document change it brought up to date by the
update
function. The render
function transforms
the current EditRecord
into HTML.
Compiler.DifferentialParser.EditRecord
init : Dict String String -> Scripta.Language.Language -> String -> Compiler.DifferentialParser.EditRecord
update : Compiler.DifferentialParser.EditRecord -> String -> Compiler.DifferentialParser.EditRecord
render : DisplaySettings -> Compiler.DifferentialParser.EditRecord -> List (Element Render.Msg.MarkupMsg)
makeSettings : String -> Maybe String -> Basics.Float -> Basics.Int -> Basics.Float -> Render.Settings.Settings
defaultSettings : Render.Settings.Settings
The export
and fileNameForExport
are functions used to transform source
text in a given markup language to standard LaTeX. The transformed text
can be used to produce a PDF file or a tar files that contains both the
standare LaTeX source and a folder of images used in the documents.
See the code in modules PDF
and Main
of Example2
for more details.
The Elm app sends data to https://pdfServ.app
, a small server
(165 lines of Haskell code) where it is turned into a PDF file or
tar archive where it is then accessible by a GET request.
See [pdfServer2
fileNameForExport : Parser.Forest.Forest Parser.Block.ExpressionBlock -> String
packageNames : Parser.Forest.Forest Parser.Block.ExpressionBlock -> List String
prepareContentForExport : Time.Posix -> Render.Settings.Settings -> Parser.Forest.Forest Parser.Block.ExpressionBlock -> String
getImageUrls : Parser.Forest.Forest Parser.Block.ExpressionBlock -> List String
banner : DisplaySettings -> Compiler.DifferentialParser.EditRecord -> Element Render.Msg.MarkupMsg
getBlockNames : Parser.Forest.Forest Parser.Block.ExpressionBlock -> List String
rawExport : Render.Settings.Settings -> Parser.Forest.Forest Parser.Block.ExpressionBlock -> String
encodeForPDF : Time.Posix -> Render.Settings.Settings -> Parser.Forest.Forest Parser.Block.ExpressionBlock -> Json.Encode.Value
The PDF module in Example2 requires these.
Render.Msg.MarkupMsg
Parser.Forest.Forest Parser.Block.ExpressionBlock
matchingIdsInAST : String -> Parser.Forest.Forest Parser.Block.ExpressionBlock -> List String