

======= Installation of DocOnce and its Dependencies =======
label{install:doconce}

idx{installation}

Below, we explain the manual installation of all software that may be
needed when working with DocOnce documents.
The impatient way to install everything that is needed is to use
Anaconda Python and the `conda` program:

DocOnce is available from the `conda-forge` channel. To add the `conda-forge` channel and subsequently install DocOnce, run the following commands.

!bc sys
Terminal> conda config --add channels conda-forge
Terminal> conda install doconce
!ec

If you do not want to use Anaconda and are
on a Debian-based Linux
computer (running, e.g., Ubuntu), you can instead run the Bash script
"`install_doconce.sh`": "https://raw.githubusercontent.com/hplgit/doconce/master/doc/src/manual/install_doconce.sh" or the equivalent Python script
"`install_doconce.py`": "https://raw.githubusercontent.com/hplgit/doconce/master/doc/src/manual/install_doconce.py".
These scripts give a comprehensive installation. Some users will prefer to
install just what is needed for them, and this is explained below.

!bwarning Version control systems are needed!
The coming installation instructions require that the version control systems
Subversion, Mercurial, and Git are installed on your computer.
!ewarning

!bnotice What about Mac and Windows?
DocOnce is primarily tested on GNU/Debian Linux systems, but also to
a minor extent on Mac OS X. Experience with Windows is limited.
Since most packages are Python-based and can be installed via `pip install`
no problems should arise on Mac and Windows. However, some of the
image processing tools and spell checking apply Unix-specific software.
!enotice

You can omit reading the next sections if you rely on `conda` or
`apt-get install` commands in the Bash script for installing DocOnce.


===== DocOnce =====

DocOnce itself is pure Python code hosted at URL:
"https://github.com/hplgit/doconce".
Installation can be done via

!bc sys
sudo pip install -e git+https://github.com/hplgit/doconce#egg=doconce
# or if doconce is already installed
sudo pip install -e git+https://github.com/hplgit/doconce#egg=doconce --upgrade
!ec
However, the recommended approach is to have a copy of the source on
the local computer and run `setup.py`:

!bc sys
git clone git@github.com:hplgit/doconce.git
cd doconce
sudo python setup.py install
cd ..
!ec
Since DocOnce is frequently updated, it becomes necessary to ensure
that you work with the most recent version:

!bc sys
cd doconce
git pull origin master
sudo python setup.py install
!ec


===== Dependencies =====

Producing HTML documents, plain text, pandoc-extended Markdown,
and wikis can be done without installing any other
software. However, if you want other formats as output
(LaTeX, Sphinx, reStructuredText) and assisting utilities such
as preprocesors, spellcheck, file differences, bibliographies,
and so on, a lot of extra software must be installed.

=== Python v2.7 ===

First you need Python version 2.7 and the `pip` installation program.
Unless you already have these, we recommend to install a comprehensive
Python bundle like "Anaconda": "https://store.continuum.io/cshop/anaconda/".

You do not need more software if you avoid using preprocessors, there
is no bibliography, and you stick to the output formats LaTeX and HTML
(you need of course LaTeX installed to process `.tex` files).

=== Preprocessors ===

If you make use of the "Preprocess": "https://github.com/hplgit/preprocess"
preprocessor, this program must be installed:

!bc sys
pip install -e \
   git+https://github.com/hplgit/preprocess#egg=preprocess --upgrade
!ec
A much more advanced alternative to Preprocess is
"Mako": "http://www.makotemplates.org". Its installation is done by

!bc sys
pip install Mako
!ec
It is recommended to install both Preprocess and Mako.

# #ifdef EXTRA
This command requires `pip` to be installed. On Debian Linux systems,
such as Ubuntu, the installation is simply done by

!bc sys
sudo apt-get install python-pip
!ec
Alternatively, one can install from the `pip` "source code": "http://pypi.python.org/pypi/pip".
# #endif

Note that neither Preprocess nor Mako is run if you do not have
preprocessor directives in your DocOnce source. That is, you only need
this extra software if you make active use of preprocessors.

=== Bibliography ===

The Python package "Publish":
"https://bitbucket.org/logg/publish" is needed if you use a bibliography
in your document (`cite` commands and a `BIBFILE:` specification).
The installation is done by

!bc sys
pip install -e hg+https://bitbucket.org/logg/publish#egg=publish
!ec

=== Image file handling ===

Different output formats require different formats of image files.
For example, PDF or PNG is used for `pdflatex`,
PostScript for
`latex`, while HTML needs JPEG, GIF, or PNG formats.  DocOnce
calls up programs from the ImageMagick suite for converting image
files to a proper format if needed. The "ImageMagick suite":
"http://www.imagemagick.org/script/index.php" can be installed on all
major platforms.  On Debian Linux (including Ubuntu) systems one can
simply write

