npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

formula-editor-plus

v1.0.2

Published

> 注意:本项目利用了mathquill.js 实现可视化编辑功能,该库必须要jquery支持,并采用Mathjax3以上版本版本渲染

Downloads

283

Readme

可视化数学公式编辑器&latex公式编辑器

注意:本项目利用了mathquill.js 实现可视化编辑功能,该库必须要jquery支持,并采用Mathjax3以上版本版本渲染

使用方式

注意:使用前需要在页面引入

一、引入JS
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/mathjax/3.2.2/es5/tex-svg-full.min.js"></script>

上述两个我采用bootcdn,此方式为demo,大家需要自己把js放到自己服务器下,安全一点

二、配置好渲染latex的js配置,目前我采用一MathJax3+,配置如下
<script>
        window.MathJax.config = {
            showMathMenu: false,
            showProcessingMessages: false, //关闭js加载过程信息
            messageStyle: 'none', //不显示信息
            extensions: ['tex2jax.js'],
            jax: ['input/TeX', 'input/MathML', 'output/SVG'],
            tex: {
                extensions: [
                    'AMSmath.js',
                    'AMSsymbols.js',
                    'enclose.js'
                ],
                Macros: {
                    RR: ['\\mathbb{R}', 0],
                    f: ['{\\bf #1}', 1],
                    overppprime: ['{{#1}^{\\prime\\prime\\prime}}', 1]
                },
                preview: 'none',
                tags: 'svg',
                inlineMath: [['$', '$'], ['$$', '$$'], ['\\(', '\\)']], //行内公式选择符
                skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code', 'a'], //避开某些标签
            },
            'HTML-CSS': {
                availableFonts: ['STIX', 'TeX'], //可选字体
                showMathMenu: false, //关闭右击菜单显示
                linebreaks: { automatic: true },
                mtextFontInherit: true
            },
            EqnChunkDelay: 100,
            svg: {
                font: 'Tex',
                undefinedFamily: 'songti',
                useFontCache: false,
                useGlobalCache: false,
                linebreaks: {
                    automatic: false,
                    width: 'container'
                },
                EqnChunk: 500,
            },
            displayAlign: 'left',
            messageStyle: 'none',
            skipStartupTypeset: false
        }
    </script>
三、引入formula-editor
  1. main.js
npm install formula-editor-plus
// es
import FormulaEditor from 'formula-editor-plus/es'
import 'formula-editor-plus/dist/es/style.css'
app.use(FormulaEditor);
  1. 组件中使用
import { FormulaEditor } from 'formula-editor-plus/es'
import 'formula-editor-plus/dist/es/style.css'
<script setup lang="ts">
import toolsLatex from './config/groupConfig.ts'
const formulaRef = ref<ComponentInstance<typeof FormulaEditor> | null>(null)
    
// 获取latex
const getLatex = () => {
  console.log('formulaRef', formulaRef.value?.latexText())
}

// 导出公式为svg
const latexExport = ()=>{
  formulaRef.value?.exportSvg()
}

// 获取latex 为svg代码
const latexSvg = ()=>{
  console.log(formulaRef.value?.svgHtml())
}

// 导出公式为图片
const svgToImage = ()=>{
  formulaRef.value?.svgToImage()
}
</script>

<template>
  <div>
    <FormulaEditor ref="formulaRef" :tools-data="toolsLatex" />
    <button @click="getLatex">获取 latex text代码</button>
    <button @click="latexSvg">获取 latex svg代码</button>
    <button @click="latexExport">导出 latex 为svg</button>
    <button @click="svgToImage">导出 latex 为png</button>
  </div>
</template>
方法和属性

类型

// 公式
interface DataItem {
    text: string,
    latex: string,
    id: number | string
}

// 顶部菜单说明
interface IListItem {
        id: number | string,
        column: number,
        title: string,
        data: DataItem[]
}

参数 | 类型 | 说明 | 默认值 ---|-----------------|---|--- latex | String | 编辑器初始化渲染的latex公式 | '' commonMath | Array | 右侧常用公式 list | 默认值查看预览效果 toolsData | Array | 顶部菜单公式 list | [] titleTools | Array | 编辑器中title常用latex list | 默认值查看预览效果 latexText() | Function | 组件实例方法,获取公式的latex代码,ref.latexText()| / svgHtml() | Function | 组件实例方法,获取公式的svg代码,ref.svgHtml() | / exportSvg() | Function | 组件实例方法,获取公式为svg进行导出,ref.exportSvg() | / svgToImage() | Function | 组件实例方法,获取公式为图片进行导出下载,ref.svgToImage() | / insertLatex(DataItem) | Function | 组件实例方法,在编辑器光标处插入latex ref.insertLatex() | /

部分预览

1.可视化编辑 Example Image

2.latex编辑 Example Image

3.顶部符号 Example Image

4.字体设置 Example Image

5.颜色设置 Example Image