diff --git a/README.md b/README.md index d8a650d72629fa2323355dc853610d450cdca59a..d591146d30e34efb5d1794195498a6fd6bd84e2c 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,14 @@ pip install codesnipper ## What it does This project address the following three challenges for administering a python-based course - - You need to maintain a (working) version for debugging as well as a version handed out to students (with code missing) - - You ideally want to make references in source code to course material *"(see equation 2.1 in exercise 5)"* but these tend to go out of date - - You want to include code snippets and code output in lectures notes/exercises/beamer slides - - You want to automatically create student solutions + - Maintain a (working) version for debugging as well as a version handed out to students (with code missing) + - Use LaTeX references in source code to link to course material (i.e. `\ref{mylabel}` -> *"(see equation 2.1 in exercise 5)"*) + - Including code snippets and console output in lectures notes/exercises/beamer slides + - Automatically create student solutions -This framework address these problems and allow you to maintain a **single**, working project repository. +This framework address these problems and allow you to maintain a **single**, working project repository. Below is an example of the snippets produced and included using simple `\inputminted{python}{...}` commands (see the `examples/` directory): + + The project is currently used in **02465** at DTU. An example of student code can be found at: - https://gitlab.gbar.dtu.dk/02465material/02465students/blob/master/irlc/ex02/dp.py diff --git a/docs/README.jinja.md b/docs/README.jinja.md index 63e1837f7ee998e95096b8c15b4df7e8f6a03833..65b596453f0598178fb861e93a0b438a6e700435 100644 --- a/docs/README.jinja.md +++ b/docs/README.jinja.md @@ -7,12 +7,14 @@ pip install codesnipper ## What it does This project address the following three challenges for administering a python-based course - - You need to maintain a (working) version for debugging as well as a version handed out to students (with code missing) - - You ideally want to make references in source code to course material *"(see equation 2.1 in exercise 5)"* but these tend to go out of date - - You want to include code snippets and code output in lectures notes/exercises/beamer slides - - You want to automatically create student solutions + - Maintain a (working) version for debugging as well as a version handed out to students (with code missing) + - Use LaTeX references in source code to link to course material (i.e. `\ref{mylabel}` -> *"(see equation 2.1 in exercise 5)"*) + - Including code snippets and console output in lectures notes/exercises/beamer slides + - Automatically create student solutions -This framework address these problems and allow you to maintain a **single**, working project repository. +This framework address these problems and allow you to maintain a **single**, working project repository. Below is an example of the snippets produced and included using simple `\inputminted{python}{...}` commands (see the `examples/` directory): + + The project is currently used in **02465** at DTU. An example of student code can be found at: - https://gitlab.gbar.dtu.dk/02465material/02465students/blob/master/irlc/ex02/dp.py diff --git a/docs/build_docs.py b/docs/build_docs.py index 30e7f4c85fe1d84bc2fbce97c74145999104dcdc..0a5f25497c3b4e69ee73d6b5b767fbe951b4ad7c 100644 --- a/docs/build_docs.py +++ b/docs/build_docs.py @@ -3,8 +3,19 @@ from slider.beamer_nup import beamer_nup import jinja2 from slider import convert import os +import glob import shutil from slider.slider_cli import slider_cli +import glob + +# def my_nup(path): +# dir = os.path.dirname(path) +# base = os.path.basename(dir) +# +# out = beamer_nup(path, output="./" + base + "_nup.pdf", nup=2) +# out_png = convert.pdf2png(out, scale_to=600) +# print(out_png) + # from example.load_references import reference_example # reference_example() @@ -12,8 +23,9 @@ def my_nup(path): dir = os.path.dirname(path) base = os.path.basename(dir) - out = beamer_nup(path, output="./" + base + "_nup.pdf", nup=2) - out_png = convert.pdf2png(out, scale_to=600) + out = beamer_nup(path, output="./" + base + "_nup.pdf", nup=1) + convert.pdfcrop(out, out) + out_png = convert.pdf2png(out, scale_to=1600) print(out_png) if __name__ == "__main__": @@ -22,7 +34,7 @@ if __name__ == "__main__": data = {} EX_BASE = "../examples" np = EX_BASE + "/latex" - import glob + dirs = ['cs101_output', 'cs101_instructor', 'cs101_students'] def dir_import(dir): @@ -46,11 +58,15 @@ if __name__ == "__main__": data = {**data, **dir_import('../examples/latex')} data['resources'] = 'https://gitlab.compute.dtu.dk/tuhe/snipper/-/raw/main' + from slider.beamer_nup import beamer_nup + + my_nup(np+"/index_samples.pdf") convert.pdf2png(np + "/index.pdf", "./index.png", scale_to=800) + convert.pdf2png(np + "/index_samples.pdf", "./index_samples.png", scale_to=800) + # Build the docs. - import glob # with open("../examples/citations.py", 'r') as f: # data['citations_orig_py'] = f.read() # for file in glob.glob("../examples/output/*.*"): diff --git a/docs/index_samples.png b/docs/index_samples.png new file mode 100644 index 0000000000000000000000000000000000000000..aa8e0afe5bf7b2b66cfee8b91ee518382c16e115 Binary files /dev/null and b/docs/index_samples.png differ diff --git a/docs/latex_nup.pdf b/docs/latex_nup.pdf new file mode 100644 index 0000000000000000000000000000000000000000..fa0291c368ede566636011afc7503ea060b25631 Binary files /dev/null and b/docs/latex_nup.pdf differ diff --git a/docs/latex_nup.png b/docs/latex_nup.png new file mode 100644 index 0000000000000000000000000000000000000000..7d89be0f4210184848a7288c127483e84ec4bd33 Binary files /dev/null and b/docs/latex_nup.png differ diff --git a/examples/latex/_minted-index_samples/7B20E3559F1053DED41741E21E252F339EA735FDB3F9B8E6364D2B389BF521CC.pygtex b/examples/latex/_minted-index_samples/7B20E3559F1053DED41741E21E252F339EA735FDB3F9B8E6364D2B389BF521CC.pygtex new file mode 100644 index 0000000000000000000000000000000000000000..62271d0a1034eb085822394baa423954895a54ac --- /dev/null +++ b/examples/latex/_minted-index_samples/7B20E3559F1053DED41741E21E252F339EA735FDB3F9B8E6364D2B389BF521CC.pygtex @@ -0,0 +1,8 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{g+gp}{\PYGZgt{}\PYGZgt{}\PYGZgt{} }\PYG{k}{for} \PYG{n}{animal} \PYG{o+ow}{in} \PYG{p}{[}\PYG{l+s+s2}{\PYGZdq{}Dog\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}cat\PYGZdq{}}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}wolf\PYGZdq{}}\PYG{p}{]:} +\PYG{g+gp}{... } \PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}An example of a four legged animal is\PYGZdq{}}\PYG{p}{,} \PYG{n}{animal}\PYG{p}{)} +\PYG{g+gp}{... } +\PYG{g+go}{An example of a four legged animal is Dog} +\PYG{g+go}{An example of a four legged animal is cat} +\PYG{g+go}{An example of a four legged animal is wolf} +\end{Verbatim} diff --git a/examples/latex/_minted-index_samples/8A4742DEEA267C826DBE680538C0F5B13F740BA21D5172E91C708EAE6B37C464.pygtex b/examples/latex/_minted-index_samples/8A4742DEEA267C826DBE680538C0F5B13F740BA21D5172E91C708EAE6B37C464.pygtex new file mode 100644 index 0000000000000000000000000000000000000000..83ab3d1580f97660fa4be02cc5bccbe5ccc63aa5 --- /dev/null +++ b/examples/latex/_minted-index_samples/8A4742DEEA267C826DBE680538C0F5B13F740BA21D5172E91C708EAE6B37C464.pygtex @@ -0,0 +1,20 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}} +\PYG{l+s+sd}{References:} +\PYG{l+s+sd}{ [Ber07] Dimitri P. Bertsekas. Dynamic Programming and Optimal Control, Vol. II. Athena Scientific, 3rd edition, 2007. ISBN 1886529302.} +\PYG{l+s+sd}{ [Her21] Tue Herlau. Sequential decision making. (See 02465\PYGZus{}Notes.pdf), 2021.} +\PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}} +\PYG{k}{def} \PYG{n+nf}{myfun}\PYG{p}{():} + \PYG{l+s+sd}{\PYGZdq{}\PYGZdq{}\PYGZdq{}} +\PYG{l+s+sd}{ Simple aux references eq. (1) in Section 1.} +\PYG{l+s+sd}{ Simple bibtex citations: (Ber07) and (Her21, Somewhere around the middle)} + +\PYG{l+s+sd}{ Example of custom command (reference notes)} +\PYG{l+s+sd}{ \PYGZgt{} (Her21, Figure 1)} + +\PYG{l+s+sd}{ Other example of custom command (reference assignment)} +\PYG{l+s+sd}{ \PYGZgt{} (Assignment 2, Section 1)} +\PYG{l+s+sd}{ \PYGZdq{}\PYGZdq{}\PYGZdq{}} + \PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}See Section 1\PYGZdq{}}\PYG{p}{)} \PYG{c+c1}{\PYGZsh{} Also works.} + \PYG{k}{return} \PYG{l+m+mi}{42} +\end{Verbatim} diff --git a/examples/latex/_minted-index_samples/8F369F331D0DCFD75669221A8600751082884E76BCBADECDBC8E7DF4511F837A.pygtex b/examples/latex/_minted-index_samples/8F369F331D0DCFD75669221A8600751082884E76BCBADECDBC8E7DF4511F837A.pygtex new file mode 100644 index 0000000000000000000000000000000000000000..b5c4eecb6d75c8d6d549df37bd70d8b9cc9af3b2 --- /dev/null +++ b/examples/latex/_minted-index_samples/8F369F331D0DCFD75669221A8600751082884E76BCBADECDBC8E7DF4511F837A.pygtex @@ -0,0 +1,6 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{c+c1}{\PYGZsh{} s\PYGZus{}tag.py} +\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}Area of square of width\PYGZdq{}}\PYG{p}{,} \PYG{n}{width}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}and height\PYGZdq{}}\PYG{p}{,} \PYG{n}{height}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}is:\PYGZdq{}}\PYG{p}{)} +\PYG{n+nb}{print}\PYG{p}{(}\PYG{n}{width}\PYG{o}{*}\PYG{n}{height}\PYG{p}{)} +\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}An extra cutout\PYGZdq{}}\PYG{p}{)} +\end{Verbatim} diff --git a/examples/latex/_minted-index_samples/B141E24BD47C480C371E2537864C3EA47C8A9F29E67E25B9A99DBCEDF8B3C63E.pygtex b/examples/latex/_minted-index_samples/B141E24BD47C480C371E2537864C3EA47C8A9F29E67E25B9A99DBCEDF8B3C63E.pygtex new file mode 100644 index 0000000000000000000000000000000000000000..bb4d81e8deaadad3f711663828bd369f72c343ad --- /dev/null +++ b/examples/latex/_minted-index_samples/B141E24BD47C480C371E2537864C3EA47C8A9F29E67E25B9A99DBCEDF8B3C63E.pygtex @@ -0,0 +1,7 @@ +\begin{Verbatim}[commandchars=\\\{\}] +Here are the first 4 square numbers +1 is a square +4 is a square +9 is a square +16 is a square +\end{Verbatim} diff --git a/examples/latex/_minted-index_samples/B681CC2DC7A4A2D7CEB1F1C0D727C1C451D39B0F25A96881F0DCE7776C7AC140.pygtex b/examples/latex/_minted-index_samples/B681CC2DC7A4A2D7CEB1F1C0D727C1C451D39B0F25A96881F0DCE7776C7AC140.pygtex new file mode 100644 index 0000000000000000000000000000000000000000..64c5b5fbd727f48f88b46dfc59e03f3770048c1c --- /dev/null +++ b/examples/latex/_minted-index_samples/B681CC2DC7A4A2D7CEB1F1C0D727C1C451D39B0F25A96881F0DCE7776C7AC140.pygtex @@ -0,0 +1,12 @@ +\begin{Verbatim}[commandchars=\\\{\}] +\PYG{k}{def} \PYG{n+nf}{primes\PYGZus{}sieve}\PYG{p}{(}\PYG{n}{limit}\PYG{p}{):} + \PYG{c+c1}{\PYGZsh{} TODO: 8 lines missing.} + \PYG{k}{raise} \PYG{n+ne}{NotImplementedError}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}Compute the list `primes` here of all primes up to `limit`\PYGZdq{}}\PYG{p}{)} + \PYG{k}{return} \PYG{n}{primes} + +\PYG{n}{width}\PYG{p}{,} \PYG{n}{height} \PYG{o}{=} \PYG{l+m+mi}{2}\PYG{p}{,} \PYG{l+m+mi}{4} +\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}Area of square of width\PYGZdq{}}\PYG{p}{,} \PYG{n}{width}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}and height\PYGZdq{}}\PYG{p}{,} \PYG{n}{height}\PYG{p}{,} \PYG{l+s+s2}{\PYGZdq{}is:\PYGZdq{}}\PYG{p}{)} +\PYG{c+c1}{\PYGZsh{} TODO: 1 lines missing.} +\PYG{k}{raise} \PYG{n+ne}{NotImplementedError}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}Compute and print area here\PYGZdq{}}\PYG{p}{)} +\PYG{n+nb}{print}\PYG{p}{(}\PYG{l+s+s2}{\PYGZdq{}and that is a fact!\PYGZdq{}}\PYG{p}{)} +\end{Verbatim} diff --git a/examples/latex/_minted-index_samples/default-pyg-prefix.pygstyle b/examples/latex/_minted-index_samples/default-pyg-prefix.pygstyle new file mode 100644 index 0000000000000000000000000000000000000000..cd0f51ac14bc0245adbc1b7a69a2d395b97b924d --- /dev/null +++ b/examples/latex/_minted-index_samples/default-pyg-prefix.pygstyle @@ -0,0 +1,101 @@ + +\makeatletter +\def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax% + \let\PYG@ul=\relax \let\PYG@tc=\relax% + \let\PYG@bc=\relax \let\PYG@ff=\relax} +\def\PYG@tok#1{\csname PYG@tok@#1\endcsname} +\def\PYG@toks#1+{\ifx\relax#1\empty\else% + \PYG@tok{#1}\expandafter\PYG@toks\fi} +\def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{% + \PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}} +\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}} + +\expandafter\def\csname PYG@tok@w\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}} +\expandafter\def\csname PYG@tok@c\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} +\expandafter\def\csname PYG@tok@cp\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}} +\expandafter\def\csname PYG@tok@k\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYG@tok@kp\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYG@tok@kt\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}} +\expandafter\def\csname PYG@tok@o\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYG@tok@ow\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} +\expandafter\def\csname PYG@tok@nb\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYG@tok@nf\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\expandafter\def\csname PYG@tok@nc\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\expandafter\def\csname PYG@tok@nn\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\expandafter\def\csname PYG@tok@ne\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}} +\expandafter\def\csname PYG@tok@nv\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\expandafter\def\csname PYG@tok@no\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}} +\expandafter\def\csname PYG@tok@nl\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}} +\expandafter\def\csname PYG@tok@ni\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}} +\expandafter\def\csname PYG@tok@na\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}} +\expandafter\def\csname PYG@tok@nt\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYG@tok@nd\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} +\expandafter\def\csname PYG@tok@s\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYG@tok@sd\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYG@tok@si\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}} +\expandafter\def\csname PYG@tok@se\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}} +\expandafter\def\csname PYG@tok@sr\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}} +\expandafter\def\csname PYG@tok@ss\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\expandafter\def\csname PYG@tok@sx\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYG@tok@m\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYG@tok@gh\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} +\expandafter\def\csname PYG@tok@gu\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}} +\expandafter\def\csname PYG@tok@gd\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}} +\expandafter\def\csname PYG@tok@gi\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}} +\expandafter\def\csname PYG@tok@gr\endcsname{\def\PYG@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}} +\expandafter\def\csname PYG@tok@ge\endcsname{\let\PYG@it=\textit} +\expandafter\def\csname PYG@tok@gs\endcsname{\let\PYG@bf=\textbf} +\expandafter\def\csname PYG@tok@gp\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} +\expandafter\def\csname PYG@tok@go\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\expandafter\def\csname PYG@tok@gt\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}} +\expandafter\def\csname PYG@tok@err\endcsname{\def\PYG@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}} +\expandafter\def\csname PYG@tok@kc\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYG@tok@kd\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYG@tok@kn\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYG@tok@kr\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYG@tok@bp\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYG@tok@fm\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\expandafter\def\csname PYG@tok@vc\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\expandafter\def\csname PYG@tok@vg\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\expandafter\def\csname PYG@tok@vi\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\expandafter\def\csname PYG@tok@vm\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\expandafter\def\csname PYG@tok@sa\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYG@tok@sb\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYG@tok@sc\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYG@tok@dl\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYG@tok@s2\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYG@tok@sh\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYG@tok@s1\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYG@tok@mb\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYG@tok@mf\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYG@tok@mh\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYG@tok@mi\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYG@tok@il\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYG@tok@mo\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYG@tok@ch\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} +\expandafter\def\csname PYG@tok@cm\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} +\expandafter\def\csname PYG@tok@cpf\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} +\expandafter\def\csname PYG@tok@c1\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} +\expandafter\def\csname PYG@tok@cs\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} + +\def\PYGZbs{\char`\\} +\def\PYGZus{\char`\_} +\def\PYGZob{\char`\{} +\def\PYGZcb{\char`\}} +\def\PYGZca{\char`\^} +\def\PYGZam{\char`\&} +\def\PYGZlt{\char`\<} +\def\PYGZgt{\char`\>} +\def\PYGZsh{\char`\#} +\def\PYGZpc{\char`\%} +\def\PYGZdl{\char`\$} +\def\PYGZhy{\char`\-} +\def\PYGZsq{\char`\'} +\def\PYGZdq{\char`\"} +\def\PYGZti{\char`\~} +% for compatibility with earlier versions +\def\PYGZat{@} +\def\PYGZlb{[} +\def\PYGZrb{]} +\makeatother + diff --git a/examples/latex/_minted-index_samples/default.pygstyle b/examples/latex/_minted-index_samples/default.pygstyle new file mode 100644 index 0000000000000000000000000000000000000000..08728b3724e3f22a955d401967aed18343c28aae --- /dev/null +++ b/examples/latex/_minted-index_samples/default.pygstyle @@ -0,0 +1,101 @@ + +\makeatletter +\def\PYGdefault@reset{\let\PYGdefault@it=\relax \let\PYGdefault@bf=\relax% + \let\PYGdefault@ul=\relax \let\PYGdefault@tc=\relax% + \let\PYGdefault@bc=\relax \let\PYGdefault@ff=\relax} +\def\PYGdefault@tok#1{\csname PYGdefault@tok@#1\endcsname} +\def\PYGdefault@toks#1+{\ifx\relax#1\empty\else% + \PYGdefault@tok{#1}\expandafter\PYGdefault@toks\fi} +\def\PYGdefault@do#1{\PYGdefault@bc{\PYGdefault@tc{\PYGdefault@ul{% + \PYGdefault@it{\PYGdefault@bf{\PYGdefault@ff{#1}}}}}}} +\def\PYGdefault#1#2{\PYGdefault@reset\PYGdefault@toks#1+\relax+\PYGdefault@do{#2}} + +\expandafter\def\csname PYGdefault@tok@w\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}} +\expandafter\def\csname PYGdefault@tok@c\endcsname{\let\PYGdefault@it=\textit\def\PYGdefault@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} +\expandafter\def\csname PYGdefault@tok@cp\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@k\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@kp\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@kt\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}} +\expandafter\def\csname PYGdefault@tok@o\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYGdefault@tok@ow\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@nb\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@nf\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@nc\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@nn\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@ne\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}} +\expandafter\def\csname PYGdefault@tok@nv\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\expandafter\def\csname PYGdefault@tok@no\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@nl\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@ni\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}} +\expandafter\def\csname PYGdefault@tok@na\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}} +\expandafter\def\csname PYGdefault@tok@nt\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@nd\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@s\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYGdefault@tok@sd\endcsname{\let\PYGdefault@it=\textit\def\PYGdefault@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYGdefault@tok@si\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}} +\expandafter\def\csname PYGdefault@tok@se\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}} +\expandafter\def\csname PYGdefault@tok@sr\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}} +\expandafter\def\csname PYGdefault@tok@ss\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\expandafter\def\csname PYGdefault@tok@sx\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@m\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYGdefault@tok@gh\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} +\expandafter\def\csname PYGdefault@tok@gu\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}} +\expandafter\def\csname PYGdefault@tok@gd\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@gi\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@gr\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@ge\endcsname{\let\PYGdefault@it=\textit} +\expandafter\def\csname PYGdefault@tok@gs\endcsname{\let\PYGdefault@bf=\textbf} +\expandafter\def\csname PYGdefault@tok@gp\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} +\expandafter\def\csname PYGdefault@tok@go\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}} +\expandafter\def\csname PYGdefault@tok@gt\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}} +\expandafter\def\csname PYGdefault@tok@err\endcsname{\def\PYGdefault@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}} +\expandafter\def\csname PYGdefault@tok@kc\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@kd\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@kn\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@kr\endcsname{\let\PYGdefault@bf=\textbf\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@bp\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@fm\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\expandafter\def\csname PYGdefault@tok@vc\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\expandafter\def\csname PYGdefault@tok@vg\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\expandafter\def\csname PYGdefault@tok@vi\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\expandafter\def\csname PYGdefault@tok@vm\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\expandafter\def\csname PYGdefault@tok@sa\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYGdefault@tok@sb\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYGdefault@tok@sc\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYGdefault@tok@dl\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYGdefault@tok@s2\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYGdefault@tok@sh\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYGdefault@tok@s1\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\expandafter\def\csname PYGdefault@tok@mb\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYGdefault@tok@mf\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYGdefault@tok@mh\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYGdefault@tok@mi\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYGdefault@tok@il\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYGdefault@tok@mo\endcsname{\def\PYGdefault@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\expandafter\def\csname PYGdefault@tok@ch\endcsname{\let\PYGdefault@it=\textit\def\PYGdefault@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} +\expandafter\def\csname PYGdefault@tok@cm\endcsname{\let\PYGdefault@it=\textit\def\PYGdefault@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} +\expandafter\def\csname PYGdefault@tok@cpf\endcsname{\let\PYGdefault@it=\textit\def\PYGdefault@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} +\expandafter\def\csname PYGdefault@tok@c1\endcsname{\let\PYGdefault@it=\textit\def\PYGdefault@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} +\expandafter\def\csname PYGdefault@tok@cs\endcsname{\let\PYGdefault@it=\textit\def\PYGdefault@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}} + +\def\PYGdefaultZbs{\char`\\} +\def\PYGdefaultZus{\char`\_} +\def\PYGdefaultZob{\char`\{} +\def\PYGdefaultZcb{\char`\}} +\def\PYGdefaultZca{\char`\^} +\def\PYGdefaultZam{\char`\&} +\def\PYGdefaultZlt{\char`\<} +\def\PYGdefaultZgt{\char`\>} +\def\PYGdefaultZsh{\char`\#} +\def\PYGdefaultZpc{\char`\%} +\def\PYGdefaultZdl{\char`\$} +\def\PYGdefaultZhy{\char`\-} +\def\PYGdefaultZsq{\char`\'} +\def\PYGdefaultZdq{\char`\"} +\def\PYGdefaultZti{\char`\~} +% for compatibility with earlier versions +\def\PYGdefaultZat{@} +\def\PYGdefaultZlb{[} +\def\PYGdefaultZrb{]} +\makeatother + diff --git a/examples/latex/index_samples.aux b/examples/latex/index_samples.aux new file mode 100644 index 0000000000000000000000000000000000000000..291c7c46f9504b6e10daebdfb9fc861863c01849 --- /dev/null +++ b/examples/latex/index_samples.aux @@ -0,0 +1,10 @@ +\relax +\gdef\minted@oldcachelist{, + default-pyg-prefix.pygstyle, + default.pygstyle, + 8F369F331D0DCFD75669221A8600751082884E76BCBADECDBC8E7DF4511F837A.pygtex, + B141E24BD47C480C371E2537864C3EA47C8A9F29E67E25B9A99DBCEDF8B3C63E.pygtex, + 7B20E3559F1053DED41741E21E252F339EA735FDB3F9B8E6364D2B389BF521CC.pygtex, + B681CC2DC7A4A2D7CEB1F1C0D727C1C451D39B0F25A96881F0DCE7776C7AC140.pygtex, + 8A4742DEEA267C826DBE680538C0F5B13F740BA21D5172E91C708EAE6B37C464.pygtex} +\gdef \@abspage@last{1} diff --git a/examples/latex/index_samples.log b/examples/latex/index_samples.log new file mode 100644 index 0000000000000000000000000000000000000000..d3cabae4f297dfc71dd93c080485b1e75a607da1 --- /dev/null +++ b/examples/latex/index_samples.log @@ -0,0 +1,334 @@ +This is pdfTeX, Version 3.141592653-2.6-1.40.23 (MiKTeX 21.8) (preloaded format=pdflatex 2021.9.3) 6 SEP 2021 10:45 +entering extended mode +**./index_samples.tex +(index_samples.tex +LaTeX2e <2021-06-01> patch level 1 +L3 programming layer <2021-08-27> +(C:\Program Files\MiKTeX\tex/latex/base\article.cls +Document Class: article 2021/02/12 v1.4n Standard LaTeX document class +(C:\Program Files\MiKTeX\tex/latex/base\size10.clo +File: size10.clo 2021/02/12 v1.4n Standard LaTeX file (size option) +) +\c@part=\count182 +\c@section=\count183 +\c@subsection=\count184 +\c@subsubsection=\count185 +\c@paragraph=\count186 +\c@subparagraph=\count187 +\c@figure=\count188 +\c@table=\count189 +\abovecaptionskip=\skip47 +\belowcaptionskip=\skip48 +\bibindent=\dimen138 +) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/geometry\geometry.sty +Package: geometry 2020/01/02 v5.9 Page Geometry + +(C:\Program Files\MiKTeX\tex/latex/graphics\keyval.sty +Package: keyval 2014/10/28 v1.15 key=value parser (DPC) +\KV@toks@=\toks16 +) +(C:\Program Files\MiKTeX\tex/generic/iftex\ifvtex.sty +Package: ifvtex 2019/10/25 v1.7 ifvtex legacy package. Use iftex instead. + +(C:\Program Files\MiKTeX\tex/generic/iftex\iftex.sty +Package: iftex 2020/03/06 v1.0d TeX engine tests +)) +\Gm@cnth=\count190 +\Gm@cntv=\count191 +\c@Gm@tempcnt=\count192 +\Gm@bindingoffset=\dimen139 +\Gm@wd@mp=\dimen140 +\Gm@odd@mp=\dimen141 +\Gm@even@mp=\dimen142 +\Gm@layoutwidth=\dimen143 +\Gm@layoutheight=\dimen144 +\Gm@layouthoffset=\dimen145 +\Gm@layoutvoffset=\dimen146 +\Gm@dimlist=\toks17 + +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/geometry\geometry.cfg)) +(C:\Program Files\MiKTeX\tex/latex/xcolor\xcolor.sty +Package: xcolor 2016/05/11 v2.12 LaTeX color extensions (UK) + +(C:\Program Files\MiKTeX\tex/latex/graphics-cfg\color.cfg +File: color.cfg 2016/01/02 v1.6 sample color configuration +) +Package xcolor Info: Driver file: pdftex.def on input line 225. + +(C:\Program Files\MiKTeX\tex/latex/graphics-def\pdftex.def +File: pdftex.def 2020/10/05 v1.2a Graphics/color driver for pdftex +) +Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1348. +Package xcolor Info: Model `hsb' substituted by `rgb' on input line 1352. +Package xcolor Info: Model `RGB' extended on input line 1364. +Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1366. +Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1367. +Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1368. +Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1369. +Package xcolor Info: Model `Gray' substituted by `gray' on input line 1370. +Package xcolor Info: Model `wave' substituted by `hsb' on input line 1371. +) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/minted\minted.sty +Package: minted 2017/07/19 v2.5 Yet another Pygments shim for LaTeX + +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/kvoptions\kvoptions.sty +Package: kvoptions 2020-10-07 v3.14 Key value format for package options (HO) + +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/generic/ltxcmds\ltxcmds.sty +Package: ltxcmds 2020-05-10 v1.25 LaTeX kernel commands for general use (HO) +) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/generic/kvsetkeys\kvsetkeys.sty +Package: kvsetkeys 2019/12/15 v1.18 Key value parser (HO) +)) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/fvextra\fvextra.sty +Package: fvextra 2019/02/04 v1.4 fvextra - extensions and patches for fancyvrb + +(C:\Program Files\MiKTeX\tex/latex/base\ifthen.sty +Package: ifthen 2020/11/24 v1.1c Standard LaTeX ifthen package (DPC) +) +(C:\Program Files\MiKTeX\tex/latex/etoolbox\etoolbox.sty +Package: etoolbox 2020/10/05 v2.5k e-TeX tools for LaTeX (JAW) +\etb@tempcnta=\count193 +) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/fancyvrb\fancyvrb.sty +Package: fancyvrb 2021/08/12 v3.8 verbatim text (tvz,hv) +\FV@CodeLineNo=\count194 +\FV@InFile=\read2 +\FV@TabBox=\box50 +\c@FancyVerbLine=\count195 +\FV@StepNumber=\count196 +\FV@OutFile=\write3 +) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/upquote\upquote.sty +Package: upquote 2012/04/19 v1.3 upright-quote and grave-accent glyphs in verba +tim +) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/lineno\lineno.sty +Package: lineno 2005/11/02 line numbers on paragraphs v4.41 +\linenopenalty=\count197 +\output=\toks18 +\linenoprevgraf=\count198 +\linenumbersep=\dimen147 +\linenumberwidth=\dimen148 +\c@linenumber=\count199 +\c@pagewiselinenumber=\count266 +\c@LN@truepage=\count267 +\c@internallinenumber=\count268 +\c@internallinenumbers=\count269 +\quotelinenumbersep=\dimen149 +\bframerule=\dimen150 +\bframesep=\dimen151 +\bframebox=\box51 +LaTeX Info: Redefining \\ on input line 3056. +) +\c@FV@TrueTabGroupLevel=\count270 +\c@FV@TrueTabCounter=\count271 +\FV@TabBox@Group=\box52 +\FV@TmpLength=\skip49 +\c@FV@HighlightLinesStart=\count272 +\c@FV@HighlightLinesStop=\count273 +\FV@LoopCount=\count274 +\FV@NCharsBox=\box53 +\FV@BreakIndent=\dimen152 +\FV@BreakIndentNChars=\count275 +\FV@BreakSymbolSepLeft=\dimen153 +\FV@BreakSymbolSepLeftNChars=\count276 +\FV@BreakSymbolSepRight=\dimen154 +\FV@BreakSymbolSepRightNChars=\count277 +\FV@BreakSymbolIndentLeft=\dimen155 +\FV@BreakSymbolIndentLeftNChars=\count278 +\FV@BreakSymbolIndentRight=\dimen156 +\FV@BreakSymbolIndentRightNChars=\count279 +\c@FancyVerbLineBreakLast=\count280 +\FV@LineBox=\box54 +\FV@LineIndentBox=\box55 +\FV@LineWidth=\dimen157 +) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/tools\calc.sty +Package: calc 2017/05/25 v4.3 Infix arithmetic (KKT,FJ) +\calc@Acount=\count281 +\calc@Bcount=\count282 +\calc@Adimen=\dimen158 +\calc@Bdimen=\dimen159 +\calc@Askip=\skip50 +\calc@Bskip=\skip51 +LaTeX Info: Redefining \setlength on input line 80. +LaTeX Info: Redefining \addtolength on input line 81. +\calc@Ccount=\count283 +\calc@Cskip=\skip52 +) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/tools\shellesc.sty +Package: shellesc 2019/11/08 v1.0c unified shell escape interface for LaTeX +Package shellesc Info: Unrestricted shell escape enabled on input line 75. +) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/ifplatform\ifplatform.sty +Package: ifplatform 2017/10/13 v0.4a Testing for the operating system + +(C:\Program Files\MiKTeX\tex/generic/pdftexcmds\pdftexcmds.sty +Package: pdftexcmds 2020-06-27 v0.33 Utility functions of pdfTeX for LuaTeX (HO +) + +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/generic/infwarerr\infwarerr.sty +Package: infwarerr 2019/12/03 v1.5 Providing info/warning/error messages (HO) +) +Package pdftexcmds Info: \pdf@primitive is available. +Package pdftexcmds Info: \pdf@ifprimitive is available. +Package pdftexcmds Info: \pdfdraftmode found. +) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/generic/catchfile\catchfile.sty +Package: catchfile 2019/12/09 v1.8 Catch the contents of a file (HO) + +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/generic/etexcmds\etexcmds.sty +Package: etexcmds 2019/12/15 v1.7 Avoid name clashes with e-TeX commands (HO) +)) +(C:\Program Files\MiKTeX\tex/generic/iftex\ifluatex.sty +Package: ifluatex 2019/10/25 v1.5 ifluatex legacy package. Use iftex instead. +)) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/xstring\xstring.sty +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/generic/xstring\xstring.tex +\integerpart=\count284 +\decimalpart=\count285 +) +Package: xstring 2021/07/21 v1.84 String manipulations (CT) +) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/framed\framed.sty +Package: framed 2011/10/22 v 0.96: framed or shaded text with page breaks +\OuterFrameSep=\skip53 +\fb@frw=\dimen160 +\fb@frh=\dimen161 +\FrameRule=\dimen162 +\FrameSep=\dimen163 +) +(C:\Users\tuhe\AppData\Roaming\MiKTeX\tex/latex/float\float.sty +Package: float 2001/11/08 v1.3d Float enhancements (AL) +\c@float@type=\count286 +\float@exts=\toks19 +\float@box=\box56 +\@float@everytoks=\toks20 +\@floatcapt=\box57 +) +\minted@appexistsfile=\read3 +\minted@bgbox=\box58 +\minted@code=\write4 +\c@minted@FancyVerbLineTemp=\count287 +\c@minted@pygmentizecounter=\count288 +\@float@every@listing=\toks21 +\c@listing=\count289 +) +runsystem(if not exist _minted-index_samples mkdir _minted-index_samples)...exe +cuted. + +runsystem(for ^%i in (pygmentize.exe pygmentize.bat pygmentize.cmd) do set > in +dex_samples.aex <nul: /p x=^%~$PATH:i>> index_samples.aex)...executed. + +runsystem(del index_samples.aex)...executed. + + +(C:\Program Files\MiKTeX\tex/latex/l3backend\l3backend-pdftex.def +File: l3backend-pdftex.def 2021-08-04 L3 backend support: PDF output (pdfTeX) +\l__color_backend_stack_int=\count290 +\l__pdf_internal_box=\box59 +) +(index_samples.aux) +\openout1 = `index_samples.aux'. + +LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. +LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 16. +LaTeX Font Info: ... okay on input line 16. + +*geometry* driver: auto-detecting +*geometry* detected driver: pdftex +*geometry* verbose mode - [ preamble ] result: +* driver: pdftex +* paper: <default> +* layout: <same size as paper> +* layoutoffset:(h,v)=(0.0pt,0.0pt) +* modes: +* h-part:(L,W,R)=(0.72229pt, 612.85042pt, 0.72229pt) +* v-part:(T,H,B)=(0.72229pt, 793.5254pt, 0.72229pt) +* \paperwidth=614.295pt +* \paperheight=794.96999pt +* \textwidth=612.85042pt +* \textheight=793.5254pt +* \oddsidemargin=-71.5477pt +* \evensidemargin=-71.5477pt +* \topmargin=-108.5477pt +* \headheight=12.0pt +* \headsep=25.0pt +* \topskip=10.0pt +* \footskip=30.0pt +* \marginparwidth=65.0pt +* \marginparsep=11.0pt +* \columnsep=10.0pt +* \skip\footins=9.0pt plus 4.0pt minus 2.0pt +* \hoffset=0.0pt +* \voffset=0.0pt +* \mag=1000 +* \@twocolumnfalse +* \@twosidefalse +* \@mparswitchfalse +* \@reversemarginfalse +* (1in=72.27pt=25.4mm, 1cm=28.453pt) + +(C:\Program Files\MiKTeX\tex/context/base/mkii\supp-pdf.mkii +[Loading MPS to PDF converter (version 2006.09.02).] +\scratchcounter=\count291 +\scratchdimen=\dimen164 +\scratchbox=\box60 +\nofMPsegments=\count292 +\nofMParguments=\count293 +\everyMPshowfont=\toks22 +\MPscratchCnt=\count294 +\MPscratchDim=\dimen165 +\MPnumerator=\count295 +\makeMPintoPDFobject=\count296 +\everyMPtoPDFconversion=\toks23 +) (_minted-index_samples/default-pyg-prefix.pygstyle) +(_minted-index_samples/default.pygstyle) +(_minted-index_samples/8F369F331D0DCFD75669221A8600751082884E76BCBADECDBC8E7DF4 +511F837A.pygtex) +(_minted-index_samples/B141E24BD47C480C371E2537864C3EA47C8A9F29E67E25B9A99DBCED +F8B3C63E.pygtex) +(_minted-index_samples/7B20E3559F1053DED41741E21E252F339EA735FDB3F9B8E6364D2B38 +9BF521CC.pygtex +LaTeX Font Info: Font shape `OT1/cmtt/bx/n' in size <8> not available +(Font) Font shape `OT1/cmtt/m/n' tried instead on input line 2. +) +(_minted-index_samples/B681CC2DC7A4A2D7CEB1F1C0D727C1C451D39B0F25A96881F0DCE777 +6C7AC140.pygtex) +(_minted-index_samples/8A4742DEEA267C826DBE680538C0F5B13F740BA21D5172E91C708EAE +6B37C464.pygtex) [1 + +{C:/Users/tuhe/AppData/Local/MiKTeX/pdftex/config/pdftex.map}] (index_samples.a +ux) ) +Here is how much of TeX's memory you used: + 5600 strings out of 478927 + 103158 string characters out of 2862359 + 462952 words of memory out of 3000000 + 23390 multiletter control sequences out of 15000+600000 + 404373 words of font info for 31 fonts, out of 8000000 for 9000 + 1141 hyphenation exceptions out of 8191 + 74i,5n,80p,341b,506s stack positions out of 5000i,500n,10000p,200000b,80000s +<C:/Program Files/MiKTeX/fonts/type1/public/amsfonts/cm/cmbx10.pfb><C:/Pro +gram Files/MiKTeX/fonts/type1/public/amsfonts/cm/cmitt10.pfb><C:/Program Files/ +MiKTeX/fonts/type1/public/amsfonts/cm/cmr10.pfb><C:/Program Files/MiKTeX/fonts/ +type1/public/amsfonts/cm/cmr5.pfb><C:/Program Files/MiKTeX/fonts/type1/public/a +msfonts/cm/cmtt8.pfb> +Output written on index_samples.pdf (1 page, 61104 bytes). +PDF statistics: + 31 PDF objects out of 1000 (max. 8388607) + 0 named destinations out of 1000 (max. 500000) + 1 words of extra memory for PDF output out of 10000 (max. 10000000) + diff --git a/examples/latex/index_samples.out b/examples/latex/index_samples.out new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/examples/latex/index_samples.pdf b/examples/latex/index_samples.pdf new file mode 100644 index 0000000000000000000000000000000000000000..d03f44e42483df8262989795ab446a6f9d3bff89 Binary files /dev/null and b/examples/latex/index_samples.pdf differ diff --git a/examples/latex/index_samples.synctex.gz b/examples/latex/index_samples.synctex.gz new file mode 100644 index 0000000000000000000000000000000000000000..5cf2122e02104d21e978a54d8caf3817f3dd184c Binary files /dev/null and b/examples/latex/index_samples.synctex.gz differ diff --git a/examples/latex/index_samples.tex b/examples/latex/index_samples.tex new file mode 100644 index 0000000000000000000000000000000000000000..5587e36ae9f953b48e6fa76c8071ce77ba8cfc9b --- /dev/null +++ b/examples/latex/index_samples.tex @@ -0,0 +1,31 @@ +\documentclass{article} +\usepackage[margin=.01in]{geometry} +\usepackage{xcolor,minted} + +\definecolor{LightGray}{HTML}{EEEEEE} +\setminted{ + breaklines, + frame=lines, + framesep=2mm, + baselinestretch=1.2, + bgcolor=LightGray, + fontsize=\footnotesize, + linenos +} + +\begin{document} +\subsubsection*{Python code include:} +\inputminted{python}{../cs101_output/s_tag.py} + +\subsubsection*{Terminal output:} +\inputminted{text}{../cs101_output/o_tag_a.txt} + +\subsubsection*{Interactive shell session:} +\inputminted{pycon}{../cs101_output/i_tag_a.shell} + +\subsubsection*{Automatic code removal:} +\inputminted{python}{../cs101_students/b_tag.py} + +\subsubsection*{References:} +\inputminted{python}{../cs101_students/references.py} +\end{document} \ No newline at end of file diff --git a/src/snipper/__pycache__/block_parsing.cpython-38.pyc b/src/snipper/__pycache__/block_parsing.cpython-38.pyc index 6e35176913d71822dbada220ed46f50a0ec7f8ad..5f0fa38e06964f4ccf08c26117b7b787eb3b0791 100644 Binary files a/src/snipper/__pycache__/block_parsing.cpython-38.pyc and b/src/snipper/__pycache__/block_parsing.cpython-38.pyc differ diff --git a/src/snipper/__pycache__/fix_bf.cpython-38.pyc b/src/snipper/__pycache__/fix_bf.cpython-38.pyc index eb22389410ff1cb4db353975d3c62a897782d50c..50edfabfa447d901387da5638cca83d0bdb560f9 100644 Binary files a/src/snipper/__pycache__/fix_bf.cpython-38.pyc and b/src/snipper/__pycache__/fix_bf.cpython-38.pyc differ diff --git a/src/snipper/__pycache__/fix_cite.cpython-38.pyc b/src/snipper/__pycache__/fix_cite.cpython-38.pyc index eeaf3694f500ec156fce7c14092ca7b9a58030d6..8182783048657d4e03b7fdc09bc39298fccc3065 100644 Binary files a/src/snipper/__pycache__/fix_cite.cpython-38.pyc and b/src/snipper/__pycache__/fix_cite.cpython-38.pyc differ diff --git a/src/snipper/__pycache__/fix_i.cpython-38.pyc b/src/snipper/__pycache__/fix_i.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b538f528512b367e6f1e99eaf64f3f4e0c4363b5 Binary files /dev/null and b/src/snipper/__pycache__/fix_i.cpython-38.pyc differ diff --git a/src/snipper/__pycache__/fix_o.cpython-38.pyc b/src/snipper/__pycache__/fix_o.cpython-38.pyc index 3ea6cd8ef8b3a3776ae9e2d534579277d4ab91b8..8d8bcdc423001db8f393bfa2700ce0c32dfc6295 100644 Binary files a/src/snipper/__pycache__/fix_o.cpython-38.pyc and b/src/snipper/__pycache__/fix_o.cpython-38.pyc differ diff --git a/src/snipper/__pycache__/fix_r.cpython-38.pyc b/src/snipper/__pycache__/fix_r.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..244529db74ad096ca7e563447f9c39f2523453c4 Binary files /dev/null and b/src/snipper/__pycache__/fix_r.cpython-38.pyc differ diff --git a/src/snipper/__pycache__/fix_s.cpython-38.pyc b/src/snipper/__pycache__/fix_s.cpython-38.pyc index 2b3e3cdf41d7861d72c4559b682c1c4012d59b8d..82d5e8e8b679eff28ef31891521b5b451b77d499 100644 Binary files a/src/snipper/__pycache__/fix_s.cpython-38.pyc and b/src/snipper/__pycache__/fix_s.cpython-38.pyc differ diff --git a/src/snipper/__pycache__/legacy.cpython-38.pyc b/src/snipper/__pycache__/legacy.cpython-38.pyc index ca245802a659eb097945ed2488813d2fc128f72b..de81fc57ca76b392afb215f36ef762b6c4553601 100644 Binary files a/src/snipper/__pycache__/legacy.cpython-38.pyc and b/src/snipper/__pycache__/legacy.cpython-38.pyc differ diff --git a/src/snipper/__pycache__/snipper_main.cpython-38.pyc b/src/snipper/__pycache__/snipper_main.cpython-38.pyc index 1d8de50a5424307ec53bd2fafd6baf3d0d974635..fd90def87e043144655478d490c81d7f34538bfe 100644 Binary files a/src/snipper/__pycache__/snipper_main.cpython-38.pyc and b/src/snipper/__pycache__/snipper_main.cpython-38.pyc differ diff --git a/src/snipper/block_parsing.py b/src/snipper/block_parsing.py index f81a7f207dd26e69935aee890332d01cd9a6bccf..cfad9c429c6c38c10c7ecbd615831ad3b80abece 100644 --- a/src/snipper/block_parsing.py +++ b/src/snipper/block_parsing.py @@ -2,6 +2,7 @@ Module for new-style block parsing. Make sure all functions are up-to-date and used. """ + def f2(lines, tag, i=0, j=0): for k in range(i, len(lines)): index = lines[k].find(tag, j if k == i else 0) @@ -21,16 +22,6 @@ def block_iterate(lines, tag): def block_split(lines, tag): - # print("\n".join(lines)) - # if tag != "#!s": - # return {} - - if tag =="#!s" and "#!s" in "".join(lines): - print("tag is", tag) - # else: - # return dict(name="asdfasdf", joined='') - - z = 234 stag = tag[:2] # Start of any next tag. def join(contents): @@ -47,8 +38,6 @@ def block_split(lines, tag): if len(tag_args) == 0: return {'': ''} # No name. - # print("TAG ARGS") - # print(tag_args) tag_args = dict([t.split("=") for t in tag_args.split(";")]) return tag_args @@ -68,7 +57,6 @@ def block_split(lines, tag): print("\n".join( lines[i:])) raise Exception("Did not find matching tag", tag) - if i == i2: # Splitting a single line. To reduce confusion, this will be treated slightly differently: l2 = lines[:i] + [lines[i][:j2], lines[i][j2:]] + lines[i2+1:] @@ -96,4 +84,29 @@ def block_split(lines, tag): contents['joined'] = join(contents) contents['start_tag_args'] = start_tag_args contents['name'] = start_tag_args[''] - return contents \ No newline at end of file + return contents + + +def indent(l): + return l[:len(l) - len(l.lstrip())] + + +def full_strip(lines, tags=None): + if tags is None: + tags = ["#!s", "#!o", "#!f", "#!b"] + for t in tags: + lines = strip_tag(lines, t) + return lines + + +def strip_tag(lines, tag): + lines2 = [] + for l in lines: + dx = l.find(tag) + if dx > 0: + l = l[:dx] + if len(l.strip()) == 0: + l = None + if l is not None: + lines2.append(l) + return lines2 \ No newline at end of file diff --git a/src/snipper/fix_bf.py b/src/snipper/fix_bf.py index 36ac1ce30fa5620266714f5d0b95d7867ebbf979..3a128bc9b5bda6057ca8643c13f09f4b4f3b4950 100644 --- a/src/snipper/fix_bf.py +++ b/src/snipper/fix_bf.py @@ -1,6 +1,6 @@ import functools - -from snipper.legacy import indent, gcoms, block_process +from snipper.legacy import gcoms, block_process +from snipper.block_parsing import indent def fix_f(lines, debug): diff --git a/src/snipper/fix_cite.py b/src/snipper/fix_cite.py index 62da31822e2542f8e20a9c65670576736e82741d..c4cfb1c07a3ba881d864557c94d76120bc69ea6a 100644 --- a/src/snipper/fix_cite.py +++ b/src/snipper/fix_cite.py @@ -51,13 +51,11 @@ def fix_bibtex(lines, bibtex): # s = s.replace(cpr, info['code_copyright']) return s.splitlines() - - -def fix_references(lines, info, strict=True): - assert False - for cmd in info['new_references']: - lines = fix_single_reference(lines, cmd, info['new_references'][cmd], strict=strict) - return lines +# def fix_references(lines, info, strict=True): +# assert False +# for cmd in info['new_references']: +# lines = fix_single_reference(lines, cmd, info['new_references'][cmd], strict=strict) +# return lines def fix_single_reference(lines, cmd, aux, strict=True): references = aux diff --git a/src/snipper/fix_i.py b/src/snipper/fix_i.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0d17a39c250627d738a3544f62fc9cc52b8c0257 100644 --- a/src/snipper/fix_i.py +++ b/src/snipper/fix_i.py @@ -0,0 +1,101 @@ +import functools +import textwrap +from snipper.legacy import block_process +from snipper.block_parsing import full_strip + + +def run_i(lines, file, output): + extra = dict(python=None, output=output, evaluated_lines=0) + def block_fun(lines, start_extra, end_extra, art, head="", tail="", output=None, extra=None): + outf = output + ("_" + art if art is not None and len(art) > 0 else "") + ".shell" + lines = full_strip(lines) + s = "\n".join(lines) + s.replace("...", "..") # passive-aggressively truncate ... because of #issues. + lines = textwrap.dedent(s).strip().splitlines() + + if extra['python'] is None: + import os + if os.name == 'nt': + import wexpect as we + else: + import pexpect as we + an = we.spawn("python", encoding="utf-8", timeout=20) + an.expect([">>>"]) + extra['python'] = an + + analyzer = extra['python'] + def rsession(analyzer, lines): + l2 = [] + for i, l in enumerate(lines): + l2.append(l) + if l.startswith(" ") and i < len(lines)-1 and not lines[i+1].startswith(" "): + if not lines[i+1].strip().startswith("else:") and not lines[i+1].strip().startswith("elif") : + l2.append("\n") + + lines = l2 + alines = [] + + # indented = False + in_dot_mode = False + if len(lines[-1]) > 0 and (lines[-1].startswith(" ") or lines[-1].startswith("\t")): + lines += [""] + + for i, word in enumerate(lines): + analyzer.sendline(word) + before = "" + while True: + analyzer.expect_exact([">>>", "..."]) + before += analyzer.before + if analyzer.before.endswith("\n"): + break + else: + before += analyzer.after + + dotmode = analyzer.after == "..." + if 'dir(s)' in word: + pass + if 'help(s.find)' in word: + pass + if dotmode: + # alines.append("..." + word) + alines.append(">>>" + analyzer.before.rstrip() if not in_dot_mode else "..." + analyzer.before.rstrip()) + in_dot_mode = True + # if i < len(lines) - 1 and not lines[i + 1].startswith(" "): + # analyzer.sendline("\n") # going out of indentation mode . + # analyzer.expect_exact([">>>", "..."]) + # alines.append("..." + analyzer.after.rstrip()) + # pass + else: + alines.append( ("..." if in_dot_mode else ">>>") + analyzer.before.rstrip()) + in_dot_mode = False + return alines + + for l in (head[extra['evaluated_lines']:] + ["\n"]): + analyzer.sendline(l) + analyzer.expect_exact([">>>", "..."]) + + + alines = rsession(analyzer, lines) + extra['evaluated_lines'] += len(head) + len(lines) + lines = alines + return lines, [outf, lines] + try: + a,b,c,_ = block_process(lines, tag="#!i", block_fun=functools.partial(block_fun, output=output, extra=extra)) + if extra['python'] is not None: + extra['python'].close() + + if len(c)>0: + kvs= { v[0] for v in c} + for outf in kvs: + out = "\n".join( ["\n".join(v[1]) for v in c if v[0] == outf] ) + out = out.replace("\r", "") + + with open(outf, 'w') as f: + f.write(out) + + except Exception as e: + print("lines are") + print("\n".join(lines)) + print("Bad thing in #!i command in file", file) + raise e + return lines \ No newline at end of file diff --git a/src/snipper/fix_o.py b/src/snipper/fix_o.py index 5caf0ac28801069d9a1b1bfc162b53010ded2b87..04689e4dd082f8cd7e21dd2ebc6d133f75474d95 100644 --- a/src/snipper/fix_o.py +++ b/src/snipper/fix_o.py @@ -1,7 +1,7 @@ import functools import os - -from snipper.legacy import indent, block_process +from snipper.legacy import block_process +from snipper.block_parsing import indent def run_o(lines, file, output): @@ -11,7 +11,6 @@ def run_o(lines, file, output): l2 = [] l2 += [id + "import sys", id + f"sys.stdout = open('{outf}', 'w')"] l2 += lines - # l2 += [indent(lines[-1]) + "sys.stdout.close()"] l2 += [indent(lines[-1]) + "sys.stdout = sys.__stdout__"] return l2, None try: diff --git a/src/snipper/fix_r.py b/src/snipper/fix_r.py new file mode 100644 index 0000000000000000000000000000000000000000..193f460e12cc6617aae338820a61e114ab77b79b --- /dev/null +++ b/src/snipper/fix_r.py @@ -0,0 +1,8 @@ +from snipper.block_parsing import indent + + +def fix_r(lines): + for i,l in enumerate(lines): + if "#!r" in l: + lines[i] = indent(l) + l[l.find("#!r") + 3:].lstrip() + return lines diff --git a/src/snipper/fix_s.py b/src/snipper/fix_s.py index b21fd60bd84239a1e078ca1afe9612eb2326a363..c74028012c46aee0d4e8ab1203393f4ca0dab887 100644 --- a/src/snipper/fix_s.py +++ b/src/snipper/fix_s.py @@ -2,16 +2,12 @@ from collections import defaultdict import os from snipper.block_parsing import block_iterate - def get_s(lines): """ Return snips from 'lines' """ blocks = defaultdict(list) for c in block_iterate(lines, "#!s"): blocks[c['name']].append(c) - if len(blocks) > 0: - print("\n".join(lines)) - print("asdf") output = {} for name, co in blocks.items(): output[name] = [l for c in co for l in c['block']] @@ -28,6 +24,7 @@ def save_s(lines, output_dir, file_path): # save file snips to disk with open(output_dir + "/" + os.path.basename(file_path)[:-3] + ("_" + name if len(name) > 0 else name) + ".py", 'w') as f: f.write(out) + s1 = """ L1 L2 #!s=a @@ -40,7 +37,6 @@ L8 L9 #!s=b went """ - if __name__ == "__main__": # for c in block_iterate(s1.splitlines(), tag="#!s"): # print(c['block']) @@ -49,6 +45,4 @@ if __name__ == "__main__": print("name:", k) print("\n".join(v)) print("="*10) - # contents = block_split(s1.splitlines(), tag="#!s") - # contents = block_split(contents['joined'], tag="#!s") - # lines2 = contents['first'] + + diff --git a/src/snipper/legacy.py b/src/snipper/legacy.py index c1220397cfe157d5a0eb4e77c5a68f5d8443d04c..d52e5ab2de07ed264b85fca7a9e6f3b6dc0bf5e0 100644 --- a/src/snipper/legacy.py +++ b/src/snipper/legacy.py @@ -1,8 +1,3 @@ -def indent(l): - v = len(l) - len(l.lstrip()) - return l[:v] - - COMMENT = '"""' diff --git a/src/snipper/snip_dir.py b/src/snipper/snip_dir.py index 6032800f8bcaede58874b7ffd14fe3595fa2c339..328e93b3cb6cda31aea20f8460f9ce08f6a25c93 100644 --- a/src/snipper/snip_dir.py +++ b/src/snipper/snip_dir.py @@ -32,7 +32,6 @@ def snip_dir(source_dir, # Sources shutil.rmtree(dest_dir) os.makedirs(dest_dir) - out = dest_dir hw = {'base': source_dir, 'exclusion': exclude} @@ -41,9 +40,7 @@ def snip_dir(source_dir, # Sources if os.path.exists(dest_dir): shutil.rmtree(dest_dir) - base = hw['base'] - - shutil.copytree(base, dest_dir) + shutil.copytree(source_dir, dest_dir) time.sleep(0.2) ls = list(Path(dest_dir).glob('**/*.*')) @@ -63,7 +60,7 @@ def snip_dir(source_dir, # Sources for f, accept in acceptable: if os.path.isdir(f) or not str(f).endswith(".py"): # We only touch .py files. continue - f_dir = os.path.normpath(f if os.path.isdir(f) else os.path.dirname(f)) + # f_dir = os.path.normpath(f if os.path.isdir(f) else os.path.dirname(f)) if accept: # slist = hw['solutions'] if not CE else [os.path.basename(f)[:-3]] # base = None @@ -74,13 +71,12 @@ def snip_dir(source_dir, # Sources # if "assignments" in str(f) and "_grade.py" in str(f): # continue info = {'new_references': [], 'code_copyright': 'Example student code. This file is automatically generated from the files in the instructor-directory'} - paths = {} + # paths = {} solution_list = [] kwargs = {} cut_files = True run_files = True - nrem = censor_file(f, info, run_files=run_files, run_out_dirs=output_dir, cut_files=cut_files, solution_list=solution_list, - include_path_base=base, + nrem = censor_file(f, run_files=run_files, run_out_dirs=output_dir, cut_files=cut_files, solution_list=solution_list, base_path=dest_dir, references=references, **kwargs) @@ -88,7 +84,6 @@ def snip_dir(source_dir, # Sources print(f"{nrem}> {f}") n += nrem for rm_file, accept in acceptable: - # rm_file = l rm_file = os.path.abspath(rm_file) if not accept: if os.path.isfile(rm_file): diff --git a/src/snipper/snipper_main.py b/src/snipper/snipper_main.py index 58ac32a2b0710ed1ac5f50a3006f81e117518d31..4b9e7da801d544266fa1d473558daf5bd3d1ddad 100644 --- a/src/snipper/snipper_main.py +++ b/src/snipper/snipper_main.py @@ -1,31 +1,13 @@ import os -import functools -import textwrap import re + +from snipper.block_parsing import full_strip +from snipper.fix_i import run_i +from snipper.fix_r import fix_r from snipper.fix_s import save_s from snipper.fix_cite import fix_citations from snipper.fix_bf import fix_f, fix_b2 from snipper.fix_o import run_o -from snipper.legacy import indent, block_process - -def fix_r(lines): - for i,l in enumerate(lines): - if "#!r" in l: - lines[i] = indent(l) + l[l.find("#!r") + 3:].lstrip() - return lines - - -def strip_tag(lines, tag): - lines2 = [] - for l in lines: - dx = l.find(tag) - if dx > 0: - l = l[:dx] - if len(l.strip()) == 0: - l = None - if l is not None: - lines2.append(l) - return lines2 def rem_nonprintable_ctrl_chars(txt): @@ -39,111 +21,6 @@ def rem_nonprintable_ctrl_chars(txt): return txt -def run_i(lines, file, output): - extra = dict(python=None, output=output, evaluated_lines=0) - def block_fun(lines, start_extra, end_extra, art, head="", tail="", output=None, extra=None): - outf = output + ("_" + art if art is not None and len(art) > 0 else "") + ".shell" - lines = full_strip(lines) - s = "\n".join(lines) - s.replace("...", "..") # passive-aggressively truncate ... because of #issues. - lines = textwrap.dedent(s).strip().splitlines() - - if extra['python'] is None: - import os - if os.name == 'nt': - import wexpect as we - else: - import pexpect as we - an = we.spawn("python", encoding="utf-8", timeout=20) - an.expect([">>>"]) - extra['python'] = an - - analyzer = extra['python'] - def rsession(analyzer, lines): - l2 = [] - for i, l in enumerate(lines): - l2.append(l) - if l.startswith(" ") and i < len(lines)-1 and not lines[i+1].startswith(" "): - if not lines[i+1].strip().startswith("else:") and not lines[i+1].strip().startswith("elif") : - l2.append("\n") - - lines = l2 - alines = [] - - # indented = False - in_dot_mode = False - if len(lines[-1]) > 0 and (lines[-1].startswith(" ") or lines[-1].startswith("\t")): - lines += [""] - - for i, word in enumerate(lines): - analyzer.sendline(word) - before = "" - while True: - analyzer.expect_exact([">>>", "..."]) - before += analyzer.before - if analyzer.before.endswith("\n"): - break - else: - before += analyzer.after - - dotmode = analyzer.after == "..." - if 'dir(s)' in word: - pass - if 'help(s.find)' in word: - pass - if dotmode: - # alines.append("..." + word) - alines.append(">>>" + analyzer.before.rstrip() if not in_dot_mode else "..." + analyzer.before.rstrip()) - in_dot_mode = True - # if i < len(lines) - 1 and not lines[i + 1].startswith(" "): - # analyzer.sendline("\n") # going out of indentation mode . - # analyzer.expect_exact([">>>", "..."]) - # alines.append("..." + analyzer.after.rstrip()) - # pass - else: - alines.append( ("..." if in_dot_mode else ">>>") + analyzer.before.rstrip()) - in_dot_mode = False - return alines - - for l in (head[extra['evaluated_lines']:] + ["\n"]): - analyzer.sendline(l) - analyzer.expect_exact([">>>", "..."]) - - - alines = rsession(analyzer, lines) - extra['evaluated_lines'] += len(head) + len(lines) - lines = alines - return lines, [outf, lines] - try: - a,b,c,_ = block_process(lines, tag="#!i", block_fun=functools.partial(block_fun, output=output, extra=extra)) - if extra['python'] is not None: - extra['python'].close() - - if len(c)>0: - kvs= { v[0] for v in c} - for outf in kvs: - out = "\n".join( ["\n".join(v[1]) for v in c if v[0] == outf] ) - out = out.replace("\r", "") - - with open(outf, 'w') as f: - f.write(out) - - except Exception as e: - print("lines are") - print("\n".join(lines)) - print("Bad thing in #!i command in file", file) - raise e - return lines - - -def full_strip(lines, tags=None): - if tags is None: - tags = ["#!s", "#!o", "#!f", "#!b"] - for t in tags: - lines = strip_tag(lines, t) - return lines - - def censor_code(lines, keep=True): dbug = True lines = fix_f(lines, dbug) @@ -152,17 +29,15 @@ def censor_code(lines, keep=True): -def censor_file(file, info, run_files=True, run_out_dirs=None, cut_files=True, solution_list=None, +def censor_file(file, run_files=True, run_out_dirs=None, cut_files=True, solution_list=None, censor_files=True, base_path=None, - include_path_base=None, strict=True, references=None): if references == None: references = {} - dbug = False with open(file, 'r', encoding='utf8') as f: s = f.read() @@ -175,17 +50,14 @@ def censor_file(file, info, run_files=True, run_out_dirs=None, cut_files=True, s try: lines = fix_citations(lines, references, strict=strict) - # lines = s.split("\n") except IndexError as e: print(e) - print("Fuckup in file, cite/reference tag not found!>", file) + print("Error in file, cite/reference tag not found!>", file) raise e if run_files or cut_files: ofiles = [] for rod in [run_out_dirs]: - # if not os.path.isdir(rod): - # os.mkdir(rod) ofiles.append(os.path.join(rod, os.path.basename(file).split(".")[0]) ) ofiles[0] = ofiles[0].replace("\\", "/") @@ -193,11 +65,9 @@ def censor_file(file, info, run_files=True, run_out_dirs=None, cut_files=True, s run_o(lines, file=file, output=ofiles[0]) run_i(lines, file=file, output=ofiles[0]) if cut_files: - save_s(lines, file_path=os.path.relpath(file, base_path), output_dir=run_out_dirs) # save file snips to disk lines = full_strip(lines, ["#!s", "#!o", '#!i']) - # lines = fix_c(lines) if censor_files: lines = fix_f(lines, dbug) lines, nB, cut = fix_b2(lines) @@ -208,7 +78,7 @@ def censor_file(file, info, run_files=True, run_out_dirs=None, cut_files=True, s if censor_files and len(cut) > 0 and solution_list is not None: fname = file.__str__() i = fname.find("irlc") - wk = fname[i+5:fname.find("\\", i+6)] + # wk = fname[i+5:fname.find("\\", i+6)] # sp = paths['02450students'] +"/solutions/" # if not os.path.exists(sp): # os.mkdir(sp)