0
votes

I have written lines of Scilab code which generate a matrix. It is a function whose argument is a vector containing two positive integers and that returns a matrix of size the values of the vector, according to some algorithm. The function also exports the matrix to a figure in LaTeX style, thanks to the prettyprint function.

I would like that figure to be exported to a PDF file, for which I used the function xs2pdf. It works almost fine. The problem is, when serving its intended purpose, the function generates a matrix of size around 40x40, and it never fits on the page. It seems to me like the PDF document created is not even A4.

I didn't include the entire code, all you need to know is that the code generates a matrix named z, and then I have the lines :

//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') ;

The matrix z is created here in order to simulate the matrix that my programme actually generates. If you run this code, having filled in the '_path_to_pdf_file' bit, do you get a decent PDF output?

1

1 Answers

1
votes

I could reproduced the same problem. Sometimes the PDF output is not even generated, and Scilab returns an error.

One workaround is to make Scilab create a new TeX file and compile it with pdflatex outside Scilab. The good part is that you can run everything from the same Scilab script. Of course, you'll need a LaTeX distribution installed.

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

I don't know if you have any knowledge of LaTeX, so I should make a few notes:

  • The output goes to current Scilab directory. All auxiliary files produced by LaTeX will also be created there.
  • It uses the standalone class, which crops the PDF output exactly to whatever is described in the .tex file. In this case, only the matrix is printed, with no margins. To use this class, you need the standalone package for LaTeX.
  • prettystring() outputs the matrix using pmatrix environment, which requires the amsmath package, thus you need this one installed too.
  • The line \setcounter{MaxMatrixCols}{c} is needed in case you have a matrix with more than 10 columns.

Here is the output: enter image description here