-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1309600
commit f15b728
Showing
8 changed files
with
175 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
layout: default | ||
title: API | MJXGUI Documentation | ||
title: API | ||
nav_order: 4 | ||
--- | ||
|
||
# API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
layout: default | ||
title: Customizing | ||
nav_order: 3 | ||
--- | ||
|
||
# Customizing | ||
MJXGUI lets you add support for functions and/or symbols that are not already present in the editor widget. | ||
|
||
## Adding A Custom Symbol | ||
To add a symbol to the editor widget that is not already present, you will need the following information - | ||
|
||
1. The LaTeX representation of the symbol | ||
2. The HTML representation of the symbol (to show in the editor widget) | ||
|
||
Once you create an MJXGUI instance, call the `MJXGUI.registerSymbol()` method to add the symbol you want. | ||
|
||
### Example: Adding ∴ to the editor | ||
For example, lets say you want to add the ∴ symbol to the editor widget. In LaTeX, you can use the `\therefore` command to render a ∴ symbol, and the HTML code for it is `&there4`; | ||
|
||
`MJXGUI.registerSymbol()` takes 2 required and 2 optional arguments - | ||
|
||
1. `latexData` - The LaTeX representation of the symbol, in this case `"\therefore"`. | ||
2. `buttonContent` - The HTML representation of the symbol, in this case `"∴"`. This HTML representation can be a simple string, an SVG, some custom HTML, an HTML character code, or LaTeX that can be typeset using MathJax (see argument 4). | ||
3. `title` - A string that will be set as the title attribute of the rendered button. | ||
4. `typeset` - A boolean that, if true, will use MathJax to typeset the HTML representation (argument 2). If you set this as true, make sure that MathJax is fully loaded when you call `registerSymbol()`. Defaults to `false`. | ||
|
||
```javascript | ||
const mjxgui = new MJXGUI('#mjxgui-button'); | ||
|
||
mjxgui.successCallback = function () { | ||
// Handle user input here | ||
} | ||
|
||
mjxgui.registerSymbol('\\therefore', '∴', 'Therefore', false); | ||
``` | ||
You can see this example [here](./examples/add-custom-symbol.html). | ||
|
||
## Adding A Custom Function | ||
Adding a function to the editor widget is a little different from adding a symbol. A function needs to know how its LaTeX should be generated, since it is not simple static LaTeX like a symbol. To add a function that is not already present, you will need - | ||
|
||
1. A class that knows how to generate the LaTeX you need for your function | ||
2. An HTML representation of the function (to show in the editor widget) | ||
|
||
You will need to create a class that extends from one of MJXGUI's many Component classes, and override the `toLatex()` method of the class. You can find a list of Component classes MJXGUI provides, along with their use cases in the [API documentation](./api/index.md). | ||
|
||
Once you create this class and an MJXGUI instance, call the `MJXGUI.registerFunction()` method to add the function you want. | ||
|
||
### Example: Adding $ sin^2 $ to the editor | ||
For example, let's say we want to add a $ sin^2 $ function to the editor. | ||
|
||
`MJXGUI.registerFunction()` takes 2 required and 2 optional arguments - | ||
|
||
1. `componentClass` - A class inheriting from one of MJXGUI's many component classes, which knows how to render it's content as LaTeX. | ||
2. `buttonContent` - The HTML representation of the function. This can be a simple string, an SVG, some custom HTML, an HTML character code, or LaTeX that can be typeset using MathJax. | ||
3. `title` - A string that will be set as the title attribute of the rendered button. | ||
4. `typeset` - A boolean that, if true, will use MathJax to typeset the HTML representation (argument 2). If you set this as true, make sure that MathJax is fully loaded when you call `registerFunction()`. Defaults to `false`. | ||
|
||
```javascript | ||
// Create the class that knows how to render sin^2 as LaTeX | ||
class SinSquaredComponent extends OneBlockComponent { | ||
toLatex() { | ||
return `\\sin^{2}{${this.blocks[0].toLatex()}}`; | ||
} | ||
} | ||
|
||
// Create an MJXGUI instance | ||
const mjxgui = new MJXGUI('#mjxgui-button'); | ||
mjxgui.successCallback = function () { | ||
// Handle user input here | ||
}; | ||
|
||
mjxgui.registerFunction( | ||
componentClass = SinSquaredComponent, | ||
buttonContent = `<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"> | ||
<msup> | ||
<mi>sin</mi> | ||
<mn>2</mn> | ||
</msup> | ||
</math>`, | ||
title = 'Sine squared', | ||
typeset = false | ||
); | ||
``` | ||
You can see this example [here](./examples/add-custom-function.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
layout: default | ||
title: Home | ||
nav_order: 5 | ||
--- | ||
|
||
# Examples | ||
1. [Example 1 - Inserting equations](./examples/basic-example.html) | ||
2. [Example 2 - Insert equations and displaying their LaTeX](./examples/insert-equation-and-latex.html) | ||
3. [Example 3 - Adding a custom symbol](./examples/add-custom-symbol.html) | ||
4. [Example 4 - Adding a custom function](./examples/add-custom-function.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.