This example will produce two files `cs101_output/o_tag_a.txt`, `cs101_output/o_tag_b.txt`:
```python
```terminal
Here are the first 4 square numbers
1 is a square
4 is a square
...
...
@@ -188,14 +188,15 @@ Here are the first 4 square numbers
16 is a square
```
and
```python
```terminal
Area of square of width 2 and height 4 is:
8
and that is a fact!
```
## The #i!-tag
The #!i-tag allows you to create interactive python shell-snippets that can be imported using the minted `pycon` environment ('\inputminted{python}{input.shell}').
The #!i-tag allows you to create interactive python shell-snippets that can be imported using
the minted `pycon` environment (`\inputminted{python}{input.shell}`).
As an example, consider the instructor file
```python
foranimalin["Dog","cat","wolf"]:#!i=a
...
...
@@ -233,6 +234,26 @@ Let's consider the following example of a simple document with a couple of refer
To use the references in code we first have to load the `references.bib` file and the `index.aux`-file and then:
- Snipper allows you to directly insert this information using `\cite` and `\ref`
- You can also define custom citation command which allows you to reference common sources like
...
...
@@ -254,28 +275,41 @@ def myfun():
print("See \ref{sec1}")# Also works.
return42
```
We can manually compile this example by first loading the aux-files and the bibliographies as follows:
```python
```
Next, we load the python file containing the reference code and fix all references based on the aux and bibliography data.
Note the last parts of the file contains the special commands `\nref` (references to lecture notes) and `\aref2` (assignment 2) which I want to define.
This can be done by changing the call to snipper as follows (`examples/process_cs101_references.py`)
The middle command is a convenience feature: It allows us to specify a special citation command `\nref{..}` which always compiles to `\cite[\ref{...}]{herlau}`. This is useful if e.g. `herlau` is the bibtex key for your lecture notes. The result is as follows:
And this then produce the output:
```python
defmyfun():#!s
"""
To solve this exercise, look at \ref{eq1} in \ref{sec1}.
You can also look at \cite{bertsekasII} and \cite{herlau}
More specifically, look at \cite[Equation 117]{bertsekasII} and \cite[\ref{fig1}]{herlau}
We can also write a special tag to reduce repetition: \nref{fig1} and \nref{sec1}.
References:
[Ber07] Dimitri P. Bertsekas. Dynamic Programming and Optimal Control, Vol. II. Athena Scientific, 3rd edition, 2007. ISBN 1886529302.
[Her21] Tue Herlau. Sequential decision making. (See 02465_Notes.pdf), 2021.
"""
return42#!s
defmyfun():
"""
Simple aux references eq. (1) in Section 1.
Simple bibtex citations: (Ber07) and (Her21, Somewhere around the middle)
Example of custom command (reference notes)
> (Her21, Figure 1)
Other example of custom command (reference assignment)
> (Assignment 2, Section 1)
"""
print("See Section 1")# Also works.
return42
```
Note this example uses the low-level api. Normally you would just pass the bibtex and aux-file to the main censor-file command.
## Additional features:
- You can name tags using `#!s=bar` to get a `foo_bar.py` snippet. This is useful when you need to cut multiple sessions. This also works for the other tags.
\ No newline at end of file
Since the aux/bibtex databases are just dictionaries it is easy to join them together from different sources.
I have written reference tags to lecture and exercise material as well as my notes and it makes reference management very easy.
@@ -94,16 +94,17 @@ As an example, Consider the instructor file
{{cs101_instructor.o_tag_py}}
```
This example will produce two files `cs101_output/o_tag_a.txt`, `cs101_output/o_tag_b.txt`:
```python
```terminal
{{ cs101_output.o_tag_a_txt }}
```
and
```python
```terminal
{{ cs101_output.o_tag_b_txt }}
```
## The #i!-tag
The #!i-tag allows you to create interactive python shell-snippets that can be imported using the minted `pycon` environment ('\inputminted{python}{input.shell}').
The #!i-tag allows you to create interactive python shell-snippets that can be imported using
the minted `pycon` environment (`\inputminted{python}{input.shell}`).
As an example, consider the instructor file
```python
{{cs101_instructor.i_tag_py}}
...
...
@@ -126,6 +127,11 @@ Let's consider the following example of a simple document with a couple of refer

The code for this document is:
```latex
{{index_tex}}
```
To use the references in code we first have to load the `references.bib` file and the `index.aux`-file and then:
- Snipper allows you to directly insert this information using `\cite` and `\ref`
- You can also define custom citation command which allows you to reference common sources like
...
...
@@ -137,21 +143,14 @@ Let's look at all of these in turn. The file we will consider in the instructor-
```python
{{cs101_instructor.references_py}}
```
We can manually compile this example by first loading the aux-files and the bibliographies as follows:
```python
{{load_references_a_py}}
```
Next, we load the python file containing the reference code and fix all references based on the aux and bibliography data.
Note the last parts of the file contains the special commands `\nref` (references to lecture notes) and `\aref2` (assignment 2) which I want to define.
This can be done by changing the call to snipper as follows (`examples/process_cs101_references.py`)
```python
{{load_references_b_py}}
{{process_cs101_references_py}}
```
The middle command is a convenience feature: It allows us to specify a special citation command `\nref{..}` which always compiles to `\cite[\ref{...}]{herlau}`. This is useful if e.g. `herlau` is the bibtex key for your lecture notes. The result is as follows:
And this then produce the output:
```python
{{citations_py}}
{{cs101_students.references_py}}
```
Note this example uses the low-level api. Normally you would just pass the bibtex and aux-file to the main censor-file command.
## Additional features:
- You can name tags using `#!s=bar` to get a `foo_bar.py` snippet. This is useful when you need to cut multiple sessions. This also works for the other tags.
Since the aux/bibtex databases are just dictionaries it is easy to join them together from different sources.
I have written reference tags to lecture and exercise material as well as my notes and it makes reference management very easy.