Skip to content

Instantly share code, notes, and snippets.

@pkra
pkra / mml2speech.js
Created February 26, 2016 16:35
Simple SRE snippet
// `$ npm install speech-rule-engine`
var sre = require('speech-rule-engine');
var mathml = '<math xmlns="http://www.w3.org/1998/Math/MathML"> <mfrac> <mn>1</mn> <mn>2</mn> </mfrac> </math>';
sre.setupEngine({semantics: true, domain: "mathspeak", style: "brief"});
console.log(sre.processExpression(mathml));
// one-half
@pkra
pkra / mathjax-accessiblemenu.html
Last active September 16, 2015 10:35
Development version of MathJax's now-accessible menu
<!DOCTYPE html>
<html>
<head>
<title>MathJax Accessible Menu Test Page</title>
<!-- Copyright (c) 2015 The MathJax Consortium -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
jax: ["input/TeX","output/HTML-CSS"],
<!DOCTYPE html>
<html>
<head>
<title>MathJax AssistiveMML Test Page</title>
<!-- Copyright (c) 2015 The MathJax Consortium -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
jax: ["input/TeX","output/HTML-CSS"],
// add to User:YOURNAME/common.js to get smooth MathJax rendering
var mathTags = $('.mwe-math-mathml-a11y');
if (mathTags.length > 0){ //only do something when there's math on the page
window.MathJax = {
SVG: {blacker: 1}, // clearer SVG output, in case people switch to SVG output
AuthorInit: function () {
MathJax.Hub.Register.StartupHook("End",function () { //when MathJax is done...
MathJax.Hub.Queue(
function(){
mathTags.removeClass('mwe-math-mathml-a11y'); // .. make the span around MathML (now MathJax output) visible
@pkra
pkra / mathjax-node-simple-perf2.js
Created July 2, 2015 20:27
MathJax-node mjpage test
var mjAPI = require("./lib/mj-page.js");
var jsdom = require("jsdom").jsdom;
var document = jsdom("<!DOCTYPE html><html lang='en'><head><title>Test</title></head><body>\\[\sqrt{f: X \to Y }0\\]\\[\sqrt{f: X \to Y }1\\]\\[\sqrt{f: X \to Y }2\\]\\[\sqrt{f: X \to Y }3\\]\\[\sqrt{f: X \to Y }4\\]\\[\sqrt{f: X \to Y }5\\]\\[\sqrt{f: X \to Y }6\\]\\[\sqrt{f: X \to Y }7\\]\\[\sqrt{f: X \to Y }8\\]\\[\sqrt{f: X \to Y }9\\]\\[\sqrt{f: X \to Y }10\\]\\[\sqrt{f: X \to Y }11\\]\\[\sqrt{f: X \to Y }12\\]\\[\sqrt{f: X \to Y }13\\]\\[\sqrt{f: X \to Y }14\\]\\[\sqrt{f: X \to Y }15\\]\\[\sqrt{f: X \to Y }16\\]\\[\sqrt{f: X \to Y }17\\]\\[\sqrt{f: X \to Y }18\\]\\[\sqrt{f: X \to Y }19\\]\\[\sqrt{f: X \to Y }20\\]\\[\sqrt{f: X \to Y }21\\]\\[\sqrt{f: X \to Y }22\\]\\[\sqrt{f: X \to Y }23\\]\\[\sqrt{f: X \to Y }24\\]\\[\sqrt{f: X \to Y }25\\]\\[\sqrt{f: X \to Y }26\\]\\[\sqrt{f: X \to Y }27\\]\\[\sqrt{f: X \to Y }28\\]\\[\sqrt{f: X \to Y }29\\]\\[\sqrt{f: X \to Y }30\\]\\[\sqrt{f: X \to Y }31\\]\\[\sqrt{f: X \to Y }32\\]\\[\sqr
@pkra
pkra / mathjax-node-simple-perf1.js
Created July 2, 2015 20:27
MathJax Node mjsingle test
var mjAPI = require("./lib/mj-single.js");
mjAPI.start();
var start = Date.now();
for (var i = 0; i < 100; i++) {
var input = "\\sqrt{f: X \\to Y }" + i;
console.log("\\[" + input + "\\]");
mjAPI.typeset({
math: input,
format: "TeX", // "inline-TeX", "MathML"
svg: true
@pkra
pkra / phantomJS-PDF-mathjax.js
Created May 25, 2015 07:46
PhantomJS MathJax PDF example
// via https://github.com/mathjax/MathJax/issues/1029#issuecomment-72348069 and http://c.utz.cc/mathjax/render.js
var webpage = require('webpage');
var capture = function (page, pageUrl, callback) {
page.open(pageUrl, function (status) {
var interval, allDone;
if (status !== 'success') {
callback(new Error('Error rendering page'));
@pkra
pkra / AMS-setcounter.js
Created May 1, 2015 20:13
MathJax: automatic equation numbering: set counter macro
window.MathJax = {
jax: ["input/TeX", "output/HTML-CSS"], //just some defaults
extensions: ["tex2jax.js", "MathMenu.js", "MathZoom.js"],
TeX: {
extensions: ["AMSmath.js", "AMSsymbols.js"],
equationNumbers: {
autoNumber: "AMS"
}
},
AuthorInit: function() {
@pkra
pkra / cheerio_wrapper.js
Created April 24, 2015 19:40
Testing cheerio for MathJax-node
#! /usr/bin/env node
var mjAPI = require("MathJax-node/lib/mj-single");
var typeset = mjAPI.typeset;
var fs = require('fs');
var path = require('path');
var async = require('async');
var cheerio = require('cheerio');
@pkra
pkra / git-diff-copy.sh
Created March 19, 2015 13:48
Bash to copy files that changed between commits to a new folder
#!/bin/bash
# founds this on SO but can't find the reference
# Target directory
TARGET=$3
echo "Coping to $TARGET"
for i in $(git diff --name-only $1 $2)
do
# First create the target directory, if it doesn't exist.
mkdir -p "$TARGET/$(dirname $i)"
# Then copy over the file.