From b032b681c703368b848c367efd20260e7df5d8fd Mon Sep 17 00:00:00 2001
From: Christoph Groth <christoph.groth@cea.fr>
Date: Thu, 29 Aug 2013 10:39:53 +0200
Subject: [PATCH] docs can be built now without installing kwant (useful i.a.
 for the debian package)

---
 INSTALL                                       | 23 +++++++++++--------
 doc/source/conf.py                            |  4 ++++
 doc/source/images/_defs.py                    | 11 +++++++++
 doc/source/images/ab_ring.py.diff             | 10 ++++----
 doc/source/images/band_structure.py.diff      | 10 ++++----
 doc/source/images/closed_system.py.diff       | 12 +++++-----
 doc/source/images/graphene.py.diff            | 10 ++++----
 doc/source/images/quantum_well.py.diff        | 10 ++++----
 doc/source/images/quantum_wire.py.diff        |  8 +++----
 doc/source/images/spin_orbit.py.diff          | 10 ++++----
 .../superconductor_band_structure.py.diff     | 10 ++++----
 .../images/superconductor_transport.py.diff   | 10 ++++----
 12 files changed, 73 insertions(+), 55 deletions(-)

diff --git a/INSTALL b/INSTALL
index b2e4124c..215c85e2 100644
--- a/INSTALL
+++ b/INSTALL
@@ -468,19 +468,22 @@ Python's configparser module
 Building the documentation
 ==========================
 
