Math should be quotable

We have a discourse forum for a scientific software, and use the math plugin. Unfortunately, math is not quotable.

If I select some text, a Quote button appears:

Clicking it results in the following:

[quote]
definition of the closeness centrality:

ci=1N−1N∑j=11dij c_i = \frac{1}{N-1} \sum_{j=1}^N\frac{1}{d_{ij}}
[/quote]

Notice that in the quotation, the math appeared as a weird textual version (unreadable) followed by the actual LaTeX source, but lacking the $ delimiters.

I assume that there is no fix for this currently. It would be nice if this could be improved in the future.

8 个赞

This is still occurring and also happens with inline math, as reported by a member on our instance:

2 个赞

Note, I agree completely we should clean this up, but it feels extremely complicated.

I am putting a pr-welcome on this in case someone with advances skills wants to give it a shot.

6 个赞

我研究了一下引用数学(我正在考虑编写一个 PR 或为其中一个做出贡献)。

在此记录一些初步的想法和发现。

因此,我的初步印象是以下几点可能可以进行修补:

  • toMarkdown 根据各种 HTML 标签匹配元素;我认为 mathjax 使用自定义元素是可检测的(可能不是 SVG 渲染),katex 也是如此?
  • selectedText 对代码块和 onebox 等元素进行一些匹配 – 也许可以检测 mathjax/katex 元素并进行转换?(注意:这里有一个钩子或类似的东西可能是一个好主意,这样转换逻辑就可以添加到 discourse-math 插件中,而不是主 discourse 代码库中)。
  • 其他几点似乎不如这两点合适。

关于方法和其他获取原始数学内容的想法。

根据 katex / mathjax+svg[^1] 的工作方式,我认为每个数学实例都有一个根 HTML 元素(可能不止一个,因为有一些隐藏的元素用于可访问性等)。所以如果我们知道数学存在的位置,我们就可以解析原始帖子中用 $ 分隔的内容(但解释器很棘手 – 可能代码库中已经有一个了?)

[^1]:我认为 mathjax+svg 可能不受支持,所以这可能不是一个问题

或者,mathjax 至少有一个右键单击 > 查看 tex 等功能(这应该是 $ 对之间的文字字符串);我不知道如何挂入其中,但如果有一种方法可以为 mathjax v2、v3 和 katex 执行此操作,那么就可以使用它将选定的格式化数学替换为 $...$(注意:这适用于内联数学,还需要涵盖另一种情况 – 它使用 $$...$$[/.../] 分隔符。)

目前存在的问题:

  • 我不知道如何实现钩子,也不知道是否有更好的东西可以使用/在 discourse 代码库中有更好的实现方式。
  • mathjax/katex 有一些未知数需要调查。
    • HTML 元素 – 如何可靠地检测它们?
    • 如何获取原始 TeX 代码?

如果任何人有关于在哪里/什么可以修补的其他想法、其他可能的实现方法或任何其他内容,请发布。

5 个赞