Skip to content
Snippets Groups Projects
Commit 2995d500 authored by tuhe's avatar tuhe
Browse files

Refactor citation + tags and update README.md

parent 73174149
No related branches found
No related tags found
No related merge requests found
......@@ -181,11 +181,17 @@ if __name__ == "__main__":
```
This example will produce two files `cs101_output/o_tag_a.txt`, `cs101_output/o_tag_b.txt`:
```python
Here are the first 4 square numbers
1 is a square
4 is a square
9 is a square
16 is a square
```
and
```python
Area of square of width 2 and height 4 is:
8
and that is a fact!
```
## The #i!-tag
......@@ -202,11 +208,20 @@ myfun(3,4) #!i=b
```
This example will produce two files `cs101_output/i_tag_a.shell`, `cs101_output/i_tag_b.shell`:
```pycon
>>> for animal in ["Dog", "cat", "wolf"]:
... print("An example of a four legged animal is", animal)
...
An example of a four legged animal is Dog
An example of a four legged animal is cat
An example of a four legged animal is wolf
```
and
```pycon
>>> def myfun(a,b):
... return a+b
...
>>> myfun(3,4)
7
```
Note that apparently there
is no library for converting python code to shell sessions so I had to write it myself, which means it can properly get confused with multi-line statements (lists, etc.). On the plus-side, it will automatically insert newlines after the end of scopes.
......@@ -216,23 +231,31 @@ Note that apparently there
One of the most annoying parts of maintaining student code is to constantly write "see equation on slide 41 bottom" only to have the reference go stale because slide 23 got removed. Well now anymore, now you can direcly refence anything with a bibtex or aux file!
Let's consider the following example of a simple document with a couple of references: (see `examples/latex/index.pdf`):
![LaTeX sample](https://gitlab.compute.dtu.dk/tuhe/snipper/-/blob/main/docs/index.png)
![LaTeX sample](https://gitlab.compute.dtu.dk/tuhe/snipper/-/raw/main/docs/index.png)
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
- Lecture notes
- Exercise sheets
- Slides for a particular week
Bibliography references can be loaded from `references.bib`-files and in-document references from the `.aux` file.
For this example, we will insert references shown in the `examples/latex/index.tex`-document. To do so, we can use these tags:
Let's look at all of these in turn. The file we will consider in the instructor-version looks like this: (`examples/cs101_instructor/references.py`):
```python
def myfun(): #!s
def myfun():
"""
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}.
Simple aux references \ref{eq1} in \ref{sec1}.
Simple bibtex citations: \cite{bertsekasII} and \cite[Somewhere around the middle]{herlau}
Example of custom command (reference notes)
> \nref{fig1}
Other example of custom command (reference assignment)
> \aref2{sec1}
"""
return 42 #!s
print("See \ref{sec1}") # Also works.
return 42
```
We can manually compile this example by first loading the aux-files and the bibliographies as follows:
```python
......
......@@ -95,11 +95,11 @@ As an example, Consider the instructor file
```
This example will produce two files `cs101_output/o_tag_a.txt`, `cs101_output/o_tag_b.txt`:
```python
{{ cs101_output.o_tag_a_py }}
{{ cs101_output.o_tag_a_txt }}
```
and
```python
{{ cs101_output.o_tag_b_py }}
{{ cs101_output.o_tag_b_txt }}
```
## The #i!-tag
......@@ -110,11 +110,11 @@ The #!i-tag allows you to create interactive python shell-snippets that can be i
```
This example will produce two files `cs101_output/i_tag_a.shell`, `cs101_output/i_tag_b.shell`:
```pycon
{{ cs101_output.i_tag_a_py }}
{{ cs101_output.i_tag_a_shell }}
```
and
```pycon
{{ cs101_output.i_tag_b_py }}
{{ cs101_output.i_tag_b_shell }}
```
Note that apparently there
is no library for converting python code to shell sessions so I had to write it myself, which means it can properly get confused with multi-line statements (lists, etc.). On the plus-side, it will automatically insert newlines after the end of scopes.
......@@ -126,12 +126,19 @@ Let's consider the following example of a simple document with a couple of refer
![LaTeX sample]({{resources}}/docs/index.png)
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
- Lecture notes
- Exercise sheets
- Slides for a particular week
Bibliography references can be loaded from `references.bib`-files and in-document references from the `.aux` file.
For this example, we will insert references shown in the `examples/latex/index.tex`-document. To do so, we can use these tags:
Let's look at all of these in turn. The file we will consider in the instructor-version looks like this: (`examples/cs101_instructor/references.py`):
```python
{{ citations_orig_py }}
{{ 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 }}
......
......@@ -19,6 +19,9 @@ def my_nup(path):
if __name__ == "__main__":
from snipper.fix_s import save_s
from snipper.snipper_main import censor_file
# from examples.process_cs101_references import main
# main()
data = {}
EX_BASE = "../examples"
np = EX_BASE + "/latex"
......@@ -42,9 +45,9 @@ if __name__ == "__main__":
# data[d][name] = f.read()
data = {**data, **dir_import('../examples')}
data['resources'] = 'https://gitlab.compute.dtu.dk/tuhe/snipper/-/blob/main'
data['resources'] = 'https://gitlab.compute.dtu.dk/tuhe/snipper/-/raw/main'
convert.pdf2png(np + "/index.pdf", "./index.png", scale_to=600)
convert.pdf2png(np + "/index.pdf", "./index.png", scale_to=800)
# Build the docs.
import glob
......
docs/index.png

25.9 KiB | W: | H:

docs/index.png

37.5 KiB | W: | H:

docs/index.png
docs/index.png
docs/index.png
docs/index.png
  • 2-up
  • Swipe
  • Onion skin
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment