-
Notifications
You must be signed in to change notification settings - Fork 92
/
von.sty
51 lines (47 loc) · 1.38 KB
/
von.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
\ProvidesPackage{von}[2016/08/06 v1.0 VON problem manager]
\usepackage{pythontex}
\usepackage{xstring}
\usepackage{xifthen}
\usepackage{color}
\newif\ifvonbrave\vonbravefalse
\DeclareOption{brave}{\vonbravetrue}
\DeclareOption{timid}{\vonbravefalse}
\DeclareOption{vonmargin}{\enablevonmargins}
\ProcessOptions\relax
\newcommand{\vonhook}[1]{}
\newcommand{\vonmarginstyle}{\scriptsize\ttfamily\color{Green}}%
\newcommand{\enablevonmargins}{%
\renewcommand{\vonhook}[1]{\marginpar{\vonmarginstyle{##1}}}}
\begin{pycode}
import von.api as api
\end{pycode}
\setpythontexoutputdir{.}
\newcommand{\@voncore}[2]{%
\ifvonbrave\py{api.get("#2", True).bodies[#1]}%
\else\py{api.get("#2", False).bodies[#1]}\fi
\vonhook{#2}}% for example a margin par
\newcommand{\voninclude}[2][0]{\@voncore{#1}{#2}}
\newcommand{\vonprehook}[1]{}
\newcommand{\vonposthook}[1]{}
\def\von{\@ifstar\@vonstar\@von}
\newcommand{\vonenvname}{problem}
\newcommand{\@von}[2][]{%
\ifvonbrave
\pyc{entry = api.get("#2", True)}
\else
\pyc{entry = api.get("#2", False)}
\fi
\pyc{src = "#1" or "#2"}
\begin{\vonenvname}[\py{(r'\href{' + entry.url + '}{' + src + '}') if entry.url is not None else src}]%
\vonprehook{#2}
\voninclude{#2}%
\vonposthook{#2}
\end{\vonenvname}%
}
\newcommand{\@vonstar}[1]{%
\begin{\vonenvname}
\vonprehook{#1}
\voninclude{#1}
\vonposthook{#1}
\end{\vonenvname}
}