Repository navigation
Expand file tree
/
Copy pathethuebung.sty
More file actions
5871 lines (5501 loc) · 258 KB
/
Copy pathethuebung.sty
File metadata and controls
5871 lines (5501 loc) · 258 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%
% Package ethuebung
%
% Some Definitions for Exercise sheets for ETH Zurich (german/english)
%
%
% !!! DO NOT EDIT THIS FILE. SEE NOTE BELOW. !!!
%
%
% The latest version of this style file, along with all necessary documentation and
% examples, can be found on github.com:
%
% https://github.com/phfaist/ethuebung
%
%
% Author: Philippe Faist (2012-2014)
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ethuebung}[2014/10/28 ethuebung package]
%
% NOTE: The same LaTeX file will compile both the "Uebungsblatt" and the "Musterloesung", by
% passing the [sol] option to the {ethuebung} package:
%
% \usepackage[sol]{ethuebung}
%
%
% NOTE: If you want the exercise sheet in German instead of in English, use
%
% \usepackage[deutch]{ethuebung} % will provide the Uebungsblatt
% or
% \usepackage[deutch,sol]{ethuebung} % will provide the Musterloesung
%
%
%
% NOTE: Do _NOT_ modify this file unless you are actively contributing to its development.
% A modified style sheet will break standards and will spread confusion as to
% which version one should use. ALL ASPECTS OF THE EXERCISE SHEET CAN BE CUSTOMIZED BY USE
% OF SPECIFIC LaTeX COMMANDS IN YOUR EXERCISE SHEET LATEX FILE. Have a look at the FAQ and
% documentation provided with the package. If you are in for more advanced customization,
% look at the source code here, but redefine the relevant commands **in your TeX
% file**. If you think there is a bug or a feature is missing from this package, you can
% contact me to propose a modification. If you fix the bug yourself, or modify this
% package in order to improve it, PLEASE let me know, in order to propagate your
% improvements or fixes upstream.
%
%
%
%
% ----
% Require some base pacakges
% ----
\RequirePackage{amssymb}
\RequirePackage{amsmath}
\RequirePackage{graphicx}
\RequirePackage{ifpdf}
\ifpdf
% This is to be done at \begin{document} to avoid an option clash with xcolor if options
% are given there. Indeed, pdfpages requires -> eso-pic requires -> xcolor ; so make
% sure this package requirement is done late.
\AtBeginDocument{\RequirePackage{pdfpages}}
\fi
% ----
% Some utilities
% ----
%
% Utility to test whether the argument contains any text.
%
% If #1 is not empty, then expands to #2, otherwise to #3.
%
\newcommand{\ueb@ifnotempty}[3]{%
{%
\setbox0=\hbox{#1}\ifdim\wd0=0pt%
#3%
\else%
#2%
\fi%
}%
}
%
%
% Utility to add a space before the argument, if the argument contains text
% Use this for combining labels for example,
% Exercise~\ref{exerciseref}\ueb@maybespace{\ref{exercisepart}} will work also in case
% \ref{exercisepart} expands to empty text.
%
% Taken from: http://tex.stackexchange.com/questions/53068/
%
%
\def\ueb@maybespace#1{%
{%
\setbox0=\hbox{#1}\ifdim\wd0=0pt%
% EMPTY
\else%
~#1% content, preceeded by a space
\fi%
}%
}
%
% Utility like \ueb@maybespace, except adds the space after the content instead of
% before.
%
\def\ueb@maybespaceafter#1{%
{%
\setbox0=\hbox{#1}\ifdim\wd0=0pt%
% EMPTY
\else%
#1~% content, then a space
\fi%
}%
}
%
% In the same spirit as before: insert space between two arguments only if both are
% non-empty.
%
\def\ueb@maybespacebetween#1#2{%
\ueb@ifnotempty{#1}{#1\ueb@maybespace{#2}}{#2}%
}
%
% Utility that takes one argument, and expands to nothing.
%
\def\ueb@killarg#1{}%
%
% utility to expand \arabic* etc. into \arabic{counter} for any given counter.
%
% This calls \ueb@defexpandstarcounter for each of \arabic, \Alph, \alph, \Roman, and
% \roman.
%
\def\ueb@defexpandexenumeratecounters#1{% e.g. {exenumeratei}
\ueb@defexpandstarcounter{#1}{\arabic}%
\ueb@defexpandstarcounter{#1}{\Alph}%
\ueb@defexpandstarcounter{#1}{\alph}%
\ueb@defexpandstarcounter{#1}{\Roman}%
\ueb@defexpandstarcounter{#1}{\roman}%
}
%
% Utility to redefine a counter formatter (e.g. \alph) to check if the argument is a star,
% and to use a specific counter if this is the case (like in enumitem)
%
% This redefines the given command (e.g. \alph) to check if the parameter is a star. If it
% is not a star, it acts normally, by expanding to \alph{<argument>} (but does not expand
% that command). If the parameter is a star, then the counter named by #2 is used:
% \alph{#2}. Again, that command is left unexpanded.
%
% See also enumitem.sty source.
%
\def\ueb@defexpandstarcounter#1#2{% e.g. {exenumeratei}{\alph}
\global\expandafter\let\csname ueb@old@\string #2\endcsname #2%
\def#2##1{%
\if*##1\@empty%
\expandafter\noexpand\csname ueb@old@\string #2\endcsname{#1}%
\else%
\expandafter\noexpand\csname ueb@old@\string #2\endcsname{##1}%
\fi%
}%
}
\newcommand{\ueb@withstarredcounters}[2][\ueb@TheStarredSymbol]{%
\begingroup%
\let\ueb@old@alph\alph%
\let\ueb@old@Alph\Alph%
\let\ueb@old@roman\roman%
\let\ueb@old@Roman\Roman%
\let\ueb@old@arabic\arabic%
\def\alph##1{\ueb@old@alph{##1}#1}%
\def\Alph##1{\ueb@old@Alph{##1}#1}%
\def\roman##1{\ueb@old@roman{##1}#1}%
\def\Roman##1{\ueb@old@Roman{##1}#1}%
\def\arabic##1{\ueb@old@arabic{##1}#1}%
#2%
\endgroup%
}
%
% Code from http://www.tug.org/TUGboat/tb17-1/tb50hose.pdf
% originally termed "\QNameLetName"
%
\def\ueb@NameLetName#1#2{%
\expandafter%
\expandafter%
\expandafter%
\let%
\expandafter%
\expandafter%
\csname#1\endcsname%
\csname#2\endcsname%
}
% ----
% Take care of exercise counters etc.
% ----
%
% Define a counter to number the exercises, and a counter for sub-exercises that is reset
% at each new exercise.
%
%
% Counter for \uebung{}/\exercise{}
%
\newcounter{uebcounter}
\setcounter{uebcounter}{0}
\renewcommand{\theuebcounter}{\arabic{uebcounter}}
\newcommand{\theHuebcounter}{\arabic{uebcounter}} % for hyperref
%
% Counter for \subuebung{}/\subexercise{}
%
\newcounter{subuebcounter}[uebcounter]
\setcounter{subuebcounter}{0}
\renewcommand{\thesubuebcounter}{\theuebcounter.\arabic{subuebcounter}}
\newcommand{\theHsubuebcounter}{\theHuebcounter.\arabic{subuebcounter}} % for hyperref
%
% internal label name for exercises. See \uebung{} and \subuebung{}: a label like this is
% automatically pinned on each new exercise.
%
\def\ueb@labelforthisexercise{exercise:\arabic{uebcounter}.\arabic{subuebcounter}}
%
% internal label name for exercise parts.
%
\def\ueb@labelforthisexercisepart{exercisepart:\arabic{uebcounter}.\arabic{subuebcounter}.\alph{exenumeratei}.\roman{exenumerateii}}
% ----
% Define what kind of LaTeX section/paragraph kind to use for new exercises,
% sub-exercises, and loesung sections.
% ----
%
% Define what kind of paragraph (or sectioning command) a \uebung{} should use. We simply
% use a plain old \paragraph{}.
%
% Note that this macro can take up to two arguments, the exercise label and the exercise
% title.
%
\newcommand{\ueb@uebparagraph}{\paragraph}
%
% Define what kind of paragraph (or sectioning command) a \subuebung{} should
% use. \subparagraph{} generates some ugly leading space, so we use a customized
% subparagraph-type sectioning command.
%
\newcommand{\ueb@subuebsubparagraph}{%
\@startsection{subparagraph}{5}%
{\z@}% no indent
{3.25ex \@plus1ex \@minus .2ex}% default taken from article.cls
{-0.5em}% default taken from article.cls
{\normalfont\normalsize\bfseries}% default taken from article.cls
}
%
% Utility to start a new paragraph with some standard lengths.
%
% #1 is indent, #2 is skip, #3 is formatting of the label.
%
% The default values are copied from article.cls.
%
\def\ueb@startsubparagraph#1#2#3{%
\@startsection{subparagraph}{5}%
{#1}%
{3.25ex \@plus1ex \@minus .2ex}%
{#2}%
{#3}%
}
%
% Utility to start a new paragraph with spacing and indent if #1 is non-empty (it's meant
% to be the subparagraph label).
%
\def\ueb@startsubparagraphSpaceIfNotEmpty#1{%
\ueb@ifnotempty{#1}{%
%
% In case we have a non-empty label
%
\gdef\ueb@tmp@dostartsection{%
\ueb@startsubparagraph{\parindent}{-1em}{\normalfont\normalsize\bfseries}%
}%
}{%
%
% In case we have an empty Label, don't start a subparagraph but simply a new
% paragraph, with some small additional space. This is needed because otherwise
% {loesung} blocks that start with \begin{exenumerate} with no exercise text add
% waaaayy too much space between the exercise heading and the first item of the list.
%
% Also, if you wish to further reduce the space.................................
%
\gdef\ueb@tmp@dostartsection{%
%
%\ueb@startsubparagraph{\z@}{\z@}{}%
%
\par%
\vspace{\ueb@subparagraphwithemptylabelparspace}%
}%
}%
%
\ueb@tmp@dostartsection%
%
}
%
% Hack... see above. this is the amount of space left after a 'loesungsubparagraph' with
% an empty label.
%
\def\ueb@subparagraphwithemptylabelparspace{1em}
%
% Define what kind of paragraph (or sectioning command) to use for the beginning of a
% `loesung' environment.
%
\newcommand{\ueb@loesungsubparagraph}{%
\ueb@startsubparagraphSpaceIfNotEmpty{\ueb@TheUebungSolLabel}%
}
%
% Define what kind of paragraph (or sectioning command) to use for the beginning of a
% `tips' environment.
%
\newcommand{\ueb@tipssubparagraph}{%
\ueb@startsubparagraphSpaceIfNotEmpty{\ueb@TheUebungTipsLabel}%
}
%
% Hooks for new exercises
%
\def\ueb@preuebunghook{}
\def\ueb@uebunghook{}
\def\ueb@presubuebunghook{}
\def\ueb@subuebunghook{}
%
% Use \ueb@AtUebung{ commands ... } and \ueb@AtSubUebung{ ... } to execute arbitrary
% commands at the beginning of a new exercise or a new sub-exercise. These commands are
% inspired by \def\AtBeginDocument in latex.ltx.
%
\def\ueb@AtBeforeUebung{\g@addto@macro\ueb@preuebunghook}
\def\ueb@AtUebung{\g@addto@macro\ueb@uebunghook}
\def\ueb@AtBeforeSubUebung{\g@addto@macro\ueb@presubuebunghook}
\def\ueb@AtSubUebung{\g@addto@macro\ueb@subuebunghook}
% ----
% Commands for new exercise and sub-exercise
% ----
% Some internal utilities first.
%
% Format an annotation to an exercise. For example, the number of points that are awarded
% for successfully completing the exercise.
%
\newcommand{\ueb@exerciseannot}[1]{%
% {\vspace*{-1.2em}\begin{flushright}\footnotesize\emph{[#1]}\end{flushright}\vspace*{-1ex}}%
{ \def\annot{\uebExerciseAnnotation{#1}}
\setbox0=\hbox{\annot}%
\setbox1=\hbox{[with short annotation]}% reference width for "short annotation"
\ifdim\wd0<\wd1%
% short annotation: can be displayed on the same line
%
{% this code taken from http://tex.stackexchange.com/questions/16330
\unskip\nobreak\hfil\penalty50
\hskip1em\hbox{}\nobreak\hfil\annot%
\parfillskip=0pt \finalhyphendemerits=0\par%
}%
\else%
% longer annotation: use new line
\\[1pt]%
{\vbox{\raggedleft\annot}}%
\fi%
}%
}
%
% Set this macro to some short text. The width of this text will be used as reference to
% what is considered a "short annotation" (ie., which will be displayed on the same line)
%
\def\ueb@shortannotationreftextwidth{[short annotation]}
%
%
% Commands to issue to pin down a number to this exercise. essentially refsteps's
% uebcounter. This also sets \uebTheUebungNumber to the current \theuebcounter.
%
\newcommand{\ueb@numberthisuebung}{%
%
% Step the exercise number counter.
%
\refstepcounter{uebcounter}%
%
% Automatically assign an internal label to this exercise. See also
% \ueb@labelforthisexercise.
%
\expandafter\label{\ueb@labelforthisexercise}%
%
\let\uebTheUebungNumber\theuebcounter%
%
}%
%
% To be called for exercises without number (\uebung*{}). Also sets \uebTheUebungNumber to
% an empty macro.
%
\newcommand{\ueb@thisuebungnonumber}{%
%
% \uebung*{}: don't number this uebung.
%
\def\uebTheUebungNumber{}%
%
}
% *** Exercise ***
%
% LaTeX Command for an *exercise title* such as "Exercise 1.". Implemented based on LaTeX
% \paragraph{} stuff.
%
% Usage is \uebung{<Uebung title>}
% \uebung*{<Uebung title>}
% \uebung{<Uebung title>}[<annotation>]
% \uebung*{<Uebung title>}[<annotation>]
%
\newcommand{\uebung}{%
%
% Produce a warning if the \uebung or \exercise command is misplaced
%
\ifdefined\ueb@marker@WarnOn@exercise%
\PackageWarning{ethuebung}{%
**** Misplaced \protect\uebung, your exercise might not appear on all versions (ex,
sol, tips) of the sheet: \ueb@marker@WarnOn@exercise.%
}%
\else%
\fi%
%
% Use latex' \@ifstar. Choose the correct corresponding \@uebungstar or \@uebung macro.
%
\@ifstar{\@uebungstar}{\@uebung}%
%
}
%
%
%
\newcommand{\@uebung}[1]{%
%
% Save the uebung title
%
\def\ueb@uebzetitle{#1}%
%
%
% Set up usual Uebung numbering
%
\def\ueb@doThisUebungNumber{\ueb@numberthisuebung}%
%
% And start the exercise, taking into account the possible annotation that might be
% there. \ueb@startuebung is a macro that takes an optional argument.
%
\ueb@startuebung%
%
}
\newcommand{\@uebungstar}[1]{%
%
% Save the uebung title
%
\def\ueb@uebzetitle{#1}%
%
% Set up no numbering
%
\def\ueb@doThisUebungNumber{\ueb@thisuebungnonumber}%
%
% And start the exercise, taking into account the possible annotation that might be
% there. \ueb@startuebung is a macro that takes an optional argument.
%
\ueb@startuebung%
%
}
%
% Start a new exercise, using the optional argument as annotation, and \ueb@uebzetitle as
% exercise title.
%
% \uebung will expand to this macro, once it has consumed the exercise title. This is
% needed so that the optional annotation can be given _after_ the exercise title.
%
\newcommand{\ueb@startuebung}[1][]{%
\def\ueb@theexannotation{#1}%
\expandafter\@@uebung{\ueb@uebzetitle}%
}
%
%
% Start a new exercise.
%
\newcommand{\@@uebung}[1]{%
%
%
% Run custom-set commands for pre-exercise, if any.
%
\ueb@preuebunghook%
%
%
% in case we're providing {exenumerate}, reset the counter to restart from (a). Note
% that this command is defined also if we don't provide {exenumerate} environment as a
% no-op.
%
\exenumeratereset%
%
%
% Prepare the commands that we will run in the uebung label. This involves incrementing
% the exercise counter. (We have to do this in the label, not before, because otherwise
% we might \refstepcount{} the counter just before a page break. Even \leavevmode does
% not help always because \paragraph{} usually adds some space.)
%
\def\ueb@tmp@fulluebunglabelarg{%
%
% Set an exercise number, and set the \ueb@ThisUebungNumber to \theuebcounter. If
% \uebung*{} was used, then this command will not do anything and set
% \ueb@ThisUebungNumber to an empty value.
%
\ueb@doThisUebungNumber{}%
%
% Display the exercise label.
%
\uebTheUebungLabel%
}%
%
% Now actually start the LaTeX \paragraph{} and display the title of the exercise. Don't
% forget to protect \ueb@tmp@fulluebunglabelarg because it is a fragile command!!
%
\ueb@uebparagraph{\protect\ueb@tmp@fulluebunglabelarg{}}{\ueb@TheExTitleFont{#1}}%
%
%
% If there is an annotation, display it
%
\ueb@ifnotempty{\ueb@theexannotation}{\ueb@exerciseannot{\ueb@theexannotation}}{}%
%
%
% Make sure we start a new paragraph, don't continue on the same line as the exercise
% title.
%
\par%
%
%
% Run custom-set commands, if any.
%
\ueb@uebunghook%
%
}
%
% In case this command gets taken into TOC or anywhere else...
%
\def\ueb@tmp@fulluebunglabelarg{}
%
% define \exercise as alias for \uebung
%
\def\exercise{\uebung}
% *** Sub-Exercise ***
%
% Like for \uebung{}.
%
\newcommand{\subuebung}[1]{%
%
% Start a new sub-exercise.
%
%
% Produce a warning if the \subuebung or \subexercise command is misplaced
%
\ifdefined\ueb@marker@WarnOn@exercise%
\PackageWarning{ethuebung}{%
**** Misplaced \protect\subuebung, your sub-exercise might not appear on all
versions (ex, sol, tips) of the sheet: \ueb@marker@WarnOn@exercise.%
}%
\else%
\fi%
%
% Run custom-set commands for pre-sub-exercise, if any.
%
\ueb@presubuebunghook%
%
%
% in case we're providing {exenumerate}, reset the counter to restart from (a).
%
\exenumeratereset%
%
% Step the sub-exercise number counter.
%
\refstepcounter{subuebcounter}%
%
% Assign an automatic label to this exercise. See also \ueb@labelforthisexercise.
%
\expandafter\label{\ueb@labelforthisexercise}%
%
%
% Now actually start the LaTeX \subparagraph{} (or whatever) and display the title of
% the exercise.
%
% To change the label displayed, use e.g. \UebungSubLabel{Aufgabe}, you don't have to
% change this source file
%
\ueb@subuebsubparagraph{\uebTheUebungSubLabel}{\ueb@TheSubExTitleFont{#1}}\hspace*{3ex}%
%
% Don't force a new paragraph, in case the user wants to continue on the same
% line. The user can still force a newline simply by leaving an empty line after \subuebung{}.
%
%
% Run custom set commands, if any
%
\ueb@subuebunghook%
%
}
%
% define \subexercise as alias for \subuebung
%
\def\subexercise{\subuebung}
%
% Keywords for exercises. This is a dummy command: it will only serve as placeholder for
% external tools that will scan the LaTeX file. This command itself expands to nothing.
%
\newcommand{\keywords}[1]{}
% ----
% Two utilities (intended for the solutions): an environment that discard its contents and
% an environment that simply shows it normally.
% ----
%
% This will be used as building block for {loesung}, {onlymusterloesung}
% etc. environments.
%
\newsavebox{\ueb@thecontentsthatwillbediscarded}
\newenvironment{uebhidecontents}{% begin hide contents environment
%
% create a box to hold the contents, and then we'll discard it
%
\setbox\ueb@thecontentsthatwillbediscarded=\vbox\bgroup%
%
% Define a marker so that we know that we're inside a {uebhidecontents} environment.
%
\def\ueb@marker@In@uebhidecontents{}%
\providecommand\ueb@marker@WarnOn@exercise{within
\protect\begin{notuebungsblatt}...\protect\end{notuebungsblatt} environment (or
such)}%
%
% Redefine some LaTeX commands to no-ops to avoid some warnings and errors like
% "undefined reference"'s, or "float lost".
%
\let\ref\ueb@killarg%
\def\figure{}\def\endfigure{}%
\def\table{}\def\endtable{}%
\let\caption\relax%
%
% This allows labels to be produced in AUX file even if they are hidden. Useful, e.g.,
% for equations within {onlyuebungsblatt} that you want to reference from the solutions.
%
\let\ueb@old@write\write%
\def\write{\immediate\ueb@old@write}%
%
}{%
% end defs
%
\egroup% close the group
%
}
\newenvironment{uebshowcontents}{% dummy environment that just displays its contents.
\bgroup%
%
% Define a marker so that we know that we're inside a {uebshowcontents} environment.
%
\def\ueb@marker@In@uebshowcontents{}%
\providecommand\ueb@marker@WarnOn@exercise{within
\protect\begin{onlyuebungsblatt}...\protect\end{onlyuebungsblatt} environment (or
such)}%
%
}{ %end defs
\egroup%
}
% ----
% Counters for equations in different contexts.
% ----
\renewcommand{\theequation}{\uebExerciseEqLabel}
%
% Creates definitions for a new `equation context' such as for solutions or for tips
% parts.
%
% For example,
% \ueb@makeeqcontext{loesung}{L.\arabic{equation}}
% will define the command \ueb@eqcontext@loesung, which you can call to enter 'loesung'
% equation context with equations numbered L.1, L.2, etc.
%
% Remember to call \ueb@eqcontext@<...> within a LaTeX group ( with braces,
% {\ueb@eqcontext@<...> ... } , or with \bgroup\ueb@eqcontext@<...> ... \egroup ), so that
% the original equation definitions are restored afterwards.
%
\def\ueb@makeeqcontext#1#2{%
\edef\ueb@tmp@eqcontextcountername{uebeq#1}%
\expandafter\newcounter{\ueb@tmp@eqcontextcountername}%
\expandafter\def\csname ueb@eqcontext@#1\endcsname{%
\expandafter\let\expandafter\c@equation\csname c@uebeq#1\endcsname%
\renewcommand{\theequation}{#2}%
\ueb@makeeqcontext@redefHequation{#1.\arabic{equation}}% for hyperref
%
}%
}%
\def\ueb@makeeqcontext@redefHequation#1{} % will be defined when importing hyperref
%
% For {loesung} sections
%
\ueb@makeeqcontext{loesung}{\uebLoesungEqLabel}
%
% For {tips} sections
%
\ueb@makeeqcontext{tips}{\uebTipsEqLabel}
% ----
% Solutions environments
% ----
% *** Solution ***
%
% Define two environments, showloesung and hideloesung. One of these two will be aliased
% to {loesung} to display or to hide loesung contents.
%
%
% A base environment that sets up font and equation numbering and encloses everything into
% a group. This is used also for \begin{onlymusterloesung}...\end{onlymusterloesung} etc.
%
\newenvironment{showloesungenv}{%
% begin shown loesung environment
%
%
% Enclose everything inside \bgroup ... \egroup, so that definitions stay local to the
% environment.
%
\bgroup%
%
% Define a marker so that we know that we're inside a {showloesungenv} environment.
%
\def\ueb@marker@In@showloesungenv{}%
\providecommand\ueb@marker@WarnOn@exercise{within \protect\begin{loesung}...\protect\end{loesung} environment}%
%
% Setup the font for the loesung
%
\ueb@TheLoesungFont%
\let\normalsize\ueb@TheLoesungFont%
%
% Setup equation numbering.
%
\ueb@eqcontext@loesung%
%
}{% end loesung-type environment defs
%
% This \par is needed to fix line spacing of the last paragraph in the loesung
% environment.
%
\par%
%
%\ueb@setueb% this is not needed since our redefinitions of equation numbering are
% enclosed inside a \bgroup ... \egroup
\egroup%
}%
%
% An environment that displays its contents, with a small label, a special font and proper
% equation numbering.
%
\newenvironment{showloesung}{%
%
% Set ourselves in a loesung-type environment
%
\showloesungenv%
%
% Define a marker so that we know that we're inside a {showloesung} environment. This is
% inside a \bgroup...\egroup so these definitions are local to the environment.
%
\def\ueb@marker@In@showloesung{}%
\def\ueb@marker@WarnOn@exercise{within \protect\begin{loesung}...\protect\end{loesung} environment}%
%
% Display the label, and start the LaTeX (sub)paragraph
%
\ueb@loesungsubparagraph{\ueb@TheUebungSolLabel}% font is already in effect
%\ueb@loesungsubparagraph{\ueb@TheLoesungFont{\ueb@TheUebungSolLabel}}%
%
% If we're outside an {exenumerate} environment, reset it so that the exenumerate that
% will be in the solution starts from (a) again.
%
\ifdefined\@enumctr\else%
\exenumeratereset% Reset {exenumerate} counter
\fi%
%
}{% end loesung environment defs
%
\endshowloesungenv%
%
\vspace{\uebLoesungEndVSpace}%
%
}
%
% An environment that discards all its contents. Loesung equation numbering is set up so
% as not to mess up surrounding equation numbering if there are equations in the
% contents.
%
\newenvironment{hideloesung}{%
%
% begin hidden loesung environment
%
%
% Use {uebhidecontents} environment defined above.
%
\uebhidecontents%
%
% Enclose everything inside \bgroup ... \egroup
%
\bgroup%
%
% Define a marker so that we know that we're inside a {hideloesung} environment.
%
\def\ueb@marker@In@hideloesung{}%
\def\ueb@marker@WarnOn@exercise{within \protect\begin{loesung}...\protect\end{loesung} environment}%
%
% The equations will still be processed and assigned numbers, but just not displayed!
%
\ueb@eqcontext@loesung%
%
%
}{% end loesung environment defs
%
%
% Close the \bgroup ... \egroup
%
\egroup%
%
%\ueb@setueb% this is not needed since our redefinitions of equation numbering are
% enclosed inside a \bgroup ... \egroup
%
% Close the {uebhidecontents} environment
%
\enduebhidecontents%
%
}
%
% define \begin{loesung}...\end{loesung} as in exercise sheet mode, i.e. just hide its
% solutions content. This will be overwritten by the \UebungMakeSolutionsSheet command.
% This makes \begin{loesung}...\end{loesung} an alias of the {hideloesung} envionment.
%
\def\loesung{\hideloesung}
\def\endloesung{\endhideloesung}
%
% define \begin{solution}...\end{solution} as an alias of the {loesung} environment,
% whichever that one actually is in the end (show or hide solutions). Use \def and not
% \let because the meaning of {loesung}/\loesung might change.
%
\def\solution{\loesung}
\def\endsolution{\endloesung}
% ----
% Solutions provided as PDF Attachments (eg. scanned handwritten solutions)
% ----
%
% solution as PDF attachment: the pdf pages are inserted at the end of the document, and
% referred to appropriately. The inserted pages are superimposed with a title referring to
% which exercise those pages offer a solution to.
%
%
% Define a counter for the attached solutions, to identify different attached
% solutions. Used for creating labels at where the solutions are included.
%
\newcounter{uebattachedsolutionscounter}
\setcounter{uebattachedsolutionscounter}{0}
%
% internal sequence of commands for including a PDF solution at end of document
%
% Usage: \ueb@solattached@AtEndDocumentCommands%
% {\ueb@labelforthisexercise}%
% {\ueb@labelforthisexercisepart}%
% {<PDF file>}%
% {<\includepdf options>}
%
\def\ueb@solattached@AtEndDocumentCommands#1#2#3#4{%
\def\ueb@solattached@labelforthisexercise{#1}%
\def\ueb@solattached@labelforthisexercisepart{#2}%
\def\ueb@solattached@pdftoinclude{#3}%
\def\ueb@solattached@pdfincludeoptions{#4}%
%
\def\ueb@solattached@theexercise{\expandafter\ref{\ueb@solattached@labelforthisexercise}}%
\def\ueb@solattached@theexercisepart{\expandafter\ref{fullexpart:\ueb@solattached@labelforthisexercisepart}}%
\def\uebattachedsolutiontheexercisenumber{\ueb@AttachSolutionTheExerciseNumber}%
%
\setlength\unitlength{1pt}%
\includepdf[pagecommand={%
\ueb@AttachSolutionIncludepdfPageCommand%
},%
picturecommand*={%
% add the label to the first page of our solutions
\refstepcounter{uebattachedsolutionscounter}\expandafter\label{solattached:\ueb@solattached@labelforthisexercisepart}%
% add any custom overlay stuff to the first page only
\ueb@AttachSolutionIncludepdfPictureCommandStar%
}, %
picturecommand={%
% add overlay stuff to each included page; this is by default our title
\ueb@AttachSolutionIncludepdfPictureCommand%
}, #4]% those where the options to \includepdf[]{}
{\ueb@solattached@pdftoinclude}% the pdf file to include
}%
%
% The command that will actually implement \pdfloesung. This takes care of inserting some
% loesung text with a reference to the page on which the PDF is included, and takes care
% of inserting proper \AtEndDocument{} stuff for PDF inclusion.
%
% Usage: \pdfloesung[<\includepdf options>]{<PDF file>}
% \pdfloesung{<PDF file>}
%
\newcommand{\ueb@dopdfloesung}[2][pages={-}]{%
%
% Insert some text that we're attaching the solution to this exercise at the end of the
% sheet, and mark the given PDF file for inclusion at end of document.
%
% Attach a label here.
%
\expandafter\label{\ueb@labelforthisexercisepart}%
%
% If we're inside an {exenumerate} environment, then pin a label to this exercise part.
%
\ifueb@haveexenum%
\expandafter\ueb@exenumfulllabel{fullexpart:\ueb@labelforthisexercisepart}%
\else\fi%
%
% Display some text inviting the user to look at the end of the document at e.g. a
% specific page number.
%
\begin{loesung}%
\def\uebthepageattached{\expandafter\pageref{solattached:\ueb@labelforthisexercisepart}}%
{\ueb@TheTextAttachedSolution}%
\end{loesung}%
%
%
% define a specific macro (identified by the PDF file name..... ugh!) for including the
% PDF at the end of the file, keeping the current values (pdf file, ex #, label)
%
\expandafter\xdef\csname AtEndDocCmds@#2\endcsname{%
\noexpand\ueb@solattached@AtEndDocumentCommands%
{\ueb@labelforthisexercise}%
{\ueb@labelforthisexercisepart}%
{#2}%
{#1}%
}%
%
% and now mark that macro to be called at the end of the document.
%
\expandafter\AtEndDocument{\csname AtEndDocCmds@#2\endcsname}%
%
}