Giter Site home page Giter Site logo

mathjax-vue's Introduction

mathjax-vue

Vue components for MathJax

Installation

Vue2

// npm
npm i --save mathjax-vue

// yarn
yarn add mathjax-vue

Vue3

// vue 3
npm i --save mathjax-vue3

// yarn
yarn add mathjax-vue3

Usage

import MathJax, { initMathJax, renderByMathjax } from 'mathjax-vue'

// Rewrite pageReady method, optimizing MathJax as required rendering and render to avoid them
// ❗️❗️ For example '<span>$$Not a formula$$</span>' is not going to render, but in fact will be rendered into formula, As below is not the el

function onMathJaxReady() {
  // The parent node of need to be rendered into the formula node set
  const el = document.getElementById('elementId')
  // ❗️❗️ When there is no el will begin to render the default root node
  renderByMathjax(el)
}

initMathJax({}, onMathJaxReady)

// vue 2
Vue.use(MathJax)

// vue3
createApp(App).use(MathJax)

OR

import { MathJax } from 'mathjax-vue'
export default {
  ...
  components: {
    MathJax,
  },
  ...

Component

<template>
  // inline
  <math-jax :latex="formula" />
  // block
  <math-jax :latex="formula" :block="true" />
</template>

API

import { initMathJax, renderByMathjax } from 'mathjax-vue'

initMathJax({})

// The default mathJax CDN link is https://cdn.bootcdn.net/ajax/libs/mathjax/3.2.0/es5/tex-svg.min.js
// If you don't want to use it or can't access it, you can replace it in the following ways

initMathJax({ url: 'Link of mathJax' })

// After the completion of the MathJax load can success
renderByMathjax(el)

Props

prop Type Description Default
latex String Latex string ""
block Boolean Css display is block false

Online demo

// vue2 https://codesandbox.io/s/funny-silence-cgzn5

// vue 3 https://codesandbox.io/s/festive-morning-ywy8up

Note

The project uses PNPM as a package management tool. If you want to try the project locally, you can follow these steps:

// Make sure your node version is above 16

npm install -g pnpm

cd xx/mathjax-vue

pnpm i/pnpm install

mathjax-vue's People

Contributors

hansongong avatar

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.