From d4b887eb01c2e8ff2cd9c5df3a3e627f7a555993 Mon Sep 17 00:00:00 2001
From: Anton Akhmerov <anton.akhmerov@gmail.com>
Date: Sun, 16 Feb 2020 14:05:43 +0100
Subject: [PATCH] switch to jupytext for markdown parsing, closes #74

---
 execute.py                                     |  9 +++------
 extra_markdown.tpl                             | 17 ++++-------------
 requirements.txt                               |  2 +-
 src/11_nearly_free_electron_model.md           |  6 +++---
 src/12_band_structures_in_higher_dimensions.md |  2 +-
 src/13_semiconductors.md                       |  2 +-
 src/1_einstein_model.md                        |  6 +++---
 src/2_debye_model.md                           |  2 +-
 src/3_drude_model.md                           |  2 +-
 src/4_sommerfeld_model.md                      |  2 +-
 src/5_atoms_and_lcao.md                        |  2 +-
 src/6_bonds_and_spectra.md                     |  2 +-
 src/7_tight_binding.md                         |  2 +-
 src/8_many_atoms.md                            |  2 +-
 src/9_crystal_structure.md                     |  2 +-
 src/lecture_8.md                               |  2 +-
 16 files changed, 25 insertions(+), 37 deletions(-)

diff --git a/execute.py b/execute.py
index bb7f4f43..62faa527 100644
--- a/execute.py
+++ b/execute.py
@@ -3,14 +3,11 @@ import shutil
 import mimetypes
 
 import nbconvert
-import notedown
+from jupytext import read
 from traitlets.config import Config
 
 from nbconvert_fix import ExtractOutputPreprocessor
 
-
-reader = notedown.MarkdownReader(code_regex='fenced')
-
 mimetypes.add_type('application/vnd.plotly.v1+json', '.json')
 
 src = Path('src')
