Factored remaining docs out of index
diff --git a/README.md b/README.md index a96a295..2b51817 100644 --- a/README.md +++ b/README.md
@@ -1,10 +1,6 @@ # [MathQuill](http://mathquill.github.com) -by [Han][], [Jeanine][], and [Mary][] (maintainers@mathquill.com) - -[Han]: http://github.com/laughinghan -[Jeanine]: http://github.com/jneen -[Mary]: http://github.com/stufflebear +by [Han](http://github.com/laughinghan), [Jeanine](http://github.com/jneen), and [Mary](http://github.com/stufflebear) (maintainers@mathquill.com) Good news! We've resumed active development and we're committed to getting things running smoothly. @@ -17,9 +13,22 @@ <big>[<img alt="slackin.mathquill.com" src="http://slackin.mathquill.com/badge.svg" align="top">](http://slackin.mathquill.com) [<img alt="freenode irc: #mathquill" src="https://img.shields.io/badge/%20freenode%20irc%20-%20%23mathquill%20-brightgreen.svg" align="top">](http://webchat.freenode.net/?channels=mathquill)</big> -## Docs +## Getting Started -Check out the docs on [Read The Docs](http://mathquill.readthedocs.org/) +Check out our [Getting Started Guide](http://mathquill.readthedocs.org/en/latest/Getting_Started/) for instructions on how to get setup up with MathQuill and start using it. + +MathQuill has a simple interface: +```javascript +var domObject = document.getElementById('#some_id'); +var config = { + handlers: {edit: myEditHandler}, + restrictMismatchedBrackets: true +} +var mathField = MQ.MathField(domObject, config); + +mathField.latex('2^{\frac{3}{2}}') // Renders the given LaTeX in the MathQuill field +console.log(mathField.latex()) // Shows '2^{\frac{3}{2}}' +``` ## Open-Source License @@ -28,6 +37,4 @@ The quick-and-dirty is you can do whatever if modifications to MathQuill are in public GitHub forks. (Other ways to publicize modifications are also fine, as -are private use modifications. See also: [MPL 2.0 FAQ][]) - -[MPL 2.0 FAQ]: https://www.mozilla.org/en-US/MPL/2.0/FAQ/ +are private use modifications. See also: [MPL 2.0 FAQ](https://www.mozilla.org/en-US/MPL/2.0/FAQ/))
diff --git a/docs/Api_Methods.md b/docs/Api_Methods.md index a1452cc..a7b4ea3 100644 --- a/docs/Api_Methods.md +++ b/docs/Api_Methods.md
@@ -6,21 +6,41 @@ var MQ = MathQuill.getInterface(2); ``` +MathQuill overwrites the global `MathQuill` variable when loaded. You can undo +that with `.noConflict()` (similar to [`jQuery.noConflict()`] +(http://api.jquery.com/jQuery.noConflict)): + +```html +<script src="/path/to/first-mathquill.js"></script> +<script src="/path/to/second-mathquill.js"></script> +<script> +var secondMQ = MathQuill.noConflict().getInterface(2); +secondMQ.MathField(...); + +var firstMQ = MathQuill.getInterface(2); +firstMQ.MathField(...); +</script> +``` + +(Warning: This lets different copies of MathQuill each power their own + math fields, but using different copies on the same DOM element won't + work. Anyway, .noConflict() is primarily to help you reduce globals.) + ## Constructors -### `MQ.StaticMath(DOM_OBJECT)` +### MQ.StaticMath(DOM_OBJECT) -Creates a non-editable MathQuill with the contents of the HTML element and returns a [static MathField object](). +Creates a non-editable MathQuill with the contents of the HTML element and returns a [static MathField object](http://mathquill.readthedocs.org/en/latest/Api_Methods/#mathfield-methods). If the element is already a static MathField, this will return a new static Mathfield object with the same ID. If the element is a different type of MathQuill element, this will return null. -### `MQ.MathField(DOM_OBJECT, CONFIG)` +### MQ.MathField(DOM_OBJECT, CONFIG) -Creates an editable MathQuill with the contents of the HTML element and returns an [editable MathField object](). +Creates an editable MathQuill with the contents of the HTML element and returns an [editable MathField object](http://mathquill.readthedocs.org/en/latest/Api_Methods/#editable-mathfield-methods). If the element is already an editable MathField, this will return a new editable Mathfield object with the same ID. If the element is a different type of MathQuill element, this will return null. -### `MQ(DOM_OBJECT)` +### MQ(DOM_OBJECT) `MQ` itself is a function that takes an HTML element and, if it's the root HTML element of a static math or math field, returns an API object for it @@ -50,7 +70,7 @@ ### ID API objects for the same MathQuill instance have the same `.id`, which will always be a unique truthy primitive value that can be used as an object key -(like an ad hoc [`Map`][] or [`Set`][]): +(like an ad hoc [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) or [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)): ```js MQ(mathFieldSpan).id === mathField.id // => true @@ -61,12 +81,9 @@ staticMath.id in setOfMathFields // => false ``` -[`Map`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map -[`Set`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set - ### Data Object Similarly, API objects for the same MathQuill instance share a `.data` object -(which can be used like an ad hoc [`WeakMap`][] or [`WeakSet`][]): +(which can be used like an ad hoc [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) or [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)): ```js MQ(mathFieldSpan).data === mathField.data // => true @@ -74,13 +91,71 @@ MQ(mathFieldSpan).data.foo // => 'bar' ``` -[`WeakMap`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap -[`WeakSet`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet - ## MathField Methods These are methods that every MathField has. +Any element that has been MathQuill-ified can be reverted: +```html +<span id="revert-me" class="mathquill-static-math"> + some <code>HTML</code> +</span> +``` +```js +MQ($('#revert-me')[0]).revert().html(); // => 'some <code>HTML</code>' +``` + +MathQuill uses computed dimensions, so if they change (because an element was +mathquill-ified before it was in the visible HTML DOM, or the font size +changed), then you'll need to tell MathQuill to recompute: + +```js +var mathFieldSpan = $('<span>\\sqrt{2}</span>'); +var mathField = MQ.MathField(mathFieldSpan[0]); +mathFieldSpan.appendTo(document.body); +mathField.reflow(); +``` + +MathQuill API objects further expose the following public methods: + +* `.el()` returns the root HTML element +* `.html()` returns the contents as static HTML +* `.latex()` returns the contents as LaTeX +* `.latex('a_n x^n')` will render the argument as LaTeX + ## Editable MathField Methods -Editable MathFields have all of the [above]() methods in addition to the ones listed here. +Editable MathFields have all of the [above](http://mathquill.readthedocs.org/en/latest/Api_Methods/#mathfield-methods) methods in addition to the ones listed here. + +Additionally, descendants of `MQ.EditableField` (currently only `MQ.MathField`) +expose: + +* `.focus()`, `.blur()` focuses or defocuses the editable field +* `.write(' - 1')` will write some LaTeX at the current cursor position +* `.cmd('\\sqrt')` will enter a LaTeX command at the current cursor position or + with the current selection +* `.select()` selects the contents (just like [on `textarea`s][] and [on + `input`s][]) +* `.clearSelection()` clears the current selection +* `.moveTo{Left,Right,Dir}End()` move the cursor to the left/right end of the + editable field, respectively. (The first two are implemented in terms of + `.moveToDirEnd(dir)` where `dir` is one of `MQ.L` or `MQ.R`, constants that + obey the contract that `MQ.L === -MQ.R` and vice versa.) +* `.keystroke(keys)` simulates keystrokes given a string like `"Ctrl-Home Del"`, + a whitespace-delimited list of [key values][] with optional prefixes +* `.typedText(text)` simulates typing text, one character at a time +* `ᴇxᴘᴇʀɪᴍᴇɴᴛᴀʟ` `.dropEmbedded(pageX, pageY, options)` insert a custom + embedded element at the given coordinates, where `options` is an object like: + + ```js + { + htmlString: '<span class="custom-embed"></span>', + text: function() { return 'custom_embed'; }, + latex: function() { return '\customEmbed'; } + } + ``` +* `ᴇxᴘᴇʀɪᴍᴇɴᴛᴀʟ` `.registerEmbed('name', function(id){return options})` allows MathQuill to parse custom embedded objects from latex, where `options` is an object like the one defined above in `.dropEmbedded`. This will parse the following latex into the embedded object you defined: `\embed{name}[id]}` + +[on `textarea`s]: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-48880622 +[on `input`s]: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-34677168 +[key values]: http://www.w3.org/TR/2012/WD-DOM-Level-3-Events-20120614/#fixed-virtual-key-codes
diff --git a/docs/Config.md b/docs/Config.md index e32b603..a09aee7 100644 --- a/docs/Config.md +++ b/docs/Config.md
@@ -2,7 +2,7 @@ ## Setting Configuration -The configuration options for a given mathField has the following structure and [properties](): +The configuration options for a given mathField has the following structure and [options](http://mathquill.readthedocs.org/en/latest/Config/#configuration-options): ```js { spaceBehavesLikeTab: true, @@ -103,11 +103,9 @@ `autoOperatorNames`, a list of the same form (space-delimited letters-only each length>=2), and overrides the set of operator names that automatically become non-italicized when typing the letters without typing a backslash first, like -`sin`, `log`, etc. (Defaults to [the LaTeX built-in operator names][Wikia], but +`sin`, `log`, etc. (Defaults to [the LaTeX built-in operator names](http://latex.wikia.com/wiki/List_of_LaTeX_symbols#Named_operators:_sin.2C_cos.2C_etc.), but with additional trig operators like `sech`, `arcsec`, `arsinh`, etc.) -[Wikia]: http://latex.wikia.com/wiki/List_of_LaTeX_symbols#Named_operators:_sin.2C_cos.2C_etc. - ### substituteTextarea `substituteTextarea`, a function that creates a focusable DOM element, called @@ -115,17 +113,13 @@ but for example, Desmos substitutes `<span tabindex=0></span>` on iOS to suppress the built-in virtual keyboard in favor of a custom math keypad that calls the MathQuill API. Unfortunately there's no universal [check for a virtual -keyboard][StackOverflow], you can't even [detect a touchscreen][stucox] (notably -[Modernizr gave up][Modernizr]) and even if you could, Windows 8 and ChromeOS +keyboard](http://stackoverflow.com/q/2593139/362030), you can't even [detect a touchscreen](http://www.stucox.com/blog/you-cant-detect-a-touchscreen/) (notably +[Modernizr gave up](https://github.com/Modernizr/Modernizr/issues/548)) and even if you could, Windows 8 and ChromeOS devices have both physical keyboards and touchscreens and you can connect physical keyboards to iOS and Android devices with Bluetooth, so touchscreen != virtual keyboard. Desmos currently sniffs the user agent for iOS, so Bluetooth keyboards just don't work in Desmos on iOS, the tradeoffs are up to you. -[StackOverflow]: http://stackoverflow.com/q/2593139/362030 -[stucox]: http://www.stucox.com/blog/you-cant-detect-a-touchscreen/ -[Modernizr]: https://github.com/Modernizr/Modernizr/issues/548 - ### Handlers Supported handlers: @@ -181,3 +175,36 @@ } }); ``` +### Changing Colors + +To change the foreground color, don't just set the `color`, also set +the `border-color`, because the cursor, fraction bar, and square root +overline are all borders, not text. (Example below.) + +Due to technical limitations of IE8, if you support it, and want to give +a MathQuill editable a background color other than white, and support +square roots, parentheses, square brackets, or curly braces, you will +need to, in addition to of course setting the background color on the +editable itself, set it on elements with class `mq-matrixed`, and then set +a Chroma filter on elements with class `mq-matrixed-container`. + +For example, to style as white-on-black instead of black-on-white: + + #my-math-input { + color: white; + border-color: white; + background: black; + } + #my-math-input .mq-matrixed { + background: black; + } + #my-math-input .mq-matrixed-container { + filter: progid:DXImageTransform.Microsoft.Chroma(color='black'); + } + +(This is because almost all math rendered by MathQuill has a transparent +background, so for them it's sufficient to set the background color on +the editable itself. The exception is, IE8 doesn't support CSS +transforms, so MathQuill uses a matrix filter to stretch parens etc, +which [anti-aliases wrongly without an opaque background](http://github.com/mathquill/mathquill/wiki/Transforms), +so MathQuill defaults to white.)
diff --git a/docs/Contributing.md b/docs/Contributing.md index a8f9408..01376a9 100644 --- a/docs/Contributing.md +++ b/docs/Contributing.md
@@ -1,3 +1,95 @@ # Contributing -## Build from Source \ No newline at end of file +## Building and Testing + +To hack on MathQuill, you're gonna want to build and test the source files +you edit. In addition to `make`, MathQuill uses some build tools written on +[Node](http://nodejs.org/#download), so you will need to install that before +running `make`. (Once it's installed, `make` automatically does `npm install`, +installing the necessary build tools.) + +- `make` builds `build/mathquill.{css,js,min.js}` +- `make dev` won't try to minify MathQuill (which can be annoyingly slow) +- `make test` builds `mathquill.test.js` (used by `test/unit.html`) and also + doesn't minify +- `make basic` builds `mathquill-basic.{js,min.js,css}` and + `font/Symbola-basic.{eot,ttf}`; serve and load them instead for a stripped- + down version of MathQuill for basic mathematics, without advanced LaTeX + commands. Specifically, it doesn't let you type LaTeX backslash commands + with `\` or text blocks with `$`, and also won't render any LaTeX commands + that can't by typed without `\`. The resulting JS is only somewhat smaller, + but the font is like 100x smaller. (TODO: reduce full MathQuill's font size.) + +## Understanding The Source Code + +All the CSS is in `src/css`. Most of it's pretty straightforward, the choice of +font isn't settled, and fractions are somewhat arcane, see the Wiki pages +["Fonts"](http://github.com/mathquill/mathquill/wiki/Fonts) and +["Fractions"](http://github.com/mathquill/mathquill/wiki/Fractions). + +All the JavaScript that you actually want to read is in `src/`, `build/` is +created by `make` to contain the same JS cat'ed and minified. + +There's a lot of JavaScript but the big picture isn't too complicated, there's 2 +thin layers sandwiching 2 broad but modularized layers: + +- At the highest level, the public API is a thin wrapper around calls to: +- "services" on the "controller", which sets event listeners that call: +- methods on "commands" in the "edit tree", which call: +- tree- and cursor-manipulation methods, at the lowest level, to move the + cursor or edit the tree or whatever. + +More specifically: + +(In comments and internal documentation, `::` means `.prototype.`.) + +- At the lowest level, the **edit tree** of JS objects represents math and text + analogously to how [the HTML DOM](http://www.w3.org/TR/html5-author/introduction.html#a-quick-introduction-to-html) represents a web page. + + (Old docs variously called this the "math tree", the "fake DOM", or some + combination thereof, like the "math DOM".) + + `tree.js` defines base classes of objects relating to the tree. + + `cursor.js` defines objects representing the cursor and a selection of + math or text, with associated HTML elements. +- Interlude: a **feature** is a unit of publicly exposed functionality, either + by the API or interacted with by typists. Following are the 2 disjoint + categories of features. +- A **command** is a thing you can type and edit like a fraction, square root, + or "for all" symbol, ∀. They are implemented as a class of node objects + in the edit tree, like `Fraction`, `SquareRoot`, or `VanillaSymbol`. + + Each command has an associated **control sequence** (as termed by Knuth; + in the LaTeX community, commonly called a "macro" or "command"), a token + in TeX and LaTeX syntax consisting of a backslash then any single + character or string of letters, like `\frac` or <code>\ </code>. Unlike + loose usage in the LaTeX community, where `\ne` and `\neq` (which print + the same symbol, ≠) might or might not be considered the same command, + in the context of MathQuill they are considered different "control + sequences" for the same "command". +- A **service** is a feature that applies to all or many commands, like typing, + moving the cursor around, LaTeX exporting, LaTeX parsing. Note that each of + these varies by command (the cursor goes in a different place when moving into + a fraction vs into a square root, they export different LaTeX, etc), cue + polymorphism: services define methods on the controller that call methods on + nodes in the edit tree with certain contracts, such as a controller method + called on initialization to set listeners for keyboard events, that when the + Left key is pressed, calls `.moveTowards` on the node just left of the cursor, + dispatching on what kind of command the node is (`Fraction::moveTowards` and + `SquareRoot::moveTowards` can insert the cursor in different places). + + `controller.js` defines the base class for the **controller**, which each + math field or static math instance has one of, and to which each service + adds methods. +- `publicapi.js` defines the global `MathQuill.getInterface()` function, the + `MQ.MathField()` etc. constructors, and the API objects returned by + them. The constructors, and the API methods on the objects they return, call + appropriate controller methods to initialize and manipulate math field and + static math instances. + +Misc.: + +`intro.js` defines some simple sugar for the idiomatic JS classes used +throughout MathQuill, plus some globals and opening boilerplate. + +Classes are defined using [Pjs](https://github.com/jneen/pjs), and the variable `_` is used by convention as +the prototype. + +`services/*.util.js` files are unimportant to the overall architecture, you can +ignore them until you have to deal with code that is using them.
diff --git a/docs/Getting_Started.md b/docs/Getting_Started.md index 3365bdc..21febd0 100644 --- a/docs/Getting_Started.md +++ b/docs/Getting_Started.md
@@ -17,15 +17,15 @@ var MQ = MathQuill.getInterface(2); ``` -All [API methods]() will be called on `MQ`. +All [API methods](http://mathquill.readthedocs.org/en/latest/Api_Methods/) will be called on `MQ`. You can also [build from the source code](). ## Basic Usage -MathQuill instances can be created on DOM objects. For the full list of constructors and API methods, see [API Methods](). +MathQuill instances can be created on DOM objects. For the full list of constructors and API methods, see [API Methods](http://mathquill.readthedocs.org/en/latest/Api_Methods). -The below examples assume that MathQuill has been properly loaded and exposed as `MQ` as shown [above](). +The below examples assume that MathQuill has been properly loaded and exposed as `MQ` as shown [above](http://mathquill.readthedocs.org/en/latest/Getting_Started/#download-and-load). ### Render Static Math @@ -41,7 +41,7 @@ ### Editable Math -To create an editable math field, call `MQ.MathField` with the dom object and the [config](). The following example shows a mathfield created on the answer span with a handler to check the answer every time an edit may occur. +To create an editable math field, call `MQ.MathField` with the dom object and the [config](http://mathquill.readthedocs.org/en/latest/Config/). The following example shows a mathfield created on the answer span with a handler to check the answer every time an edit may occur. ```html <p><span id="answer">x=</span></p>
diff --git a/docs/index.md b/docs/index.md index 19adf2c..2b51817 100644 --- a/docs/index.md +++ b/docs/index.md
@@ -1,225 +1,40 @@ # [MathQuill](http://mathquill.github.com) -MathQuill is a web formula editor designed to make typing math easy and beautiful. To view a demo, check out our [website](http://mathquill.com/). +by [Han](http://github.com/laughinghan), [Jeanine](http://github.com/jneen), and [Mary](http://github.com/stufflebear) (maintainers@mathquill.com) -## Everything Below this still needs to be refactored +Good news! We've resumed active development and we're committed to getting +things running smoothly. +Find a dusty corner? [Let us know.](https://github.com/mathquill/mathquill/issues) -Any element that has been MathQuill-ified can be reverted: +MathQuill is a web formula editor designed to make typing math easy and beautiful. To view a demo, please view our [website](http://mathquill.com/). The MathQuill project is currently supported by its [partners](http://mathquill.com/partners.html). We are bound by a [Code of Conduct](http://mathquill.readthedocs.org/en/latest/Code_of_Conduct/). -```html -<span id="revert-me" class="mathquill-static-math"> - some <code>HTML</code> -</span> -``` -```js -MQ($('#revert-me')[0]).revert().html(); // => 'some <code>HTML</code>' +We'd love to hear from you-we love offering help and receiving feedback. + +<big>[<img alt="slackin.mathquill.com" src="http://slackin.mathquill.com/badge.svg" align="top">](http://slackin.mathquill.com) +[<img alt="freenode irc: #mathquill" src="https://img.shields.io/badge/%20freenode%20irc%20-%20%23mathquill%20-brightgreen.svg" align="top">](http://webchat.freenode.net/?channels=mathquill)</big> + +## Getting Started + +Check out our [Getting Started Guide](http://mathquill.readthedocs.org/en/latest/Getting_Started/) for instructions on how to get setup up with MathQuill and start using it. + +MathQuill has a simple interface: +```javascript +var domObject = document.getElementById('#some_id'); +var config = { + handlers: {edit: myEditHandler}, + restrictMismatchedBrackets: true +} +var mathField = MQ.MathField(domObject, config); + +mathField.latex('2^{\frac{3}{2}}') // Renders the given LaTeX in the MathQuill field +console.log(mathField.latex()) // Shows '2^{\frac{3}{2}}' ``` -MathQuill uses computed dimensions, so if they change (because an element was -mathquill-ified before it was in the visible HTML DOM, or the font size -changed), then you'll need to tell MathQuill to recompute: +## Open-Source License -```js -var mathFieldSpan = $('<span>\\sqrt{2}</span>'); -var mathField = MQ.MathField(mathFieldSpan[0]); -mathFieldSpan.appendTo(document.body); -mathField.reflow(); -``` +The Source Code Form of MathQuill is subject to the terms of the Mozilla Public +License, v. 2.0: http://mozilla.org/MPL/2.0/ -MathQuill API objects further expose the following public methods: - -* `.el()` returns the root HTML element -* `.html()` returns the contents as static HTML -* `.latex()` returns the contents as LaTeX -* `.latex('a_n x^n')` will render the argument as LaTeX - -Additionally, descendants of `MQ.EditableField` (currently only `MQ.MathField`) -expose: - -* `.focus()`, `.blur()` focuses or defocuses the editable field -* `.write(' - 1')` will write some LaTeX at the current cursor position -* `.cmd('\\sqrt')` will enter a LaTeX command at the current cursor position or - with the current selection -* `.select()` selects the contents (just like [on `textarea`s][] and [on - `input`s][]) -* `.clearSelection()` clears the current selection -* `.moveTo{Left,Right,Dir}End()` move the cursor to the left/right end of the - editable field, respectively. (The first two are implemented in terms of - `.moveToDirEnd(dir)` where `dir` is one of `MQ.L` or `MQ.R`, constants that - obey the contract that `MQ.L === -MQ.R` and vice versa.) -* `.keystroke(keys)` simulates keystrokes given a string like `"Ctrl-Home Del"`, - a whitespace-delimited list of [key values][] with optional prefixes -* `.typedText(text)` simulates typing text, one character at a time -* `ᴇxᴘᴇʀɪᴍᴇɴᴛᴀʟ` `.dropEmbedded(pageX, pageY, options)` insert a custom - embedded element at the given coordinates, where `options` is an object like: - - ```js - { - htmlString: '<span class="custom-embed"></span>', - text: function() { return 'custom_embed'; }, - latex: function() { return '\customEmbed'; } - } - ``` -* `ᴇxᴘᴇʀɪᴍᴇɴᴛᴀʟ` `.registerEmbed('name', function(id){return options})` allows MathQuill to parse custom embedded objects from latex, where `options` is an object like the one defined above in `.dropEmbedded`. This will parse the following latex into the embedded object you defined: `\embed{name}[id]}` - -[on `textarea`s]: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-48880622 -[on `input`s]: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-34677168 -[key values]: http://www.w3.org/TR/2012/WD-DOM-Level-3-Events-20120614/#fixed-virtual-key-codes - -MathQuill overwrites the global `MathQuill` variable when loaded. You can undo -that with `.noConflict()` (similar to [`jQuery.noConflict()`] -(http://api.jquery.com/jQuery.noConflict)): - -```html -<script src="/path/to/first-mathquill.js"></script> -<script src="/path/to/second-mathquill.js"></script> -<script> -var secondMQ = MathQuill.noConflict().getInterface(2); -secondMQ.MathField(...); - -var firstMQ = MathQuill.getInterface(2); -firstMQ.MathField(...); -</script> -``` - -(Warning: This lets different copies of MathQuill each power their own - math fields, but using different copies on the same DOM element won't - work. Anyway, .noConflict() is primarily to help you reduce globals.) - -#### Configuration Options - - - -**A Note On Changing Colors:** - -To change the foreground color, don't just set the `color`, also set -the `border-color`, because the cursor, fraction bar, and square root -overline are all borders, not text. (Example below.) - -Due to technical limitations of IE8, if you support it, and want to give -a MathQuill editable a background color other than white, and support -square roots, parentheses, square brackets, or curly braces, you will -need to, in addition to of course setting the background color on the -editable itself, set it on elements with class `mq-matrixed`, and then set -a Chroma filter on elements with class `mq-matrixed-container`. - -For example, to style as white-on-black instead of black-on-white: - - #my-math-input { - color: white; - border-color: white; - background: black; - } - #my-math-input .mq-matrixed { - background: black; - } - #my-math-input .mq-matrixed-container { - filter: progid:DXImageTransform.Microsoft.Chroma(color='black'); - } - -(This is because almost all math rendered by MathQuill has a transparent -background, so for them it's sufficient to set the background color on -the editable itself. The exception is, IE8 doesn't support CSS -transforms, so MathQuill uses a matrix filter to stretch parens etc, -which [anti-aliases wrongly without an opaque background][Transforms], -so MathQuill defaults to white.) - -[Transforms]: http://github.com/mathquill/mathquill/wiki/Transforms - -## Building and Testing - -To hack on MathQuill, you're gonna want to build and test the source files -you edit. In addition to `make`, MathQuill uses some build tools written on -[Node](http://nodejs.org/#download), so you will need to install that before -running `make`. (Once it's installed, `make` automatically does `npm install`, -installing the necessary build tools.) - -- `make` builds `build/mathquill.{css,js,min.js}` -- `make dev` won't try to minify MathQuill (which can be annoyingly slow) -- `make test` builds `mathquill.test.js` (used by `test/unit.html`) and also - doesn't minify -- `make basic` builds `mathquill-basic.{js,min.js,css}` and - `font/Symbola-basic.{eot,ttf}`; serve and load them instead for a stripped- - down version of MathQuill for basic mathematics, without advanced LaTeX - commands. Specifically, it doesn't let you type LaTeX backslash commands - with `\` or text blocks with `$`, and also won't render any LaTeX commands - that can't by typed without `\`. The resulting JS is only somewhat smaller, - but the font is like 100x smaller. (TODO: reduce full MathQuill's font size.) - -## Understanding The Source Code - -All the CSS is in `src/css`. Most of it's pretty straightforward, the choice of -font isn't settled, and fractions are somewhat arcane, see the Wiki pages -["Fonts"](http://github.com/mathquill/mathquill/wiki/Fonts) and -["Fractions"](http://github.com/mathquill/mathquill/wiki/Fractions). - -All the JavaScript that you actually want to read is in `src/`, `build/` is -created by `make` to contain the same JS cat'ed and minified. - -There's a lot of JavaScript but the big picture isn't too complicated, there's 2 -thin layers sandwiching 2 broad but modularized layers: - -- At the highest level, the public API is a thin wrapper around calls to: -- "services" on the "controller", which sets event listeners that call: -- methods on "commands" in the "edit tree", which call: -- tree- and cursor-manipulation methods, at the lowest level, to move the - cursor or edit the tree or whatever. - -More specifically: - -(In comments and internal documentation, `::` means `.prototype.`.) - -- At the lowest level, the **edit tree** of JS objects represents math and text - analogously to how [the HTML DOM][] represents a web page. - + (Old docs variously called this the "math tree", the "fake DOM", or some - combination thereof, like the "math DOM".) - + `tree.js` defines base classes of objects relating to the tree. - + `cursor.js` defines objects representing the cursor and a selection of - math or text, with associated HTML elements. -- Interlude: a **feature** is a unit of publicly exposed functionality, either - by the API or interacted with by typists. Following are the 2 disjoint - categories of features. -- A **command** is a thing you can type and edit like a fraction, square root, - or "for all" symbol, ∀. They are implemented as a class of node objects - in the edit tree, like `Fraction`, `SquareRoot`, or `VanillaSymbol`. - + Each command has an associated **control sequence** (as termed by Knuth; - in the LaTeX community, commonly called a "macro" or "command"), a token - in TeX and LaTeX syntax consisting of a backslash then any single - character or string of letters, like `\frac` or <code>\ </code>. Unlike - loose usage in the LaTeX community, where `\ne` and `\neq` (which print - the same symbol, ≠) might or might not be considered the same command, - in the context of MathQuill they are considered different "control - sequences" for the same "command". -- A **service** is a feature that applies to all or many commands, like typing, - moving the cursor around, LaTeX exporting, LaTeX parsing. Note that each of - these varies by command (the cursor goes in a different place when moving into - a fraction vs into a square root, they export different LaTeX, etc), cue - polymorphism: services define methods on the controller that call methods on - nodes in the edit tree with certain contracts, such as a controller method - called on initialization to set listeners for keyboard events, that when the - Left key is pressed, calls `.moveTowards` on the node just left of the cursor, - dispatching on what kind of command the node is (`Fraction::moveTowards` and - `SquareRoot::moveTowards` can insert the cursor in different places). - + `controller.js` defines the base class for the **controller**, which each - math field or static math instance has one of, and to which each service - adds methods. -- `publicapi.js` defines the global `MathQuill.getInterface()` function, the - `MQ.MathField()` etc. constructors, and the API objects returned by - them. The constructors, and the API methods on the objects they return, call - appropriate controller methods to initialize and manipulate math field and - static math instances. - -[the HTML DOM]: http://www.w3.org/TR/html5-author/introduction.html#a-quick-introduction-to-html - -Misc.: - -`intro.js` defines some simple sugar for the idiomatic JS classes used -throughout MathQuill, plus some globals and opening boilerplate. - -Classes are defined using [Pjs][], and the variable `_` is used by convention as -the prototype. - -[pjs]: https://github.com/jneen/pjs - -`services/*.util.js` files are unimportant to the overall architecture, you can -ignore them until you have to deal with code that is using them. +The quick-and-dirty is you can do whatever if modifications to MathQuill are in +public GitHub forks. (Other ways to publicize modifications are also fine, as +are private use modifications. See also: [MPL 2.0 FAQ](https://www.mozilla.org/en-US/MPL/2.0/FAQ/))