!bc sys
sudo apt-get install imagemagick
!ec

The convenience program `doconce combine_images`, for combining several
images into one, will use `montage` and `convert` from ImageMagick and
the `pdftk`, `pdfnup`, and `pdfcrop` programs from the `texlive-extra-utils`
Debian package. The latter gets installed by

!bc sys
sudo apt-get install texlive-extra-utils
!ec

Automatic image conversion from EPS to PDF calls up `epstopdf`, which
can be installed by

!bc sys
sudo apt-get install texlive-font-utils
!ec

=== Spellcheck ===

The utility `doconce spellcheck` applies the `ispell` program for
spellcheck. On Debian (including Ubuntu) it is installed by

!bc sys
sudo apt-get install ispell
!ec



=== Ptex2tex for LaTeX Output ===

Originally, DocOnce relied on the "ptex2tex": "http://code.google.com/p/ptex2tex" program for very flexible choice of typesetting of
verbatim code blocks. A simplified version, `doconce ptex2tex`, is bundled
with DocOnce. However, even greater flexibility is now offered by the
`--latex_code_style=` option to `doconce format` so unless you already are
a `ptex2tex` user, it is recommended to forget about `ptex2tex` and
just use the `--latex_code_style=` option.

The stand-alone `ptex2tex` program is installed by

!bc sys
svn checkout http://ptex2tex.googlecode.com/svn/trunk/ ptex2tex
cd ptex2tex
sudo python setup.py install
!ec
It may happen that you need additional style files, you can run
a script, `cp2texmf.sh`:

!bc sys
cd latex
sh cp2texmf.sh  # copy stylefiles to ~/texmf directory
cd ../..
!ec
This script copies some special stylefiles that
that `ptex2tex` potentially makes use of. Some more standard stylefiles
are also needed. These are installed by

!bc sys
sudo apt-get install texlive
!ec
on Debian Linux (including Ubuntu) systems. TeXShop on Mac comes with
the necessary stylefiles (if not, they can be found by googling and installed
manually in the `~/texmf/tex/latex/misc` directory).

Note that the `doconce ptex2tex` command, which needs no installation
beyond DocOnce itself, can be used as a simpler alternative to the `ptex2tex`
program.

=== Pygments and the Minted Code Style ===

The *minted* LaTeX style is
popular for typesetting code.
This style requires the package "Pygments": "http://pygments.org"
to be installed. On Debian Linux, the simplest approach is to
install `sphinx`:

!bc sys
pip install sphinx
!ec

All use of the minted style requires the `-shell-escape` command-line
argument when running LaTeX, i.e., `pdflatex -shell-escape`.

Inline comments apply the `todonotes` LaTeX package if the option
`--latex_todonotes` is given.  The `todonotes` package requires
several other packages: `xcolor`, `ifthen`, `xkeyval`, `tikz`, `calc`,
`graphicx`, and `setspace`. The relevant Debian packages for
installing all this are listed below.


=== LaTeX packages ===

Many LaTeX packages are potentially needed, depending on various
constructions in the text and command-line options used when compling DocOnce to
LaTeX. The
standard packages always required are `relsize`, `makeidx`,
`setspace`, `color`, `amsmath`, `amsfonts`, `xcolor`, `bm`,
`microtype`, `inputenc`, and `hyperref`.
Optional packages that might be included in the `.tex` output are `minted`,
`listings`, `fancyvrb`, `xunicode`, `inputenc`, `helvet`, `mathpazo`, `wrapfig`,
`calc`, `ifthen`, `xkeyval`, `tikz`, `graphicx`, `setspace`, `shadow`,
`disable`, `todonotes`, `lineno`, `xr`, `framed`, `mdframe`,
`movie15`, `a4paper`, and `a6paper`.

Relevant Debian packages that gives you all of these LaTeX packages are

!bc
texlive
texlive-extra-utils
texlive-latex-extra
texlive-font-utils
!ec
Alternatively, one may pull in `texlive-full` to get all available
style files.

If you want to use the *anslistings* code environment with `ptex2tex`
(`.ptex2tex.cfg` styles `Python_ANS`, `Python_ANSt`, `Cpp_ANS`, etc.) or
`doconce ptex2tex` (`envir=ans` or `envir=ans:nt`), you need the
`anslistings.sty` file. It can be obtained from
the "ptex2tex source": "https://code.google.com/p/ptex2tex/source/browse/trunk/latex/styles/with_license/anslistings.sty". The same code style is in
``modern DocOnce'' just implemented by the command-line option

!bc
"--latex_code_style=default:lst[style=yellow2_fb]"
!ec



=== Sphinx or reStructuredText Output ===

Output to `sphinx` or `rst` requires the
"Sphinx software": "http://sphinx.pocoo.org",
installed by

