Compile this document with
doconce format execute.do.txt --execute
Hidden execution cells can be used to perform operations that need to be done before the following cells are executed:
import os
os.listdir(".")
a = 1
e = 0
f = 3
This is a cell that should execute automatically:
b = 2
c = a + b
print("The result is {}".format(c))
c
This is a cell that should plot and output:
from pylab import *
x = linspace(0, 10, 100)
plot(x, x*x)
show()
To improve quality when exporting to LaTeX, the following code has automatically been run to enable PDF export in notebooks.
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('png', 'pdf')
Predefined output can be omitted by passing --ignore_output
to DocOnce.
This will remove all environments ending with out
.
a = 2
print(a)
2
This is a code block that should not be executed:
while True:
i = 2
This is some formatted stuff, which is underlined and stuff and maybe even contains \( a + 2b \).
If code contains errors, it will still be run and the exception shown as part of the output:
for a in range(10)
print(a)
The working directory is the same as the .do.txt file.
You may want to use os.chdir
to change the directory.
with open("../LICENSE") as f:
print(f.read())