<%doc>
This is a test on Doconce.
The Mako preprocessor is used.
</%doc>

TITLE: A Test Document
AUTHOR: Hans Petter Langtangen Email: hpl@simula.no at Center for Biomedical Computing, Simula Research Laboratory and Department of Informatics, University of Oslo
AUTHOR: Kaare Dump at Segfault Inc, Cyberspace
AUTHOR: A. Dummy Author
AUTHOR: I. S. Overworked at Inst1 and Inst2, Somewhere and Third Inst, Elsewhere and Fourth Inst
AUTHOR: J. Doe mail: j_doe@cyberspace.com
# latex demands DATE
DATE: today

The format of this document is
% if FORMAT == 'html':
plain, homemade HTML (from Doconce).
  % elif FORMAT == 'latex':
plain, homemade LaTeX (from Doconce).
  % elif FORMAT == 'pdflatex':
plain, homemade pdfLaTeX (from Doconce).
  %else:
${FORMAT}
% endif


__Abstract.__
This is a document with many test constructions for doconce syntax.
It was used heavily for the development and kept for testing
numerous constructions, also special and less common cases.

And exactly for test purposes we have an extra line here, which
is part of the abstract.

========= Chapter 1 =========

======= Section 0 =======

======= Section 1 =======
label{sec1}

Just a little bit of text
and then a list:

  * item1
  * item2
  * item3 which continues
    on the next line to test that feature
  * and a sublist
    * with indented subitem1
    * and a subitem2
  * and perhaps an ordered sublist
    o first item
    o second item,
      continuing on a new line

===== Subsection 1 =====

More text, with a reference back to Section ref{sec1} and further
to Section ref{subsubsec:ex}. idx{`somefunc` function}

Let's do some copying from files too. First from subroutine up to the very end,

@@@CODE ../doc/manual/__testcode.f fromto: subroutine@
and then just the subroutine,
@@@CODE ../doc/manual/__testcode.f from-to:a comment@^C\s+END1
and finally the complete file:
@@@CODE ../doc/manual/__testcode.f

===== Subsection 2 =====
label{subsec:ex}
idx{figures}

Test of figures.

FIGURE:[../doc/manual/figs/streamtubes, width=200] Visualization of flow by streamtubes. label{fig:impact}

idx{movies}
Test of movies.

MOVIE: [../doc/manual/figs/mjolnir.mpeg, width=700 height=400] Mjolnir tsunami (by Sylfest Glimsdal).

# Empty caption:

MOVIE: [../doc/manual/figs/wavepacket.mpeg, width=700 height=400]

MOVIE: [../doc/manual/figs/wavepacket_*.png, width=700 height=400] Movie based on collection of frames (here just a few frames compared with the full wavepacket.mpeg movie).

# Check out the correct with and height of YouTube movies from the
# embed command that the YouTube page can generate

MOVIE: http://www.youtube.com/watch?v=_O7iUiftbKU, width=420 height=315] Movies can be uploaded to YouTube and embedded as HTML or as a link.

===== Table Demo =====
label{subsec:table}

Let us take this table from the manual:
idx{some `class X` which is convenient}

% if FORMAT == "latex":
\begin{table}
\caption{
Table of velocity and acceleration.
label{mytab}
}
% endif

  |--------------------------------|
  |time  | velocity | acceleration |
  |--l--------r-----------r--------|
  | 0.0  | 1.4186   | -5.01        |
  | 2.0  | 1.376512 | 11.919       |
  | 4.0  | 1.1E+1   | 14.717624    |
  |--------------------------------|

% if FORMAT == "latex":
\end{table}
% endif

The Doconce source code reads
!bc cod
  |--------------------------------|
  |time  | velocity | acceleration |
  |--l--------r-----------r--------|
  | 0.0  | 1.4186   | -5.01        |
  | 2.0  | 1.376512 | 11.919       |
  | 4.0  | 1.1E+1   | 14.717624    |
  |--------------------------------|
!ec

Here is yet another table to test that we can handle more than
one table:

  |--l-------l----------l----------|
  |time  | velocity | acceleration |
  |--l-------l----------l----------|
  | 0.0  | 1.4186   | -5.01        |
  | 1.0  | 1.376512 | 11.919       |
  | 3.0  | 1.1E+1   | 14.717624    |
  |--------------------------------|

===== URLs ======
label{subsubsec:ex}

Here are some nice URLs, e.g., hpl's home page "hpl":"http://folk.uio.no/hpl",
or the URL if desired, "URL": "http://folk.uio.no/hpl".
Here is a plain file link "URL": "testdoc.do.txt", or "url":"testdoc.do.txt",
or URL: "testdoc.do.txt" or url : "testdoc.do.txt" or "a link
with newline": "testdoc.do.txt". Can test spaces
with the link with word too: "hpl": "http://folk.uio.no/hpl" or
"hpl" : "http://folk.uio.no/hpl". The old syntax must also be
tested: http://folk.uio.no/hpl<hpl's homepage>. Now also `file:///`
works: "link to a file":"file:///home/hpl/vc/doconce/trunk/test/tmp_HTML.html"
is fine to have.

# Comments should be inserted outside paragraphs (because of reST):
# note that when there is no http: or file:, it can be a file link
# if the link name is URL, url, "URL", or "url".

