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

mathjax-server

v1.3.1

Published

Server listens for POST with MathJax config. Returns rendered version.

Downloads

19

Readme

mathjax-server

Nodejs server receives JSON post, returns MathJax-rendered version.

This project is a server front-end for the MathJax-node library. https://github.com/mathjax/mathjax-node

Installation

Requires the GitHub repository for MathJax-node:

npm install https://github.com/mathjax/MathJax-node/tarball/master

npm install mathjax-server

Run Server Example

To run the server on port 8003, put these two lines in a file, test_server.js, say, which lives in your node_modules/mathjax-server directory (along with index.js)

var server = require('./index');
server.start(8003);

and run the command:

node test_server.js

Run Client Example

A test client for the server.

The example contains LaTeX math expression in JSON object pdata as input. The server returns SVG rendering of the expression, including a text version as alt text.

var http=require('http');
var pdata = {
    "format": "TeX",
    "math": "b + y = \\sqrt{f} = \\sum_n^5 {x}",
    "svg":true,
    "mml":false,
    "png":false,
    "speakText": true,
    "speakRuleset": "mathspeak",
    "speakStyle": "default",
    "ex": 6,
    "width": 1000000,
    "linebreaks": false,
};

var datastring = JSON.stringify(pdata);

var options = {
  'hostname': 'localhost',
  'port': 8003,
  'path': '/',
  'method': 'POST',
  'headers': {
    'Content-Type': 'application/json',
    'Content-Length': datastring.length
    }
};

var request = http.request(options, function(response){
    response.setEncoding('utf-8');
    var body = '';
    response.on('data', function(data){body += data;});
    response.on('end', function(){
        console.log(body);
    });
});

request.on('error', function(e) {
  console.log('problem with request: ' + e.message);
});

request.write(datastring);
request.end();

index.js

Server listens for POST requests containing MathJax configuration and math as a string. Returns rendered math.

The input math string can be in LaTeX or MathML. The output rendering can be SVG, PNG, or MathML. Additionally, you can specify that speech text rendering is added as alt text.

See the documentation for Mathjax-node for more information on PNG outputs.

The JSON data to post to the server contains the following keys.

  • format: Specifies the format of the math you are sending. Values can be MathML, TeX, or inline-TeX.
  • math: Specifies the math expression to be rendered.
  • svg: Specifies whether to return the math rendered as an SVG image.
  • mml: Specifies whether to return the math rendered in MathML.
  • png: Specifies whether to return the math rendered as a PNG image.
  • dpi: Specifies the dpi for the image when requesting PNG.
  • speakText: Specifies whether to provide a readable version of the math as alt text in the rendered version.
  • ex: Specifies x-height in pixels.
  • width: Specifies maximum width for rendered image.
  • linebreaks: Specifies whether to allow lines to break.