!bc sys
pip install sphinx --upgrade
!ec

DocOnce comes with many Sphinx themes that are not part of the
standard Sphinx source distribution:

 * cloud and redcloud: URL: "https://bitbucket.org/ecollins/cloud_sptheme"
 * bootstrap: URL: "https://github.com/ryan-roemer/sphinx-bootstrap-theme"
 * solarized: URL: "https://bitbucket.org/miiton/sphinxjp.themes.solarized"
 * impressjs: URL: "https://github.com/shkumagai/sphinxjp.themes.impressjs"
 * sagecellserver: URL: "https://github.com/kriskda/sphinx-sagecell"

Appropriate installation commands for these themes are

!bc sys
pip install -e hg+https://bitbucket.org/ecollins/cloud_sptheme#egg=cloud_sptheme
pip install -e git+https://github.com/ryan-roemer/sphinx-bootstrap-theme#egg=sphinx-bootstrap-theme
pip install -e hg+https://bitbucket.org/miiton/sphinxjp.themes.solarized#egg=sphinxjp.themes.solarized
pip install -e git+https://github.com/shkumagai/sphinxjp.themes.impressjs#egg=sphinxjp.themes.impressjs
pip install -e git+https://github.com/kriskda/sphinx-sagecell#egg=sphinx-sagecell
!ec

It can also be handy to have special typesetting of IPython sessions:

!bc sys
pip install -e git+https://bitbucket.org/hplbit/pygments-ipython-console#egg=pygments-ipython-console
!ec

To make OpenOffice or LibreOffice documents from `rst` output, you
will need more software, typically the following on a Debian system:

!bc sys
sudo apt-get install unoconv libreoffice libreoffice-dmaths
!ec

#There is a possibility to create PDF files from reST documents
#using ReportLab instead of LaTeX. The enabling software is
#"rst2pdf": "http://code.google.com/p/rst2pdf". Either download the tarball
#or clone the svn repository, go to the `rst2pdf` directory and
#run the usual `sudo python setup.py install`.

=== Markdown and Pandoc Output ===

The DocOnce format `pandoc` outputs the document in various Markdown
versions: the Pandoc
extended Markdown format (which via the `pandoc` program can be
translated to a range of other formats), strict Markdown, and
GitHub-flavored Markdown. Installation of "Pandoc":
"http://johnmacfarlane.net/pandoc/", written in Haskell, is most
easily done by

!bc sys
sudo apt-get install pandoc
!ec
on Debian (Ubuntu) systems.

=== Epydoc Output ===

When the output format is `epydoc` one needs that program too, installed
by
!bc sys
svn co https://epydoc.svn.sourceforge.net/svnroot/epydoc/trunk/epydoc epydoc
cd epydoc
sudo make install
cd ..
!ec

__Remark.__ Several of the packages above installed from source code
are also available in Debian-based system through the
`apt-get install` command. However, we recommend installation directly
from the version control system repository as there might be important
updates and bug fixes. For `svn` directories, go to the directory,
run `svn update`, and then `sudo python setup.py install`. For
Mercurial (`hg`) directories, go to the directory, run
`hg pull; hg update`, and then `sudo python setup.py install`.

=== Analyzing file differences ===

The `doconce diff file1 file prog` command for illustrating differences between
two files `file1` and `file2` using the program `prog` requires `prog`
to be installed. By default, `prog` is `difflib` which comes with Python
and is always present if you have DocOnce installed. Another choice, `diff`,
should be available on all Unix/Linux systems. Other choices, their
URL, and their `sudo apt-get install` command on Debian (Ubuntu) systems
appear in the table below.

|---------------------------------------------------------------------------|
| Program      | URL                      | Debian/Ubuntu install           |
|-------l--------------------l----------------------------l-----------------|
| `pdiff`      | "a2ps": "http://www.gnu.org/software/a2ps/" "wdiff": "http://www.gnu.org/software/wdiff/" | `sudo apt-get install a2ps wdiff texlive-latex-extra texlive-latex-recommended` |
| `latexdiff`  | "latexdiff": "http://www.ctan.org/pkg/latexdiff" | `sudo apt-get install latexdiff` |
| `kdiff3`     | "kdiff3": "http://kdiff3.sourceforge.net/" | `sudo apt-get install kdiff3` |
| `diffuse`    | "diffuse": "http://diffuse.sourceforge.net/" | `sudo apt-get install diffuse` |
| `xxdiff`     | "xxdiff": "http://xxdiff.sourceforge.net/local/" | `sudo apt-get install xxdiff` |
| `meld`       | "meld": "http://meldmerge.org/" | `sudo apt-get install meld` |
| `tkdiff.tcl` | "tkdiff": "https://sourceforge.net/projects/tkdiff/" | not in Debian |
|---------------------------------------------------------------------------|
