Latex 公式录入模板
安装
sh
npm i @tomiaa/latex-template
简单使用
ts
import { KLatexTemplate } from "@tomiaa/latex-template"
new KLatexTemplate("#latex", {
// 当点击了公式后触发
onInput(latex, detail) {
// latex 公式字符串
// detail 当前点击项的详细信息
console.log(latex, detail)
},
})
// or 或者
const ins = new KLatexTemplate(document.getElementById("latex"))
ins.onInput = (latex, detail) => {
console.log(latex, detail)
}
demo
查看代码
vue
<template>
<div ref="latexContainer"></div>
</template>
<script setup lang="ts">
import { ref, onMounted } from "vue"
import { KLatexTemplate } from "@tomiaa/latex-template"
import { ElMessage } from "element-plus"
const latexContainer = ref()
onMounted(() => {
new KLatexTemplate(latexContainer.value).onInput = latex => {
ElMessage.success(`公式代码为:${latex}`)
}
})
</script>
<style scoped lang="scss">
:deep(svg) {
display: inline;
}
:deep(p) {
margin: 0;
}
</style>