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