Code Monkey home page Code Monkey logo

angular-katex's Introduction

angular-katex

npm version bower version build status

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:

<script type="text/javascript" src="bower_components/angular/angular.js"></script>
<script type="text/javascript" src="bower_components/katex/dist/katex.min.js"></script>
<script type="text/javascript" src="bower_components/angular-katex/angular-katex.js"></script>

Add the specific module to your dependencies:

angular.module('myApp', ['katex', ...])

Usage examples

Live demo

<!-- Tag element -->
<katex>x^2</katex>

<!-- Attribute -->
<div katex>x^2</div>

<!-- Attribute value -->
<div katex="x^2"></div>

<!-- expr attribute value -->
<katex expr="x^2"></katex>

<!-- Bind to scope
  $scope.tex = {pow: 'x^2'}
  -->
<katex bind="tex.pow"></katex>

<!-- Set display mode -->
<katex expr="x^2" display-mode></katex>

<!-- Set error handler -->
<!-- on-error locals:
  $expr: (string) expression
  $err: (object) error
  $setText: (function) set element text
  -->
<katex expr="\" on-error="$setText('Bad Expression: ' + $expr + ' . ' + $err)"></katex>

<!-- Use auto-render -->
<div katex auto-render>
  <p>The following formula is rendered</p>
  $$x^2$$
</div>

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 the katex.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 if katexOnError directive is used. By default, it appends a span element with the error message and the katex-error class: <span class="katex-error">Error: message</span>. This function can be used to use MathJax as a fallback.

angular-katex's People

Contributors

tfoxy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-katex's Issues

Anyway to set self-defined left and right delimiters for katex formulation?

Although in the end of readme.md, it suggests the property of defaultOptions of katexConfigProvider can manipulate something related, I tried but failed. What I did is based on the live example on JS Bin as follows:

angular.module('app', ['katex'])
    .config('katexConfig', katexConfig);

katexConfig.$inject = ['katexConfigProvider'];

function katexConfig(katexConfigProvider) {
  katexConfigProvider.defaultOptions = {delimiters : [{left: '#!@#$', right: '#$#!@', display: false}]};
};

As is stated above, I try to pass the option object which is defined according to auto render options to katexConfigProvider.defaultOptions. On this basis, I hope the formulations can be identified by self-defined delimiters in the way of #!@#$formulation#$#!@. However, it is not recognized. Therefore I don't know if there is any way to achieve this target provided by angular-katex. Otherwise I can only use the native katex on which I can successfully do this. Looking forward to hear from you! Thanks!

Using katex-bind with auto-render and html

Hi,

I have the following code in my directive:

<p katex-bind="text" auto-render></p>

The text I want to render contains not only plain text but also HTML and of course some latex code (escaped with \\( and \\). When I look at the rendered output I see the latex parts compiled correctly but the html code is not rendered and just displays as source code. Is there a way I can have both the html rendered correctly and also the latex?

Using Angular 1.4 and latest angular-katex.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.