jxxcarlson/meenylatex/15.2.0

MiniLatex.API

Parse, render and export MiniLaTeX, a subset of LaTeX. This is the package's only module: everything an app needs goes through it.

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

Rendering

type alias LaTeXMsg =
LaTeXMsg

Messages emitted by rendered MiniLaTeX: a paragraph was clicked. Read the paragraph's id with clickedParagraphId.

clickedParagraphId : LaTeXMsg -> String

The DOM id of the paragraph that was clicked, e.g. "p.0.3". Use it to highlight the paragraph, or to find its source lines through the paragraph's data-line / data-lines attributes.

render : String -> List (Html LaTeXMsg)

Parse and render a MiniLaTeX source string. Each logical paragraph becomes one element, carrying data-line / data-lines attributes for editor sync.

Parse once, update incrementally

type Data

A parsed MiniLaTeX document. Create it with parse, keep it in your model, and refresh it with update when the source changes.

parse : String -> Data

Parse a MiniLaTeX source string.

update : String -> Data -> Data

Bring Data up to date with new source text. Only the paragraphs that changed are re-parsed.

renderData : Data -> List (Html LaTeXMsg)

Render parsed Data, with the same output as render.

source : Data -> String

The source text that Data was parsed from.

Table of contents

type alias TocEntry =
{ level : Int
, number : String
, title : String
, id : String
}

One numbered heading: level is 1 for \section, 2 for \subsection and 3 for \subsubsection; number is its label, e.g. "2.1"; id is the DOM id of the rendered heading, for links and scrolling.

tableOfContents : Data -> List TocEntry

The numbered headings of the document, in order.

Export

toLaTeX : String -> String

Map MiniLaTeX source to a complete standard LaTeX document, ready for xelatex: preamble, \begin{document}, body, \end{document}.

toLaTeXBody : String -> String

Map MiniLaTeX source to standard LaTeX: the document body only.

String
-> List
{ url : String
, filename : String
}

The images in MiniLaTeX source: each one's url, and the filename the output of toLaTeX uses for it, as image/<filename>. Download the images there before compiling.

Markdown

toMarkdown : String -> String

Convert MiniLaTeX source to Markdown: sections become headings, math stays as $...$ / $$...$$, and other macros and environments map to their nearest Markdown equivalents.