tsengwoody / Access8Math

Allows access math content written by MathML ; Assist writing math content by LaTeX
GNU General Public License v2.0
31 stars 15 forks source link

how to use this code directly in python #97

Closed xinkez closed 3 months ago

xinkez commented 5 months ago

Hi,

It's a great work to translate MathML content.

I want to use this code directly in the python, for example, given the latex formula "\tfrac{x}{y+6}*10", which function should I call? It can output the pronunciation text results of Chinese.

Thank you in advance.

Best Regard, Xinke

tsengwoody commented 5 months ago

To convert a LaTeX formula into spoken Chinese text using Python, you'll need to follow a two-step process. This involves first converting LaTeX to MathML, and then converting that MathML into spoken text. since Access8Math is designed for use with the NVDA screen reader and may not be directly usable in a standalone Python environment, you might need to extract and adapt the necessary parts. step1. LaTeX to MathML:Access8Math use latex2mathml package step2. MathML to text: Access8Math use custom algorithm Please refer to the following source code for implementation details: addon/globalPlugins/Access8Math/write.py -> TextMathEditField class -> script_interact method(step1) addon/globalPlugins/Access8Math/interaction.py -> A8MProvider class -> getSpeechForMathMl method(step2)

xinkez commented 5 months ago

Hi, Thank you. I follow your suggestions of "extract and adapt the necessary parts". My code is below:

Example1: ''' latex_input = "\frac{a}{x+y}"

mathMl = latex2mathml.converter.convert(latex_input) mathcontent = MathContent("zh_CN", mathMl) speechSequence = translate_SpeechCommand_CapNotification(mathcontent.pointer.serialized()) ''' It can output the result "['分数', 'x', '加', 'y', '分之', 'a', '结束分数']", but I expect the result to be "['x', '加', 'y', '分之', 'a']".

Example2: ''' latex_input = "\angle ACE=180^{\circ}"

mathMl = latex2mathml.converter.convert(latex_input) mathcontent = MathContent("zh_CN", mathMl) speechSequence = translate_SpeechCommand_CapNotification(mathcontent.pointer.serialized()) '''

It can output the result "['角', 'A', 'C', 'E', '等于', '标记', '180', '上标', '合成', '结束标记']", but I expect the result to be "['角', 'A', 'C', 'E', '等于', '180', '度']".

What should I do? Do you have any suggestions? Thank you in advance.

tsengwoody commented 5 months ago

"configure analyze_math_meaning is not active. You should set "analyze_math_meaning" to True when initializing A8M_PM pass config value(Access8MathConfig["settings"]["analyze_math_meaning"])

xinkez commented 5 months ago

Hi,

Thank you. When I configure "analyze_math_meaning" to "True", it works. However, there is another question:

''' latex = r'\frac{1}{4}=0.25' ''' It can output the result "['4', '分之', '1', '等于', '0点25']", but I expect the result to be "['4', '分之', '1', '等于', '0.25']". I want to keep '.' in '0.25' unchanged.

What should I do? Do you have any suggestions? Thank you in advance.

"configure analyze_math_meaning is not active. You should set "analyze_math_meaning" to True when initializing A8M_PM pass config value(Access8MathConfig["settings"]["analyze_math_meaning"])

cary-rowen commented 5 months ago

Do you plan to contribute code to the project?

xinkez commented 4 months ago

Do you plan to contribute code to the project?

Sorry, my time commitment would not be guaranteed.

WinterStraw commented 1 month ago

Hi, 你好,

It's a great work to translate MathML content.翻译 MathML 内容是一项伟大的工作。

I want to use this code directly in the python, for example, given the latex formula "\tfrac{x}{y+6}10", which function should I call? It can output the pronunciation text results of Chinese.我想直接在python中使用这段代码,例如,给定乳胶公式“\tfrac{x}{y+6}10”,我应该调用哪个函数?可以输出中文的发音文本结果。

Thank you in advance.先感谢您。

Best Regard, 最良好的问候, Xinke  新科

Can you participate in the discussion on #103 ? I couldn't be more grateful for your earlier exploration.

hezhenfan commented 1 month ago

Hi, 你好 Thank you. I follow your suggestions of "extract and adapt the necessary parts". My code is below:谢谢。我遵循您的建议“提取和调整必要的部分”。我的代码如下:

Example1: 示例1: ''' latex_input = "\frac{a}{x+y}"latex_input = “\frac{a}{x+y}”

mathMl = latex2mathml.converter.convert(latex_input)mathMl = latex2mathml.converter.convert(latex_input) mathcontent = MathContent("zh_CN", mathMl)Mathcontent = mathcontent(“z_CN”, mathminl) speechSequence = translate_SpeechCommand_CapNotification(mathcontent.pointer.serialized())speechSequence = translate_SpeechCommand_CapNotification(mathcontent.pointer.serialized()) ''' It can output the result "['分数', 'x', '加', 'y', '分之', 'a', '结束分数']", but I expect the result to be "['x', '加', 'y', '分之', 'a']".它可以输出结果“['分数', 'x', '加', 'y', '分之', 'a', '结束分数']”,但我预计结果是“['x', '加', 'y', '分之', 'a']”。

Example2: 示例2: ''' latex_input = "\angle ACE=180^{\circ}"latex_input = “\angle ACE=180^{\circ}”

mathMl = latex2mathml.converter.convert(latex_input)mathMl = latex2mathml.converter.convert(latex_input) mathcontent = MathContent("zh_CN", mathMl)Mathcontent = mathcontent(“z_CN”, mathminl) speechSequence = translate_SpeechCommand_CapNotification(mathcontent.pointer.serialized())speechSequence = translate_SpeechCommand_CapNotification(mathcontent.pointer.serialized()) '''

It can output the result "['角', 'A', 'C', 'E', '等于', '标记', '180', '上标', '合成', '结束标记']", but I expect the result to be "['角', 'A', 'C', 'E', '等于', '180', '度']".

What should I do? Do you have any suggestions? Thank you in advance.我该怎么办?你有什么建议吗?先谢谢你。

Thank you for your exploration. Could you please tell me how you reference the translate_SpeechCommand_CapNotification function? Do I need the NVDA code? I look forward to your reply.