我编写了Scilab代码行,用于生成矩阵。它是一个函数,其参数是一个包含两个正整数的向量,并根据某种算法返回一个大小为矩阵的矩阵。由于def insert_node(self, newNode):
if newNode == self.key:
return False
elif newNode < self.key:
if self.left_child:
return self.left_child.insert_node(newNode)
else:
self.left_child = BinaryTreeNode(newNode)
return True
else:
if self.right_child:
return self.right_child.insert_node(newNode)
else:
self.right_child = BinaryTreeNode(newNode)
return True
函数,该函数还将矩阵导出为LaTeX样式的图形。
我希望将该图导出为PDF文件,我使用函数prettyprint
。它工作得很好。问题是,当服务于其预期目的时,该函数生成大小约为40x40的矩阵,并且它永远不适合页面。在我看来,创建的PDF文档甚至不是A4。
我没有包含整个代码,您需要知道的是代码生成一个名为xs2pdf
的矩阵,然后我就有了这些代码:
z
此处创建矩阵//just for this post
z=rand(40,40)
//export to figure
A=prettyprint(z) ;
clf ;
xstring(0,0,A) ;
//export to PDF
xs2pdf(0, '_path_to_pdf_file') ;
以模拟程序实际生成的矩阵。如果你运行这段代码,填写z
位,你得到一个不错的PDF输出吗?
答案 0 :(得分:1)
我可以复制同样的问题。有时甚至不会生成PDF输出,Scilab会返回错误。
一种解决方法是让Scilab创建一个新的TeX文件,并使用Scilab外的pdflatex
进行编译。好的部分是你可以从同一个Scilab脚本运行所有东西。当然,您需要安装LaTeX发行版。
r = 40; c = 40;
z = rand(r,c);
A = prettyprint(z) ;
texfile = "\documentclass{standalone}" + ...
"\usepackage{graphics}" + ...
"\usepackage{amsmath}" + ...
"\setcounter{MaxMatrixCols}{"+ string(c) +"}" + ...
"\begin{document}" + ...
A + ...
"\end{document}"
filename = "matrix.tex";
write(filename,texfile) //write() cannot overwrite a file
dos("pdflatex " + filename) //use unix() instead of dos() in case you're not on Windows
我不知道你是否对LaTeX有任何了解,所以我应该做一些笔记:
standalone
类,它将PDF输出精确地裁剪为.tex文件中描述的内容。在这种情况下,只打印矩阵,没有边距。要使用此类,您需要LaTeX的standalone
包。prettystring()
使用pmatrix
环境输出矩阵,这需要amsmath
包,因此您也需要安装此包。\setcounter{MaxMatrixCols}{c}
。