[](https://www.npmjs.com/package/ng-katex) [](https://travis-ci.org/garciparedes/ng-katex) [




To install the module you can simply type it on your command line:
```
npm install ng-katex --save
To add the module to your project add the KatexModule to import's field of your parent module:`js
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { KatexModule } from 'ng-katex';
import { AppComponent } from './app/app.component';
@NgModule({
imports: [
BrowserModule,
KatexModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
class AppModule {}
platformBrowserDynamic().bootstrapModule(AppModule);
`
#### Important!
If you're using angular-cli, add the katex css import to your styles.css:
`css`
@import '~katex/dist/katex.css';
If you're not using the angular-cli, import the stylesheet to your index.html:
`html`
You can write a LaTeX equation as follows:
`js
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
})
export class AppComponent {
equation: string = '\\sum_{i=1}^nx_i';
}
Also, you can add options to ng-katex components with:
`js
import { Component } from '@angular/core';
import { KatexOptions } from 'ng-katex';
@Component({
selector: 'my-app',
template: `
})
export class AppComponent {
equation: string = '\\sum_{i=1}^nx_i';
options: KatexOptions = {
displayMode: true,
};
}
The options object structure is defined here.
If you want to write a paragraph with LaTeX equations, you can do it as follows:
`js
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template:
})
export class AppComponent {
paragraph: string =
You can write text, that contains expressions like this: $x ^ 2 + 5$ inside them. As you probably know.
You also can write expressions in display mode as follows: $$\\sum_{i=1}^n(x_i^2 - \\overline{x}^2)$$.
In first case you will need to use \\$expression\\$ and in the second one \\$\\$expression\\$\\$.
To scape the \\$ symbol it's mandatory to write as follows: \\\\$
;`
}
If you want to write HTML with LaTeX equations, you can do it as follows: (Security Note: this bypasses Angular DOM Sanitization)
`js
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template:
})
export class AppComponent {
html: string =
:
;
}
``- Sergio García Prado @garciparedes
- Joshua Claxton @joshclax
See CONTRIBUTING.md
ng-katex is licensed under MIT license.