# Using Macros in MiniLatex

User defined macros in math mode are totally legit in MiniLatex.  One way to insert them is like this:


That is, enclose the definitions in double dollar signs.  Do this in the body of the text. You can now use these macros in the usual way, e.g. $\bra a | b \ket$.

If you are using www.knode.io , there is another way.  Make a plain text document titled, say “TeX Macros.”  The actual title is irrelevant. Put the macro definitions in this document. Take not of the document ID number (it is displayed in the footer).  Let’s suppose that the ID is 453.  Then, in the keywords field of the document that is to use the macros, put the text “texmacros:453”, as in the figure below.  That’s all there is to it!

You can try this out using the Demo App.

# Handling Latex Errors: Emulating Elm

One of the many things that I admire about Elm as a programming language is the quality of the compiler’s error messages.  The “hooks” for providing good error messages are provided by the Error data structure in the elm-tools/parser package.  The goal, then, is to make MiniLatex producs as informative and helpful as does Elm.  This work is just beginning, but here is a sample of what is possible:

To do this, I’ve added the type LXError Error to the alternatives that make up the LatexExpression type used by the parser — a recursive type that represents the abstract syntax tree.  The Error type, which comes from the elm-tools parser, looks like this:

type alias Error = {
row : Int
, col : Int
, source : String
, problem : Problem
, context : List Context
}

It gives enough information so with a suitable dictionary of error data and a bit of logic one can return good error messages.  The challenge now is to collect and analyze errors, then wire this kind of intelligence in to MiniLatex.

I’ve implemented only a few error messages as of this writing, but you can experiment with the MiniLatex Demo App.

# Bibliographies

Today I posted changes to MiniLatex that allow users to create bibliographies in the customary way using \cite in the body of the document and \bibitem for entries in the bibliography.  Whenever the user presses the full-render button, the citations are resolved in the text as live links in the HTML rendered on-screen.  Since the syntax used is standard LaTeX, running an exported document through pdflatex also resolves the bibliography.

Here is a full example:

\begin{tableofcontents}

\bibitem[A64]{abraham64} Abraham, Hank. Lives of Famous Hackers.
Caveman Press 1964, pp 1001.

\bibitem[U79]{dave} Ungar, Dave.  Principles of Fermentation,
Better Bread Publishing, 1979, pp. 32.

\end{tableofcontents}

In the body of the article, one would refer to the Ungar article as

as noted in \cite{dave}, fermentation causes ...

When rendered, the bibliography would look like the below:

[A64] Abraham, Hank. Lives of Famous Hackers.
Caveman Press 1964, pp 1001.

[U79] Ungar, Dave. Principles of Fermentation,
Better Bread Publishing, 1979, pp. 32.

The citation would be an active link as in the text “as noted in [U79], fermentation …”

Please see the MiniLatex Demo App for an example of the bibliography in action.