V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
zxCoder
V2EX  ›  问与答

vue 中显示带有 latex 数学语法的 html 内容的方案

  •  
  •   zxCoder · 2021-01-28 23:10:23 +08:00 · 817 次点击
    这是一个创建于 1188 天前的主题,其中的信息可能已经有所发展或是发生改变。

    查了好多也没找到有效的做法

    后台获取到的是一个字符串,是 html 格式,然后里面带有一些 latex 公式,例如

    "Then, Mikaela will count and give you the number of pairs of vertices $$$(s, t)$$$ where $$$s \in S$$$ and $$$t \in T$$$ such that the simple path from $$$s$$$ to $$$t$$$ contains $$$v$$$.</p><p>Mikaela the Goddess is busy and will be available to answer at most $$$11\,111$$$ questions.</p><p>This is your only chance. Your task is to determine the tree and report its edges.</p>"
    

    用 vue 的 v-html 可以直接展示 html,但是其中的 latex 公式不知道要怎么办,网上找的几种 mathjax 的方法都不好用而且很麻烦

    第 1 条附言  ·  2021-01-29 10:26:01 +08:00

    怀疑人生 一开始还感觉这应该是个很正常的需求,结果面向搜索引擎编程失败。。。

    第 2 条附言  ·  2021-01-29 11:10:26 +08:00

    已解决!

    后台把html标签里的那些latex公式替换成svg图片,然后前端直接展示html就行

    用的这个网站的api

    https://private.codecogs.com/eqneditor/integration/htmlequations.php

    2 条回复    2021-01-29 00:21:39 +08:00
    iConnect
        1
    iConnect  
       2021-01-29 00:02:12 +08:00 via Android
    你试下 $nextTick 方法,一定要让数据加载完之后再让 mathjax 渲染 LaTeX,mathjax 提前渲染了这时 v-html 数据还没加载完就无效果了
    XiaoxiaoPu
        2
    XiaoxiaoPu  
       2021-01-29 00:21:39 +08:00
    找到一个应该可以用的 mathjax vue 封装 github.com/justforuse/vue-mathjax
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   911 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:56 · PVG 06:56 · LAX 15:56 · JFK 18:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.