V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
zxCoder
V2EX  ›  问与答

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

  •  
  •   zxCoder · Jan 28, 2021 · 1260 views
    This topic created in 1928 days ago, the information mentioned may be changed or developed.

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

    后台获取到的是一个字符串,是 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 的方法都不好用而且很麻烦

    Supplement 1  ·  Jan 29, 2021

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

    Supplement 2  ·  Jan 29, 2021

    已解决!

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

    用的这个网站的api

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

    2 replies    2021-01-29 00:21:39 +08:00
    iConnect
        1
    iConnect  
       Jan 29, 2021 via Android
    你试下 $nextTick 方法,一定要让数据加载完之后再让 mathjax 渲染 LaTeX,mathjax 提前渲染了这时 v-html 数据还没加载完就无效果了
    XiaoxiaoPu
        2
    XiaoxiaoPu  
       Jan 29, 2021
    找到一个应该可以用的 mathjax vue 封装 github.com/justforuse/vue-mathjax
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3286 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 13:01 · PVG 21:01 · LAX 06:01 · JFK 09:01
    ♥ Do have faith in what you're doing.