Generate PDF output.

    Use Sphinx to produce LaTeX, then use external tools such as
    TeXLive to convert the .tex file to a PDF.

    This task uses the following options, searching first in the
    "pdf" then "sphinx" section of the options.

    docroot
      the root under which Sphinx will be working.
      default: docs
    builddir
      directory under the docroot where the resulting files are put.
      default: build
    sourcedir
      directory under the docroot for the source files
      default: (empty string)
    doctrees
      the location of the cached doctrees
      default: $builddir/doctrees
    confdir
      the location of the sphinx conf.py
      default: $sourcedir
    outdir
      the location of the generated output files
      default: $builddir/$builder
    force_all
      write all files, not just new and changed
    freshenv
      don't use the saved environment, always read all files
    builder
      the name of the sphinx builder to use
      default: pdf
    pdflatex
      the name of the command to use to make a PDF
      default: pdflatex

def pdf(options):
    """Generate PDF output.

    Use Sphinx to produce LaTeX, then use external tools such as
    TeXLive to convert the .tex file to a PDF.

    This task uses the following options, searching first in the
    "pdf" then "sphinx" section of the options.

    docroot
      the root under which Sphinx will be working.
      default: docs
    builddir
      directory under the docroot where the resulting files are put.
      default: build
    sourcedir
      directory under the docroot for the source files
      default: (empty string)
    doctrees
      the location of the cached doctrees
      default: $builddir/doctrees
    confdir
      the location of the sphinx conf.py
      default: $sourcedir
    outdir
      the location of the generated output files
      default: $builddir/$builder
    force_all
      write all files, not just new and changed
    freshenv
      don't use the saved environment, always read all files
    builder
      the name of the sphinx builder to use
      default: pdf
    pdflatex
      the name of the command to use to make a PDF
      default: pdflatex
    """
    rc = run_sphinx(options, 'pdf')
    if rc:
        print('skipping the rest of the build, sphinx returned', rc)
        return rc
    options.order('pdf')
    pdflatex = options.get('pdflatex', 'pdflatex')
    paths = _get_paths(options)
    outdir = options.get('outdir', paths.builddir / options.builder)
    sh('cd %s; PDFLATEX="%s" make -e' % (outdir, pdflatex))
    return