Skip to content

Commit 6f33d75

Browse files
committed
add print version
1 parent 37b52e0 commit 6f33d75

File tree

7 files changed

+654
-19
lines changed

7 files changed

+654
-19
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ $(PDF_EXERCISE): exercise/build/main.pdf
1212
cp $< $@
1313

1414
slides/build/main.pdf:
15+
./make_print_version.py slides/part1.tex && \
16+
./make_print_version.py slides/part2.tex && \
1517
cd slides && mkdir -p build && \
1618
lualatex -halt-on-error -jobname=build/main main.tex
1719

make_print_version.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
6+
7+
if __name__ == '__main__':
8+
if len(sys.argv) != 2:
9+
print(f'Error: Usage {sys.argv[0]} [file_name]')
10+
sys.exit(1)
11+
12+
file_name = sys.argv[1]
13+
if not os.path.isfile(file_name):
14+
print(f'Error: File \'{file_name}\' does not exist!')
15+
sys.exit(1)
16+
17+
out_lines = []
18+
skip_state = False
19+
with open(file_name, 'r') as f:
20+
for line in f.readlines():
21+
if line.strip().startswith('% REMOVE_FOR_PRINT {'):
22+
if skip_state:
23+
print('Parsing error!')
24+
sys.exit(2)
25+
26+
skip_state = True
27+
elif line.strip().startswith('% REMOVE_FOR_PRINT }'):
28+
if not skip_state:
29+
print('Parsing error!')
30+
sys.exit(3)
31+
32+
skip_state = False
33+
elif not skip_state:
34+
out_lines.append(line)
35+
36+
file_name = file_name.rstrip('.tex') + '_pv.tex'
37+
with open(file_name, 'w') as f:
38+
f.write(''.join(out_lines))

slides/main.tex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
\documentclass[compress,aspectratio=1610]{beamer}
22

3+
\usepackage{ifthen}
4+
\newboolean{printversion}
5+
\setboolean{printversion}{true}
6+
37
\usepackage[english]{babel}
48
\usepackage[english]{isodate}
59
\isodate
@@ -50,7 +54,10 @@
5054

5155
\maketitle
5256

57+
\ifthenelse{\boolean{printversion}}{%
58+
\include{part1_pv}
59+
\include{part2_pv}}{
5360
\include{part1}
54-
\include{part2}
61+
\include{part2}}
5562

5663
\end{document}

slides/part1.tex

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ \section{Syntax}
5353
\end{lstlisting}
5454
\end{frame}
5555

56-
\begin{frame}[fragile]{A: \texttt{444}}
56+
% REMOVE_FOR_PRINT {
57+
\begin{frame}[fragile,noframenumbering]{A: \texttt{444}}
5758
\begin{lstlisting}[language=python]
5859
#!/usr/bin/env python3
5960

@@ -66,6 +67,7 @@ \section{Syntax}
6667

6768
\hfill \textbf{Why?} \only<2>{implicit capture by reference}
6869
\end{frame}
70+
% REMOVE_FOR_PRINT }
6971

7072
\begin{frame}[fragile]{Fix}
7173
\begin{lstlisting}[language=python]
@@ -88,24 +90,30 @@ \section{Syntax}
8890
\begin{frame}[fragile]{Q: What is the output of the program?}
8991
\inputcpplisting{snippet34a}
9092

93+
% REMOVE_FOR_PRINT {
9194
\only<2>{\textbf{\textcolor{vertexDarkRed}{error:}} \enquote{k} is not captured}
95+
% REMOVE_FOR_PRINT }
9296
\end{frame}
9397

9498
\begin{frame}[fragile]{Q: What is the output of the program?}
9599
\inputcpplisting{snippet34b}
96100
\end{frame}
97101

98-
\begin{frame}[fragile]{A: \text{234}}
102+
% REMOVE_FOR_PRINT {
103+
\begin{frame}[fragile,noframenumbering]{A: \text{234}}
99104
\inputcpplisting{snippet34b}
100105
\end{frame}
106+
% REMOVE_FOR_PRINT }
101107

102108
\begin{frame}[fragile]{Q: What is the output of the program?}
103109
\inputcpplisting{snippet34c}
104110
\end{frame}
105111

106-
\begin{frame}[fragile]{A: \texttt{555} (not \texttt{444})}
112+
% REMOVE_FOR_PRINT {
113+
\begin{frame}[fragile,noframenumbering]{A: \texttt{555} (not \texttt{444})}
107114
\inputcpplisting{snippet34c}
108115
\end{frame}
116+
% REMOVE_FOR_PRINT }
109117

