--- original
+++ modified
@@ -9,6 +9,7 @@
 # --------------------------
 #  - kwant.continuum.discretize
 
+import _defs
 
 import kwant
 import scipy.sparse.linalg
@@ -20,10 +21,19 @@
 from matplotlib import pyplot as plt
 
 
+def save_figure(file_name):
+    if not file_name:
+        return
+    for extension in ('pdf', 'png'):
+        plt.savefig('.'.join((file_name,extension)),
+                    dpi=_defs.dpi, bbox_inches='tight')
+
+
 def stadium_system(L=20, W=20):
     hamiltonian = "k_x**2 + k_y**2 + V(x, y)"
     template = kwant.continuum.discretize(hamiltonian)
-    print(template)
+    with open('discretizer_verbose.txt', 'w') as f:
+        print(template, file=f)
 
     def stadium(site):
         (x, y) = site.pos
@@ -44,7 +54,7 @@
     ham = syst.hamiltonian_submatrix(params=dict(V=potential), sparse=True)
     evecs = scipy.sparse.linalg.eigsh(ham, k=10, which='SM')[1]
     kwant.plotter.map(syst, abs(evecs[:, n])**2, show=False)
-    plt.show()
+    save_figure('discretizer_gs')
 
 
 def qsh_system(a=20, L=2000, W=1000):
@@ -91,7 +101,8 @@
     plt.ylim(-0.05, 0.05)
     plt.xlabel('momentum [1/A]')
     plt.ylabel('energy [eV]')
-    plt.show()
+    save_figure('discretizer_qsh_band')
+
     # get scattering wave functions at E=0
     wf = kwant.wave_function(syst, energy=0, params=params)
 
@@ -119,7 +130,7 @@
 
     ax1.set_title('Probability density')
     ax2.set_title('Spin density')
-    plt.show()
+    save_figure('discretizer_qsh_wf')
 
 
 def lattice_spacing():
@@ -160,7 +171,7 @@
 
     plot(ax1, a=1)
     plot(ax2, a=.25)
-    plt.show()
+    save_figure('discretizer_lattice_spacing')
 
 
 def substitutions():
@@ -173,15 +184,18 @@
         sympify('k_x**2 * sz + alpha * k_x * sx', locals=subs),
     )
 
-    print(e[0] == e[1] == e[2])
+    with open('discretizer_subs_1.txt', 'w') as f:
+        print(e[0] == e[1] == e[2], file=f)
 
     subs = {'A': 'A(x) + B', 'V': 'V(x) + V_0', 'C': 5}
-    print(sympify('k_x * A * k_x + V + C', locals=subs))
+    with open('discretizer_subs_2.txt', 'w') as f:
+        print(sympify('k_x * A * k_x + V + C', locals=subs), file=f)
 
 
 def main():
     template = kwant.continuum.discretize('k_x * A(x) * k_x')
-    print(template)
+    with open('discretizer_intro_verbose.txt', 'w') as f:
+        print(template, file=f)
 
     syst = stadium_system()
     plot_eigenstate(syst)
