Equation Element

Generate an HTML string for displaying an SVG equation as an image in a GitHub Markdown file.

Usage

var createElement = require( '@stdlib/_tools/markdown/img-svg-equation' );

createElement( [options] )

Generates an HTML string for displaying an SVG equation as an image in a GitHub Markdown file.

var html = createElement();
// returns '<div class="equation" align="center" data-raw-text="" data-equation="">\n    <img src="" alt="">\n    <br>\n</div>'

The function accepts the following options:

  • className: element class name. Default: 'equation'.
  • align: element alignment. Default: 'center'.
  • raw: raw equation text.
  • label: equation label.
  • src: image source URL.
  • alt: alternative image text.

Each option corresponds an HTML attribute. For example, to set the image source URL, set the src option.

var opts = {
    'src': 'https://cdn.rawgit.com/stdlib-js/stdlib/master/docs/img/eqn1.svg'
};

var html = createElement( opts );
// returns '<div class="equation" align="center" data-raw-text="" data-equation="">\n    <img src="https://cdn.rawgit.com/stdlib-js/stdlib/master/docs/img/eqn1.svg" alt="">\n    <br>\n</div>'

To include a raw equation TeX or LaTeX string in the element, set the raw option.

var opts = {
    'raw': '\\Gamma ( n ) = (n-1)!',
    'src': 'https://cdn.rawgit.com/stdlib-js/stdlib/master/docs/img/eqn1.svg'
};

var html = createElement( opts );
// returns '<div class="equation" align="center" data-raw-text="\Gamma ( n ) = (n-1)!" data-equation="">\n    <img src="https://cdn.rawgit.com/stdlib-js/stdlib/master/docs/img/eqn1.svg" alt="">\n    <br>\n</div>'

Examples

var createElement = require( '@stdlib/_tools/markdown/img-svg-equation' );

var opts = {
    'className': 'eqn',
    'align': 'left',
    'raw': '\\operatorname{erf}(x) = \\frac{2}{\\sqrt\\pi}\\int_0^x e^{-t^2}\\,\\mathrm dt',
    'label': 'eq:erf',
    'src': 'https://cdn.rawgit.com/stdlib-js/stdlib/master/docs/img/eqn.svg',
    'alt': 'Error function.'
};

var html = createElement( opts );

console.log( html );
// => '<div class="eqn" align="left" data-raw-text="\operatorname{erf}(x) = \frac{2}{\sqrt\pi}\int_0^x e^{-t^2}\,\mathrm dt" data-equation="eq:erf">\n    <img src="https://cdn.rawgit.com/stdlib-js/stdlib/master/docs/img/eqn.svg" alt="Error function.">\n    <br>\n</div>'

CLI

Usage

Usage: gheqn [options]

Options:

  -h,  --help               Print this message.
  -V,  --version            Print the package version.
       --class name         Element class name. Default: equation.
       --align alignment    Element alignment. Default: center.
       --raw text           Raw equation text.
       --label label        Equation label.
       --src url            Image source URL.
       --alt text           Alternative image text.

Examples

$ gheqn --raw '\Gamma ( n ) = (n-1)!' --src 'https://cdn.rawgit.com/stdlib-js/stdlib/master/docs/img/eqn1.svg'
<div class="equation" align="center" data-raw-text="\Gamma ( n ) = (n-1)!" data-equation="">
    <img src="https://cdn.rawgit.com/stdlib-js/stdlib/master/docs/img/eqn1.svg" alt="">
    <br>
</div>