网问答>>如何将latex表达式‘begin{cases}{x+y=a}{x-y=b}{x+z=c}end{cases}’原样传递给python端?
问题
未解决

如何将latex表达式‘begin{cases}{x+y=a}{x-y=b}{x+z=c}end{cases}’原样传递给python端?

时间:2024-09-21 03:56:17
从php传递参数$argument 给python,让python返回mathml表达式。问题是将$argument传递给python时,反斜框及双反斜杠会被两次转义,送达python端处理时会面目全非,latex2mathml无法正常识别。将$argument怎样处理后送到python端,并能被latex2mathml。 试了一下,只有当$argument =begin{cases}{x+y=a}{x-y=b}{x+z=c}end{cases};时,latex2mathml才会正确识别公式。 试了json_encode,替换字符等方法都不行,?php//$argument 为示例,从数据库分离出的latex表达式,$argument值是变化的$argument =begin{cases}{x+y=a}{x-y=b}{x+z=c}end{cases};$pythonpath="C:/Users/Administrator/AppData/Local/Programs/Python/Python38-32/python";$script_path = "C:/Users/Administrator/AppData/Local/Programs/Python/Python38-32/latex2mathml-master/example2.py"; $result = shell_exec($pythonpath." ".$script_path." ".$argument);echo "textarea style=width:800px; height:200px;".iconv("EUC-CN", "UTF-8//IGNORE",$result)."/textareabr/";echo htmlspecialchars($result);?example.py代码:import sys#argument = repr(sys.argv[1])argument = sys.argv[1]from latex2mathml.converter import convertdef convert_to_mathml(latex_input): mathml_output = convert(latex_input) print(mathml_output)if __name__ == "__main__": convert_to_mathml(argument)#example.py完
本类最有帮助
Copyright © 2008-2013 www.wangwenda.com All rights reserved.冀ICP备12000710号-1
投诉邮箱: