Something went wrong. Try again.
fork of mathquill to add matrix support. used in cartesium
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152<!doctype html><html> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>MathQuill Matrix Demo</title> <link rel="stylesheet" href="support/home.css" /> <link rel="stylesheet" href="../build/mathquill.css" /> <style> #field { font-size: 24px; } #rows, #columns { width: 4em; } #latex { width: 100%; } button { margin: 4px; } .colored { color: #75e1af; background: #18212b; padding: 12px; } </style> </head> <body> <div id="body"> <h1>MathQuill Matrix Demo</h1> <p> Edit cells with arrow keys and Tab. Drag the blue dot at the matrix containing the cursor to resize it live; press Escape to restore the starting size and contents. Use the controls below for direct commands. Type <code>#32</code> to make a 3-by-2 matrix. The shorthand is enabled with <code>matrixShortcuts: true</code>. </p> <p> <span id="field">\begin{bmatrix}1&2\\3&4\end{bmatrix}</span> </p> <p> <label ><input id="resize-handles" type="checkbox" checked /> Show matrix resize dot</label > <label >Environment <select id="environment"> <option>matrix</option> <option>pmatrix</option> <option selected>bmatrix</option> <option>Bmatrix</option> <option>vmatrix</option> <option>Vmatrix</option> </select></label > <label >Rows <input id="rows" type="number" min="1" value="3" size="3" /></label> <label >Columns <input id="columns" type="number" min="1" value="2" size="3" /></label> <button id="new">Insert matrix</button> <button id="resize-shape">Resize current matrix</button> </p> <p> The API call <code>matrixCmd('resize', rows, columns)</code> keeps the top-left cells and grows with empty cells. </p> <p id="resize"> <button data-command="addRow" data-direction="-1"> Add row before </button> <button data-command="addRow">Add row after</button> <button data-command="deleteRow">Delete row</button> <button data-command="addColumn" data-direction="-1"> Add column before </button> <button data-command="addColumn">Add column after</button> <button data-command="deleteColumn">Delete column</button> </p> <p> <label>LaTeX <textarea id="latex" rows="4"></textarea></label ><button id="load">Load LaTeX</button> </p> <p id="speech"></p> <p class="colored"> <span id="tall" >\begin{bmatrix}1\\2\\3\\4\\5\\6\\7\\8\end{bmatrix}+\left[x\right]</span > </p> </div> <script src="../build/mathquill.js"></script> <script> const MQ = MathQuill.getInterface(3); const latex = document.getElementById('latex'); const speech = document.getElementById('speech'); let mq; function update(field) { latex.value = field.latex(); speech.textContent = field.mathspeak(); } mq = MQ.MathField(document.getElementById('field'), { matrixShortcuts: true, matrixResizeHandles: true, handlers: { edit: update } }); update(mq); document.getElementById('resize-handles').onchange = function (event) { mq.config({ matrixResizeHandles: event.target.checked }); }; document.querySelectorAll('button').forEach(function (button) { button.addEventListener('mousedown', function (event) { event.preventDefault(); }); }); document.getElementById('new').onclick = function () { mq.matrixCmd( 'new', document.getElementById('environment').value, Number(document.getElementById('rows').value), Number(document.getElementById('columns').value) ).focus(); }; document.getElementById('resize-shape').onclick = function () { mq.matrixCmd( 'resize', Number(document.getElementById('rows').value), Number(document.getElementById('columns').value) ).focus(); }; document.querySelectorAll('#resize button').forEach(function (button) { button.onclick = function () { if (button.dataset.direction) mq.matrixCmd( button.dataset.command, Number(button.dataset.direction) ); else mq.matrixCmd(button.dataset.command); mq.focus(); }; }); document.getElementById('load').onclick = function () { mq.latex(latex.value).focus(); }; MQ.StaticMath(document.getElementById('tall')); </script> </body></html>