@@ -56,8 +53,8 @@ exporter = nbconvert.MarkdownExporter(
 writer = nbconvert.writers.FilesWriter(build_directory=str(target))
 
 for source_file in src.glob('*.md'):
-    fname = source_file.name[:-len('.md')]
-    notebook = reader.reads(source_file.read_text())
+    fname = source_file.stem
+    notebook = read(source_file)
 
     output, resources = exporter.from_notebook_node(
         notebook,
diff --git a/extra_markdown.tpl b/extra_markdown.tpl
index 8bf79caa..63f2c704 100644
--- a/extra_markdown.tpl
+++ b/extra_markdown.tpl
@@ -1,34 +1,25 @@
 {% extends 'markdown.tpl' %}
 
 {% block input %}
-{% if cell.metadata.attributes and cell.metadata.attributes.initialize %}
+{% if "initialize" in cell.metadata.tags %}
 <div class="thebelab-init-code">
   <pre class="thebelab-code" data-executable="true" data-language="python">
     {{cell.source}}
   </pre>
 </div>
+{% else %}
+<pre class="thebelab-code" data-executable="true" data-language="python">{{cell.source}}</pre>
 {% endif %}
 {% endblock %}
 
 {% block display_data %}
-{% if cell.metadata.attributes and cell.metadata.attributes.editable == 'false' and not cell.metadata.attributes.initialize %}
-{{ super() }}
-{% elif cell.metadata.attributes and cell.metadata.attributes.initialize %}
-{% if output.data['text/html'] %}
-<div>
-  {{ output.data['text/html'] }}
-</div>
-{% endif %}
-{% else %}
-<pre class="thebelab-code" data-executable="true" data-language="python">{{cell.source}}</pre>
-<div class="thebelab-output" data-output="true" markdown="1">
+<div class="thebelab-output" data-output="true">
 {% if output.data['text/html'] %}
 {{ output.data['text/html'] }}
 {% else %}
 {{ super() }}
 {% endif %}
 </div>
-{% endif %}
 {% endblock %}
 
 {% block error %}
diff --git a/requirements.txt b/requirements.txt
index e7ff3639..57fe229c 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -8,6 +8,6 @@ matplotlib
 scipy
 wikitables
 pandas
-notedown
+jupytext
 python-markdown-math
 mkdocs-material
diff --git a/src/11_nearly_free_electron_model.md b/src/11_nearly_free_electron_model.md
index 56fe3ab6..4fd9cc84 100644
--- a/src/11_nearly_free_electron_model.md
+++ b/src/11_nearly_free_electron_model.md
@@ -1,4 +1,4 @@
-```{python initialize=true}
+```python tags=["initialize"]
 import numpy as np
 import plotly.offline as py
 import plotly.graph_objs as go
@@ -169,7 +169,7 @@ Let's consider a 1D crystal with a period $a$. Let $k_0$ be any wave number of a
         - Apply $\left<\phi_m\right|$ to the Schrödinger equation.
         - To evaluate $\left<\phi_m\right| \hat{H} \left| \phi_n\right>$, it may be helpful to separate the kinetic energy and potential energy of the Hamiltonian.
 
-5. Why is the dispersion relation only affected near $k=0$ and at the edge of the Brillouin zone (see also figures [above](#repeated-vs-reduced-vs-extended-brillouin-zone))? 
+5. Why is the dispersion relation only affected near $k=0$ and at the edge of the Brillouin zone (see also figures [above](#repeated-vs-reduced-vs-extended-brillouin-zone))?
 
     ??? hint
         To answer this question, only consider consider two free electron wavefunctions in the Hamiltonian and ignore all the others. Between what two of free electron wavefunctions does the coupling give significant contribution to the energy levels of the free electron wavefunctions?
@@ -190,4 +190,4 @@ Consider a 1D crystal with a periodic potential given by delta peaks: $$V(x) = -
 2. Make a sketch of the lower band.
 3. We now use the tight binding model, where we know that the dispersion relation can be described by $$E = \varepsilon_0 - 2 t \cos (ka).$$ Find an expression for $\varepsilon_0=\left<n\right| \hat{H} \left|n\right>$ and $-t=\left<n-1\right| \hat{H} \left| n \right>$, where $\left<x|n\right>$ represent the wavefunction of a single delta peak well at site $n$. You may make use of the results obtained in [exercise 2 of lecture 5](/5_atoms_and_lcao/#exercise-2-application-of-the-lcao-model) or [look up the wavefunction](https://en.wikipedia.org/wiki/Delta_potential).
 4. Compare the bands obtained in exercise 1 and 2: what are the minima and bandwidths (difference between maximum and minimum) of those bands?
-5. For what $a$ and $\lambda$ is the nearly free electron model more accurate? And for what $a$ and $\lambda$ is the tight binding model more accurate?
\ No newline at end of file
+5. For what $a$ and $\lambda$ is the nearly free electron model more accurate? And for what $a$ and $\lambda$ is the tight binding model more accurate?
diff --git a/src/12_band_structures_in_higher_dimensions.md b/src/12_band_structures_in_higher_dimensions.md
index 754e879a..e665d29d 100644
--- a/src/12_band_structures_in_higher_dimensions.md
+++ b/src/12_band_structures_in_higher_dimensions.md
@@ -1,4 +1,4 @@
-```{python initialize=true}
+```python tags=["initialize"]
 import numpy as np
 import plotly.offline as py
 import plotly.graph_objs as go
diff --git a/src/13_semiconductors.md b/src/13_semiconductors.md
index c17563c7..61708cc4 100644
--- a/src/13_semiconductors.md
+++ b/src/13_semiconductors.md
@@ -1,4 +1,4 @@
-```{python initialize=true}
+```python tags=["initialize"]
  
 from matplotlib import pyplot
 
diff --git a/src/1_einstein_model.md b/src/1_einstein_model.md
index 6e57a127..b012dbdd 100644
--- a/src/1_einstein_model.md
+++ b/src/1_einstein_model.md
@@ -12,7 +12,7 @@ jupyter:
     name: python3
 ---
 
-```{python initialize=true}
+```python tags=["initialize"]
 import pandas
 
 from matplotlib import pyplot
@@ -38,7 +38,7 @@ _(based on chapter 2.1 of the book)_
 
     - Write down the energy spectrum and partition function of a quantum harmonic oscillator
     - Describe the equipartition theory
-    - Write down the Bose-Einstein distribution 
+    - Write down the Bose-Einstein distribution
 
 
 !!! summary "Learning goals"
@@ -235,7 +235,7 @@ $$
 \langle E \rangle=\frac{1}{2}\hbar\omega_0+\frac{\hbar\omega_0}{ {\rm e}^{\hbar\omega_0/k_{\rm B}T}-1}
 $$
 
-The left plot below shows the Bose-Einstein distribution vs energy. We see that low-energy states are more likely to be occupied than high-energy states. The right plot shows the increasing thermal energy in the oscillator for increasing temperature and highlights the zero-point energy $\hbar\omega_0/2$ that remains in the oscillator at $T=0$ (a consequence of the uncertainty principle). Moreover, we see that the energy in the oscillator becomes approximately constant when $k_{\rm B}T\ll\hbar \omega_0$. This implies that the heat capacity becomes small when $k_{\rm B}T<\hbar \omega_0$ and goes to zero when $T\rightarrow0$. 
+The left plot below shows the Bose-Einstein distribution vs energy. We see that low-energy states are more likely to be occupied than high-energy states. The right plot shows the increasing thermal energy in the oscillator for increasing temperature and highlights the zero-point energy $\hbar\omega_0/2$ that remains in the oscillator at $T=0$ (a consequence of the uncertainty principle). Moreover, we see that the energy in the oscillator becomes approximately constant when $k_{\rm B}T\ll\hbar \omega_0$. This implies that the heat capacity becomes small when $k_{\rm B}T<\hbar \omega_0$ and goes to zero when $T\rightarrow0$.
 
 ```python
 xline = [1, 1];
diff --git a/src/2_debye_model.md b/src/2_debye_model.md
index 9a83e816..23f0583c 100644
--- a/src/2_debye_model.md
+++ b/src/2_debye_model.md
@@ -12,7 +12,7 @@ jupyter:
     name: python3
 ---
 
-```{python initialize=true}
+```python tags=["initialize"]
 from matplotlib import pyplot
 from mpl_toolkits.axes_grid1 import make_axes_locatable
 
diff --git a/src/3_drude_model.md b/src/3_drude_model.md
index 02cd6a08..3da34bdb 100644
--- a/src/3_drude_model.md
+++ b/src/3_drude_model.md
@@ -1,4 +1,4 @@
-```{python initialize=true}
+```python tags=["initialize"]
 from matplotlib import pyplot
 
 import numpy as np
diff --git a/src/4_sommerfeld_model.md b/src/4_sommerfeld_model.md
index e680c7e5..3be17938 100644
--- a/src/4_sommerfeld_model.md
+++ b/src/4_sommerfeld_model.md
@@ -1,4 +1,4 @@
-```{python initialize=true}
+```python tags=["initialize"]
 from matplotlib import pyplot
 
 import numpy as np
diff --git a/src/5_atoms_and_lcao.md b/src/5_atoms_and_lcao.md
index e0b22957..24beb569 100644
--- a/src/5_atoms_and_lcao.md
+++ b/src/5_atoms_and_lcao.md
@@ -1,4 +1,4 @@
-```{python initialize=true}
+```python tags=["initialize"]
 from matplotlib import pyplot
 
 import numpy as np
diff --git a/src/6_bonds_and_spectra.md b/src/6_bonds_and_spectra.md
index f5cc05d8..3068244e 100644
--- a/src/6_bonds_and_spectra.md
+++ b/src/6_bonds_and_spectra.md
@@ -1,4 +1,4 @@
-```{python initialize=true}
+```python tags=["initialize"]
 from matplotlib import pyplot
 
 import numpy as np
diff --git a/src/7_tight_binding.md b/src/7_tight_binding.md
index dff34807..a8c96b48 100644
--- a/src/7_tight_binding.md
+++ b/src/7_tight_binding.md
@@ -1,4 +1,4 @@
-```{python initialize=true}
+```python tags=["initialize"]
 import matplotlib
 from matplotlib import pyplot
 
diff --git a/src/8_many_atoms.md b/src/8_many_atoms.md
index 3c589165..9869dff1 100644
--- a/src/8_many_atoms.md
+++ b/src/8_many_atoms.md
@@ -1,4 +1,4 @@
-```{python initialize=true}
+```python tags=["initialize"]
 import matplotlib
 from matplotlib import pyplot
 
diff --git a/src/9_crystal_structure.md b/src/9_crystal_structure.md
index d345c654..a78bb7f9 100644
--- a/src/9_crystal_structure.md
+++ b/src/9_crystal_structure.md
@@ -12,7 +12,7 @@ jupyter:
     name: python3
 ---
 
-```{python initialize=true}
+```python tags=["initialize"]
 import matplotlib.pyplot as plt
 
 import numpy as np
diff --git a/src/lecture_8.md b/src/lecture_8.md
index a3717429..289bb380 100644
--- a/src/lecture_8.md
+++ b/src/lecture_8.md
@@ -1,4 +1,4 @@
-```{python initialize=true}
+```python tags=["initialize"]
 from matplotlib import pyplot
 
 import numpy as np
-- 
GitLab