Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] 增加Markdown数学公式渲染条件 #1609

Closed
zhairuoxun opened this issue Mar 17, 2024 · 37 comments
Closed

[Request] 增加Markdown数学公式渲染条件 #1609

zhairuoxun opened this issue Mar 17, 2024 · 37 comments
Labels
🌠 Feature Request New feature or request | 特性与建议

Comments

@zhairuoxun
Copy link

zhairuoxun commented Mar 17, 2024

🥰 需求描述

希望\( \)\[ \]括住的数学公式也可以渲染

🧐 解决方案

ai助手在涉及到公式时,经常首选利用 \[ \]\( \)来将公式括住,而lobechat往往只把用$$括住的公式渲染,因此经常会导致很多公式可读性很差,希望可以考虑调整

📝 补充信息

No response

@zhairuoxun zhairuoxun added the 🌠 Feature Request New feature or request | 特性与建议 label Mar 17, 2024
@lobehubbot
Copy link
Member

👀 @zhairuoxun

Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible.
Please make sure you have given us as much context as possible.
非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


🥰 Description of requirements

It is hoped that mathematical formulas enclosed by ( ) and [ ] can also be rendered

🧐 Solution

When it comes to formulas, AI assistants often prefer to use \[ \] and \( \) to enclose formulas, while lobechat often only renders formulas enclosed in $$, so it often causes Many formulas are very poorly readable. I hope they can consider adjusting them.

📝 Supplementary information

No response

@zhuozhiyongde
Copy link
Contributor

确实是一个好建议,虽然我之前一直采用 prompt 的方式来提示它,但是还是有概率出现这种情况。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


It is indeed a good suggestion. Although I have always used prompt to prompt it, there is still a probability that this situation will occur.

@zhuozhiyongde
Copy link
Contributor

