将Maple输出的LaTex导出到txt文件

December 17, 2023
测试
测试
测试
测试
4 分钟阅读

将Maple输出的LaTex导出到txt文件

1. 生成LATEX

Maple可以把它的表达式转换成LATEX, 使用latex命令即可:

> latex(x^2+y^2=z^2);

{x}^{2}+{y}^{2}={z}^{2}

    还可以将转换结果存为一个文件(LatexFile):

> latex(x^2 + y^2 = z^2, LatexFile);

测试通过:

interface(prettyprint=0);
> latex(x^2 + y^2 = z^2, res.txt);
> with(linalg):

 matrix(2,2,[5,4,6,3]);
 latex(subs(LambertW=lambertW,erf=Erf,arctanh=Artanh,[%]),"C:/Users/Bravo/Desktop/test1.txt"); 
> latex(BesselK(nu, z)+BesselJ(nu, z), output = string)
"{{\sl K}_{\nu}\left(z\right)}+{{\sl J}_{\nu}\left(z\right)}"

注意: LambertW erf arctanh这几个命令会导致Latex命令报错,需要在使用的时候替换掉

MyLaTeX := module()
 export ModuleApply, ExprsToLaTeX, CleanLaTeX;
 option package;
     ModuleApply := CleanLaTeX;
     ExprsToLaTeX := proc()
         return cat("", `latex/print`(_passed));
     end proc;
     CleanLaTeX := proc(expr, regsubs :: seq(string=string), $)
         return foldr(StringTools:-RegSubs
                      , ExprsToLaTeX(expr)
                      , ListTools:-Reverse([regsubs])[]
                      , "\\\\!"            = ""      # remove \!
                      , "{([0-9])}"        = "\\1 "  # strip braces from single digits
                      , "\\\\_"            = "_"     # change \_ to _
                      , " \\\\right\\)"    = ")"     # remove \right)
                      , " \\\\left\\( "    = "("     # remove \left)
                      , "{\\\\it ([^}]*)}" = "\\1"   # remove italics from variables
                      , "\\\\,"            = " "     # remove \
    , "(([a-zA-Z1-9]+))/(([a-zA-Z1-9]+))" = "\\\\frac {\\1} {\\3}"
   # , "\:\:" = "->"
                     );
     end proc;
 end module:

相关链接:

http://www.mapleprimes.com/questions/201975-Maple-Error-Using-Latex-Command-How-To-Resolve#comment207767

Better LaTeX output from Maple? - MaplePrimes http://www.mapleprimes.com/posts/43828-Better-LaTeX-Output-From-Maple

继续阅读

更多来自我们博客的帖子

如何安装 BuddyPress
由 测试 December 17, 2023
经过差不多一年的开发,BuddyPress 这个基于 WordPress Mu 的 SNS 插件正式版终于发布了。BuddyPress...
阅读更多
Filter如何工作
由 测试 December 17, 2023
在 web.xml...
阅读更多
如何理解CGAffineTransform
由 测试 December 17, 2023
CGAffineTransform A structure for holding an affine transformation matrix. ...
阅读更多