You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want to add a function to the editor widget that is not present out of the box, you will need to write a component class that will inherit from one of GUIMath's built-in component classes. You will then have to override the `toLatex()` method of the class to define how the LaTeX should be generated for your component.
27
+
If you want to add a function to the editor widget that is not present out of the box, you will need to write a component class that will inherit from one of GUIMath's built-in component classes. You will then have to define how the component is rendered into HTML and LaTeX by defining the `toHTML()` and `toLatex()` methods.
28
28
29
29
To identify which component class you should inherit from, determine how many blocks your function has. For example, a fraction has two blocks - the numerator and the denominator, and the square root function has just one block. As a guideline, you can usually consider each `{}` in the LaTeX representation of a function as a block - fraction is written as `\frac{}{}`, therefore it has 2 blocks, and square root is written as `\sqrt{}`, and therefore has only 1 block.
30
30
31
-
Once you determine which component class to inherit from, you will need to override the `toLatex()` method. This is where you will be able to define how the LaTeX is generated for your function. Inside the `toLatex()` method, you can access the `blocks` attribute of the instance, and call `toLatex()` for each block to construct the final LaTeX expression step-by-step. There is an example implementation under each heading below to demonstrate.
31
+
Once you determine which component class to inherit from, you will need to override the `toHTML()` and `toLatex()` methods.
32
+
33
+
For any questions about implementing custom components, please [start a discussion on GitHub](https://github.com/hrushikeshrv/guimath/discussions)
34
+
35
+
## Defining `toHTML(cursorBlock, cursorPosition)`
36
+
This is where you will be able to define how the HTML is generated for your function. See the examples below to get a quick idea of how to implement this method. `toHTML()` is supplied two arguments:
37
+
38
+
1.`cursorBlock` - The `Block` instance that the cursor is currently in
39
+
2.`cursorPosition` - The position of the cursor within the block it is in (`Number`)
40
+
41
+
You will likely not need to use these arguments yourself in your implementation. They are used during rendering to provide feedback for hover and click events, and to highlight which `Block` the cursor is currently in. All this is handled by the `GUIMath` and `Block` class for you. However, it is important that you pass these same arguments to any recursive calls to `toHTML()` you make to preserve this functionality.
42
+
43
+
You should return a string containing what the HTML representation of the component should look like in the editor window. For more guidance on how to implement this method, see the examples below or [start a discussion on GitHub](https://github.com/hrushikeshrv/guimath/discussions).
44
+
45
+
## Defining `toLatex()`
46
+
This is where you will be able to define how the LaTeX is generated for your function. See the examples below to get a quick idea of how to implement this method.
47
+
48
+
Inside the `toLatex()` method, you can access the `blocks` attribute of the `GUIMath` instance, and call `toLatex()` for each block to construct the final LaTeX expression step-by-step. There is an example implementation under each heading below to demonstrate. For more guidance on how to implement this method, see the examples below or [start a discussion on GitHub](https://github.com/hrushikeshrv/guimath/discussions).
32
49
33
50
## One Block Component
34
-
Inherit from this class if your function has one block. Examples of functions which have one block include $ \sqrt{\boxed{}} $, $ \sin{\boxed{}} $, $ \sin^{2}{\boxed{}} $, etc.
51
+
Inherit from this class if your function has one block. Examples of functions which have one block include square root ($ \sqrt{\boxed{}} $), sine ($ \sin{\boxed{}} $), sine squared ($ \sin^{2}{\boxed{}} $), etc.
Inherit from this class if your function has two blocks. Examples of functions which have two blocks include $ \frac{\boxed{}}{\boxed{}} $, $ \sqrt[\boxed{}]{\boxed{}} $, etc.
73
+
Inherit from this class if your function has two blocks. Examples of functions which have two blocks include fraction ($ \frac{\boxed{}}{\boxed{}} $), n-th root ($ \sqrt[\boxed{}]{\boxed{}} $), etc.
Inherit from this class if your function has three blocks. Examples of functions which have three blocks include $ \sum_{\boxed{}}^{\boxed{}}{\boxed{}} $, $ \int_{\boxed{}}^{\boxed{}}{\boxed{}} $, etc.
94
+
Inherit from this class if your function has three blocks. Examples of functions which have three blocks include sum ($ \sum_{\boxed{}}^{\boxed{}}{\boxed{}} $), integral ($ \int_{\boxed{}}^{\boxed{}}{\boxed{}} $), etc.
Inherit from this class if your function has more than three blocks.
121
+
Inherit from this class if your function has more than three blocks. For more guidance on how to extend this class, [start a discussion on GitHub](https://github.com/hrushikeshrv/guimath/discussions).
Copy file name to clipboardExpand all lines: docs/api/guimath-instance.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ Currently, the following options are supported -
29
29
|`id`| String |`""`| Additional id to add to the GUIMath widget's root element. |
30
30
31
31
## Writing A Success Callback
32
-
The success callback you supply is run when the user is done entering an equation and clicks on the “✔” button. This is where you will be able to access the LaTeX for the entered equation, and handle it however you want. It is recommended to supply this function after creating an GUIMath instance instead of passing it to the constructor, just because supplying it later lets you use both regular functions and arrow functions as the callback without having to worry about `this` in context.
32
+
The success callback you supply is run when the user is done entering an equation and clicks on the “✔” button. This is where you will be able to access the LaTeX for the entered equation, and handle it however you want. It is recommended to supply this function after creating a GUIMath instance instead of passing it to the constructor, just because supplying it later lets you use both regular functions and arrow functions as the callback without having to worry about `this` in context.
This is version 1.0, dated 22 June 2009, of the GUST Font License.
2
+
(GUST is the Polish TeX Users Group, http://www.gust.org.pl)
3
+
4
+
For the most recent version of this license see http://www.gust.org.pl/fonts/licenses/GUST-FONT-LICENSE.txt or http://tug.org/fonts/licenses/GUST-FONT-LICENSE.txt
5
+
6
+
This work may be distributed and/or modified under the conditions of the LaTeX Project Public License, either version 1.3c of this license or (at your option) any later version.
7
+
8
+
Please also observe the following clause:
9
+
10
+
1) it is requested, but not legally required, that derived works be distributed only after changing the names of the fonts comprising this work and given in an accompanying "manifest", and that the files comprising the Work, as listed in the manifest, also be given new names. Any exceptions to this request are also given in the manifest.
11
+
12
+
We recommend the manifest be given in a separate file named MANIFEST-<fontid>.txt, where <fontid> is some unique identification of the font family. If a separate "readme" file accompanies the Work, we recommend a name of the form README-<fontid>.txt.
13
+
14
+
The latest version of the LaTeX Project Public License is in http://www.latex-project.org/lppl.txt and version 1.3c or later is part of all distributions of LaTeX version 2006/05/20 or later.
0 commit comments