html-formulae

0.4.1 • Public • Published

html-formulæ Build Status Code Climate Dependency Status

npm

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

\&forall;(x,y)\&isin;setR^2:␣␣[y>0.&.(x!=0.||.y=1)]<=>[\&exist;a>0:.a^x=y]

compiles down to:

&forall;(x,y)&isin;&#8477;<sup>2</sup>:&ensp;[y&gt;0&thinsp;&amp;&thinsp;(x&ne;0&thinsp;&or;&thinsp;y=1)]&thinsp;&hArr;&thinsp;[&exist;a&gt;0:&thinsp;a<sup>x</sup>=y]

∀(x,y)∈ℝ2: [y>0 & (x≠0 ∨ y=1)] ⇔ [∃a>0: ax=y]

Syntax

  1. \ escapes.
  2. ^ and '_' stand for superscript and subscript, TeX-style grouping ({}) is supported. Example: x^{x_0} is rendered as xx0.
  3. Newlines are autoencoded to <br/>.
  4. There is also some built-in logic that protects hyphens in compound words from being interpreted as minuses, same for TT and BB.
  5. Some characters come with some spacing around: <=>, =>, =<, <==>, ==>, ==<, ']]`.

The complete table of symbols:

Sequence Description
mbscriptAmbscriptZ, mbscriptambscriptz 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: ⊐, ≔, ≝
+-, -+, &amp;, 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, \&forall; and \&exist; 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); // -> HTML

options.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-formulae

License

MIT

Package Sidebar

Install

npm i html-formulae

Weekly Downloads

1

Version

0.4.1

License

MIT

Last publish

Collaborators

  • eush77