darioteixeira / lambdoc

Lambdoc is a library providing support for semantically complex documents in Ocsigen web applications
GNU General Public License v2.0
17 stars 1 forks source link

Support for document-wide abbreviations of math formulas in Lambtex? #30

Open radekm opened 9 years ago

radekm commented 9 years ago

Is it possible to create document-wide abbreviations for frequently used mathematical formulas? Eg. \mathbb{N} for natural numbers. I have tried macros but it seems that blahtex commands such as \mathbb cannot be used in macros - since following code

\newmacro{nat}{0}{\mathbb{N}}

results in error "Reference to undefined macro 'mathbb'.". I have also tried \newcommand from blahtex but scope of the definitions introduced by \newcommand is limited to a single mathematical environment.

darioteixeira commented 9 years ago

What you want is already supported. Note that the third parameter to \newmacro must be an inline sequence, and raw TeX mathematics are not an inline sequence, which is why you are getting errors. Fixing it is simple: just tell Lambtex to expect inline TeX maths by wrapping them between [$ and $]. (See Chapter 13 of the Lambtex manual.)

\newmacro{nat}{0}{[$\mathbb{N}$]}
radekm commented 9 years ago

Ok. Can these macros be used inside math? When I define

\newmacro{nat}{0}{[$ \mathbb{N} $]}

then I can use the macro in a paragraph. But writing

\begin{mathtex}
n \in \nat
\end{mathtex}

leads to an error "Invalid MathTeX expression ' n \in \nat ' in command 'mathtex'.".

darioteixeira commented 9 years ago

No, you can't use them inside mathtex environments. The contents of the mathtex environment are not parsed by Lambdoc, being instead fed verbatim into a function from the Blahcaml library for validation and conversion into MathML.