110118
\begin{frame}[fragile]{\texttt{C++}'s Lambda Expression}
111119
\textbf{Capturing rules}
@@ -146,32 +154,40 @@ \section{Syntax}
146154
\begin{frame}[fragile]{Q: What is the output of the program?}
147155
\inputcpplisting{snippet9a}
148156

157+
% REMOVE_FOR_PRINT {
149158
\only<2>{\textbf{\textcolor{vertexDarkRed}{error:}} cannot assign to a variable captured by copy in a non-mutable lambda}
159+
% REMOVE_FOR_PRINT }
150160
\end{frame}
151161

152162
\begin{frame}[fragile]{Q: What is the output of the program?}
153163
\inputcpplisting{snippet9b}
154164
\end{frame}
155165

156-
\begin{frame}[fragile]{A: \texttt{121}}
166+
% REMOVE_FOR_PRINT {
167+
\begin{frame}[fragile,noframenumbering]{A: \texttt{121}}
157168
\inputcpplisting{snippet9b}
158169
\end{frame}
170+
% REMOVE_FOR_PRINT }
159171

160172
\begin{frame}[fragile]{Q: What is the output of the program?}
161173
\inputcpplisting{snippet9c}
162174
\end{frame}
163175

164-
\begin{frame}[fragile]{A: \texttt{122}}
176+
% REMOVE_FOR_PRINT {
177+
\begin{frame}[fragile,noframenumbering]{A: \texttt{122}}
165178
\inputcpplisting{snippet9c}
166179
\end{frame}
180+
% REMOVE_FOR_PRINT }
167181

168182
\begin{frame}[fragile]{Q: What is the output of the program?}
169183
\inputcpplisting{snippet9d}
170184
\end{frame}
171185

172-
\begin{frame}[fragile]{A: \texttt{12}}
186+
% REMOVE_FOR_PRINT {
187+
\begin{frame}[fragile,noframenumbering]{A: \texttt{12}}
173188
\inputcpplisting{snippet9d}
174189
\end{frame}
190+
% REMOVE_FOR_PRINT }
175191

176192
\begin{frame}[fragile]{Q: What is the output of the program?}
177193
\inputcpplisting{snippet10}
@@ -181,13 +197,15 @@ \section{Syntax}
181197
\end{center}
182198
\end{frame}
183199

184-
\begin{frame}[fragile]{A: \texttt{11235}}
200+
% REMOVE_FOR_PRINT {
201+
\begin{frame}[fragile,noframenumbering]{A: \texttt{11235}}
185202
\inputcpplisting{snippet10}
186203

187204
\begin{center}
188205
(\href{https://en.cppreference.com/w/cpp/utility/exchange}{\texttt{cppreference.com/w/cpp/utility/exchange}})
189206
\end{center}
190207
\end{frame}
208+
% REMOVE_FOR_PRINT }
191209

192210
\begin{frame}{\texttt{C++}'s Lambda Expression}
193211
Remember, lambda expressions are pure syntactic sugar and are equivalent to \texttt{struct}s with an appropriate \texttt{operator()()} overload \ldots
@@ -197,22 +215,28 @@ \section{Syntax}
197215
\inputcpplisting{snippet11}
198216
\end{frame}
199217

200-
\begin{frame}[fragile]{A: \texttt{11}}
218+
% REMOVE_FOR_PRINT {
219+
\begin{frame}[fragile,noframenumbering]{A: \texttt{11}}
201220
\inputcpplisting{snippet11}
202221
\end{frame}
222+
% REMOVE_FOR_PRINT }
203223

204224
\begin{frame}[fragile]{Q: What is the output of the program?}
205225
\inputcpplisting{snippet12}
206226
\end{frame}
207227

208-
\begin{frame}[fragile]{A: \texttt{66}}
228+
% REMOVE_FOR_PRINT {
229+
\begin{frame}[fragile,noframenumbering]{A: \texttt{66}}
209230
\inputcpplisting{snippet12}
210231
\end{frame}
232+
% REMOVE_FOR_PRINT }
211233

212234
\begin{frame}[fragile]{Q: What is the output of the program?}
213235
\inputcpplisting{snippet13}
214236

237+
% REMOVE_FOR_PRINT {
215238
\only<2>{\textbf{\textcolor{vertexDarkRed}{error:}} call to implicitly-deleted copy ctor}
239+
% REMOVE_FOR_PRINT }
216240
\end{frame}
217241

218242
\begin{frame}[plain,noframenumbering]
@@ -226,21 +250,25 @@ \section{Stateful Lambdas}
226250
\inputcpplisting{snippet14}
227251
\end{frame}
228252

229-
\begin{frame}[fragile]{A: \texttt{3}}
253+
% REMOVE_FOR_PRINT {
254+
\begin{frame}[fragile,noframenumbering]{A: \texttt{3}}
230255
\inputcpplisting{snippet14}
231256
\end{frame}
257+
% REMOVE_FOR_PRINT }
232258

233259
\begin{frame}[fragile]{Q: What is the output of the program?}
234260
\inputcpplisting{snippet15}
235261
\end{frame}
236262

237-
\begin{frame}[fragile]{A: \texttt{5}}
263+
% REMOVE_FOR_PRINT {
264+
\begin{frame}[fragile,noframenumbering]{A: \texttt{5}}
238265
\inputcpplisting{snippet15}
239266

240267
\begin{center}
241268
($^*$ undefined in a threaded context, since \texttt{static} is not thread-safe!)
242269
\end{center}
243270
\end{frame}
271+
% REMOVE_FOR_PRINT }
244272

245273
\begin{frame}[fragile]{Stateful Lambdas}
246274
\textbf{Fibonacci (again)}:
@@ -338,9 +366,14 @@ \section{Best Practices}
338366
\end{lstlisting}
339367
\hfill \ldots given a sufficient implementation of \texttt{filters}
340368

341-
\only<2>{\scalebox{1.2}{\textbf{No! Horrible code!}}
342-
343-
Capturing only applies to non-\texttt{static} local variables. Why does this work?}
369+
% REMOVE_FOR_PRINT {
370+
\only<2>{%
371+
% REMOVE_FOR_PRINT }
372+
\scalebox{1.2}{\textbf{No! Horrible code!}}
373+
Capturing only applies to non-\texttt{static} local variables. Why does this work?
374+
% REMOVE_FOR_PRINT {
375+
}
376+
% REMOVE_FOR_PRINT }
344377
\end{frame}
345378

346379
\begin{frame}[fragile]{Avoid default capture modes}

0 commit comments

Comments
 (0)