diff --git a/README.md b/README.md index 6b55ae02f4ad3f7e2ca14748a0dc718f4292ebf8..a91b40be83d84e2c9284d95f68c14e4e294119a2 100644 --- a/README.md +++ b/README.md @@ -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`): - + +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 diff --git a/docs/README.jinja.md b/docs/README.jinja.md index 6aebde05a5a76cae666330380cd52515ca15e35c..9ec7614165db6b5837c69313dcd9065657f3737a 100644 --- a/docs/README.jinja.md +++ b/docs/README.jinja.md @@ -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  +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 }} diff --git a/docs/build_docs.py b/docs/build_docs.py index 35d26b81f01163799c4fabdaf406b971d025eaed..ecfe1f4e7feb81e8d1fb2e75538aa2f06650b14f 100644 --- a/docs/build_docs.py +++ b/docs/build_docs.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 diff --git a/docs/index.png b/docs/index.png index cc301ed50412b50ddcfd4aadf7e951fa8df86676..c41a66ad8c73762aabf174feb8b7aca449c12723 100644 Binary files a/docs/index.png and b/docs/index.png differ diff --git a/examples/__pycache__/process_cs101_references.cpython-38.pyc b/examples/__pycache__/process_cs101_references.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..74f942ad2766b6037003c369531f014928de9702 Binary files /dev/null and b/examples/__pycache__/process_cs101_references.cpython-38.pyc differ