-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathCloze.sty
More file actions
156 lines (154 loc) · 3.67 KB
/
Copy pathMathCloze.sty
File metadata and controls
156 lines (154 loc) · 3.67 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{latex2anki}
\newif\ifplastex
\RequirePackage{amsmath,amssymb}% note that amssym includes amsfonts
\ifplastex\else\RequirePackage{xcolor}\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifplastex\else
\RequirePackage[a4paper]{geometry}
\geometry{paperwidth=.5\paperwidth,paperheight=.25\paperheight,left=2em,right=2em,bottom=1em,top=2em}
\pagestyle{empty}
\setlength{\parindent}{0in}
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifplastex
\newenvironment{note}[1]{}{}
\newcommand{\field}{
((FIELDSEPARATOR))
}
\newcommand{\cloze}[1]{((CLOZE#1))}
\newcommand{\hint}{((HINT))}
\newcommand{\clend}{((CLEND))}
\else
\newcounter{fieldcounter}
\newcounter{notecounter}%only for debugging
\newif\ifnote\notefalse
\newif\iffield\fieldfalse
\newif\ifcloze\clozefalse
\newif\ifhint\hintfalse
\newcommand{\field}{%
%%% syntax error detection:
\ifcloze%
\PackageError{latex2anki}{unclosed cloze (missing clend command before field command)}{}%
\fi%
\ifnote\else%
\PackageError{latex2anki}{field command can only be used in note environment}{}%
\fi
\fieldtrue
%%%
\ifcase\value{fieldcounter}%
\par\bigskip
\bfseries
% Titel
\or%
\par\bigskip
\mdseries
% Prompt
\or%
\par\bigskip
\textit{Background info:}
% Zusatz
\or%
\par\bigskip
\vfill
\hfill \color{gray}%Kapitelname
\or%
-- %Def/Satz/Bsp
\or%
% Nummer
\else
%%% syntax error detection:
\PackageError{latex2anki}{note environment has more than 6 fields}{}%
%%%
\fi
\stepcounter{fieldcounter}%
}
\newenvironment{note}[1]{%
\stepcounter{notecounter}%
\PackageInfo{latex2anki}{((BEGINNOTE \arabic{notecounter}))}%
%%% syntax error detection:
\notetrue%
%%%
\setcounter{fieldcounter}{0}%
%\pagecolor{yellow}%
\color{black}%
\begin{samepage}%
{\tiny%
\par\noindent\rule{\textwidth}{0.8pt}%
\par\texttt{\parbox[t]{\textwidth}{#1}}%uuid
}%
}{%
\end{samepage}%
%%% syntax error detection:
\ifcloze%
\PackageError{latex2anki}{unclosed cloze (missing clend command before end of note)}{}%
\fi%
\notefalse%
\fieldfalse%
%%%
\clearpage%
}
\newcommand{\cloze}[1]{%
\ifmmode
\text{\textbf{\textcolor{gray}{\{}}}%
\else
\textbf{\textcolor{gray}{\{}}%
\fi
%%% syntax error detection:
\ifcloze
\PackageError{latex2anki}{unclosed cloze (missing clend command next cloze)}{}%
\fi
\iffield\else%
\PackageError{latex2anki}{missing field command before cloze command}
\fi
\clozetrue%
%%%
\ifcase\numexpr#1-1\relax%
\color{blue}%
\or%
\color{green}%
\or%
\color{purple}%
\or%
\color{pink}%
\else%
\color{gray}%
\fi%
}
\newcommand{\hint}{%
%%% syntax error detection:
\ifcloze\else%
\PackageInfo{latex2anki}{Possibly misplaced hint command: is this hint between a cloze and a clend?}{}%
\fi%
\ifhint%
\PackageError{latex2anki}{misplaced hint command: cloze cannot have more than one hint}{}%
\fi%
\hinttrue%
%%%
\color{gray}
\ifmmode
\text{\textbf{\textcolor{gray}{~:~}}}%
\else
\textbf{\textcolor{gray}{~:~}}%
\fi
}
\newcommand{\clend}{%
%%% syntax error detection:
\ifcloze\else
\PackageInfo{latex2anki}{Possibly misplaced clend command: is there a cloze to close here?}{}%
\fi
\clozefalse%
\hintfalse%
%%%
% Need to end in text mode when called within text mode,
% otherwise \clend causes spacing issues when used at the end
% of a paragraph. This is the reason I employ \ifmmmode here.
\ifmmode
\text{\textbf{\textcolor{gray}{\}}}}%
\else
\textbf{\textcolor{gray}{\}}}%
\fi
\color{black}%
}
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%