html-formulae v0.4.1
html-formulæ

html-formulae is a mini-language for describing mathematical formulas that compiles to HTML.
It is designed to be:
- readable, say markdown for formulas;
- lightweight, it should not take much to start using it in no time;
- flexible, plain HTML entities and tags should be supported, too.
Some features (dashes, quotation marks, whitespace) also make html-formulae suitable for plain text.
Try it: http://eush77.github.io/html-formulae-app/
Example
\∀(x,y)\∈setR^2:␣␣[y>0.&.(x!=0.||.y=1)]<=>[\∃a>0:.a^x=y]compiles down to:
∀(x,y)∈ℝ<sup>2</sup>: [y>0 & (x≠0 ∨ y=1)] ⇔ [∃a>0: a<sup>x</sup>=y]∀(x,y)∈ℝ2: y>0 & (x≠0 ∨ y=1) ⇔ ∃a>0: ax=y
Syntax
\escapes.^and '_' stand for superscript and subscript, TeX-style grouping ({}) is supported. Example:x^{x_0}is rendered as xx0.- Newlines are autoencoded to
<br/>. - There is also some built-in logic that protects hyphens in compound words from being interpreted as minuses, same for
TTandBB. - Some characters come with some spacing around:
<=>,=>,=<,<==>,==>,==<, ']]`.
The complete table of symbols:
| Sequence | Description |
|---|---|
mbscriptA–mbscriptZ, mbscripta–mbscriptz | Mathematical bold script letters: 𝓐–𝓩, 𝓪–𝔃 |
setP, setN, setZ, setQ, setR, setC, setF | Abstract and common number sets: ℙ, ℕ, ℤ, ℚ, ℝ, ℂ, 𝔽 |
+, -, *, /, &&, ǀǀ, ! | Arithmetic and logical operators: +, −, ⋅, /, ∧, ∨, ¬ |
=, ==, <, <=, >, >=, !=, /=, ~, ~~, <<, >> | Comparison relations: =, ═, <, ≤, >, ≥, ≠, ≠, ∼, ≈, ≪, ≫ |
<=>, =>, =<, <==>, ==>, ==<, ǀ-, ǀ=, TT, BB | Inference relations and constants: ⇔, ⇒, ⇐, ⟺, ⟹, ⟸, ⊢, ⊨, ⊤, ⊥ |
<->, ->, <-, <-->, -->, <-- | Other arrows: ↔, →, ←, ⟷, ⟶, ⟵ |
]], :=, =def= | “Let” and defining signs: ⊐, ≔, ≝ |
+-, -+, &, oo | Various symbols: ±, ∓ &, ∞ |
---, -- | Dashes (em-dash, en-dash): —, – |
ˋˋ, '', <<<, >>> | Quotation marks: “, ”, «, » |
␣␣␣, ␣␣, . | Whitespace sequences: em-space, en-space, thin-space |
Note: backticks, pipes and spaces in the table above are replaced with other similar-looking (visible) characters.
HTML
HTML is also supported, but must be properly escaped.
For example, \∀ and \∃ are rather commonly used entities, check the complete list.
Another example: \<b\>bold\</b\>.
API
htmlFormulae(options, code)
Compile code to HTML.
The function is curried with dyn-curry, so you can fix options and get the converter function back:
var converter = htmlFormulae(options);
converter(code); // -> HTMLoptions.wrap controls whether the output should be wrapped in a tag. null disables wrapping.
> htmlFormulae('2_2')
'2<sub>2</sub>'
> htmlFormulae({ wrap: 'p' }, '2_2')
'<p>2<sub>2</sub></p>'| Option | Type | Required? | Default |
|---|---|---|---|
| wrap | string | No | null |
CLI
html-formulae comes with a simple CLI.
Usage: html-formulae [-w <tagname> | --wrap <tagname>]Install
npm install html-formulaeLicense
MIT
