angular-katex
Display math with KaTex and AngularJS.
Requirements
Load into your app
You can get it from Bower
bower install angular-katex
or npm
npm install angular-katex
Load the script files in your application:
Add the specific module to your dependencies:
angular
Usage examples
<!-- Tag element -->x^2 <!-- Attribute -->x^2 <!-- Attribute value --> <!-- expr attribute value --> <!-- Bind to scope $scope.tex = {pow: 'x^2'} --> <!-- Set display mode --> <!-- Set error handler --><!-- on-error locals: $expr: (string) expression $err: (object) error $setText: (function) set element text --> <!-- Use auto-render --> The following formula is rendered $$x^2$$
To use the auto-render extension,
the file auto-render.min.js
is needed.
If you installed katex with bower, it is inside bower_components/katex/dist/contrib
.
Configuration
katexConfigProvider
have the following properties:
defaultOptions
: object that is passed to thekatex.render
function as the options parameter. By default, it is{}
.errorHandler
: function that is called when there is an error while parsing the expression. It has three parameters:error
,expression
,element
. It does not get called ifkatexOnError
directive is used. By default, it appends a span element with the error message and thekatex-error
class:<span class="katex-error">Error: message</span>
. This function can be used to use MathJax as a fallback.