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

将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:


相关链接:

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


全部评论

相关推荐

努力学习的小绵羊:我反倒觉得这种挺好的,给不到我想要的就别浪费大家时间了
点赞 评论 收藏
分享
已老实求offer😫:有点像徐坤(没有冒犯的意思哈)
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务