# Ticket #6591: trac_6591_view_viewer_tightpage-nt.patch

File trac_6591_view_viewer_tightpage-nt.patch, 5.6 KB (added by Nicolas M. Thiéry, 13 years ago)

Apply only this one (it includes the doc patch)

• ## sage/misc/latex.py

# HG changeset patch
# User Nicolas M. Thiery <nthiery@users.sf.net>
# Date 1248384456 -7200
# Node ID 1854d6c7e956416dffbbb2a616d8fa590a4a68ba
# Parent  cc6a63da77324a1b009217c47676918e7039ea77
#6591: Implement view(object, viewer='pdf') and view(object, tightpage = True)

diff --git a/sage/misc/latex.py b/sage/misc/latex.py
 a def jsmath(x, mode='display'): x = str(x) return html(delimiter + x + delimiter) def view(objects, title='SAGE', debug=False, sep='', tiny=False, pdflatex=None, **kwds): def view(objects, title='SAGE', debug=False, sep='', tiny=False, pdflatex=None, viewer = None, tightpage = None, **kwds): r"""nodetex Compute a latex representation of each object in objects, compile, and display typeset. If used from the command line, this requires def view(objects, title='SAGE', debug=Fa -  pdflatex - bool (default: False): use pdflatex. -  viewer -- string or None (default: None): specify a viewer to use; currently the only options are None and 'pdf'. -  tightpage - bool (default: False): use the LaTeX package 'preview' with the 'tightpage' option. 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. If note in notebook mode, the output is displayed in a separate viewer displaying a dvi (or pdf) file, with 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 def view(objects, title='SAGE', debug=Fa adds a horizontal line between objects, and sep='\\newpage' inserts a page break between objects. If pdflatex is True, then this produces a pdf file. If pdflatex is True, then this produces a pdf file. Otherwise, it produces a dvi file, and if the program dvipng is installed, it checks the dvi file by trying to convert it to a png file.  If this conversion fails, the dvi file probably contains some postscript special commands or it has other issues which might make displaying it a problem; in this case, the file is converted to a pdf file, which is then displayed. If in notebook mode, this usually uses jsMath -- see the next paragraph for the exception -- to display the output in the notebook. Only the first argument, objects, is relevant; the others are ignored. If objects is a list, each object is printed on its own line. Setting viewer to 'pdf' forces the use of a separate viewer, even in notebook mode. This also sets pdflatex to True. Setting the option tightpage to True tells LaTeX to use the package 'preview' with the 'tightpage' option. Then, each object is typeset in its own page, and that page is cropped to exactly the size of the object. This is typically useful for very large pictures (like graphs) generated with tikz. This only works when using a separate viewer. Note that the object are currently typeset in plain math mode rather than displaymath, because the later imposes a limit on the width of the picture. Technically, tightpage adds \\usepackage[tightpage,active]{preview} \\PreviewEnvironment{page} to the \LaTeX preamble, and replaces the \$ and \$ around each object by \\begin{page}$ and $\\end{page}. If in notebook mode with viewer equal to None, this usually uses jsMath -- see the next paragraph for the exception -- to display the output in the notebook. Only the first argument, objects, is relevant; the others are ignored. If objects is a list, each object is printed on its own line. In the notebook, this *does* *not* use jsMath if the LaTeX code for objects contains a string in def view(objects, title='SAGE', debug=Fa if isinstance(objects, LatexExpr): s = str(objects) else: s = _latex_file_(objects, title=title, sep=sep, tiny=tiny, debug=debug) if tightpage == True: latex_options = {'extra_preamble':'\\usepackage[tightpage,active]{preview}\\PreviewEnvironment{page}', 'math_left':'\\begin{page}$', 'math_right':'$\\end{page}'} else: latex_options = {} s = _latex_file_(objects, title=title, sep=sep, tiny=tiny, debug=debug, **latex_options) # notebook if EMBEDDED_MODE: if EMBEDDED_MODE and viewer is None: jsMath_okay = True for t in latex.jsmath_avoid_list(): if s.find(t) != -1: def view(objects, title='SAGE', debug=Fa print ''%png_link  # put comma at end of line? return # command line if viewer == "pdf": pdflatex = True if pdflatex is None: pdflatex = _Latex_prefs._option["pdflatex"] tmp = tmp_dir('sage_viewer')