### Navigation

- index
- modules |
- next |
- previous |
- Miscellaneous »

# 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

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

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`

  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

  `browser`(app=None)

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

    INPUTS:

    - `app` – `None` 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

  `dvi_viewer`(app=None)

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

    INPUTS:

    - `app` – `None` 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

  `pdf_viewer`(app=None)

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

    INPUTS:

    - `app` – `None` 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

  `png_viewer`(app=None)

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

    INPUTS:

    - `app` – `None` 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

`sage.misc.viewer.``browser`()

  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.

  This will start with ‘sage-native-execute’, which sets the environment appropriately.

  EXAMPLES:

      sage: from sage.misc.viewer import browser
      sage: browser() # random -- depends on OS, etc.
      'sage-native-execute sage-open'
      sage: browser().startswith('sage-native-execute')
      True

`sage.misc.viewer.``default_viewer`(viewer=None)

  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.
      'sage-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.

`sage.misc.viewer.``dvi_viewer`()

  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.

  This will start with ‘sage-native-execute’, which sets the environment appropriately.

  EXAMPLES:

      sage: from sage.misc.viewer import dvi_viewer
      sage: dvi_viewer() # random -- depends on OS, etc.
      'sage-native-execute sage-open'
      sage: dvi_viewer().startswith('sage-native-execute')
      True

`sage.misc.viewer.``pdf_viewer`()

  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.

  This will start with ‘sage-native-execute’, which sets the environment appropriately.

  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()
      'sage-native-execute acroread'
      sage: viewer.pdf_viewer('old_pdf_app')

`sage.misc.viewer.``png_viewer`()

  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.

  This will start with ‘sage-native-execute’, which sets the environment appropriately.

  EXAMPLES:

      sage: from sage.misc.viewer import png_viewer
      sage: png_viewer() # random -- depends on OS, etc.
      'sage-native-execute xdg-open'
      sage: png_viewer().startswith('sage-native-execute')
      True

### Navigation

- index
- modules |
- next |
- previous |
- Miscellaneous »