npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mathematical

v0.1.2

Published

Quickly convert math equations into beautiful SVGs/PNGs/MathML.

Downloads

8

Readme

Mathematical-Node

Quickly convert math equations into beautiful SVGs (or PNGs/MathML). A port of the Ruby Mathematical for Node.js.

Build Status

Mathematical

Installation

npm install mathematical

Usage

The simplest way to do this is

Mathematical = require 'mathematical'

new Mathematical.render(string_with_math)

string_with_math should just be a string of math TeX inline ($..$) or display ($$..$$) style math.

The output will be a hash, with keys that depend on the format you want:

  • If you asked for an SVG, you'll get:
    • width: the width of the resulting image
    • height: the height of the resulting image
    • svg: the actual string of SVG
  • If you asked for a PNG, you'll get:
    • width: the width of the resulting image
    • height: the height of the resulting image
    • png: the PNG data
  • If you asked for MathML, you'll get:
    • mathml: the MathML data

Options

new Mathematical takes an optional object to define a few options:

  • ppi - A double determining the pixels per inch of the resulting SVG (default: 72.0).
  • zoom - A double determining the zoom level of the resulting SVG (default: 1.0).
  • base64 - A boolean determining whether Mathematical's output should be a base64-encoded SVG string (default: false).
  • maxsize - A numeral indicating the MAXSIZE the output string can be. (default: unsigned long).
  • format - A string indicating whether you want an "svg", "png", or "mathml" output. (default: svg).

Pass these in like this:

opts = { ppi: 200.0, zoom: 5.0, base64: true }
renderer = new Mathematical(opts)
renderer.render('$a \ne b$')

Building

Before building this gem, you must install the following programs and libraries:

  • glib-2.0
  • gdk-pixbuf-2.0
  • xml2
  • cairo
  • pango
  • libffi
  • ruby
  • bison

You will also need fonts for cmr10, cmmi10, cmex10, and cmsy10.

Mac install

To install these dependencies on a Mac, everything can be installed via Homebrew:

brew install glib gdk-pixbuf cairo pango libffi

Install the fonts with:

cd ~/Library/Fonts
curl -LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/cmex10.ttf \
     -LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/cmmi10.ttf \
     -LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/cmr10.ttf \
     -LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/cmsy10.ttf \
     -LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/esint10.ttf \
     -LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/eufm10.ttf \
     -LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/msam10.ttf \
     -LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/msbm10.ttf \
     -LO http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/ttf/cmmi10.ttf

xml2 should already be on your machine.

*nix install

To install these dependencies on a *nix machine, fetch the packages through your package manager. For example:

sudo apt-get -qq -y install libglib2.0-dev libxml2-dev libcairo2-dev libpango1.0-dev libffi ttf-lyx libgdk-pixbuf2.0-dev

Windows install

On a Windows machine, I have no idea. Pull requests welcome!

Hacking

After cloning the repo:

script/bootstrap
grunt test

If there were no errors, you're done! Otherwise, make sure to follow the dependency instructions.