vue-katex-auto-render

A KaTeX auto render library for vue directive.
4,869 6
Install
npm install vue-katex-auto-render
Latest Version:0.2.0
License:MIT
Last Updated:Mar 25, 2024
Links: GitHub  ·  npm
Maintainer: haoran_yu

Vue KaTeX Auto-render

KaTeX enables fast math typesetting for the web. Vue KaTeX Auto-render is a plugin to help you use KaTeX together with auto-render extension of KaTeX.

License: MIT

Requirements

Vue 2.x

Installation

npm install --save vue-katex-auto-render
Make it work with Vue

You have to import it and register it as a custom directive.

import Katex from 'vue-katex-auto-render'
Vue.directive('katex', Katex);

Usage

You can use the v-katex directive on any element of your template. And then put the content that you expect KaTeX to deal within some delimiters. The delimiters is a list of delimiters to look for math. Each delimiter has three properties:

  • left: A string which starts the math expression (i.e. the left delimiter).
  • right: A string which ends the math expression (i.e. the right delimiter).
  • display: A boolean of whether the math in the expression should be rendered in display mode or not.

The default value of delimiters for Vue KaTeX Auto-render is:

[
  {left: "$$", right: "$$", display: true},
  {left: "$", right: "$", display: false},
  {left: "\\(", right: "\\)", display: false},
  {left: "\\[", right: "\\]", display: true}
]

Any content within given delimiters in the tags with v-katex marked will then be treated as something need to be processed by KaTeX.

For example,

<template>
  <div v-katex>
    $$% Here is some comment
    f({x}) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}
    \,d\xi$$
  </div>
</template>

The code above will have the following as an output.

image

More Configurations

You may also pass some configurations to customize the result. For example, if you only want to support rendering KaTeX within same mark like [KaTeX_start]...[Katex_end] you can do something like:

<template>
  <div v-katex="options">
    [KaTeX_start]f({x}) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi[KaTeX_end]
  </div>
</template>
<script>
export default {
  data: function() {
    return {
      options: {
        delimiters: [
          {left: "[KaTeX_start]", right: "[KaTeX_end]", display: true}
        ]
      }
    };
  }
}
</script>

Beside the option of delimiters, you can set ignoredTags, ignoredClasses, errorCallback, preProcess, etc as you need. You may refer to document of Auto-render Extension for further descriptions of the these options.

License

Vue KaTeX Auto-render is released under the MIT license.

Related Packages

vue-katex

Vue plugin for KaTeX

30,224 128
@hsorby/vue3-katex

Vue 3 plugin for KaTeX

26,276 128
@janniks/vue3-katex

Vue 3 plugin for KaTeX

24,822 128
vatex

A plugin of vue latex(base on katex), support vue2 and vue3

11,153 47
vue3-katex

Vue 3 plugin for KaTeX

7,631 4

Version History

Version Released License
0.2.0 MIT
0.1.4 MIT
0.1.3 MIT
0.1.2 MIT
0.1.1 MIT