Skip to content

Commit

Permalink
Merge pull request #49 from mathjax/v4-samples
Browse files Browse the repository at this point in the history
Update samples to work with v4 loaders
  • Loading branch information
zorkow authored Feb 2, 2024
2 parents 4ae412b + 6aba36a commit a3c930e
Show file tree
Hide file tree
Showing 99 changed files with 1,299 additions and 511 deletions.
8 changes: 4 additions & 4 deletions samples/asciimath-document.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {AsciiMath} from '../mathjax3/js/input/asciimath.js';
import {CHTML} from '../mathjax3/js/output/chtml.js';
import {AsciiMath} from 'mathjax-full/js/input/asciimath.js';
import {CHTML} from 'mathjax-full/js/output/chtml.js';
import {adaptor, htmlDocument} from './lib/chooseHTML.js';
import {STATE} from '../mathjax3/js/core/MathItem.js';
import {STATE} from 'mathjax-full/js/core/MathItem.js';

const OPTIONS = {
InputJax: new AsciiMath(),
Expand Down
12 changes: 6 additions & 6 deletions samples/asciimath-json.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {AsciiMath} from '../mathjax3/js/input/asciimath.js';
import {RegisterHTMLHandler} from '../mathjax3/js/handlers/html.js';
import {chooseAdaptor} from '../mathjax3/js/adaptors/chooseAdaptor.js';
import {STATE} from '../mathjax3/js/core/MathItem.js';
import {AsciiMath} from 'mathjax-full/js/input/asciimath.js';
import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html.js';
import {chooseAdaptor} from 'mathjax-full/js/adaptors/chooseAdaptor.js';
import {STATE} from 'mathjax-full/js/core/MathItem.js';

RegisterHTMLHandler(chooseAdaptor());

const html = mathjax.document('<html></html>', {
InputJax: new AsciiMath()
});

import {JsonMmlVisitor} from '../mathjax3/js/core/MmlTree/JsonMmlVisitor.js';
import {JsonMmlVisitor} from 'mathjax-full/js/core/MmlTree/JsonMmlVisitor.js';
const visitor = new JsonMmlVisitor();
const toJSON = (node => visitor.visitTree(node));

Expand Down
8 changes: 4 additions & 4 deletions samples/asciimath2mml-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ global.MathJax = {
failed: (error => console.log(`>> MathJax(${error.package || '?'}): ${error.message} ${error.stack}`)),
load: ['adaptors/liteDOM', 'input/asciimath'],
paths: {
mathjax: '../mathjax3/components/dist',
mathjax: 'mathjax-full/components/dist',
// mathjax: './components/dist',
sre: '../mathjax3/js/a11y/sre-node'
sre: 'mathjax-full/js/a11y/sre-node'
},
source: require('../mathjax3/components/src/source.js').source,
source: require('mathjax-full/components/src/source.js').source,
// require: (url) => System.import(url)
require: require
},
Expand All @@ -25,5 +25,5 @@ global.MathJax = {
//require('../components/src/tex-chtml/tex-chtml.js');

//require('../components/dist/startup.js');
require('../mathjax3/components/src/startup/startup.js');
require('mathjax-full/components/src/startup/startup.js');

12 changes: 6 additions & 6 deletions samples/asciimath2mml.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {AsciiMath} from '../mathjax3/js/input/asciimath.js';
import {RegisterHTMLHandler} from '../mathjax3/js/handlers/html.js';
import {chooseAdaptor} from '../mathjax3/js/adaptors/chooseAdaptor.js';
import {STATE} from '../mathjax3/js/core/MathItem.js';
import {AsciiMath} from 'mathjax-full/js/input/asciimath.js';
import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html.js';
import {chooseAdaptor} from 'mathjax-full/js/adaptors/chooseAdaptor.js';
import {STATE} from 'mathjax-full/js/core/MathItem.js';

RegisterHTMLHandler(chooseAdaptor());

let html = mathjax.document('<html></html>', {
InputJax: new AsciiMath()
});

import {SerializedMmlVisitor as MmlVisitor} from '../mathjax3/js/core/MmlTree/SerializedMmlVisitor.js';
import {SerializedMmlVisitor as MmlVisitor} from 'mathjax-full/js/core/MmlTree/SerializedMmlVisitor.js';
let visitor = new MmlVisitor();
let toMml = (node => visitor.visitTree(node, html.document));

Expand Down
4 changes: 2 additions & 2 deletions samples/asyncLoad.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '../mathjax3/js/util/asyncLoad/node.js';
import {asyncLoad} from '../mathjax3/js/util/AsyncLoad.js';
import 'mathjax-full/js/util/asyncLoad/node.js';
import {asyncLoad} from 'mathjax-full/js/util/AsyncLoad.js';

asyncLoad('../js/util/entities/all.js')
.then(() => console.log("OK"))
Expand Down
2 changes: 1 addition & 1 deletion samples/bits.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {BitFieldClass} from '../mathjax3/js/util/BitField.js';
import {BitFieldClass} from 'mathjax-full/js/util/BitField.js';

const MyBits = BitFieldClass('test1', 'test2');

Expand Down
6 changes: 3 additions & 3 deletions samples/css.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {CHTML} from '../mathjax3/js/output/chtml.js';
import {liteAdaptor} from '../mathjax3/js/adaptors/liteAdaptor.js';
import {HTMLDocument} from '../mathjax3/js/handlers/html/HTMLDocument.js';
import {CHTML} from 'mathjax-full/js/output/chtml.js';
import {liteAdaptor} from 'mathjax-full/js/adaptors/liteAdaptor.js';
import {HTMLDocument} from 'mathjax-full/js/handlers/html/HTMLDocument.js';

const chtml = new CHTML();

Expand Down
4 changes: 2 additions & 2 deletions samples/find-asciimath.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {AsciiMath} from '../mathjax3/js/input/asciimath.js';
import {AsciiMath} from 'mathjax-full/js/input/asciimath.js';
import {adaptor, htmlDocument} from './lib/chooseHTML.js';
import {printFound} from './lib/found.js';

Expand Down
4 changes: 2 additions & 2 deletions samples/find-mml.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {MathML} from '../mathjax3/js/input/mathml.js';
import {MathML} from 'mathjax-full/js/input/mathml.js';
import {htmlDocument} from './lib/chooseHTML.js';

const OPTIONS = {
Expand Down
4 changes: 2 additions & 2 deletions samples/find-strings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {TeX} from '../mathjax3/js/input/tex.js';
import {TeX} from 'mathjax-full/js/input/tex.js';
import {adaptor, htmlDocument} from './lib/chooseHTML.js';
import {printFound} from './lib/found.js';

Expand Down
6 changes: 3 additions & 3 deletions samples/find-tex-dollars.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {TeX} from '../mathjax3/js/input/tex.js';
import {APPEND} from '../mathjax3/js/util/Options.js';
import {TeX} from 'mathjax-full/js/input/tex.js';
import {APPEND} from 'mathjax-full/js/util/Options.js';
import {htmlDocument} from './lib/chooseHTML.js';
import {printFound} from './lib/found.js';

Expand Down
4 changes: 2 additions & 2 deletions samples/find-tex.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {TeX} from '../mathjax3/js/input/tex.js';
import {TeX} from 'mathjax-full/js/input/tex.js';
import {htmlDocument} from './lib/chooseHTML.js';
import {printFound} from './lib/found.js';

Expand Down
6 changes: 3 additions & 3 deletions samples/html-full.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {RegisterHTMLHandler} from '../mathjax3/js/handlers/html.js';
import {chooseAdaptor} from '../mathjax3/js/adaptors/chooseAdaptor.js';
import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html.js';
import {chooseAdaptor} from 'mathjax-full/js/adaptors/chooseAdaptor.js';

RegisterHTMLHandler(chooseAdaptor());

Expand Down
6 changes: 3 additions & 3 deletions samples/lib/chooseHTML.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {mathjax} from '../../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {RegisterHTMLHandler} from '../../mathjax3/js/handlers/html.js';
import {chooseAdaptor} from '../../mathjax3/js/adaptors/chooseAdaptor.js';
import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html.js';
import {chooseAdaptor} from 'mathjax-full/js/adaptors/chooseAdaptor.js';

export const adaptor = chooseAdaptor();

Expand Down
15 changes: 15 additions & 0 deletions samples/lite-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {adaptor, htmlDocument} from './lib/chooseHTML.js';

const HTML = process.argv[3] || `
<p id="test">abx</p>
<p class="fred">fred</p>
<p>def</p>
<div class="fred">div</div>
`;

const html = htmlDocument(HTML);

//console.log(adaptor.elementsByClass(adaptor.body(html.document), 'fred'));
console.log(adaptor.getElements(['.fred'], html.document));
10 changes: 5 additions & 5 deletions samples/mfenced.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {MathML} from '../mathjax3/js/input/mathml.js';
import {RegisterHTMLHandler} from '../mathjax3/js/handlers/html.js';
import {chooseAdaptor} from '../mathjax3/js/adaptors/chooseAdaptor.js';
import {STATE} from '../mathjax3/js/core/MathItem.js';
import {MathML} from 'mathjax-full/js/input/mathml.js';
import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html.js';
import {chooseAdaptor} from 'mathjax-full/js/adaptors/chooseAdaptor.js';
import {STATE} from 'mathjax-full/js/core/MathItem.js';

RegisterHTMLHandler(chooseAdaptor());

Expand Down
12 changes: 6 additions & 6 deletions samples/mml-bbox.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {MathML} from '../mathjax3/js/input/mathml.js';
import {CHTML} from '../mathjax3/js/output/chtml.js';
import {RegisterHTMLHandler} from '../mathjax3/js/handlers/html.js';
import {chooseAdaptor} from '../mathjax3/js/adaptors/chooseAdaptor.js';
import {STATE} from '../mathjax3/js/core/MathItem.js';
import {MathML} from 'mathjax-full/js/input/mathml.js';
import {CHTML} from 'mathjax-full/js/output/chtml.js';
import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html.js';
import {chooseAdaptor} from 'mathjax-full/js/adaptors/chooseAdaptor.js';
import {STATE} from 'mathjax-full/js/core/MathItem.js';

const adaptor = chooseAdaptor();
RegisterHTMLHandler(adaptor);
Expand Down
12 changes: 6 additions & 6 deletions samples/mml-doc.js-orig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {mathjax} from '../mathjax3/mathjax.js';
import {mathjax} from 'mathjax-full/mathjax.js';

import {MathML} from '../mathjax3/input/mathml.js';
//import {CHTML} from '../mathjax3/output/chtml.js';
import {SVG} from '../mathjax3/output/svg.js';
import {RegisterHTMLHandler} from '../mathjax3/handlers/html.js';
import {browserAdaptor} from '../mathjax3/adaptors/browserAdaptor.js';
import {MathML} from 'mathjax-full/input/mathml.js';
//import {CHTML} from 'mathjax-full/output/chtml.js';
import {SVG} from 'mathjax-full/output/svg.js';
import {RegisterHTMLHandler} from 'mathjax-full/handlers/html.js';
import {browserAdaptor} from 'mathjax-full/adaptors/browserAdaptor.js';

RegisterHTMLHandler(browserAdaptor());

Expand Down
12 changes: 6 additions & 6 deletions samples/mml-nodes.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {MathML} from '../mathjax3/js/input/mathml.js';
import {RegisterHTMLHandler} from '../mathjax3/js/handlers/html.js';
import {chooseAdaptor} from '../mathjax3/js/adaptors/chooseAdaptor.js';
import {STATE} from '../mathjax3/js/core/MathItem.js';
import {MathML} from 'mathjax-full/js/input/mathml.js';
import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html.js';
import {chooseAdaptor} from 'mathjax-full/js/adaptors/chooseAdaptor.js';
import {STATE} from 'mathjax-full/js/core/MathItem.js';

RegisterHTMLHandler(chooseAdaptor());

let html = mathjax.document('<html></html>', {
InputJax: new MathML()
});

import {TestMmlVisitor as MmlVisitor} from '../mathjax3/js/core/MmlTree/TestMmlVisitor.js';
import {TestMmlVisitor as MmlVisitor} from 'mathjax-full/js/core/MmlTree/TestMmlVisitor.js';
let visitor = new MmlVisitor();
let toMathML = (node => visitor.visitTree(node, html.document));

Expand Down
12 changes: 6 additions & 6 deletions samples/mml2html.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {MathML} from '../mathjax3/js/input/mathml.js';
import {CHTML} from '../mathjax3/js/output/chtml.js';
import {RegisterHTMLHandler} from '../mathjax3/js/handlers/html.js';
import {chooseAdaptor} from '../mathjax3/js/adaptors/chooseAdaptor.js';
import {STATE} from '../mathjax3/js/core/MathItem.js';
import {MathML} from 'mathjax-full/js/input/mathml.js';
import {CHTML} from 'mathjax-full/js/output/chtml.js';
import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html.js';
import {chooseAdaptor} from 'mathjax-full/js/adaptors/chooseAdaptor.js';
import {STATE} from 'mathjax-full/js/core/MathItem.js';

const adaptor = chooseAdaptor();
RegisterHTMLHandler(adaptor);
Expand Down
12 changes: 6 additions & 6 deletions samples/mml2svg.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {MathML} from '../mathjax3/js/input/mathml.js';
import {SVG} from '../mathjax3/js/output/svg.js';
import {RegisterHTMLHandler} from '../mathjax3/js/handlers/html.js';
import {chooseAdaptor} from '../mathjax3/js/adaptors/chooseAdaptor.js';
import {STATE} from '../mathjax3/js/core/MathItem.js';
import {MathML} from 'mathjax-full/js/input/mathml.js';
import {SVG} from 'mathjax-full/js/output/svg.js';
import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html.js';
import {chooseAdaptor} from 'mathjax-full/js/adaptors/chooseAdaptor.js';
import {STATE} from 'mathjax-full/js/core/MathItem.js';

const adaptor = chooseAdaptor();
RegisterHTMLHandler(adaptor);
Expand Down
16 changes: 8 additions & 8 deletions samples/notagids.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {mathjax} from '../mathjax3/js/mathjax.js';
import {mathjax} from 'mathjax-full/js/mathjax.js';

import {TeX} from '../mathjax3/js/input/tex.js';
import {RegisterHTMLHandler} from '../mathjax3/js/handlers/html.js';
import {chooseAdaptor} from '../mathjax3/js/adaptors/chooseAdaptor.js';
import {AllPackages} from '../mathjax3/js/input/tex/AllPackages.js';
import {STATE} from '../mathjax3/js/core/MathItem.js';
import {TeX} from 'mathjax-full/js/input/tex.js';
import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html.js';
import {chooseAdaptor} from 'mathjax-full/js/adaptors/chooseAdaptor.js';
import {AllPackages} from 'mathjax-full/js/input/tex/AllPackages.js';
import {STATE} from 'mathjax-full/js/core/MathItem.js';

import {AbstractTags, TagsFactory} from '../mathjax3/js/input/tex/Tags.js';
import {AbstractTags, TagsFactory} from 'mathjax-full/js/input/tex/Tags.js';

class NoIdTags extends AbstractTags {

Expand All @@ -30,7 +30,7 @@ let html = mathjax.document(
'',
{InputJax: new TeX({packages: {'[-]': ['bussproofs']}, tags: 'noID'})});

import {SerializedMmlVisitor} from '../mathjax3/js/core/MmlTree/SerializedMmlVisitor.js';
import {SerializedMmlVisitor} from 'mathjax-full/js/core/MmlTree/SerializedMmlVisitor.js';
let visitor = new SerializedMmlVisitor();
let toMml = (node => visitor.visitTree(node));

Expand Down
37 changes: 15 additions & 22 deletions samples/tables/lib/dual-tables.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {MathML} from "../../../mathjax3/input/mathml.js";
import {CHTML} from "../../../mathjax3/output/chtml.js";
import {SVG} from "../../../mathjax3/output/svg.js";
import {HTMLMathItem} from "../../../mathjax3/handlers/html/HTMLMathItem.js";
import {HTMLDocument} from "../../../mathjax3/handlers/html/HTMLDocument.js";
import {handleRetriesFor} from "../../../mathjax3/util/Retries.js";
import {browserAdaptor} from "../../../mathjax3/adaptors/browserAdaptor.js";
import {MathML} from "mathjax-full/js/input/mathml.js";
import {CHTML} from "mathjax-full/js/output/chtml.js";
import {SVG} from "mathjax-full/js/output/svg.js";
import {HTMLMathItem} from "mathjax-full/js/handlers/html/HTMLMathItem.js";
import {HTMLDocument} from "mathjax-full/js/handlers/html/HTMLDocument.js";
import {handleRetriesFor} from "mathjax-full/js/util/Retries.js";
import {browserAdaptor} from "mathjax-full/js/adaptors/browserAdaptor.js";

let mml = new MathML({forceReparse: true});
let chtml = new CHTML({fontURL: '../../mathjax2/css/'});
let svg = new SVG();
let chtml = new CHTML({fontURL: '../../node_modules/mathjax-modern-font/chtml/woff'});
let svg = new SVG({});

let docs = {
CHTML: new HTMLDocument(document, browserAdaptor(), {InputJax: mml, OutputJax: chtml}),
Expand Down Expand Up @@ -75,7 +75,7 @@ function linkTables(n, m, arrow) {
return '<a href="tables-' + N + '.html"' + (n === m ? ' disabled="true"' : '') + '>&#x' + arrow + ';</a>';
}

const testNo = parseInt(this.location.pathname.match(/-(\d+)\.html$/)[1]);
const testNo = parseInt(window.location.pathname.match(/-(\d+)\.html$/)[1]);
const maxTest = 60;

const nav = document.body.appendChild(document.createElement('div'));
Expand All @@ -86,16 +86,9 @@ nav.innerHTML = [
].join(' ');


docs.CHTML
.findMath({elements: ['mjx-chtml-table']})
.compile()
.getMetrics()
.typeset()
.updateDocument();
chtml.options.elements = ['mjx-chtml-table'];
svg.options.elements = ['mjx-svg-table'];

docs.CHTML.render();
docs.SVG.render();

docs.SVG
.findMath({elements: ['mjx-svg-table']})
.compile()
.getMetrics()
.typeset()
.updateDocument();
Loading

0 comments on commit a3c930e

Please sign in to comment.