MathKey enables you to share math by converting your keyboard formulated input to
presentation and
content markup. Since the math generated is based on open standards, it does not depend on mathKey and may be shared anywhere. MathKey works best with
mathML enabled web browsers.
This program is open source. In general, you may use it however you wish, but you may not fork it.
Documentation
Type math into a mathKey enabled input. You may also:
- Copy math to paste in your documents:
- for presentation:
- click the formula, or,
- focus the formula and press ctrl+c
- for content:
- double click the formula, or,
- focus the formula and press ctrl+c+c
- Style most math using chainable font modifiers:
- size (large, small)
- visibility (bold, light, hide)
- type (serif, struck, script, mono)
Examples:
hide:0 + large:A + small:b - bold:100.0 - light:10 = struck:R
, or,
bold:Energy = small:bold:mass ** light:large:C^2
The strike modifier is also available during borrow and carry (see example)
- Modify the interpretation of input or view the current set of math keys by pressing ctrl+` (hold control key and backtick) within a mathKey enabled text area.
- Share the math in a mathKey enabled text area:
- press the share icon, or
- pres ctrl+' (hold control key and apostrophe)
- Use shared content such as external math or an image. Import objects into as follows:
- single object: stackrel("url")
- example: stackrel("https://mathkey.org/mk/#intx")
- reusable reference: stackrel(name,"url")
- example: stackrel(a,"https://mathkey.org/mk/#intx")
- Images may be resized by appending height and/or width:
stackrel("https://mathkey.org/images/mklogo.png 64h")
, or,
stackrel(a,"https://mathkey.org/images/mklogo.png 256w")
, or,
stackrel(a,"https://mathkey.org/images/mklogo.png 32h 128w")
Integration
Quickstart
- Include the javascript source:
<script type="text/javascript" src="mathKey.js" data-mk-autostart="false"></script>
- Present input element keystrokes as MathML within an output element:
mathKey.processIO(input, output);
If the input is a textarea, any translated symbols within the
input.value
are first literalized by backspace before deletion by subsequent keystrokes. A complete list of rules may be accessed via CTRL+` sequence within the input.
Initialization
Set the script tag attribute
data-mk-autostart to a callback:
//data-mk-autostart="initMk":
function initMk(mathKey) {
mathKey.configure({parameters});
}
If
data-mk-autostart is otherwise true, mathKey will be initialized with default configuration parameters.
If
data-mk-autostart was not present or false, mathKey will not be initialized.
mathKey.configure([{parameters}]); //may be used to re-initialize/configure mathKey anytime
Configuration parameters
checkformathml
: Check if the browser natively supports MathML // true
notifyifnomathml
: warn the user if their browser does not support MathML // true
notifywarnings
: notify the user of warnings using a standard alert // true
notifywarningscallback
: override the alert and notify this callback function with an array of warnings instead // null
document
: Parent object // document
translateonstart
: translate elements of a predefined class to presentation markup upon instatiation //true
translateclass
: Translate the contents of elements with this class by default when translate() is called // "_MK_"
fallbackcssurl
: fallback css file for non MathML compliant browsers
fallbackliburl
: fallback library for non MathML compliant browsers
mstyle
: Attributes for primary presentation MathML style // {displaystyle:'true', scriptsizemultiplier:'0.8', scriptminsize:'6px', mathcolor:'', fontfamily:'serif'}
manage
: a key for a CTRL+key sequence to bring up a rule entry management interface // "`"
managementinterface
: Management interface template // { mkMng = {html:["header","prepend entry with","entry html containing %MKROWCOLOR% %MKENTRY% merge parameters","append entry with","footer html"], rowcolors:["#ffffff","#fcfcfc"], style: {} }
Methods
processIO(input, output [,callback])
: process keystrokes within an input textarea and generate presentationML within an output container. A mathKey property that provides access to contentML is created on the output object
translate([class=translateclass])
: translate objects of this class to MathML. After translation, the mktranslated event is fired
parseR(str)
: Translates str to return a MathML node
rgetSymbol(str)
: Returns str suffix as a mathKey entry
updateIO(input, output[, insertvalue=null, callback])
: process the input textarea and generate math at the output node. If insertvalue is provided, it will be inserted at the current cursor position first. Call updateIO() without arguments to reuse the previous input, output and callback
insertText(input, text, startfromcursor, endfromcursor)
: inserts text within an input object at an offset from the current cursor position to an offset from the current cursor position.
reParen(str)
: fix missing parentheses [experimental]
management()
: call the management interface or override it with mathKey.management=function(symbols){};
reInit()
: refresh mathKey internal state (i.e. after adding/deleting rules via a user defined management function)
manageReset()
: resets mathKey rules to original values
Support
License
mathKey.js: Copyright (c) 2018-2028 TR (tr[at]mathkey.org)
By exercising any rights granted by this license (the "License"), You agree and accept to be bound by the terms and conditions herein. To the extent that the License may be interpreted as a contract, You are granted consideration of Your agreement with these terms and conditions by consideration for your utility of the software (the "Software", "mathKey.js"), and the Copyright (the "Licensor", "TR") specified in the notice above is granted consideration for utilitizing the software from acceptance of the Software through its utilization.
Subject to Your agreement to be bound by the terms and conditions herein the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable License that shall permit You to deal in the Software and permit those upon whom You furnish the Software to use the Software, without limitation to Your rights to use, link to, copy, and/or sell copies of the Software, subject to the following terms and conditions:
Any alteration, arrangement, transformation, or other modification of the Software is an Adapted Work. Any process of publication to alter, arrange, transform, or otherwise modify the Software to an Adapted Work is disclosure of Adapted Work.
You may exercise rights to alter, arrange, transform, or otherwise modify the Software subject to the former and following terms and conditions:
Except in disclosure and distribution as part of the Software through express consent of the Licensor, Adapted Work shall not be disclosed or distributed to any recipient without such recipient of express prior agreement to not publish such Adapted Work. The Text of the License must be included in such Adapted Work.
Rights are hereby granted, free of charge, for You to publish and distribute the Software subject to the former and following terms and conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
The full text of the License, from the above Copyright notice to this license notice, (the "Text") must be included in all copies or substantial portions of the Software.