How to save the output of view locally (and not open the output)?

25 views
Skip to first unread message

slabbe

unread,
Nov 7, 2015, 4:34:49 PM11/7/15
to sage-support
This opens a pdf:

sage: g = graphs.PetersenGraph()
sage: s = latex(g)
sage: view(s, tightpage=True)

But is there a way to just save that pdf file locally and not open it?

John H Palmieri

unread,
Nov 7, 2015, 8:56:22 PM11/7/15
to sage-support

Until you quite the Sage session, the file should be saved some place like .sage/temp/HOSTNAME/9348/sage.pdf   (9348 is some random number). So if you don't mind having it open, it is available. I thought there was another way to do this, but I can't find a simple one. You can do:

   sage: from sage.misc.latex import _latex_file_
   sage: t = _latex_file_(s)   # the contents of the file to be run through LaTeX

Or even better, mimic the effects of tightpage=True:

   sage: t = _latex_file_(s, extra_preamble='\\usepackage[tightpage,active]{preview}\\PreviewEnvironment{page}',
        math_left='\\begin{page}$', math_right='$\\end{page}')

Then save to a file and run PDFLaTeX on it:

    sage: file = "/home/palmieri/my_file.tex"
    sage: O = open(file, 'w')
    sage: O.write(t)
    sage: O.close
    sage: from sage.misc.latex import _run_latex_
    sage: _run_latex_(file)

--
John
Reply all
Reply to author
Forward
0 new messages