def view(self): if not self._viewer is None: viewer = self._viewer else: viewer = dvi_viewer() self._build() F = os.path.splitext(self._filename)[0] + ".dvi" cmd = "cd %s; %s %s " % (self._dir, viewer, F) os.system(cmd + " 2>/dev/null 1>/dev/null &")
def view(self): if not self._viewer is None: viewer = self._viewer else: viewer = dvi_viewer() self._build() F = os.path.splitext(self._filename)[0] + '.dvi' cmd = 'cd %s; %s %s ' % (self._dir, viewer, F) os.system(cmd + " 2>/dev/null 1>/dev/null &")
def view(objects, title='SAGE', debug=False, sep='', tiny=False, **kwds): r"""nodetex Compute a latex representation of each object in objects, compile, and display typeset. If used from the command line, this requires that latex be installed. INPUT: - ``objects`` - list (or object) - ``title`` - string (default: 'Sage'): title for the document - ``debug`` - bool (default: False): print verbose output - ``sep`` - string (default: ''): separator between math objects - ``tiny`` - bool (default: False): use tiny font. OUTPUT: Display typeset objects. This function behaves differently depending on whether in notebook mode or not. If not in notebook mode, this opens up a window displaying a dvi (or pdf) file, displaying the following: the title string is printed, centered, at the top. Beneath that, each object in objects is typeset on its own line, with the string sep inserted between these lines. The value of ``sep`` is inserted between each element of the list ``objects``; you can, for example, add vertical space between objects with ``sep='\\vspace{15mm}'``, while ``sep='\\hrule'`` adds a horizontal line between objects, and ``sep='\\newpage'`` inserts a page break between objects. If in notebook mode, this uses jmath to display the output in the notebook. Only the first argument, objects, is relevant; the others are ignored. If objects is a list, the result is typeset as a Python list, e.g. [12, -3.431] - each object in the list is not printed on its own line. EXAMPLES:: sage: sage.misc.latex.EMBEDDED_MODE=True sage: view(3) <html><span class="math">3</span></html> sage: sage.misc.latex.EMBEDDED_MODE=False """ if EMBEDDED_MODE: print typeset(objects) return if isinstance(objects, LatexExpr): s = str(objects) else: s = _latex_file_(objects, title=title, debug=debug, sep=sep, tiny=tiny) from sage.misc.viewer import dvi_viewer viewer = dvi_viewer() tmp = tmp_dir('sage_viewer') open('%s/sage.tex'%tmp,'w').write(s) os.system('ln -sf %s/common/macros.tex %s'%(SAGE_DOC, tmp)) O = open('%s/go'%tmp,'w') #O.write('export TEXINPUTS=%s/doc/commontex:.\n'%SAGE_ROOT) # O.write('latex \\\\nonstopmode \\\\input{sage.tex}; xdvi -noscan -offsets 0.3 -paper 100000x100000 -s %s sage.dvi ; rm sage.* macros.* go ; cd .. ; rmdir %s'%(zoom,tmp)) # Added sleep 1 to allow viewer to open the file before it gets removed # Yi Qiang 2008-05-09 O.write('latex \\\\nonstopmode \\\\input{sage.tex}; %s sage.dvi ; sleep 1 rm sage.* macros.* go ; cd .. ; rmdir %s' % (viewer, tmp)) O.close() if not debug: direct = '1>/dev/null 2>/dev/null' else: direct = '' os.system('cd %s; chmod +x go; ./go %s&'%(tmp,direct))