Determination of programs for viewing web pages, etc.#

The function default_viewer() defines reasonable defaults for these programs. To use something else, use viewer. First import it:

sage: from sage.misc.viewer import viewer
>>> from sage.all import *
>>> from sage.misc.viewer import viewer

On OS X, PDFs are opened by default using the ‘open’ command, which runs whatever has been designated as the PDF viewer in the OS. To change this to use ‘Adobe Reader’:

sage: viewer.pdf_viewer('open -a /Applications/Adobe\ Reader.app') # not tested
>>> from sage.all import *
>>> viewer.pdf_viewer('open -a /Applications/Adobe\ Reader.app') # not tested

Similarly, you can set viewer.browser(...), viewer.dvi_viewer(...), and viewer.png_viewer(...). You can make this change permanent by adding lines like these to your SAGE_STARTUP_FILE (which is $HOME/.sage/init.sage by default):

from sage.misc.viewer import viewer
viewer.pdf_viewer('open -a /Applications/Adobe\ Reader.app')

Functions and classes#

class sage.misc.viewer.Viewer[source]#

Bases: SageObject

Set defaults for various viewing applications: a web browser, a dvi viewer, a pdf viewer, and a png viewer.

EXAMPLES:

sage: from sage.misc.viewer import viewer
sage: old_browser = viewer.browser()  # indirect doctest
sage: viewer.browser('open -a /Applications/Firefox.app')
sage: viewer.browser()
'open -a /Applications/Firefox.app'
sage: viewer.browser(old_browser) # restore old value
>>> from sage.all import *
>>> from sage.misc.viewer import viewer
>>> old_browser = viewer.browser()  # indirect doctest
>>> viewer.browser('open -a /Applications/Firefox.app')
>>> viewer.browser()
'open -a /Applications/Firefox.app'
>>> viewer.browser(old_browser) # restore old value
browser(app=None)[source]#

Change the default browser. Return the current setting if arg is None, which is the default.

INPUT:

  • appNone or a string, the program to use

EXAMPLES:

sage: from sage.misc.viewer import viewer
sage: old_browser = viewer.browser()
sage: viewer.browser('open -a /Applications/Firefox.app') # indirect doctest
sage: viewer.browser()
'open -a /Applications/Firefox.app'
sage: viewer.browser(old_browser) # restore old value
>>> from sage.all import *
>>> from sage.misc.viewer import viewer
>>> old_browser = viewer.browser()
>>> viewer.browser('open -a /Applications/Firefox.app') # indirect doctest
>>> viewer.browser()
'open -a /Applications/Firefox.app'
>>> viewer.browser(old_browser) # restore old value
dvi_viewer(app=None)[source]#

Change the default dvi viewer. Return the current setting if arg is None, which is the default.

INPUT:

  • appNone or a string, the program to use

EXAMPLES:

sage: from sage.misc.viewer import viewer
sage: old_dvi_app = viewer.dvi_viewer()
sage: viewer.dvi_viewer('/usr/bin/xdvi') # indirect doctest
sage: viewer.dvi_viewer()
'/usr/bin/xdvi'
sage: viewer.dvi_viewer(old_dvi_app) # restore old value
>>> from sage.all import *
>>> from sage.misc.viewer import viewer
>>> old_dvi_app = viewer.dvi_viewer()
>>> viewer.dvi_viewer('/usr/bin/xdvi') # indirect doctest
>>> viewer.dvi_viewer()
'/usr/bin/xdvi'
>>> viewer.dvi_viewer(old_dvi_app) # restore old value
pdf_viewer(app=None)[source]#

Change the default pdf viewer. Return the current setting if arg is None, which is the default.

INPUT:

  • appNone or a string, the program to use

EXAMPLES:

sage: from sage.misc.viewer import viewer
sage: old_pdf_app = viewer.pdf_viewer()
sage: viewer.pdf_viewer('/usr/bin/pdfopen') # indirect doctest
sage: viewer.pdf_viewer()
'/usr/bin/pdfopen'
sage: viewer.pdf_viewer(old_pdf_app) # restore old value
>>> from sage.all import *
>>> from sage.misc.viewer import viewer
>>> old_pdf_app = viewer.pdf_viewer()
>>> viewer.pdf_viewer('/usr/bin/pdfopen') # indirect doctest
>>> viewer.pdf_viewer()
'/usr/bin/pdfopen'
>>> viewer.pdf_viewer(old_pdf_app) # restore old value
png_viewer(app=None)[source]#