% if FORMAT == "latex":

===== Some LaTeX Constructs =====

Let's check abbr. of some common kind, e.g. the well-known i.e.
7-9 as an example. Moreover, Dr. Tang and Prof. Monsen,
or maybe also prof. Ting,
will go to the Dept. of Science to test how Mr. Hansen is doing together
with Ms. Larsen. A sentence containing "refines lines" could easily
fool a regex substitution with only i.e. since the dot matches anything.
Also, look at Fig. 4 to see how the data compares with Tab. ref{mytab}.
% endif

===== LaTeX Mathematics =====

Here is an equation without label using backslash-bracket environment:
!bt
\[ a = b + c \]
!et
or with number and label, as in (ref{my:eq1}), using the equation environment:
!bt
\begin{equation}
{\partial u\over\partial t} = \nabla^2 u label{my:eq1}
\end{equation}
!et
We can refer to this equation by (ref{my:eq1}).

Here is a system without equation numbers, using the align-astrisk environment:
!bt
\begin{align*}
\pmb{a} &= \pmb{q}\times\pmb{n} \\
b &= \nabla^2 u + \nabla^4 v
\end{align*}
!et


% if FORMAT in ('latex', 'pdflatex', 'sphinx', 'html', 'pandoc'):
And here is a system of equations with labels in an align environment:
!bt
\begin{align}
a &= q + 4 + 5+ 6 label{eq1} \\
b &= \nabla^2 u + \nabla^4 x label{eq2}
\end{align}
!et
We can refer to (ref{eq1})-(ref{eq2}).

Or with multline?
!bt
\begin{multline}
a = b = q + \\
  f + \nabla\cdot\nabla u
label{multiline:eq1}
\end{multline}
!et
Maybe split is better:
!bt
\begin{equation}
label{split:envir:eq}
\begin{split}
a = b = q &+ \\
  & f + \nabla\cdot\nabla u
\end{split}
\end{equation}
!et
And we can refer to the last equation by (ref{split:envir:eq}).

What about gather?
!bt
\begin{gather}
a = b \\
c = d + 7 + 9
\end{gather}
!et

And what about alignat?
!bt
\begin{alignat}{2}
a &= q + 4 + 5+ 6\qquad & \mbox{for } q\geq 0 label{eq1a} \\
b &= \nabla^2 u + \nabla^4 x & x\in\Omega label{eq2a}
\end{alignat}
!et
Let us refer to (ref{eq1})-(ref{eq2}) again, and to the
alignat variant (ref{eq1a})-(ref{eq2a}), and to (ref{my:eq1}).

Here is eqnarray in action:
!bt
\begin{eqnarray}
{\partial u\over\partial t} &=& \nabla^2 u + f, label{myeq1}\\
{\partial v\over\partial t} &=& \nabla\cdot(q(u)\nabla v) + g label{myeq2}
\end{eqnarray}
!et
% endif

More mathematical typesetting is demonstrated in the exercises below.

======= Exercises =======

===== Problem: Flip a Coin =====
label{demo:ex:1}
file = flip_coin.py
solution = mysol.txt

Make a program that simulates flipping a coin $N$ times.
Print out "tail" or "head" for each flip and
let the program count the number of heads.


__Hint 1.__ Use `r = random.random()` and define head as `r <= 0.5`.

__Hint 2.__ Draw an integer among $\{1,2\}$ with
`r = random.randint(1,2)` and define head when `r` is 1.


===== Exercise: Compute a Probability =====

label{demo:ex:2}  solution =/my/home/hpl/sol/file1.txt

What is the probability of getting a number between 0.5 and 0.6 when
drawing uniformly distributed random numbers from the interval $[0,1)$?
To answer this question empirically, let a program
draw $N$ such random numbers using Python's standard `random` module,
count how many of them, $M$, that fall in the interval $(0.5,0.6)$, and
compute the probability as $M/N$. Run the program with the four
values $N=10^i$ for $i=1,2,3,6$.

===== Project: Explore Distributions of Random Circles =====

label{proj:circle1}
file=circles.pdf

The formula for a circle is given by
!bt
\begin{align}
x &= x_0 + R\cos 2\pi t,\\
y &= y_0 + R\sin 2\pi t,
\end{align}
!et
where $R$ is the radius of the circle, $(x_0,y_0)$ is the
center point, and $t$ is a parameter in the unit interval $[0,1]$.
For any $t$, $(x,y)$ is a point on the circle.
The formula can be used to generate `n` points on a circle:
!bc pycod
import numpy as np

def circle(R, x0, y0, n=501):
    t = np.linspace(0, 1, n)
    x = x0 + R*np.cos(2*np.pi*t)
    y = y0 + R*np.sin(2*np.pi*t)
    return x, y
!ec

# Often in an exercise we have some comments about the solution
# which we normally want to migrate to the end.

The goal of this project is to draw $N$ circles with random
center and radius. Plot each circle using the `circle` function
above. The following cases should be explored:

 * $R$ normally distributed and $(x_0,y_0)$ uniformly distributed
 * $R$ uniformly distributed and $(x_0,y_0)$ normally distributed
 * $R$ and $(x_0,y_0)$ normally distributed

__Hint.__ Use the `numpy.random` module to draw the
$x_0$, $y_0$, and $R$ quantities.


