https://github.com/navsgh/katex-expression
A web component to render KaTeX expression
https://github.com/navsgh/katex-expression
katex latex stenciljs stenciljs-components web-components
Last synced: 18 days ago
JSON representation
A web component to render KaTeX expression
- Host: GitHub
- URL: https://github.com/navsgh/katex-expression
- Owner: navsgh
- License: mit
- Created: 2019-07-16T13:18:48.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-03-25T20:06:39.000Z (about 1 year ago)
- Last Synced: 2024-04-24T12:06:17.130Z (12 months ago)
- Topics: katex, latex, stenciljs, stenciljs-components, web-components
- Language: TypeScript
- Size: 538 KB
- Stars: 11
- Watchers: 0
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-stenciljs - Katex Expression
README
# KaTeX Expression
A web component/custom element (``) to render [KaTeX](https://katex.org/) expressions.
[](https://www.npmjs.com/package/@navsnpm/katex-expression)
[](https://stenciljs.com/)
[](https://www.webcomponents.org/element/@navsnpm/katex-expression)## Table of Contents
- [Installation](#installation)
- [HTML](#html)
- [React/Angular/Vue](#reactangularvue)
- [Usage](#usage)
- [Basic](#basic)
- [Katex Options](#katex-options)
- [Error Handling](#error-handling)
- [Properties](#properties)
- [Events](#events)## Installation
### HTML
Insert the following script tags in the `` section of your html
```html
```
### React/Angular/Vue
Install `` using npm
```
npm i --save @navsnpm/katex-expression
```- Angular 8 example: Refer the repo [katex-expression-ng](https://github.com/navsgh/katex-expression-ng)
> Note: Katex css, js, & fonts are bundled in this package. You can skip including them in your application. Please refer [package.json](./package.json) for KaTeX version.
## Usage
### Basic
Use the `` tag anywhere in your html. Set the `expression` attribute to the katex expression.
```html
```
### KaTeX Options
`katex-options` accepts a json str for KaTeX rendering options. Refer [KaTeX API Options](https://katex.org/docs/options.html) for more information. Example usage for `katex-options`:
```html
```
### Error Handling
`Error` objects are emitted via the `onError` event. Handle this event to re-throw, pipe exceptions to Sentry or elsewhere. Example non-JSX usage below:
```html
const element = document.querySelector('#expression');
element.addEventListener('onError', error => {
console.error('<katex-expression> error:', error)
})```
> Note: Katex errors are emitted if `katex-options.throwOnError` is true. Other exceptions are emitted by default.
## Properties
| Property | Attribute | Description | Type | Default |
| -------------- | --------------- | -------------------------- | -------- | ----------- |
| `expression` | `expression` | katex expression to render | `string` | `undefined` |
| `katexOptions` | `katex-options` | Katex options json | `string` | `undefined` |## Events
| Event | Description | Type |
| --------- | ------------------------------- | ------------------ |
| `onError` | Emits `Error` object on exception | `CustomEvent` |## License
``is licensed under the [MIT License](http://opensource.org/licenses/MIT).