不过有一说一,这个修改似乎和渲染方式有关,如果现在的解析是基于正则的,那非常好改,但是如果是基于成熟的 md AST 解析框架,可能就会比较难弄了(没看过代码

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


However, one thing to say is that this modification seems to be related to the rendering method. If the current parsing is based on regular expressions, it is very easy to modify, but if it is based on the mature md AST parsing framework, it may be more difficult to do (I have not seen the code)

@zhairuoxun
Copy link
Author

不过有一说一,这个修改似乎和渲染方式有关,如果现在的解析是基于正则的,那非常好改,但是如果是基于成熟的 md AST 解析框架,可能就会比较难弄了(没看过代码

我不懂开发,所以技术困难什么的确实不清楚,只是使用过程中遇到了,试着提出来,希望对软件完善有所帮助。

我确实也是一直用prompt来解决这个问题的,但是在助手市场中很多助手都没有给这样的prompt,导致经常需要增加要求,并且修改以后AI助手还不一定能记住,所以这个也还是合理的,希望开发者们可以考虑吧

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


But one thing to say is that this modification seems to be related to the rendering method. If the current parsing is based on regular expressions, it is very easy to modify, but if it is based on the mature md AST parsing framework, it may be more difficult to do (I haven’t seen it yet) code

I don't know much about development, so I really don't know about technical difficulties. I just encountered them during use. I will try to raise them, hoping to help improve the software.

I have indeed been using prompts to solve this problem, but many assistants in the assistant market do not give such prompts, which often requires adding requirements, and the AI ​​assistant may not be able to remember them after modifications, so this is still reasonable. , I hope developers can consider it

@zhuozhiyongde
Copy link
Contributor

即使要做,我认为这也应该是一个附加的可选 docker 参数或者设置项,而非一个默认的配置项,因为我们不清楚是否存在别的输入/输出会有这样的格式,这种格式的确是 latex 的标准格式,但是不是 markdown 的标准格式。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Even if it is done, I think this should be an additional optional docker parameter or setting item, rather than a default configuration item, because we don't know if other input/output will have such a format. This format does It is the standard format of latex, but not the standard format of markdown.

@arvinxx
Copy link
Contributor

arvinxx commented Mar 17, 2024

#1602 (comment) 一起考虑吧。后面搞一个专门的配置页用于设置各种 markdown 语法的渲染效果。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Consider this along with #1602 (comment). A special configuration page will be created later to set the rendering effects of various markdown syntaxes.

@zhuozhiyongde
Copy link
Contributor

#1602 (comment) 一起考虑吧。后面搞一个专门的配置页用于设置各种 markdown 语法的渲染效果。

其实我见过有同时支持选择 纯文本/Markdown/LaTeX 之一渲染的前端(逃

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Consider this with #1602 (comment). A special configuration page will be created later to set the rendering effects of various markdown syntaxes.

In fact, I have seen front-ends that support one of the rendering options of plain text/Markdown/LaTeX (escape

@zhairuoxun
Copy link
Author

即使要做,我认为这也应该是一个附加的可选 docker 参数或者设置项,而非一个默认的配置项,因为我们不清楚是否存在别的输入/输出会有这样的格式,这种格式的确是 latex 的标准格式,但是不是 markdown 的标准格式。

嗯嗯,这样比较好!

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Even if it is done, I think this should be an additional optional docker parameter or setting item, rather than a default configuration item, because we don't know if there are other input/outputs that have such a format. It is indeed the standard format of latex, but not the standard format of markdown.

Hmm, this is better!

@arvinxx
Copy link
Contributor

arvinxx commented Mar 17, 2024

其实我见过有同时支持选择 纯文本/Markdown/LaTeX 之一渲染

是指三选一还是同时渲染?

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


In fact, I have seen that there is support for selecting one of plain text/Markdown/LaTeX rendering at the same time.

Does it mean to choose one of the three or render at the same time?

@zhuozhiyongde
Copy link
Contributor

zhuozhiyongde commented Mar 17, 2024

其实我见过有同时支持选择 纯文本/Markdown/LaTeX 之一渲染

是指三选一还是同时渲染?

三选一,选择一个渲染方式,好像可以在对话项旁边还是设置页切换来着,忘了是哪个项目了

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


In fact, I have seen that there is support for selecting one of plain text/Markdown/LaTeX rendering at the same time.

Does it mean to choose one of the three or render at the same time?

Choose one from three

@MapleEve
Copy link
Contributor

其实我见过有同时支持选择 纯文本/Markdown/LaTeX 之一渲染

是指三选一还是同时渲染?

应该是思源的三选一,这个没办法(也没必要)同时渲染。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


In fact, I have seen that there is support for selecting one of plain text/Markdown/LaTeX rendering at the same time.

Does it mean to choose one of the three or render at the same time?

It should be one of Siyuan's three choices. There is no way (and no need) to render these at the same time.

@Wxh16144
Copy link
Contributor

#1602 (comment) 一起考虑吧。后面搞一个专门的配置页用于设置各种 markdown 语法的渲染效果。

#1620 这个问题也可以关联起来,属于同一类型反馈

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Consider this with #1602 (comment). A special configuration page will be created later to set the rendering effects of various markdown syntaxes.

#1620 This issue can also be related and belongs to the same type of feedback

@MoonWeSif
Copy link

确实是一个好建议,虽然我之前一直采用 prompt 的方式来提示它,但是还是有概率出现这种情况。

你好,我在使用的时候也遇到了类似的问题,方便问一下prompt应该如何编写吗,对于前端上数学表达式的渲染问题了解的不多

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


This is indeed a good suggestion. Although I have always used prompt to prompt it, there is still a probability that this situation will occur.

Hello, I also encountered similar problems when using it. Can I ask how to write the prompt? I don’t know much about the rendering of mathematical expressions on the front end.

@zhuozhiyongde
Copy link
Contributor

确实是一个好建议,虽然我之前一直采用 prompt 的方式来提示它,但是还是有概率出现这种情况。

你好,我在使用的时候也遇到了类似的问题,方便问一下prompt应该如何编写吗,对于前端上数学表达式的渲染问题了解的不多

{{text}}

注意事项:
- 如果你需要用到公式或数学表达式,请在输出中使用符合 Markdown 语法的 LaTeX 表达式, 即用美元符号 $ 包裹行内公式, 用双美元符号 $$ 包裹块级公式。

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


This is indeed a good suggestion. Although I have always used prompt to prompt it, there is still a probability that this situation will occur.

Hello, I also encountered similar problems when using it. Can I ask how to write the prompt? I don’t know much about the rendering of mathematical expressions on the front end.

{{text}}

Precautions:
- If you need to use formulas or mathematical expressions, please use LaTeX expressions that conform to Markdown syntax in the output, that is, wrap inline formulas with the dollar sign $, and wrap block-level formulas with the double dollar sign $$.

@MapleEve
Copy link
Contributor

确实是一个好建议,虽然我之前一直采用 prompt 的方式来提示它,但是还是有概率出现这种情况。

你好,我在使用的时候也遇到了类似的问题,方便问一下prompt应该如何编写吗,对于前端上数学表达式的渲染问题了解的不多

{{text}}

注意事项:
- 如果你需要用到公式或数学表达式,请在输出中使用符合 Markdown 语法的 LaTeX 表达式, 即用美元符号 $ 包裹行内公式, 用双美元符号 $$ 包裹块级公式。

这个可以放到agent里面,如果agent偶尔出错再放到 text 里,这样会省下一些token,但是prompt是没错的

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


This is indeed a good suggestion. Although I have always used prompt to prompt it, there is still a probability that this situation will occur.

Hello, I also encountered similar problems when using it. Can I ask how to write the prompt? I don’t know much about the rendering of mathematical expressions on the front end.

{{text}}

Notes:
- If you need to use formulas or mathematical expressions, please use LaTeX expressions that conform to Markdown syntax in the output, that is, wrap inline formulas with the dollar sign $, and wrap block-level formulas with the double dollar sign $$.

This can be placed in the agent. If the agent occasionally makes errors, put it in text. This will save some tokens, but the prompt is correct.

@zhuozhiyongde
Copy link
Contributor

临时解决方案:

  1. 复制出来结果
  2. 执行正则替换

正则替换:

  1. (\\\(\s*|\s*\\\)) 替换为 $
  2. \\[\[\]] 替换为 $$

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Temporary solution:

  1. Copy the result
  2. Perform regular replacement

Regular replacement:

  1. (\\\(\s*|\s*\\\)) replaced with $
  2. Replace \\[\[\]] with $$

@canisminor1990
Copy link
Member

感觉可以在助手设置里加一个配置项

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I feel like I can add a configuration item to the assistant settings.

@canisminor1990
Copy link
Member

canisminor1990 commented Jun 24, 2024

Fixed in @lobehub/ui: lobehub/lobe-ui#168

@lobehubbot
Copy link
Member

@zhairuoxun

This issue is closed, If you have any questions, you can comment and reply.
此问题已经关闭。如果您有任何问题,可以留言并回复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌠 Feature Request New feature or request | 特性与建议
Projects
None yet
Development

No branches or pull requests

8 participants