2019-09-17 20:42:36 +03:00
# CKEditor 5 mathematical feature
2019-10-01 18:18:13 +03:00
This is the best* TeX-based mathematical plugin for CKEditor 5. You can use it to insert, edit and view mathematical equation and formulas. This plugin supports MathJax, KaTeX and custom typesetting engines.
2019-09-17 21:06:18 +03:00
2019-10-01 18:18:13 +03:00
## Examples
[Link to examples repository ](https://github.com/isaul32/ckeditor5-math-examples )
2019-09-17 21:06:18 +03:00
## Installation
Install plugin with NPM or Yarn
2019-09-17 21:09:08 +03:00
2019-09-17 21:06:18 +03:00
`npm install ckeditor5-math --save-dev`
Add import into ckeditor.js file
```js
import Mathematics from 'ckeditor5-math/src/math';
```
Add it to builtinPlugins
```js
InlineEditor.builtinPlugins = [
// ...
2019-09-28 18:03:05 +03:00
Mathematics
2019-09-17 21:06:18 +03:00
];
```
__Add math button to toolbar__ and optional math config to default config
```js
InlineEditor.defaultConfig = {
toolbar: {
items: [
// ...
2019-09-28 18:03:05 +03:00
'math'
2019-09-17 21:06:18 +03:00
]
},
// ...
math: {
engine: 'mathjax',
outputType: 'script',
forceOutputType: false
2019-09-28 18:03:05 +03:00
}
2019-09-17 21:06:18 +03:00
};
```
### Copying plugin's theme for Lark
2019-10-01 18:58:18 +03:00
Copy __theme/ckeditor5-math__ folder from [https://github.com/isaul32/ckeditor5-theme-lark ](https://github.com/isaul32/ckeditor5-theme-lark ) to your lark theme repository fork or install
`npm install @ckeditor/ckeditor5-theme-lark@https://github.com/isaul32/ckeditor5-theme-lark --save-dev`
2019-08-31 20:48:37 +03:00
2019-09-28 18:03:05 +03:00
### Styles
Styles requires PostCSS like offical CKEditor plugins.
2019-09-17 21:12:20 +03:00
2019-09-28 18:03:05 +03:00
## Configuration & Usage
2019-09-17 20:42:36 +03:00
2019-09-28 18:03:05 +03:00
### Available typesetting engines
__MathJax__
2019-10-01 23:11:51 +03:00
- Tested by using version __2.7.5__ and __TeX-MML-AM_HTMLorMML__ configuration. It has also experimental (__CHTML__, __SVG__ ) support for __3.0.0__ or newer version.
2019-09-17 20:42:36 +03:00
- Use __ \\( \\)__ delimiters for inline and __ \\[ \\]__ delimiters for display
2019-09-28 18:03:05 +03:00
__KaTeX__
2019-09-17 20:42:36 +03:00
- Tested by using version __0.11.0__
- Doesn't support preview feature because __ .ck-reset_all *__ css rules from ckeditor5-ui and ckeditor5-theme-lark breaks it.
2019-09-28 18:03:05 +03:00
__Custom__
It's possible to implement with engine config. For example, this feature can be used when use back end rendering.
```js
InlineEditor.defaultConfig = {
// ...
math: {
engine: (equation, element, display) => {
// ...
}
}
}
```
2019-10-01 18:18:13 +03:00
- __equation__ is equation in TeX format without delimiters.
- __element__ is DOM element reserved for rendering.
- __display__ is boolean. Typesetting should be inline when false.
2019-09-17 20:42:36 +03:00
2019-08-31 20:48:37 +03:00
2019-09-28 18:03:05 +03:00
### Plugin options
2019-09-17 20:42:36 +03:00
```js
InlineEditor.defaultConfig = {
// ...
math: {
engine: 'mathjax', // or katex or function (equation, element, display) => { ... }
2019-09-28 13:02:32 +03:00
outputType: 'script', // or span or math
2019-09-17 21:06:18 +03:00
forceOutputType: false // forces output to use outputType
2019-09-17 20:42:36 +03:00
}
}
```
2019-09-28 18:03:05 +03:00
### Supported input and output formats
Supported input and output formats are:
```html
<!-- MathJax style http://docs.mathjax.org/en/v2.7-latest/advanced/model.html #how -mathematics-is-stored-in-the-page -->
< script type = "math/tex" > \sqrt { \frac { a }{ b }}</ script >
< script type = "math/tex; mode=display" > \sqrt { \frac { a }{ b }}</ script >
<!-- CKEditor 4 style https://ckeditor.com/docs/ckeditor4/latest/features/mathjax.html -->
< span class = "math-tex" > \( \sqrt{\frac{a}{b}} \)</ span >
< span class = "math-tex" > \[ \sqrt{\frac{a}{b}} \]</ span >
```
2019-10-01 18:18:13 +03:00
### Paste support
#### Plain TeX paste
Paste equations with __delimiters__ . For example:
__\\[__ x=\frac{-b\pm\sqrt{b^2-4ac}}{2a} __ \\]__
or
__\\(__ x=\frac{-b\pm\sqrt{b^2-4ac}}{2a} __ \\)__
#### Paste support from Microsoft Word
Use [__paste from office__ ](https://github.com/isaul32/ckeditor5-paste-from-office ) fork instead of offical.
Install paste from office fork
`npm install @ckeditor/ckeditor5-paste-from-office@github:isaul32/ckeditor5-paste-from-office --save-dev`
```js
import PasteFromOffice from '@ckeditor/ckeditor5 -paste-from-office/src/pastefromoffice';
import Mathematics from 'ckeditor5-math/src/math';
// ...
InlineEditor.builtinPlugins = [
// ...
PasteFromOffice,
Mathematics
];
```
2019-09-17 21:12:20 +03:00
2019-09-17 21:06:18 +03:00
## Todo
- Fix KaTex preview
2019-09-28 13:02:32 +03:00
- MathML input and output when using MathJax version 3
2019-09-28 19:21:38 +03:00
- Make tests
2019-10-01 18:18:13 +03:00
[*] at least in my opinion