0.4.1 • Published 9 years ago

html-formulae v0.4.1

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

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&(x0y=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:

SequenceDescription
mbscriptAmbscriptZ, mbscriptambscriptzMathematical bold script letters: 𝓐𝓩, 𝓪𝔃
setP, setN, setZ, setQ, setR, setC, setFAbstract and common number sets: , , , , , , 𝔽
+, -, *, /, &&, ǀǀ, !Arithmetic and logical operators: +, , , /, , , ¬
=, ==, <, <=, >, >=, !=, /=, ~, ~~, <<, >>Comparison relations: =, , <, , >, , , , , , ,
<=>, =>, =<, <==>, ==>, ==<, ǀ-, ǀ=, TT, BBInference relations and constants: , , , , , , , , ,
<->, ->, <-, <-->, -->, <--Other arrows: , , , , ,
]], :=, =def=Let and defining signs: , ,
+-, -+, &amp;, ooVarious 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>'
OptionTypeRequired?Default
wrapstringNonull

CLI

html-formulae comes with a simple CLI.

Usage:  html-formulae [-w <tagname> | --wrap <tagname>]

Install

npm install html-formulae

License

MIT