Change the default png viewer. Return the current setting if arg is None, which is the default.

INPUT:

  • appNone or a string, the program to use

EXAMPLES:

sage: from sage.misc.viewer import viewer
sage: old_png_app = viewer.png_viewer()
sage: viewer.png_viewer('display') # indirect doctest
sage: viewer.png_viewer()
'display'
sage: viewer.png_viewer(old_png_app) # restore old value
>>> from sage.all import *
>>> from sage.misc.viewer import viewer
>>> old_png_app = viewer.png_viewer()
>>> viewer.png_viewer('display') # indirect doctest
>>> viewer.png_viewer()
'display'
>>> viewer.png_viewer(old_png_app) # restore old value
sage.misc.viewer.browser()[source]#

Return the program used to open a web page. By default, the program used depends on the platform and other factors, like settings of certain environment variables. To use a different program, call viewer.browser('PROG'), where ‘PROG’ is the desired program.

EXAMPLES:

sage: from sage.misc.viewer import browser
sage: browser() # random -- depends on OS, etc.
'open'
>>> from sage.all import *
>>> from sage.misc.viewer import browser
>>> browser() # random -- depends on OS, etc.
'open'
sage.misc.viewer.default_viewer(viewer=None)[source]#

Set up default programs for opening web pages, PDFs, PNGs, and DVI files.

INPUT:

  • viewer: None or a string: one of ‘browser’, ‘pdf’, ‘png’, ‘dvi’ – return the name of the corresponding program. None is treated the same as ‘browser’.

EXAMPLES:

sage: from sage.misc.viewer import default_viewer
sage: default_viewer(None) # random -- depends on OS, etc.
'open'
sage: default_viewer('pdf') # random -- depends on OS, etc.
'xdg-open'
sage: default_viewer('jpg')
Traceback (most recent call last):
...
ValueError: Unknown type of viewer: jpg.
>>> from sage.all import *
>>> from sage.misc.viewer import default_viewer
>>> default_viewer(None) # random -- depends on OS, etc.
'open'
>>> default_viewer('pdf') # random -- depends on OS, etc.
'xdg-open'
>>> default_viewer('jpg')
Traceback (most recent call last):
...
ValueError: Unknown type of viewer: jpg.
sage.misc.viewer.dvi_viewer()[source]#

Return the program used to display a dvi file. By default, the program used depends on the platform and other factors, like settings of certain environment variables. To use a different program, call viewer.dvi_viewer('PROG'), where ‘PROG’ is the desired program.

EXAMPLES:

sage: from sage.misc.viewer import dvi_viewer
sage: dvi_viewer() # random -- depends on OS, etc.
'open'
>>> from sage.all import *
>>> from sage.misc.viewer import dvi_viewer
>>> dvi_viewer() # random -- depends on OS, etc.
'open'
sage.misc.viewer.pdf_viewer()[source]#

Return the program used to display a pdf file. By default, the program used depends on the platform and other factors, like settings of certain environment variables. To use a different program, call viewer.pdf_viewer('PROG'), where ‘PROG’ is the desired program.

EXAMPLES:

sage: from sage.misc.viewer import pdf_viewer, viewer
sage: old_pdf_app = viewer.pdf_viewer()
sage: viewer.pdf_viewer('acroread')
sage: pdf_viewer()
'acroread'
sage: viewer.pdf_viewer('old_pdf_app')
>>> from sage.all import *
>>> from sage.misc.viewer import pdf_viewer, viewer
>>> old_pdf_app = viewer.pdf_viewer()
>>> viewer.pdf_viewer('acroread')
>>> pdf_viewer()
'acroread'
>>> viewer.pdf_viewer('old_pdf_app')
sage.misc.viewer.png_viewer()[source]#

Return the program used to display a png file. By default, the program used depends on the platform and other factors, like settings of certain environment variables. To use a different program, call viewer.png_viewer('PROG'), where ‘PROG’ is the desired program.

EXAMPLES:

sage: from sage.misc.viewer import png_viewer
sage: png_viewer() # random -- depends on OS, etc.
'xdg-open'
>>> from sage.all import *
>>> from sage.misc.viewer import png_viewer
>>> png_viewer() # random -- depends on OS, etc.
'xdg-open'