-To build the documentation, Kwant has to be installed as described above.
-Additionally, the `Sphinx documentation generator <http://sphinx.pocoo.org/>`_
-is required.  If PDF documentation is to be built, the tools from the `libRSVG
-<http://live.gnome.org/LibRsvg>`_ (Debian/Ubuntu package ``librsvg2-bin``) are
-needed to convert SVG drawings into the PDF format.
-
-HTML documentation is built by entering the ``doc`` subdirectory of the
-Kwant package and executing ``make html``.  PDF documentation is generated by
-executing ``make latex`` followed by a ``make all-pdf`` in ``doc/build/latex``.
+To build the documentation, the `Sphinx documentation generator
+<http://sphinx.pocoo.org/>`_ is required.  If PDF documentation is to be built,
+the tools from the `libRSVG <http://live.gnome.org/LibRsvg>`_ (Debian/Ubuntu
+package ``librsvg2-bin``) are needed to convert SVG drawings into the PDF
+format.
+
+As a prerequisite for building the documentation, Kwant must have been built
+successfully using ``./setup.py build`` as described above (or Kwant must be
+already installed in Python's search path).  HTML documentation is built by
+entering the ``doc`` subdirectory of the Kwant package and executing ``make
+html``.  PDF documentation is generated by executing ``make latex`` followed by
+``make all-pdf`` in ``doc/build/latex``.
 
 Because of some quirks of how Sphinx works, it might be necessary to execute
 ``make clean`` between building HTML and PDF documentation.  If this is not
-done, Sphinx might mistakenly use PNG files for PDF output or other problems may
+done, Sphinx may mistakenly use PNG files for PDF output or other problems may
 appear.
 
 
diff --git a/doc/source/conf.py b/doc/source/conf.py
index 87a93c1c..f4077fce 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -12,6 +12,10 @@
 # serve to show the default.
 
 import sys, os
+
+from distutils.util import get_platform
+sys.path.insert(0, "../../build/lib.{0}-{1}.{2}".format(
+        get_platform(), *sys.version_info[:2]))
 import kwant
 
 # -- General configuration -----------------------------------------------------
diff --git a/doc/source/images/_defs.py b/doc/source/images/_defs.py
index e01fa4f5..dabed078 100644
--- a/doc/source/images/_defs.py
+++ b/doc/source/images/_defs.py
@@ -1,3 +1,14 @@
+################################################################
+# Prepend Kwant's build directory to sys.path
+################################################################
+import sys
+from distutils.util import get_platform
+sys.path.insert(0, "../../../build/lib.{0}-{1}.{2}".format(
+        get_platform(), *sys.version_info[:2]))
+
+################################################################
+# Define constants for plotting
+################################################################
 pt_to_in = 1. / 72.
 
 # Default width of figures in pts
diff --git a/doc/source/images/ab_ring.py.diff b/doc/source/images/ab_ring.py.diff
index ce73ce4a..4793b772 100644
--- a/doc/source/images/ab_ring.py.diff
+++ b/doc/source/images/ab_ring.py.diff
@@ -1,13 +1,13 @@
 --- original
 +++ modified
-@@ -16,6 +16,7 @@
+@@ -9,6 +9,7 @@
+ #    example, but in the tutorial main text)
+ #  - Modifcations of hoppings/sites after they have been added
  
- # For plotting
- from matplotlib import pyplot
 +import _defs
+ from cmath import exp
+ from math import pi
  
- 
- def make_system(a=1, t=1.0, W=10, r1=10, r2=20):
 @@ -37,12 +38,13 @@
      sys[lat.shape(ring, (0, r1 + 1))] = 4 * t
      sys[lat.neighbors()] = -t
diff --git a/doc/source/images/band_structure.py.diff b/doc/source/images/band_structure.py.diff
index 2fceecb0..1a848e85 100644
--- a/doc/source/images/band_structure.py.diff
+++ b/doc/source/images/band_structure.py.diff
@@ -1,13 +1,13 @@
 --- original
 +++ modified
-@@ -10,6 +10,7 @@
+@@ -6,6 +6,7 @@
+ # --------------------------
+ #  - Computing the band structure of a finalized lead.
  
- # For plotting.
- from matplotlib import pyplot
 +import _defs
+ import kwant
  
- def make_lead(a=1, t=1.0, W=10):
-     # Start with an empty lead with a single square lattice
+ # For plotting.
 @@ -33,10 +34,19 @@
  
  def main():
diff --git a/doc/source/images/closed_system.py.diff b/doc/source/images/closed_system.py.diff
index 693d44a5..9b3c0dc0 100644
--- a/doc/source/images/closed_system.py.diff
+++ b/doc/source/images/closed_system.py.diff
@@ -1,13 +1,13 @@
 --- original
 +++ modified
-@@ -17,6 +17,7 @@
+@@ -8,6 +8,7 @@
+ #  - Use of `hamiltonian_submatrix` in order to obtain a Hamiltonian
+ #    matrix.
  
- # For plotting
- from matplotlib import pyplot
 +import _defs
- 
- 
- def make_system(a=1, t=1.0, r=10):
+ from cmath import exp
+ import numpy as np
+ import kwant
 @@ -65,29 +66,39 @@
  
          energies.append(ev)
diff --git a/doc/source/images/graphene.py.diff b/doc/source/images/graphene.py.diff
index 741576cd..0ed96e47 100644
--- a/doc/source/images/graphene.py.diff
+++ b/doc/source/images/graphene.py.diff
@@ -1,13 +1,13 @@
 --- original
 +++ modified
-@@ -17,6 +17,7 @@
+@@ -8,6 +8,7 @@
+ #    lattice, namely graphene
  
- # For plotting
- from matplotlib import pyplot
+ from __future__ import division  # so that 1/2 == 0.5, and not 0
 +import _defs
+ from math import pi, sqrt, tanh
  
- 
- # Define the graphene lattice
+ import kwant
 @@ -100,22 +101,40 @@
          smatrix = kwant.smatrix(sys, energy)
          data.append(smatrix.transmission(0, 1))
diff --git a/doc/source/images/quantum_well.py.diff b/doc/source/images/quantum_well.py.diff
index c1bcd61b..0d6c0fa7 100644
--- a/doc/source/images/quantum_well.py.diff
+++ b/doc/source/images/quantum_well.py.diff
@@ -1,13 +1,13 @@
 --- original
 +++ modified
-@@ -10,6 +10,7 @@
+@@ -6,6 +6,7 @@
+ # --------------------------
+ #  - Functions as values in Builder
  
- # For plotting
- from matplotlib import pyplot
 +import _defs
+ import kwant
  
- 
- def make_system(a=1, t=1.0, W=10, L=30, L_well=10):
+ # For plotting
 @@ -52,19 +53,25 @@
          smatrix = kwant.smatrix(sys, energy, args=[-welldepth])
          data.append(smatrix.transmission(1, 0))
diff --git a/doc/source/images/quantum_wire.py.diff b/doc/source/images/quantum_wire.py.diff
index 21dce730..a4ac0f71 100644
--- a/doc/source/images/quantum_wire.py.diff
+++ b/doc/source/images/quantum_wire.py.diff
@@ -1,12 +1,12 @@
 --- original
 +++ modified
-@@ -10,6 +10,7 @@
+@@ -8,6 +8,7 @@
+ #  - Making scattering region and leads
+ #  - Using the simple sparse solver for computing Landauer conductance
  
++import _defs
  from matplotlib import pyplot
  import kwant
-+import _defs
- 
- # First, define the tight-binding system
  
 @@ -65,7 +66,10 @@
  sys.attach_lead(right_lead)
diff --git a/doc/source/images/spin_orbit.py.diff b/doc/source/images/spin_orbit.py.diff
index 5f737a9d..14b9d53b 100644
--- a/doc/source/images/spin_orbit.py.diff
+++ b/doc/source/images/spin_orbit.py.diff
@@ -1,13 +1,13 @@
 --- original
 +++ modified
-@@ -17,6 +17,7 @@
+@@ -10,6 +10,7 @@
+ # --------------------------
+ #  - Numpy matrices as values in Builder
  
- # For matrix support
- import tinyarray
 +import _defs
+ import kwant
  
- # define Pauli-matrices for convenience
- sigma_0 = tinyarray.array([[1, 0], [0, 1]])
+ # For plotting
 @@ -67,19 +68,24 @@
          smatrix = kwant.smatrix(sys, energy)
          data.append(smatrix.transmission(1, 0))
diff --git a/doc/source/images/superconductor_band_structure.py.diff b/doc/source/images/superconductor_band_structure.py.diff
index 5271aa49..5fac2e20 100644
--- a/doc/source/images/superconductor_band_structure.py.diff
+++ b/doc/source/images/superconductor_band_structure.py.diff
@@ -1,13 +1,13 @@
 --- original
 +++ modified
-@@ -17,6 +17,7 @@
+@@ -10,6 +10,7 @@
+ #  - Main motivation is to contrast to the implementation of superconductivity
+ #    in tutorial5b.py
  
- # For plotting
- from matplotlib import pyplot
 +import _defs
+ import kwant
  
- tau_x = tinyarray.array([[0, 1], [1, 0]])
- tau_z = tinyarray.array([[1, 0], [0, -1]])
+ import numpy as np
 @@ -46,11 +47,20 @@
      # Make system and finalize it right away.
      lead = make_lead().finalized()
diff --git a/doc/source/images/superconductor_transport.py.diff b/doc/source/images/superconductor_transport.py.diff
index 947651df..3fd835a3 100644
--- a/doc/source/images/superconductor_transport.py.diff
+++ b/doc/source/images/superconductor_transport.py.diff
@@ -1,13 +1,13 @@
 --- original
 +++ modified
-@@ -11,6 +11,7 @@
+@@ -7,6 +7,7 @@
+ # - Implementing electron and hole ("orbital") degrees of freedom
+ #   using different lattices
  
- # For plotting
- from matplotlib import pyplot
 +import _defs
+ import kwant
  
- 
- def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4),
+ # For plotting
 @@ -82,19 +83,24 @@
                      smatrix.transmission(0, 0) +
                      smatrix.transmission(1, 0))
-- 
GitLab