summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/exesheet/exesheet.dtx
blob: 04cdd77b5b9e805a54e0ed203148715c172b41ac (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
% \iffalse meta-comment
%
% Copyright (C) 2020-2021 by Antoine Missier <antoine.missier@ac-toulouse.fr>
% ----------------------------------------------------------------------
% 
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
%    http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX 
% version 2005/12/01 or later.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{exesheet.dtx}
%</driver>
%<class|package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
%<class>\ProvidesClass{exesheet}
%<package>\ProvidesPackage{exesheet}
%<*class|package>
[2023/01/16 v2.0 .dtx exesheet file]
%</class|package>
%<*driver>
\documentclass{ltxdoc}
%
% uncomment the following lines if you want to use the exesheet class instead of ltxdoc
%\usepackage{doc}
%\AtBeginDocument{\MakeShortVerb{\|}}
%\providecommand\marg[1]{{\ttfamily\{}\meta{#1}{\ttfamily\}}}
%\providecommand\oarg[1]{{\ttfamily[}\meta{#1}{\ttfamily]}}
\usepackage[exetoc=false,marginwidth=unset,display=notes]{exesheet}
\usepackage{schooldocs}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{lmodern}
\usepackage{multicol}
\usepackage{hyperref}
\usepackage{sectsty}
\usepackage{pstricks}
\usepackage{array}
\usepackage{spacingtricks}
\usepackage{centeredline}
%
\psset{unit=1cm}
\geometry{textwidth=355pt,vmarginratio=1:1,hmarginratio=3:2}
% altered by schoodocs, now very close from the default geometry used by ltxdoc.
% The following instruction gives the same margin width
% as with display=notes without altering the margin ratio
\leftnotemarginwidth{0.55} % special setting here
\newcommand{\ds}{\displaystyle}
\newcommand{\bs}{\textbackslash}
\definecolor{darkbrown}{rgb}{0.5,0.1,0.1}
\allsectionsfont{\sffamily\color{darkbrown}}
\renewcommand{\labelexercisestyle}{\rmfamily\color{black}}
\renewcommand{\labelsubpartstyle}{\rmfamily\color{black}}
\renewcommand{\annexstyle}{\rmfamily\color{black}\MakeUppercase}
\renewcommand{\correctionstyle}{\rmfamily\color{correctioncolor}}
\renewcommand{\titlestyle}{\LARGE\sffamily\bfseries}
%
\DisableCrossrefs
%\CodelineIndex
%\RecordChanges
\title{The \textsf{exesheet} class and package}
\subject{Antoine Missier \\
    \texttt{antoine.missier@ac-toulouse.fr}}
\date{\filedate, \fileversion}
\hypersetup{%
    colorlinks,
    linkcolor=blue,
    pdftitle={exesheet},
    pdfsubject={LaTeX class and package},
    pdfauthor={Antoine Missier}
}

\begin{document}
\DocInput{exesheet.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{1118}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v0.0}{2010/09/01}{Initial personal version}
% \changes{v0.9}{2020/01/02}{Initial documentation in french}
% \changes{v1.0}{2020/07/22}{Initial public version with documentation in english}
% \changes{v1.1}{2021/08/30}{
%    Macro tablenum (also used by siunitx) replaced by tablenum1, 
%    small modifications due to changes in tasks package}
%
% \changes{v1.2}{2021/09/18}{
%    Bug correction in macros tablenum1 and tablenuma, 
%    using the translations package for internationalization}
%
% \changes{v1.3}{2021/11/15}{
%    Bad spacing in the exe macro and bug correction in the starred version of this macro}
%
% \changes{v2.0}{2022/12/28}{
%    options toc and setlist with kvoptions (instead of notoc and nosetlist),
%    introducing the key 'output' instead of old commands questionsonly, answersonly,
%    introducing the key 'display' instead of old command displaypts, displaypoints,
%        displaynotes,
%    introducing the keys 'margin' and 'noteragged' to set how the notes are displayed,
%    introducing the key 'correct'}
% \changes{v2.0}{2023/01/02}{
%    documentation update,
%    new option checkpts}
% \changes{v2.0}{2023/01/09}{
%    new option 'marginwidth', 
%    modifying hmarginratio from 5:1 to 3:1 when display=notes,
%    correct management of two side mode documents}
% \changes{v2.0}{2023/01/16}{
%    \enskip between titles and their optional argument,
%    simplifying macros markingstyle and notestyle,
%    use of ragged2e package,
%    code revision and simplification,
%    documentation update}
%
% \GetFileInfo{exesheet.dtx}
%
% \maketitle
% \tableofcontents
% \enlargethispage{1ex}
%
% \section{Introduction}
%
% The \textsf{exesheet} \emph{package} is used for typesetting exercise or exam sheets.
% In addition, the \textsf{exesheet} \emph{class} loads the \textsf{schooldocs} package.
% This one makes adjustments for margins and title and defines various layout styles 
% with particular header and footer, appropriate for exercise sheets (among others).
% See the \textsf{schooldocs} documentation for more details.
% The \textsf{exesheet} \emph{class} is based on \textsf{article} 
% and passes to it its unknown options.
%
% Many other packages are dedicated to exercise sheets.
% Most propose to encapsulate each exercise in an environment
% whereas \textsf{exesheet} begins each exercise with |\exercise|, 
% which works like a subsection (with the same features)
% and is suitable for documents consisting exclusively of exercises.
% The package provides also alternative formatting, 
% more relevant for short exercises.
%
% Another specificity of the \textsf{exesheet} package is the particular settings
% for enumeration lists, 
% useful for the numbering of questions or answers inside an exercise.
%
% Other packages provide often more or less elaborate mechanisms
% to manage the placement of answers.
% \textsf{exesheet} has no such ambitions, however,
% for all exercises of the sheet, you can display questions only, 
% answers only or both, but always at the place they are inserted
% in the source file. On the other hand this choice may be very flexible:
% you can do a correct version for all exercises together, or a correction per exercise,
% per part (subpart of exercise), per question, per sub-question.
%
% Finally this package enables to display 
% a detailed marking scheme in the margin,
% with optional explanations or remarks, 
% and with consistency control.
%
% Many settings can be changed and several options manage the output document.
% These options are based on the keyval mechanism: \texttt{key=value}
% (thanks to Maxime Chupin and Denis Bitouzé for their wise ideas to improve this package).
% The options can be passed to class or package, \eg
% \begin{center}
% |\documentclass[a4paper,11pt,output=answers,display=pts]{exesheet}|
% \end{center}
% or later with the |\exesheetset|\marg{options} command.
% In the example above, \texttt{a4paper,11pt} are options
% passed to the underlying class \textsf{article}.
%
%\medskip
% \emph{In the current document, a frame is used to highlight 
% examples output.}
%
% \section{Titles}
%
% \subsection{The \texttt{\bs exercise} command}
%
% \DescribeMacro{\exercise}
% Each exercise begins with the |\exercise|\oarg{opt} command. 
% This command typesets \textbf{\exercisename}, as a document
% subsection, followed by automatic numbering,
% unique for the whole document.
% The optional parameter \meta{opt} is used to put additional text
% on the same title line, for example to precise a subject or a marking scheme.
% |\exercise[(to begin)]| yields:
%
% \exercise[(to begin)]
% \psframe(-0.25,1.3)(12.75,-0.3)
% Try to use this first command now, it's easy.
%
% \bigskip
% To bring additional text closer to the exercise number, 
% we can use |\unskip| which eliminates preceding space, 
% and also |\hrulefill| can be put in the optional argument 
% to produce an horizontal rule.
% See the following example, obtained with \\
% |\exercise[\unskip*** (difficult)]|:
% \exercise[\unskip*** (difficult)]
% \psframe(-0.25,1.3)(12.75,-0.3)
% Calculate $1+1$.
%
% \bigskip
% Several settings can be changed by refining the following commands.
%
% \medskip
% \DescribeMacro{\exercisename}
% The word ``\exercisename'' has automatic translation in a few languages
% \footnote{Translation is currently integrated into the package 
% for the following languages: French, German, Spanish, Italian, Portuges.}
% according to the loaded language (by \textsf{babel} or \textsf{polyglossia}).
% It can be redefined, with |\renewcommand|,
% or better you can use (in the preamble) macros from the \textsf{translations} 
% package (allowing dynamic language change), \eg \\
% |\DeclareTranslation{Swedish}{exesheet-exercise}{\"Ovning}}|.
%
% \DescribeMacro{\labelexercise}
% This command calls |\exercisename| following by the exercise number.
% It can be redefined. For example, to add a period after the exercise number:
% |\renewcommand{\labelexercise}{\exercisename~\theexercise.}|
%
% \DescribeMacro{\theexercise}
% To change only the numbering type, redefine
% the |\theexercise| command, based on the |exercise| counter.
%
% \DescribeMacro{\labelexercisestyle}
% This macro (which is empty by default) allows to define a particular style
% for exercise titles. In the present document, we defined in the preamble:
% |\renewcommand{\labelexercisestyle}{\rmfamily\color{black}}|
% \footnote{In the present document, to highlight real sections and subsections titles,
% their color and font have been modified with the
% \texttt{\bs allsectionsfont} macro from the \textsf{sectsty} package.}.
%
% \medskip
% \DescribeMacro{\exercise*}
% The starred version |\exercise*|\oarg{opt}\marg{label}
% allows to choose another \meta{label} for a particular exercise
% and removes the numbering. For instance:
% |\exercise*[(Fermat's theorem)]{Problem}| yields:
%
% \exercise*[(Fermat's theorem)]{Problem}
% \psframe(-0.25,1.3)(12.75,-0.7)
% Prove that there are no positive integers $x, y, z$ such that $x^n+y^n=z^n$
% for any integer $n$ greater than 2.
%
% \subsection{The \texttt{\bs subpart} command}
%
% \DescribeMacro{\subpart}
% An exercise may contain several parts that we obtain 
% with the |\subpart|\oarg{opt} command, typeset like a sub-subsection.
% \exercise
% \subpart[(preliminary)]
% \psframe(-0.25,1.95)(12.75,-1.85)
% First of all, prepare your cup of tea.
% \subpart
% Now you are ready to make the current exercise.
%
% \bigskip
% The following macros manage formatting in the same way as for |\exercise|.
%
% \medskip
% \DescribeMacro{\thesubpart}
% By default, the subpart numbering uses letters : A, B, C, etc.
% This numbering type can be redefined with the |\thesubpart| command based on
% the |subpart| counter, for instance |\renewcommand\thesubpart{\arabic{subpart}}|.
%
% \DescribeMacro{\subpartname} \DescribeMacro{\labelsubpart} 
% \DescribeMacro{\labelsubpartstyle}
% The |\subpart| command
% uses |\subpartname| (with automatic translation in a few languages 
% according to the selected language),
% |\labelsubpart| and |\labelsubpartstyle|, which can be changed.
%
% \medskip
% \DescribeMacro{\subpart*}
% Like |\exercise*|, the starred version |\subpart*|\oarg{opt}\marg{label}
% allows to freely typeset the subpart \marg{label}, for instance
% |\subpart*{First part}|.
%
% \subsection{The \texttt{\bs annex} command}
% \DescribeMacro{\annex}
% The |\annex|\oarg{opt} command typesets the title \textbf{ANNEX}, 
% in uppercase letters, centered
% and in the subsection style,
% with an optional parameter, added on the same line.
%
% \vspace{-\baselineskip}
% \noindent\psframe(-0.25,-0.3)(12.75,-1.3)
% \annex[(to return)]
%
% \bigskip
% \DescribeMacro{\annexname}
% The word ``\annexname'' has automatic translation in a few languages.
% It can be extended to other languages or modified by redefining |\annexname|
% or with macros from the \textsf{translations} package.
%
% \DescribeMacro{\annexstyle}
% The annex title style is set by the |\annexstyle| macro,
% defined as follows: |\newcommand\annexstyle{\MakeUppercase}|.
% This command may be redefined as one wants.
%
% \subsection{Exercise titles in table of contents} \label{toc}
% \DescribeMacro{[exetoc=\meta{bool}]}
% By default, the titles \textbf{\exercisename}, \textbf{\subpartname} 
% or \textbf{\annexname}, appear in the table of contents
% (or in the pdf file summary when \textsf{hyperref} package is used). 
% To avoid this, you can set the option \texttt{exetoc=false} (default is \texttt{true}).
% But notice that title optional arguments will always be ignored in the table of contents.
%
% \subsection{Short exercises: the \texttt{\bs exe} command}
% \DescribeMacro{\exe}
% The |\exe| command starts an exercise by the abbreviation \textbf{\exname}.\ 
% followed by the exercise number,
% without using sectioning commands, and the exercise body begins on the same
% line. An exercise starts a new paragraph without indentation.
%
% \exe This is a short exercise who
% can contain several paragraphs or questions however.
%
% \noindent\psframe(-0.25,1.4)(12.75,-1.2)
% \indent Here for example starts a new paragraph.
% \exe This is another short exercise.
%
% \bigskip
% \DescribeMacro{\exname} \DescribeMacro{\exlabel} \DescribeMacro{\exsepmark}
% The abbreviation \textbf{\exname} may be changed by
% redefining |\exname| or with macros from the \textsf{translations} package.
% The |\exlabel| macro calls |\exname| following by a period then the exercise number,
% and |\exsepmark| typesets a long dash.
% One can change these features by redefining these commands.
%
% \medskip
% \DescribeMacro{\exe*}
% The starred version prints no separator as shown below:
%
% \vspace{-\baselineskip}
% \noindent\psframe(-0.25,-0.35)(12.75,-1.1) 
% \exe* Another short exercise without separator.
% 
% \section{Enumerations and lists}
%
% \subsection{List settings} \label{setlist}
% \DescribeEnv{enumerate} \DescribeMacro{\item}
% Enumeration lists are intended to represent questions and sub-questions
% inside exercises. For a good highlight,
% labels are typeset in bold. 
% Moreover, they are left aligned, at the start of the line, 
% without indentation, and the vertical space between items
% is increased compared with \LaTeX\ standard lists.
% These settings are done by the |\setlist| command
% \footnote{Labels may also be changed occasionally in an optional argument 
% \eg \texttt{\bs begin\{enumerate\}[A.]},
% or globally thanks to \texttt{\bs labelenumi} 
% and \texttt{\bs labelenumii} commands.}
% from the \textsf{enumitem} package of Javier Bezos.
% Lists with \texttt{itemize} environment are kept in their default 
% configuration
% \footnote{The \texttt{french} option of the \textsf{babel} package
% alters \texttt{itemize} lists behavior and uses long dashes
% as labels for each list level.
% This behavior is problematic when mathematics follows the dash
% symbol because the latter may be confused with the minus sign.
% Default \texttt{itemize} lists are restored.}.
%
% \vspace{-\baselineskip}
% \noindent\psframe(-0.25,-0.35)(12.75,-3.6) 
% \exercise
% \begin{enumerate}
% \item First question
% \begin{enumerate}
% \item First sub-question
% \item Second sub-question
% \end{enumerate}
% \item Second question
% \end{enumerate}
%
% \smallskip
% \DescribeMacro{[setlist=\meta{bool}]}
% One can avoid enumeration list alterations and restore \LaTeX\ 
% default settings with the option |[setlist=false]| 
% (default value is \texttt{true} of course).
%
% \subsection{List of exercises : the \texttt{exenumerate} environment}
% \DescribeEnv{exenumerate}
% When an exercise sheet is made of short independent questions,
% it would be ill-advised to display the complete title \textbf{\exercisename} for each. 
% In addition to the |\exe| command, previously presented,
% we provide an even lighter solution with the |exenumerate| environment.
% It's only an enumeration list in which
% spaces between items are further increased compared to those of \texttt{enumerate}.
% Below is an example (the main list is an \texttt{exenumerate} environment but the
% sub-list is produced with common \texttt{enumerate} environments):
%
% \vspace{-\baselineskip}
% \noindent\psframe(-0.25,-0.3)(12.75,-5.3) 
% \begin{exenumerate}
% \item Translate the following sentences in English: 
% \begin{enumerate}
% \item Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi.
% \item Nam lacus libero, pretium at, lobortis vitae, ultricies et, tellus.
% \end{enumerate}
% \item  Translate the following sentence in German:
% \par Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna,
% vitae ornare odio metus a mi. 
% \item  Translate the following sentences in French: 
% Cum sociis natoque penatibus 
% et magnis dis parturient montes, nascetur ridiculus mus.
% \end{exenumerate}
%
% \medskip
% The environment takes an optional parameter, like \texttt{enumerate}, 
% which enables, among others, 
% to typeset alternative list labels, \eg
% |\begin{exenumerate}[A.]|.
% There are many other options (see the \textsf{enumitem} package documentation).
%
% \subsection{Items aligned by row: \texttt{tablenum1$\mid$a}, \texttt{tablitem}}
% \DescribeEnv{tablenum1} 
% \DescribeEnv{tablenuma}
% \DescribeEnv{tablitem}
% These three environments are used to typeset short questions (\texttt{tablenum1}),
% sub-questions (\texttt{tablenuma}) or \texttt{itemize} lists (\texttt{tablitem})
% on the same line. They have the same syntax:
% |\begin{tablenum1}|\oarg{opt}|(|\meta{cols}|)|.
% The \meta{cols} parameter is the number of columns used by the environment. It must be
% \emph{in parentheses}. This parameter can be omitted, then its value is 2.
% As for classic lists, each item begins with the |\item| command.
%
% These three environments are defined by the
% |\NewTasksEnvironment| macro, from the \textsf{tasks} package by Clemens Niederberger.
% They take an optional argument \meta{opt}
% explained in the documentation of this package, 
% \eg |label=\arabic*)| produces an Arabic numbering
% following by a closing parenthesis (like in \texttt{enumitem} package).
% There are also many possibilities to place items in an original way,
% for instance, the |\item*| command allows to
% specify the number of columns the item is supposed to span.
% In the following example,
% the five |\item| are placed in order between
% |\begin{tablenum1}(3)| and |\end{tablenum1}|.
% Notice that numbering is made line by line.
%
% \exercise
% \psframe(-0.25,1.3)(12.75,-2.7)
% Give the derivative of the following functions:
% \begin{tablenum1}(3)
% \item $\ds f(x) = \frac{1-x^2}{\mathrm{e}^x +\mathrm{e}^{-x}}$,
% \item $\ds g(x) = \ln \left( \frac{1-x}{1+x^2}\right)$,
% \item $\ds h(x) = \int_{0}^{1}\mathrm{e}^{xy}\, \mathrm{d}y$,
% \item $\ds k(x) = \sum_{i=1}^{\infty}\frac{1}{x^i}$,
% \item $\ds l(x) = \int_{\frac{1}{x}}^{x}\frac{1}{\ln t}\, \mathrm{d}t$.
% \end{tablenum1}
%
% \smallskip
% For \texttt{tablenuma}, labels are
% letters (a, b, c, \ldots) surrounded
% by parentheses. This cannot be modified globally,
% except by redefining the environment with |\RenewTasksEnvironment|.
% If the \textsf{exesheet} package is called with the option \texttt{setlist=false},
% labels of \texttt{tablenum1} and \texttt{tablenuma} environments
% are displayed with indentation and in normal font instead of bold.
%
% \subsection{Items aligned by column: \texttt{colsenum}, \texttt{colsitem}}
% \DescribeEnv{colsenum}    
% To get numbering of items by column, we provide the
% \texttt{colsenum} environment: |\begin{colsenum}|\oarg{opt}\marg{cols}.
% The mandatory parameter is the number of columns
% and the optional one will be passed to \texttt{enumerate},
% allowing, for example, to change the type of numbering (a, A, etc.).
% To use this environment, we have to load the
% \textsf{multicol} package in the preamble.
% Here an example with |\begin{colsenum}{3}|:
%
% \exercise
% \psframe(-0.25,1.3)(12.75,-2.65)
% Give the derivative of the following functions:
% \begin{colsenum}{3}
% \item $\ds f(x) = \frac{1-x^2}{\mathrm{e}^x +\mathrm{e}^{-x}}$,
% \item $\ds g(x) = \ln \left( \frac{1-x}{1+x^2}\right)$,
% \item $\ds h(x) = \int_{0}^{1}\mathrm{e}^{xy}\, \mathrm{d}y$,
% \item $\ds k(x) = \sum_{i=1}^{\infty}\frac{1}{x^i}$,
% \item $\ds l(x) = \int_{\frac{1}{x}}^{x}\frac{1}{\ln t}\, \mathrm{d}t$.
% \end{colsenum}
%
% \medskip
% \DescribeEnv{colsenum*}
% We will notice that, on each line, items are not necessarily well
% aligned, which can produce inelegant effects. 
% On the other hand, the \texttt{colsenum} environment doesn't try to align columns 
% from the bottom by adjusting space between items.
% If we want to get this
% (which is the default option in \textsf{multicol}), we have the
% \texttt{colsenum*} environment (same syntax than \texttt{colsenum}).
% Here what we get in that case, with the same exercise:
%
% \exercise
% \psframe(-0.25,1.3)(12.75,-2.65)
% Give the derivative of the following functions:
% \begin{colsenum*}{3}
% \item $\ds f(x) = \frac{1-x^2}{\mathrm{e}^x +\mathrm{e}^{-x}}$,
% \item $\ds g(x) = \ln \left( \frac{1-x}{1+x^2}\right)$,
% \item $\ds h(x) = \int_{0}^{1}\mathrm{e}^{xy}\, \mathrm{d}y$,
% \item $\ds k(x) = \sum_{i=1}^{\infty}\frac{1}{x^i}$,
% \item $\ds l(x) = \int_{\frac{1}{x}}^{x}\frac{1}{\ln t}\, \mathrm{d}t$.
% \end{colsenum*}
%
% \medskip
% We can see that these alignments are less good than those
% obtained by row numbering. The column numbering
% may nevertheless be preferable when there are many items with variable heights,
% and a number of items which can be different from one column to the other.
% Moreover, an advantage of \texttt{colsenum} is that the choice of labels 
% is automatic depending on the list level (and the language),
% unlike \texttt{tablenum1} or \texttt{tablenuma}. 
%
% \bigskip
% \DescribeEnv{colsitem} 
% \DescribeEnv{colsitem*}
% For \texttt{itemize} lists, the environment \texttt{colsitem}
% produces items aligned by column rather than by lines as for
% \texttt{tablitem}:
% |\begin{colsitem}|\oarg{opt}\marg{cols}. The optional parameter,
% which is passed to the underlying \texttt{itemize} environment, 
% allows to change the item label (bullet by default).
% And, as for \texttt{colsenum*}, the \texttt{colsitem*} environment
% produces an alignment of columns from the bottom.
%
% \section{Questions and solutions}
%
% \subsection{Environments \texttt{questions} and \texttt{answers}}
% \label{output}
%
% \DescribeEnv{questions} \DescribeEnv{answers}
% The package provides the two environments \texttt{questions} and \texttt{answers}
% to make optionally appear or disappear questions and answers of exercises.
%
% \bigskip
% \DescribeMacro{[output=\meta{opt}]}
% The output is controlled by the \texttt{output} key option: it takes three
% recognized values: \texttt{questions}, \texttt{answers}, \texttt{both}.
% The \texttt{questions} value allows to display questions without answers,
% \texttt{answers} displays answers without questions,
% \texttt{both} (the default option) displays  both.
% 
% \bigskip
% \DescribeMacro{\correctionstyle} \DescribeMacro{correctioncolor}
% \DescribeMacro{\correctionname}
% In the case (by default) where questions and answers are displayed both,
% answers are then typeset in the style
% |\correctionstyle|, which uses the color \texttt{correctioncolor}.
% This color may be changed with the |\definecolor| macro
% \footnote{from the \textsf{xcolor} package by Uwe Kern 
% which is loaded by \textsf{exesheet}.}
% (by default |\definecolor{correctioncolor}{rgb}{0,0.2,0.6}| = kind of dark blue).
% Moreover, with \texttt{output=both}
% the title \textbf{\correctionname} is displayed at the beginning
% of \texttt{answers} environments.
% It is defined by the |\correctionname| macro (with translation in a few languages
% and that can changed:
% for example you may prefer ``Solution''
% than ``\correctionname'').
% The style defined by |\correctionstyle| will apply to the title
% as for the whole environment.
% Here an example.
%
% \vspace{-\baselineskip}
% \noindent\psframe(-0.25,-0.25)(12.75,-6.7) 
% \exercise
% \begin{questions}
% \begin{enumerate}
% \item Is the \textsf{exesheet} package useful ? 
% \item Isn't there any other packages that deal with exercises ?
% \end{enumerate}
% \end{questions}
% \begin{answers}
% \begin{enumerate}
% \item Yes, the \textsf{exesheet} package is useful for teachers.
% \item There are many other packages that deal with exercises, and
% give the ability to produce separately questions and solutions, for example
% \textsf{exercise} by Paul Pichaureau, \textsf{exercises} by Roger Jud,
% \textsf{exsheets} (superseded by \textsf{xsim}) by Clemens Niederberger,
% \textsf{exframe} by Niklas Beisert,
% \textsf{exam} by Philip Hirschhorn,
% \textsf{answers} by Mike Piff and Joseph Wright,
% \textsf{probsoln} by Nicola Talbot, etc.
% \end{enumerate}
% \end{answers}
%
% \medskip
% When only answers are displayed, the text color remains black and
% the word ``\correctionname'' is not displayed.
%
% \subsection{About the title ``\correctionname'' in \texttt{answers} environments}
% Internally, we have used the |\comment| and |\endcomment| macros
% from the \textsf{versions} package by Uwe Lück.
% Other excellent packages allow to manage
% selectively piece of code. Let us mention 
% \textsf{verbatim} by Rainer Schöpf, \textsf{comment} by Victor Eijkhout, 
% \textsf{version} by Donald Arseneau and Stephen Bellantoni,
% \textsf{optional} by Donald Arseneau
% and \textsf{codesection} by Matthias Pospiech.
%
% The \textsf{versions} package provides furthermore 
% the |\includeversion|\marg{env} and
% |\excludeversion|\marg{env} macros who allow to make appear or disappear
% any environment \meta{env} and these optional environments
% may be nested
% \footnote{The \textsf{codesection} package also allows
% such nesting, including in the preamble, as well as 
% the \textsf{optional} package, but the latter manages only short optional code.}.
%
% However the \texttt{questions} and \texttt{answers} environments
% perform another task, not only making appear or disappear piece of text.
% In what format should the output yield the title \textbf{\correctionname} 
% and at which level should it be put in the table of contents
% (or in the summary of the pdf file)?
% In fact it depends on which level the environment has been nested.
% We can make a single \texttt{answers} environment for the whole
% sheet or an \texttt{answers} environment
% for each exercise, for each exercise part, for each question or sub-question.
% In fact, the typeset of the title \textbf{\correctionname}
% and his level in the table of contents will be computed by the environment.
%
% \medskip
% \DescribeEnv{answers\oarg{level}}
% Nevertheless, one can imagine twisted situations in which 
% the title level will not be correct.
% Moreover, the user may want to change the level of the title.
% It is then possible to force the level of the title ``\correctionname''
% with |\begin{answers}|\oarg{level}.
% The optional \meta{level} parameter is defined as follows:
% 1 for section level titles,
% 2 for subsections (like \textbf{\exercisename}), 
% 3 for sub-subsections (like \textbf{\partname}),
% another number for lower levels
% (that will not appear in the table of contents).
%
% \pagebreak
% \DescribeMacro{answers*}
% The starred version \texttt{answers*} makes the title
% \textbf{\correctionname} completely disappear.
%
% \subsection{Commands \texttt{\bs question}, \texttt{\bs answer} and \texttt{\bs answerspace}}
% \label{answerspace}
% \DescribeMacro{\question}\DescribeMacro{\answer}
% Instead of \texttt{questions} and \texttt{answers} environments,
% we can also use simple |\question|\marg{ques} and |\answer|\marg{ans} macros
% in which display of \meta{ques} and \meta{ans} arguments 
% are controlled by the same previous key option \texttt{output=\meta{opt}}.
% It may be more suitable when questions and answers are short, for instance
% if you want to display the answer after each question item.
% The title ``\correctionname'' will not appear on the beginning
% of each answer; answers are typeset with |\correctionstyle|
% if \texttt{output=both}.
% But these commands don't work with \texttt{verbatim} text inside,
% whereas \texttt{questions} and \texttt{answers} environments allow that.
%
% \bigskip
% \DescribeMacro{\answerspace}
% Some teachers are used to give to their students documents in which questions are typeset
% but instead of answers you have blank space, so that the paper is intended to be
% fulfilled by the students. 
% For this purpose, thanks to a suggestion of Maxime Chupin,
% we provide the macro |\answerspace|\oarg{height},
% in which the parameter height is a valid length, \eg |\answerspace{3cm}|.
%
% \DescribeMacro{[answerspace=\meta{bool}]}
% This vertical space display is optional and is controlled by the key
% \texttt{answerspace} which can be \texttt{true} or \texttt{false} (by default).
% Of course this macro is not intended to be placed inside \texttt{answers}
% environments, but anywhere else.
%
% \section{Marginal notes for marking scheme} 
%
% The \textsf{exesheet} package allows to display in margins a marking
% scheme with comments and explanations about answers.
%
% \subsection{The \texttt{\bs points} command}\label{points}
% \DescribeMacro{\points}
% The |\points|\marg{pts} command displays the number of points awarded for an exercise.
% It is intended to be entered in the optional argument of the 
% |\exercise| command
% \footnote{Using this command in the optional argument of 
% \texttt{\bs exercise} is incompatible with
% the \textsf{memoir} class which redefines section commands.}.
% For instance
% |\exercise[\points{5}]| yields:
% \exercise[\points{5}]
% \psframe(-0.25,1.3)(12.75,-0.4)
% Try to read this document to the end without drinking tea and you get five points.
%
% \bigskip
% When only correction is displayed in an exercise, the |\points| macro is patched 
% to suppress the display of points.
% An extended solution for printing answers with the scale will be presented
% in section \ref{totalpoints}, including a new |\totalpoints| macro.
%
% \bigskip
% \DescribeMacro{\pointsname} \DescribeMacro{\pointname}
% The word ``\pointsname'' (or in the singular ``\pointname''
% if \meta{pts} is inferior to 2), is added and, like before,
% gets automatic translation in a few languages
% (and can be changed).
% 
% \DescribeMacro{\pointsstyle} \DescribeMacro{pointscolor}
% The style used by the |\points| command may be redefined with |\pointsstyle|. 
% The color is set by |pointscolor| with the |\definecolor| command,
% and you can change it, 
% \eg: |\definecolor{pointscolor}{named}{blue}|.
%
% \subsection{The \texttt{\bs pts} command} \label{pts}
% \DescribeMacro{\pts}
% When exercises are typeset with the |\exe| macro,
% or as a list with the \texttt{exenumerate} environment,
% the marking scheme can be displayed in the margin, on the line where
% we put the |\pts|\marg{num} command (in general the first line of the exercise).
% The \meta{num} parameter is the number of points assigned to the exercise.
% Below what we obtain with with |\exe\pts{3}... \exe\pts{1.5}...|
%
% \vspace{-\baselineskip}
% \noindent\psframe(-3.0,-0.25)(12.75,-1.95)
% \exe \pts{3} The first exercise with a marking scheme.
% \exe \pts{1.5} The second one.
% 
% \bigskip
% \DescribeMacro{\ptsname} \DescribeMacro{\ptname} 
% \DescribeMacro{ptscolor} \DescribeMacro{\ptsstyle}
% The abbreviation ``\ptsname'' (or ``\ptname''
% when the number of points is inferior to 2)
% is automatically added with macros |\ptsname| or |\ptname| 
% (translated in a few languages if \textsf{babel} ore \textsf{polyglossia} are loaded).
% The display color of the points is defined by \texttt{ptscolor}, which can be changed
% with |\definecolor|: by default |\definecolor{ptscolor}{named}{red}|.
% The display style is defined by |\ptsstyle|: among other things, it adds parenthesis around.
%
% \bigskip
% \DescribeMacro{[display=\meta{opt}]} 
% The display of the marking scheme is controlled by the
% option key \texttt{display}.
% By default |display=none| and the marking scheme will not be displayed.
% Use |display=pts| to make it appear.
% More details about this key are given in \ref{margin}.
%
% \medskip
% \DescribeMacro{[marginpos=\meta{opt}]} 
% The side where to place the scale is controlled by the |marginpos| key option
% whose possible values are (first) \texttt{left} or \texttt{right}.
% The default is \texttt{left}
% (although the default behavior of \LaTeX{} is to place marginal notes on the right side). 
% This option has no effect when
% |display=none|.
%
% For a \emph{two side} document, the default behavior is to typeset text in the outer margin
% which will be enlarged relatively to the inner margin (that contains the binding).
% The outer margin is on the right hand side for odd pages and on the left hand side
% for even pages. So the \texttt{marginpos} key option can take those two additional 
% values.
% When you give a \texttt{left} or \texttt{right} value with a two side document,
% it will be converted to default value, \texttt{outer}, with a warning message.
%
% \medskip
% \DescribeMacro{twoside mode}
% For a document is in twoside mode, marginal notes sometimes appear on the wrong 
% side of a page. This is a known bug of \LaTeX\ for which the solution
% is to call the package \textsf{mparhack} (what is done by \textsf{exesheet}
% for a twoside mode document) and to \emph{run \LaTeX\ twice}. 
% If necessary you get a warning message to rerun.
% 
% \subsection{Commands \texttt{\bs totalexe}, \texttt{\bs note*} and \texttt{\bs note}}
%
% \label{note}
% To give a more detailed marking scheme, we get
% the following commands.
%
% \medskip
% \DescribeMacro{\totalexe}
% |\totalexe|\marg{num} displays the total number of points of an exercise,
% by default inside an oval box, with the word ``\ptsname'' (or ``\ptname'') 
% added and in bold red.
% In the next example, the exercise title has been obtained with |\exercise[\totalexe{4}]|.
%
% \medskip
% \DescribeMacro{\note*} 
% For each answer or solution in the correct version, the command
% |\note*|\marg{num} states the number of points of that question.
% The appearance is somewhat different from the one obtained with |\pts|:
% by default the number is displayed without being followed by ``\ptsname'' or ``\ptname'',
% without parenthesis, and in bold. 
% In the answer 3 of the next example, just after |\item|, we used: |\note*{1.5}|.
%
% \medskip
% \DescribeMacro{\note}
% The |\note|\marg{comment} macro is used to give details about the marking scheme
% and to indicate how points are awarded.
% In a comment argument you can use |\\| to get a line break,
% or even |\\[|\meta{height}|]| to increase the line break from \meta{height}.
%
% \DescribeMacro{\note\oarg{num}}
% It is often convenient to put |\note*|\marg{num}|\note|\marg{comment} 
% at the beginning of an answer. In that case \LaTeX\ will place the margin
% notes one under the other and will protest with: 
% \texttt{LaTeX Warning: Marginpar on page \ldots\@ moved.} \\
% This is not a real problem because generally \LaTeX\ is able to
% manage the placement of these
% marginal notes, one below the other. Nevertheless, one can avoid unnecessary protests by 
% compacting both commands in a single one and typing the number of points
% as an optional argument of note:
% |\note|\oarg{num}\marg{comment}.
%
% The first comment on the following example is obtained (just after |\item|) with\\
% |\note[1]{0.5 for the anti-derivative\\0.5 for simplifying}|.
%
% \exercise[\totalexe{4}] \label{totalexe}
% \begin{questions}
% \psframe(-3.5,1.3)(12.75,-14)
% For each following question, say if the assertion is true or false.
% Justify the answer carefully.
% \begin{tablenum1}
% \item $\ds \int_{0}^{\sqrt{3}}\frac{1}{x+\sqrt{3}} \,\mathrm{d}x = \ln 2$,
% \item $\ds \int_{2}^{\mathrm{e}} \frac{1}{x\ln x} \,\mathrm{d}x = -\ln 2$,
% \item* The function $F$ defined on $\mathbf{R}$ by 
% $F(x) = \ds \int_{0}^{x}\frac{1}{t^2+t+1}\,\mathrm{d} t$ is increasing on $\mathbf{R}$.
% \end{tablenum1}
% \end{questions}
% 
% \begin{answers}
% \begin{enumerate}
%    \item \note[1]{0.5 for the anti-derivative\\0.5 for simplifying}
%    We calculate:
%    \[ \int_{0}^{\sqrt{3}}\frac{1}{x+\sqrt{3}}\,\mathrm{d}x
%        = \bigg[ \ln\left(x+\sqrt{3}\right) \bigg]_0^{\sqrt{3}}
%        = \ln\left(2\sqrt{3}\right)-\ln \sqrt{3}
%        = \ln\left(\frac{2 \sqrt{3}}{\sqrt{3}}\right)
%        =\ln 2.
%    \]
%    \textbf{TRUE}.
%
%    \item \note[1.5]{1 for the anti-derivative \\0.5 for final value \\[2ex]
%        other method: $\frac{1}{x \ln x} >0$ on $[2, \mathrm{e}]$ 
%        whereas $-\ln2<0$
%    }
%    We have $\ds\frac{1}{x \ln x}= \frac{\frac{1}{x}}{\ln x}= \frac{u'(x)}{u(x)}$
%    with $u(x)=\ln x$, which is positive on $[2, \mathrm{e}]$. Hence
%
%    \[ \int_{2}^{\mathrm{e}}\frac{1}{x \ln x}\,\mathrm{d}x
%        = \Big[ \ln(\ln x) \Big]_2^\mathrm{e}
%        = \ln(\ln \mathrm{e})-\ln(\ln2)= \ln1 -\ln(\ln2)=-\ln(\ln2).
%    \]
%    \textbf{FALSE}.
%
%    \item \note*{1.5}
%    The function $F$ defined on $\mathbf{R}$ by
%    \[ F(x)= \int_{0}^{x}\frac{1}{t^2+t+1}\, \mathrm{d}t \]
%    is derivable on $\mathbf{R}$ and its derivative is such that
%    $F'(x)=\frac{1}{x^2+x+1}$.
%    \note{0.5 for $F'$\\1 for the sign of $F'$ and conclusion}
%    The denominator is a quadratic polynomial, always positive because its discriminant is
%    $\Delta=-3 <0$.
%    Thus $F$ is increasing on $\mathbf{R}$. \\
%    \textbf{TRUE}.
% \end{enumerate}
% \end{answers}
% In the comment of answer 2, a wider vertical space is produced at line break
% with the optional argument |\\[2ex]|.
% The last comment, not placed beside the number of points of answer 3,
% has been produced by placing on the first line after the formula:
% |\note{0.5 for $F'$\\1 for the sign of $F'$ and conclusion}|.
%
% \medskip
% \DescribeMacro{markingcolor} \DescribeMacro{\markingstyle} \DescribeMacro{\ptsboxlength}
% The points display color, in |\totalexe| and |\note*|,
% is defined by \texttt{markingcolor}
% and the style by |\markingstyle|, which are modifiable.
% The oval box produced by |\totalexe| is obtained with the |\ovalbox| command
% of the \textsf{fancybox} package (by Timothy Van Zandt),
% with corner arcs set by |\cornersize{1}|.
% The length of the box is not adjusted to content but depends on the value
% of |\ptsboxlength| in order to keep uniform appearance
% from one exercise to the other.
%
% \medskip
% \DescribeMacro{notecolor} \DescribeMacro{\notestyle} 
% Comment notes are typeset by default in a dark green color
% defined by |\definecolor{notecolor}{rgb}{0.0,0.4,0.0}|.
% The style of the comment is set by the |\notestyle| macro.
%
% \subsection{Margin notes options} \label{margin}
%
% \DescribeMacro{[display=\meta{opt}]}
% The \texttt{display} key option controls how the marking scheme
% will be displayed: as seen previously (subsection \ref{pts}), 
% \texttt{display=none} displays nothing. With \texttt{display=pts}
% the numbers passed as argument to |\pts|, |\totalexe|, |\note*|
% or as optional argument of |\note|\oarg{num}\texttt{\{...\}} will be displayed.
% The last possible value is \texttt{display=notes} which displays the full marginal
% notes with points and comments (the mandatory argument of |\note|)
% as seen in the previous example.
%
% \medskip
% \DescribeMacro{[marginpos=\meta{opt}]}
% As seen previously in subsection \ref{pts}, the side where to place the scale is controlled 
% by the \texttt{marginpos} key option
% whose possible values are \texttt{left} and \texttt{right} 
% (or \texttt{inner} and \texttt{outer} if the document is in two side mode).
%
% \medskip
% \DescribeMacro{[marginwidth=\meta{opt}]}
% The key option \texttt{marginwidth} controls margins layout. 
% The possible values are
% \texttt{standard}, \texttt{expand} or \texttt{unset}.
%
% This option has no effect when \texttt{display=none}.
% In that case, left and right margins have same width,
% except for a two side mode document for which the ratio between left and right
% margin is 2:3. 
% Otherwise the key \texttt{marginwidth} acts as follow:
% \begin{description}
% \item[\texttt{standard}] 
% The left margin is enlarged and the 
% right one is reduced, with a ratio of 3:2 (or 2:3 if \texttt{marginpos=left}).
% The text body is shifted without altering the text width.
% The margin paragraph width remains relatively short; it depends also on page geometry.
% This option is not suitable for verbose comments.
% 
% \item[\texttt{expand}] It is the default value.
% The behavior is the same than with the
% \texttt{standard} value if \texttt{display=pts}, but if \texttt{display=notes}
% the margin is expanded with a ratio of 3:1 (or 1:3) and margin paragraph width
% is increased.
%
% \item[\texttt{unset}] The previous settings may not suit to anyone, 
% so you have this other option.
% In that case, no setting will be proceeded on the margin width and you
% can make your own setting. For that, you have the convenient macro |\geometry|
% from the \textsf{geometry} package (by Hideo Umeki).
% For example you can put in the preamble 
% \centeredline{|\geometry{hmarginratio=2:1,marginparwidth=2.5cm}|.}
%
% If \texttt{marginpos=right}, you must invert the ratio, \eg 1:2 instead of 2:1.
% If \texttt{marginwidth} is not set to \texttt{unset}, 
% such a command will have no effect.
% \end{description}

% The margin settings are valid
% for the whole document and must be set in the preamble.
%
% \medskip
% \DescribeMacro{[noteragged=\meta{opt}]}
% For the mandatory argument of |\note|, text alignment in margins 
% is controlled by the package option \texttt{noteragged},
% which can take the following values: 
% \texttt{left}, \texttt{right}, \texttt{center}, \texttt{justify} or \texttt{twoside}.
% The default value is \texttt{noteragged=left}. It means that the text 
% is right aligned, which is a common behavior for text in the left margin;
% \texttt{noteragged=right} yields a left aligned text;
% \texttt{justify} means that the text is justified, which is the default setting
% of \LaTeX\ marginal notes. 
% Finally \texttt{noteragged=twoside} is equivalent to \texttt{noteragged=left} for odd pages
% and \texttt{noteragged=right} for even pages, if the document is in two side mode.
% It has no effect otherwise (the default value \texttt{noteragged=left} will be taken
% and a warning message appears in the shell).
%
% When \texttt{display} is not set to \texttt{notes}, the \texttt{noteragged} option
% has no effect because it concerns only text put in mandatory argument of |\note|.
% 
% \subsection{The \texttt{\bs totalpoints} command} \label{totalpoints}
%
% \DescribeMacro{\totalpoints}
% The |\totalpoints|\marg{num} macro is intended
% to replace |\points| when using a detailed marking scheme.
% When the scale is not displayed,
% it is equivalent to |\points| and when the scale is displayed,
% it is equivalent to |\totalexe|.
% For example, in the exercise \ref{totalexe}, we should use
% |\totalpoints| rather than |\totalexe|,
% because, when the detailed marking scheme is not displayed, the total points will be typeset
% as in the exercise \ref{points} rather than in the margin.
%
% \subsection{Marking scheme consistency checking}\label{scale}
%
% \DescribeMacro{[checkpts=\meta{bool}]}
% The marking scheme can be checked
% \footnote{Thanks to Denis Bitouzé for his suggestion about this feature.}
% with the keyval option \texttt{[checkpts=true]},
% the default value is \texttt{false}.
%
% \medskip
% For each exercise, the sum of points awarded for each question (with |\pts|, |\note*|
% or |\note[ ]| is compared to the total of the exercise given in 
% |\points|, |\totalexe| or |totalpoints|.
% A warning message appear in the shell to indicate if the scale is valid or not
% for the exercise. For example:
% \begin{center}
% \texttt{Package exesheet warning: Exercise 3: sum of points is 4.5pt instead of 5pt.}
% \end{center}
% Depending on your language, you can use comma notation numbers (4,5 as well as 4.5).
% The checking takes place at the beginning of the next exercise. If no points are specified
% for the questions, no warning message will be displayed at this level.
%
% \medskip
% \DescribeMacro{\totalsheet}
% At the end of the sheet, the last exercise is checked, then a global checking
% is made on the whole sheet. For that, the total points of the sheet must be specified
% in the preamble with the |\totalsheet|\marg{total} macro
% (else you get a warning message).
% If subtotal points have been awarded for exercises, the global comparison
% is between the sum of these subtotals and the total of points recorded
% with the |\totalsheet| macro.
% If not, the audit covers the sum of points awarded for each individual question.
% A warning message indicates the result of this last checking.
% Finally a last message indicate if all the scale controls have been successfully
% passed or not.
%
% \section{Options} \label{options}
%
% \subsection{Summary of available options}
%
% Here we present a summary table of available options. Explanations of use
% are given in the corresponding sections.
% The default value is typeset in bold.
%
% \begin{center} \ttfamily
% \setlength{\extrarowheight}{1pt}
% \begin{tabular}{llc}
% \hline
% \textsf{Key} & \textsf{Possible values} & \textsf{See section} \\
% \hline
% exetoc & \textbf{true}, false & \ref{toc} \\
% setlist & \textbf{true}, false & \ref{setlist} \\
% output & questions, answers, \textbf{both} & \ref{output} \\
% answerspace & true, \textbf{false} & \ref{answerspace}\\
% display & \textbf{none}, pts, notes & \ref{pts}, \ref{margin} \\
% marginpos & \textbf{left} (inner), right (\textbf{outer}) & \ref{pts}, \ref{margin} \\
% marginwidth & standard, \textbf{expand}, unset &  \ref{margin} \\
% noteragged & \textbf{left}, right, center, justify, twoside & \ref{margin} \\
% checkpts & true, \textbf{false} & \ref{scale} \\
% correct & true, \textbf{false}, conditional & \hyperlink{correct}{see below} \\
% \hline
% \end{tabular}
% \end{center}
%
% When an invalid key is passed, an error is produced, but
% when a value is not recognized, a warning message occur:\\
% \texttt{Value `\meta{value}'\ is not supported by option `\meta{key}'\ 
% on input line \ldots} \\
% For each option, you can set them with class or package calling: \eg \\
% |\usepackage[output=answers,display=notes,noteragged=right]{exesheet}|
%
% \bigskip
% \DescribeMacro{\exesheetset}
% You can also use the |\exesheetset|\{list of \meta{key}=\meta{value} options\}
% command.
% Nevertheless, only the options \texttt{output}, \texttt{answerspace}, \texttt{display}, 
% and \texttt{noteragged}, 
% can be changed dynamically, even in the document body, although this is not really expected.
% The others are usable in the preamble only.
% Dynamic options are processed at each call, the others will be processed once,
% at begin document.
% \hypertarget{correct}{}
%
% \bigskip
% \DescribeMacro{[correct=\meta{opt}]} 
% A special option, \texttt{correct}, can be used only when calling the \textsf{exesheet}
% class or in combination with the \textsf{schooldocs} package.
% Its effect is to add ``\correctname'' (or its translation)
% in the document title and headers.
% Possible values are: \texttt{true}, \texttt{false} (by default) or \texttt{conditional}.
% The value \texttt{correct=conditional}, means \texttt{true} if answers are displayed,
% \texttt{false} otherwise.
%
% \subsection{Alternative (deprecated) commands}
% 
% Previously to version 2.0, we used some special commands to set output and display options.
% Thanks to a suggestion of Maxime Chupin, keyval options have been implemented 
% in the package.
% Although the latter is more convenient,
% the old commands will be presented here
% and maintained for now, for compatibility reasons.
% When using them, a warning message will appear, but these commands still work.
% However previous options \texttt{nosetlist} and \texttt{notoc}
% are no longer supported.
%
% \bigskip
% \DescribeMacro{\questionsonly} \DescribeMacro{\answersonly}
% These two commands are equivalent to respectively \texttt{output=questions} 
% and \texttt{output=answers}.
%
% \medskip
% \DescribeMacro{\displaypts} \DescribeMacro{\displaypoints} 
% These two commands are now equivalent to \texttt{display=pts}.
%
% \medskip
% \DescribeMacro{\displaynotes}\DescribeMacro{\displaynotesright}
% These two commands mean \texttt{display=notes}
% and moreover \texttt{marginpos=right} for the latter.
%
% \StopEventually{}
%
% \section{Implementation}
%
% \subsection{Options and required packages}
% The \texttt{exesheet} class is based on the \texttt{article} class
% and passes to it all its unknown options.
% |\ProcessKeyvalOptions*| is useless in class, will be done by the package.
%    \begin{macrocode}
%<*class>
\RequirePackage{kvoptions}
\DeclareBoolOption[true]{exetoc}
\DeclareBoolOption[true]{setlist}
\DeclareStringOption[both]{output}
\DeclareStringOption[none]{display}
\DeclareBoolOption[false]{answerspace}
\DeclareStringOption[left]{marginpos}
\DeclareStringOption[expand]{marginwidth}
\DeclareStringOption[left]{noteragged}
\DeclareBoolOption[false]{checkpts}
\DeclareStringOption[false]{correct}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions \relax
\LoadClass{article}
\RequirePackage{exesheet}
\RequirePackage{schooldocs}
%</class>
%    \end{macrocode}
%
% Then options are defined thanks to \textsf{kvoptions} package (based on \textsf{keyval}).
% String options are processed in separate macros 
% defined in the corresponding sections of each.
% These process macros will be executed when package is loaded
% (at end of package because |\exs@process...| aren't recognized at the beginning),
% or at begin document for options whose
% effect cannot be changed dynamically
% and must be set in the preamble
% (they will be processed once).
%
% A special case is \texttt{setlist} when used with \textsf{babel-french}.
% It will then be processed immediately and disabled (see below for explanations).
% 
%    \begin{macrocode}
%<*package>
\@ifclassloaded{exesheet}{}{
    \RequirePackage{kvoptions}
    \DeclareBoolOption[true]{exetoc}
    \DeclareBoolOption[true]{setlist} 
    \DeclareStringOption[both]{output}
    \DeclareStringOption[none]{display}
    \DeclareBoolOption[false]{answerspace}
    \DeclareStringOption[left]{marginpos}
    \DeclareStringOption[expand]{marginwidth}
    \DeclareStringOption[left]{noteragged}
    \DeclareBoolOption[false]{checkpts}
    \DeclareStringOption[false]{correct}
}

\ProcessKeyvalOptions*

\def\exs@process@dynoptions{
    \exs@process@output
    \exs@process@display 
    \exs@process@noteragged
}

\AtEndOfPackage{\exs@process@dynoptions}
\AtBeginDocument{
    \newif\ifexesheet@multicol
    \@ifpackageloaded{multicol}{
        \exesheet@multicoltrue}{\exesheet@multicolfalse}
        % to set the rule to the right color in answers environments
    \exs@process@setlist
    \exs@process@marginpos
    \exs@process@marginwidth
    \exs@process@checkpts
    \exs@process@correct
    \DisableKeyvalOption[action=warning,package=exesheet]{exesheet}{setlist}
    \DisableKeyvalOption[action=warning,package=exesheet]{exesheet}{marginpos}
    \DisableKeyvalOption[action=warning,package=exesheet]{exesheet}{marginwidth}
    \DisableKeyvalOption[action=warning,package=exesheet]{exesheet}{checkpts}
    \DisableKeyvalOption[action=warning,package=exesheet]{exesheet}{correct}
}

%    \end{macrocode}
% \begin{macro}{\exesheetset}
% The macro |\exesheetset| can receive keyval options.
% It can be used anywhere in the document to modify some settings,
% but has no effect on non dynamic options if called outside the preamble;
% thanks to |\DisableKeyValOption| a warning message occur in that case.
%    \begin{macrocode}  
\def\exesheetset#1{\setkeys{exesheet}{#1}\exs@process@dynoptions}

%    \end{macrocode}
% \end{macro}
% Now we load several packages.
% The \texttt{shortlabel} option in the \textsf{enumitem} package allows to use labels like in 
% the \textsf{enumerate} package \eg 1., a), A. etc.
% The \textsf{mparhack} package (by Tom Sgouros and Stefan Ulrich)
% is loaded only for two side mode documents.
%    \begin{macrocode}
\RequirePackage{ifthen}
\RequirePackage{geometry}
\RequirePackage{xcolor}
\RequirePackage[shortlabels]{enumitem}
\RequirePackage{tasks}
\RequirePackage{versions}
\RequirePackage{fancybox}
\RequirePackage{translations}
\RequirePackage{ragged2e}
\ifthenelse{\boolean{@twoside}}{\RequirePackage{mparhack}}{}

%    \end{macrocode}
%
% \subsection{Internationalization}
% Here we define keywords and their translation in French, German, Spanish
% Italian, Portuguese, thanks to macros of the \textsf{translations} package 
% by Clemens Niederberger. It detects the used language 
% loaded by \textsf{babel} or \textsf{polyglossia}.
%
% Accented characters cannot be used here because they are not recognized 
% if \textsf{inputenc} is loaded after \textsf{exesheet}.
% So we have used basic \LaTeX\ control sequences to produce them.
%
%    \begin{macrocode}
\DeclareTranslationFallback{exesheet-exercise}{Exercise}
\DeclareTranslationFallback{exesheet-subpart}{Part}
\DeclareTranslationFallback{exesheet-annex}{Annex}
\DeclareTranslationFallback{exesheet-ex}{Ex}
\DeclareTranslationFallback{exesheet-points}{points}
\DeclareTranslationFallback{exesheet-point}{point}
\DeclareTranslationFallback{exesheet-correction}{Correction}
\DeclareTranslationFallback{exesheet-pts}{pts}
\DeclareTranslationFallback{exesheet-pt}{pt}

\DeclareTranslation{English}{exesheet-exercise}{Exercise}
\DeclareTranslation{English}{exesheet-subpart}{Part}
\DeclareTranslation{English}{exesheet-annex}{Annex}
\DeclareTranslation{English}{exesheet-ex}{Ex}
\DeclareTranslation{English}{exesheet-points}{points}
\DeclareTranslation{English}{exesheet-point}{point}
\DeclareTranslation{English}{exesheet-correction}{Correction}
\DeclareTranslation{English}{exesheet-pts}{pts}
\DeclareTranslation{English}{exesheet-pt}{pt}

\DeclareTranslation{French}{exesheet-exercise}{Exercice}
\DeclareTranslation{French}{exesheet-subpart}{Partie}
\DeclareTranslation{French}{exesheet-annex}{Annexe}
\DeclareTranslation{French}{exesheet-ex}{Ex}
\DeclareTranslation{French}{exesheet-points}{points}
\DeclareTranslation{French}{exesheet-point}{point}
\DeclareTranslation{French}{exesheet-correction}{Correction}
\DeclareTranslation{French}{exesheet-pts}{pts}
\DeclareTranslation{French}{exesheet-pt}{pt}

\DeclareTranslation{German}{exesheet-exercise}{\"Ubung}
\DeclareTranslation{German}{exesheet-subpart}{Teil}
\DeclareTranslation{German}{exesheet-annex}{Anhang}
\DeclareTranslation{German}{exesheet-ex}{\"Ub}
\DeclareTranslation{German}{exesheet-points}{Punkte}
\DeclareTranslation{German}{exesheet-point}{Punkt}
\DeclareTranslation{German}{exesheet-correction}{Verbesserung}
\DeclareTranslation{German}{exesheet-pts}{P.}
\DeclareTranslation{German}{exesheet-pt}{P.}

\DeclareTranslation{Spanish}{exesheet-exercise}{Ejercicio}
\DeclareTranslation{Spanish}{exesheet-subpart}{Parte}
\DeclareTranslation{Spanish}{exesheet-annex}{Anexo}
\DeclareTranslation{Spanish}{exesheet-ex}{Ej}
\DeclareTranslation{Spanish}{exesheet-points}{puntos}
\DeclareTranslation{Spanish}{exesheet-point}{punto}
\DeclareTranslation{Spanish}{exesheet-correction}{Correcci\'on}
\DeclareTranslation{Spanish}{exesheet-pts}{ptos}
\DeclareTranslation{Spanish}{exesheet-pt}{pto}

\DeclareTranslation{Italian}{exesheet-exercise}{Esercizio}
\DeclareTranslation{Italian}{exesheet-subpart}{Parte}
\DeclareTranslation{Italian}{exesheet-annex}{Annesso}
\DeclareTranslation{Italian}{exesheet-ex}{Es}
\DeclareTranslation{Italian}{exesheet-points}{punti}
\DeclareTranslation{Italian}{exesheet-point}{punto}
\DeclareTranslation{Italian}{exesheet-correction}{correzione}
\DeclareTranslation{Italian}{exesheet-pts}{pti}
\DeclareTranslation{Italian}{exesheet-pt}{pt}

\DeclareTranslation{Portuges}{exesheet-exercise}{Exerc\'icio}
\DeclareTranslation{Portuges}{exesheet-subpart}{Parte}
\DeclareTranslation{Portuges}{exesheet-annex}{Anexo}
\DeclareTranslation{Portuges}{exesheet-ex}{Ex}
\DeclareTranslation{Portuges}{exesheet-points}{pontos}
\DeclareTranslation{Portuges}{exesheet-point}{ponto}
\DeclareTranslation{Portuges}{exesheet-correction}{Corre\c c\~ao}
\DeclareTranslation{Portuges}{exesheet-pts}{pts}
\DeclareTranslation{Portuges}{exesheet-pt}{pt}

\newcommand*\exercisename{\GetTranslation{exesheet-exercise}}
\newcommand*\subpartname{\GetTranslation{exesheet-subpart}}
\newcommand*\annexname{\GetTranslation{exesheet-annex}}
\newcommand*\exname{\GetTranslation{exesheet-ex}}
\newcommand*\pointsname{\GetTranslation{exesheet-points}}
\newcommand*\pointname{\GetTranslation{exesheet-point}}
\newcommand*\correctionname{\GetTranslation{exesheet-correction}}
\newcommand*\ptsname{\GetTranslation{exesheet-pts}}
\newcommand*\ptname{\GetTranslation{exesheet-pt}}

%    \end{macrocode}
%
% \subsection{Titles}
%
% The \texttt{exercise} counter numbers exercises for the whole document 
% regardless of any section.
% To reset the counter at some point, just write |\setcounter{exercise}{0}|
% and for an automatic reset at each section,
% add in the preamble \\
% |\makeatletter \@addtoreset{exercise}{section} \makeatother|.
%
% The parts counter depends on \texttt{exercise} and is reset
% at each new exercise.
%
% Commands |\labelexercisestyle| and |\labelsubpartstyle|
% are empty, but allow to personalize the style, for instance:\\
% |\renewcommand\labelexercisestyle{\sffamily}|.
%
% The |\exe@check| macro checks the marking scheme, it will be defined
% in section \ref{MSoptions}.
% By default, the table of contents displays the titles of exercises and parts,
% |\ifexesheet@exetoc| is \texttt{true}.
% To display in it only exercise titles but not parts,
% place in the preamble |\setcounter{tocdepth}{2}|.
%
% \begin{macro}{\exercise}
%    \begin{macrocode}
\newcounter{exercise}

\newcommand{\labelexercise}{\exercisename\space \theexercise}
\newcommand{\labelexercisestyle}{}
\newcommand*{\@exercise}[1][]{%
    \ifexesheet@checkpts \exe@check{\labelexercise} \fi
    % curiously the \execheck must be done before \refstepcounter !
    \refstepcounter{exercise}
    \subsection*{\labelexercisestyle\labelexercise\enskip #1}
    \ifexesheet@exetoc
        \addcontentsline{toc}{subsection}{\labelexercise}
    \fi
}
\newcommand*{\@@exercise}[2][]{%
    \ifexesheet@checkpts \exe@check{#2} \fi
    \subsection*{\labelexercisestyle #2\enskip #1}
    \setcounter{subpart}{0} % resets the parts counter
    \ifexesheet@exetoc
        \addcontentsline{toc}{subsection}{#2}
    \fi
}
\newcommand{\exercise}{\@ifstar{\@@exercise}{\@exercise}}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\subpart}
%    \begin{macrocode}
\newcounter{subpart}[exercise] %
\renewcommand{\thesubpart}{\Alph{subpart}}

\newcommand{\labelsubpart}{\subpartname~\thesubpart}
\newcommand{\labelsubpartstyle}{}
\newcommand*{\@subpart}[1][]{%
    \refstepcounter{subpart}%
    \subsubsection*{\labelsubpartstyle\labelsubpart\enskip #1}
    \ifexesheet@exetoc
        \addcontentsline{toc}{subsubsection}{\labelsubpart}
    \fi
}
\newcommand*{\@@subpart}[2][]{%
    \subsubsection*{\labelsubpartstyle #2\enskip #1}
    \ifexesheet@exetoc
        \addcontentsline{toc}{subsubsection}{#2}
    \fi
}
\newcommand{\subpart}{\@ifstar{\@@subpart}{\@subpart}}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\annex}
%    \begin{macrocode}
\newcommand{\annexstyle}{\MakeUppercase}
\newcommand*{\annex}[1][]{%
    \subsection*{\mbox{}\hfill\annexstyle{\annexname} #1\hfill\mbox{}}
    \ifexesheet@exetoc
        \addcontentsline{toc}{subsection}{\annexname}
    \fi
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\exe}
%    \begin{macrocode}
\newcommand{\exlabel}{\exname.~\theexercise}
\newcommand{\exsepmark}{---}
\newcommand{\@exe}{\bigskip\refstepcounter{exercise}
    \par\noindent\textbf{\exlabel~\exsepmark}~}
\newcommand{\@@exe}{\bigskip\refstepcounter{exercise}
    \par\noindent\textbf{\exlabel}~}
\newcommand{\exe}{\@ifstar{\@@exe}{\@exe}}

%    \end{macrocode}
% \end{macro}
%
% \subsection{Enumerations and lists}
%
% \begin{macro}{\exenumerate}
% The |\setlist| command comes from the \textsf{enumitem} package
% (|\setenumerate| is obsolete). By default |itemsep=1ex| for lists of first level,
% and |leftmargin=1.5em| allows to align labels on the start of lines.
%    \begin{macrocode}
\newenvironment{exenumerate}[1][]{%
    \setlist[enumerate]{font=\bfseries}
    \setlist[enumerate,1]{leftmargin=1.5em,
        itemsep=3ex plus 1ex minus 1ex,topsep=3ex plus 1ex minus 1ex}
    \setlist[enumerate,3]{noitemsep,nolistsep}
    \setlist[itemize]{noitemsep,nolistsep}
    \begin{enumerate}[#1]
        }{\end{enumerate}}

%    \end{macrocode}
% \end{macro}
% When using \textsf{babel} with the option \texttt{french},
% \texttt{itemize} lists are modified with the same dash label for each list level. 
% These modifications are canceled here to restore default 
% \LaTeX\ \texttt{itemize} lists (labels and spaces).
% We have create the |\standardfrenchlists| command which must be called into
% |AtBeginDocument| or not, depending on whether
% \textsf{exesheet} is loaded before \textsf{babel} or after.
%    \begin{macrocode}
\newcommand\standardfrenchlists{%
    \@ifpackagewith{babel}{french}{
        \frenchsetup{StandardLists=true}
    }{}
}
\ifexesheet@setlist
    \standardfrenchlists % necessary when exesheet is loaded after babel
    \DisableKeyvalOption[action=warning,package=exesheet]{exesheet}{setlist}
\fi

\def\exs@process@setlist{% must be executed at begin document
  \ifexesheet@setlist
    \standardfrenchlists % if exesheet is loaded before babel package
    \setlist[enumerate]{font=\bfseries}
    \setlist[enumerate,1]{topsep=1.5ex plus 1ex minus 1ex,leftmargin=1.5em}
  \fi
%    \end{macrocode}

% \DescribeEnv{tablenum1} \DescribeEnv{tablenuma}
% The |\NewTasks| command comes from the \textsf{tasks} package.
% It allows to define environments \texttt{tablenum1}, \texttt{tablenuma}
% and \texttt{tablitem}.
% Horizontal spaces are adjusted to get good alignments with
% items of other \texttt{enumerate} (or \texttt{itemize}) environments.
%    \begin{macrocode}
  \ifexesheet@setlist
    \NewTasksEnvironment[label=\arabic*.,label-format=\bfseries,
        column-sep=1em,label-align=right,
        item-indent=1.5em,label-width=1em,label-offset=0.5em,
        after-item-skip=0.5ex plus 0.5ex minus 0.5ex]{tablenum1}[\item](2)
    \NewTasksEnvironment[label=(\alph*),label-format=\bfseries,
        column-sep=1em,label-align=right,
        item-indent=2.15em,label-width=1.6em,label-offset=0.5em,
        after-item-skip=0.5ex plus 0.5ex minus 0.5ex]{tablenuma}[\item](2)
  \else
    \NewTasksEnvironment[label=\arabic*.,
        column-sep=1em,
        after-item-skip=0.5ex plus 0.5ex minus 0.5ex]{tablenum1}[\item](2)
    \NewTasksEnvironment[label=(\alph*),
        column-sep=1em,label-align=right,
        item-indent=2.15em,label-width=1.6em,label-offset=0.5em,
        after-item-skip=0.5ex plus 0.5ex minus 0.5ex]{tablenuma}[\item](2)
  \fi
} % end of macro \exs@process@setlist

%    \end{macrocode}
% \DescribeEnv{tablitem}
%    \begin{macrocode}
\NewTasksEnvironment[label=\labelitemi,
    label-align=right,
    item-indent=2.3333em,label-offset=0.5em,
    after-item-skip=0.5ex plus 0.5ex minus 0.5ex]{tablitem}[\item](2)

%    \end{macrocode}
% \DescribeEnv{colsenum}
%    \begin{macrocode}
\newenvironment{colsenum}[2][]{%
    \setlength{\multicolsep}{2ex}
    \raggedcolumns % default is \flushcolumns
    \begin{multicols}{#2} % #2 = number of columns
    \begin{enumerate}[#1] % #1 = options of enumerate
    }{
    \end{enumerate}
    \end{multicols}
}

%    \end{macrocode}
% \DescribeEnv{colsenum*}
%    \begin{macrocode}
\newenvironment{colsenum*}[2][]{%
    \setlength{\multicolsep}{2ex}
    \begin{multicols}{#2} % #2 = number of columns
    \begin{enumerate}[#1] % #1 = options of enumerate
    }{
    \end{enumerate}
    \end{multicols}
}

%    \end{macrocode}
% \DescribeEnv{colsitem}
%    \begin{macrocode}
\newenvironment{colsitem}[2][]{%
    \setlength{\multicolsep}{2ex}
    \raggedcolumns
    \begin{multicols}{#2}
    \begin{itemize}[#1]
    }{
    \end{itemize}
    \end{multicols}
}

%    \end{macrocode}
% \DescribeEnv{colsitem*}
%    \begin{macrocode}
\newenvironment{colsitem*}[2][]{%
    \setlength{\multicolsep}{2ex}
    \begin{multicols}{#2}
    \begin{itemize}[#1]
    }{
    \end{itemize}
    \end{multicols}
}

%    \end{macrocode}
%
% \subsection{Questions and answers}
%
% \begin{macro}{\exs@process@output}
% |exesheet@questions| and |exesheet@answers| booleans
% control the display of corresponding environments.
% They are set by the \texttt{output} key option in the
% |\exs@process@output| macro.
%    \begin{macrocode}
\newboolean{exesheet@questions}\setboolean{exesheet@questions}{true}
\newboolean{exesheet@answers}\setboolean{exesheet@answers}{true}

\def\exs@process@output{
    \ifthenelse{\equal{\exesheet@output}{questions}}{
        \setboolean{exesheet@questions}{true}
        \setboolean{exesheet@answers}{false}
    }{% else if
    \ifthenelse{\equal{\exesheet@output}{answers}}{
        \setboolean{exesheet@questions}{false}
        \setboolean{exesheet@answers}{true}
    }{% else if
    \ifthenelse{\equal{\exesheet@output}{both}}{
        \setboolean{exesheet@questions}{true}
        \setboolean{exesheet@answers}{true}
    }{% else
    \PackageWarning{exesheet}{Value `\exesheet@output'
         is not supported by option `output'}
    }}}
}

%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{questions}
% We use the \textsf{versions} package  by Uwe Lück
% who provides |\comment| and |\endcomment| macros, 
% that allow the magic of conditional displays (we can also find them 
% in \textsf{verbatim} or \textsf{version} packages).
% The noteworthy \textsf{codesection} package, allows to encapsulate 
% optional code between the macros |\BeginCodeSection|\marg{skip} 
% and |\EndCodeSection|\marg{skip},
% both in the text body and in the preamble,
% but these macros cannot be used inside an environment 
% as we did here for |\comment| and |\endcomment|.
%
% Some tests are made by |\ifthenelse{\bolean{...}}|
% because |\comment| and |\endcomment| causes some hassle 
% with the \TeX\ structure |\if| \ldots |\else| \ldots |\fi|.
% The two counters |exe@ini| and |subpart@ini| are used in
% the following |\set@toclevel| macro.
%    \begin{macrocode}
\newcounter{exe@ini}
\newcounter{subpart@ini}

\newenvironment{questions}{
    \ifthenelse{\boolean{exesheet@questions}}{%
        \setcounter{exe@ini}{\value{exercise}}
        \setcounter{subpart@ini}{\value{subpart}}
    }{\comment}
}{\ifthenelse{\boolean{exesheet@questions}}{}{\endcomment}}

%    \end{macrocode}
% \end{environment}
% \begin{environment}{answers}
% The internal macro |\set@toclevel| calculates the title level (counter |toc@level|)
% to get a correct typesetting of the word ``\correctionname'' at the start of an
% \texttt{answers} environment (when \texttt{questions} and \texttt{answers} are
% displayed together). The principle is to compare the state of counters
% \texttt{exercise} and \texttt{subpart} with those saved at the time of
% the call of the \texttt{questions} environment. The |\@enumdepth| counter indicates the 
% \texttt{enumerate} list level in which we are (0 = out of lists).
% The optional parameter of the \texttt{answers} environment allows to force this title level.
%    \begin{macrocode}
\newcounter{@toclevel}
\newcommand{\set@toclevel}[1][]{
    \ifthenelse{\equal{#1}{}}{
        \ifthenelse{\value{exercise} > \value{exe@ini}}{
            \setcounter{@toclevel}{1}
        }{% else
        \ifthenelse{\equal{\the\@enumdepth}{0}}{
            % we're not in an enumerate environment
            \ifthenelse{\(\value{subpart} > \value{subpart@ini}\)
                \or \(\value{subpart} = 0\)}{
              \setcounter{@toclevel}{2}
            }{\setcounter{@toclevel}{3}}
        }{\setcounter{@toclevel}{4}}}
    }{\setcounter{@toclevel}{#1}}}

%    \end{macrocode}
% The internal macro |\typeset@correctionname|,
% typesets the word ``\correctionname'' at the right level.
%    \begin{macrocode}
\definecolor{correctioncolor}{rgb}{0,0.2,0.6} % kind of dark blue
\newcommand{\correctionstyle}{\color{correctioncolor}}

\newcommand{\typeset@correctionname}{
    \ifthenelse{\value{@toclevel} = 1}{
        \section*{\correctionstyle\correctionname}
        \ifexesheet@exetoc
            \addcontentsline{toc}{section}{\correctionname}
        \fi
        \setcounter{exercise}{0}
    }{% else if
    \ifthenelse{\value{@toclevel} = 2}{%
        \subsection*{\correctionstyle\correctionname}
        \ifexesheet@exetoc
            \addcontentsline{toc}{subsection}{\correctionname}
        \fi
        \setcounter{subpart}{0}
    }{% else if
    \ifthenelse{\value{@toclevel} = 3}{%
        \subsubsection*{\correctionstyle\correctionname}
        \ifexesheet@exetoc
            \addcontentsline{toc}{subsubsection}{\correctionname}
        \fi
    }{% else
    \par\textbf{\correctionstyle\correctionname}\par
    }}}
}

%    \end{macrocode}
% Then we can write the \texttt{answers} environment.
%    \begin{macrocode}
\newenvironment{answers}[1][]{% #1 is the optional level
    \ifthenelse{\boolean{exesheet@answers}}{%
        \ifthenelse{\boolean{exesheet@questions}}{
            \set@toclevel[#1]
            \typeset@correctionname
            \correctionstyle%
            \ifexesheet@multicol
                \renewcommand{\columnseprulecolor}{\color{correctioncolor}}
            \fi
        }{}
    }{\comment}
}{\ifthenelse{\boolean{exesheet@answers}}{}{\endcomment}}

\newenvironment{answers*}{
    \ifthenelse{\boolean{exesheet@answers}}{}{\comment}
}{\ifthenelse{\boolean{exesheet@answers}}{}{\endcomment}}

%    \end{macrocode}
% In the \texttt{answers} environment, when placing |\correctionstyle|
% before |\subsubsection| (case of |\typeset@correctionname|),
% the preceding vertical space may be too wide.
% \end{environment}
%
% \begin{macro}{\question}
%    \begin{macrocode}
\newcommand{\question}[1]{\ifexesheet@questions #1\fi}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\answer}
%    \begin{macrocode}
\newcommand{\answer}[1]{%
    \ifexesheet@answers%
        \ifexesheet@questions \correctionstyle #1\else #1\fi
    \fi
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\answerspace}
% The \texttt{answerspace} macro was a suggestion of Maxime Chupin
% to permit students to write answers on the given paper.
%    \begin{macrocode}
\newcommand\answerspace[1]{
    \ifexesheet@answerspace \par\vspace{#1} \fi}

%    \end{macrocode}
% \end{macro}
%
% \subsection{Marking scheme options processing} \label{MSoptions}
%
% Options \texttt{display}, \texttt{marginpos}, \texttt{marginwidth} 
% and \texttt{noteragged} are processed with the following internal commands.
%
% \medskip
% The \texttt{display} key option sets the value of the two booleans
% |exesheet@pts| and |exesheet@notes|. 
% |exesheet@pts| controls the display of the content of |\pts| and of optional arguments
% of |\note|,
% whereas |exesheet@notes| controls mandatory arguments of |\note|.
%
% \begin{macro}{\exs@process@display}
%    \begin{macrocode}
\newboolean{exesheet@pts}
\newboolean{exesheet@notes}

\def\exs@process@display{
    \ifthenelse{\equal{\exesheet@display}{pts}}{
        \setboolean{exesheet@pts}{true}
        \setboolean{exesheet@notes}{false}
    }{% else if
    \ifthenelse{\equal{\exesheet@display}{notes}}{
        \setboolean{exesheet@pts}{true}
        \setboolean{exesheet@notes}{true}
    }{% else if
    \ifthenelse{\equal{\exesheet@display}{none}}{
        \setboolean{exesheet@pts}{false}
        \setboolean{exesheet@notes}{false}
    }{% else
    \PackageWarning{exesheet}{Value `\exesheet@display'
         is not supported by option `display'}
    }}}
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\exs@process@marginpos}
% The \texttt{marginpos} key option takes value \texttt{left} (the default) or \texttt{right}
% (or \texttt{inner} and \texttt{outer}). In practice \texttt{inner} is equivalent to
% \texttt{left}
% but, in two side mode, \texttt{left} (the default value) or \texttt{right} 
% are converted to \texttt{outer} (the default value for two side mode).
%    \begin{macrocode}
\newboolean{exesheet@leftmargin}

\def\exs@process@marginpos{
    \ifthenelse{\equal{\exesheet@marginpos}{left}}{
        \if@twoside%
            \PackageWarningNoLine{exesheet}{Default `marginpos' option
                \MessageBreak
                for two side documents is `outer'.\MessageBreak
                Use `inner' to change the side}
            \def\exesheet@marginpos{outer}
            \setboolean{exesheet@leftmargin}{false}
            \normalmarginpar
        \else% default
            \setboolean{exesheet@leftmargin}{true}
            \reversemarginpar
        \fi
    }{% else if
    \ifthenelse{\equal{\exesheet@marginpos}{right}}{
        \if@twoside%
            \PackageWarningNoLine{exesheet}{Default `marginpos' option
                \MessageBreak
                for two side documents is `outer'.\MessageBreak
                Use `inner' to change the side}
            \def\exesheet@marginpos{outer}
        \fi
        \setboolean{exesheet@leftmargin}{false}
        \normalmarginpar
    }{% else if
    \ifthenelse{\equal{\exesheet@marginpos}{inner}}{
        \setboolean{exesheet@leftmargin}{true}
        \reversemarginpar
    }{% else if
    \ifthenelse{\equal{\exesheet@marginpos}{outer}}{
        \setboolean{exesheet@leftmargin}{false}
        \normalmarginpar
    }{% else
    \PackageWarningNoLine{exesheet}{Value `\exesheet@marginpos'
         is not supported by option `marginpos'}
    }}}}
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\exs@process@marginwidth}
% The \texttt{marginwidth} option changes the ratio between left and right margins
% depending on what has to be displayed in the margin (only points or full 
% notes)
% \footnote{So that the effect on the margin ratio is correct, this option is processed
% at begin document, after other commands 
% that also could alter page geometry.}.
%
% When \texttt{display=notes}, the additional length \texttt{1\,in} matches 
% the default free space to the left of |\oddsidemargin|.
%
% The macros |\standardmarginwidthfactor| and |\largemarginwidthfactor|
% represent the ratio between total margin width and |\marginparwidth|.
%
%    \begin{macrocode}
\def\standardmarginwidthfactor{0.6}
\def\largemarginwidthfactor{0.8}

\newcommand*{\leftnotemarginwidth}[1]{
    \setlength{\marginparwidth}{\oddsidemargin}
    \addtolength{\marginparwidth}{1in}
    \addtolength{\marginparwidth}{-\marginparsep}
    \setlength{\marginparwidth}{#1\marginparwidth}
}

\newcommand*\rightnotemarginwidth[1]{
    \setlength{\marginparwidth}{\paperwidth}
    \addtolength{\marginparwidth}{-\textwidth}
    \addtolength{\marginparwidth}{-\oddsidemargin}
    \addtolength{\marginparwidth}{-\marginparsep}
    \addtolength{\marginparwidth}{-1in}
    \setlength{\marginparwidth}{#1\marginparwidth} 
}

\def\exesheet@smallmargins{
    \geometry{hmarginratio=1:1}
    \leftnotemarginwidth{\standardmarginwidthfactor} % right gives the same
}
\def\exesheet@standardmargins{
    \ifexesheet@leftmargin
        \geometry{hmarginratio=3:2}
        \leftnotemarginwidth{\standardmarginwidthfactor}
    \else
        \geometry{hmarginratio=2:3}
        \rightnotemarginwidth{\standardmarginwidthfactor}
    \fi
}
\def\exesheet@largemargins{
    \ifexesheet@leftmargin
        \geometry{hmarginratio=3:1}
        \leftnotemarginwidth{\largemarginwidthfactor}
    \else
        \geometry{hmarginratio=1:3}
        \rightnotemarginwidth{\largemarginwidthfactor}
    \fi
}

\def\exs@process@marginwidth{
    \ifthenelse{\equal{\exesheet@marginwidth}{standard}}{
        \ifthenelse{\equal{\exesheet@display}{none}}{
            \if@twoside
                \exesheet@standardmargins
            \else
                \exesheet@smallmargins
            \fi
        }{% else display=pts or notes
            \exesheet@standardmargins
        }
    }{% else if
    \ifthenelse{\equal{\exesheet@marginwidth}{expand}}{
        \ifthenelse{\equal{\exesheet@display}{none}}{
            \if@twoside
                \exesheet@standardmargins
            \else
                \exesheet@smallmargins
            \fi
        }{% else if
        \ifthenelse{\equal{\exesheet@display}{pts}}{
            \exesheet@standardmargins
        }{% else display=notes
            \exesheet@largemargins
        }}
    }{% else if  
        \ifthenelse{\equal{\exesheet@marginwidth}{unset}}{
        % do nothing
    }{% else
    \PackageWarningNoLine{exesheet}{Value `\exesheet@marginwidth'
         is not supported by option `marginwidth'}
    }}}
}

%    \end{macrocode}
% \end{macro}
% For a two side mode document, the package \textsf{geometry} doesn't set the margin 
% paragraph width correctly by default, it's too large. So we made here an explicit setting
% useful in the case of \texttt{marginwidth=unset}. Otherwise, the setting is
% made by the \texttt{marginwidth} key option.
% 
%    \begin{macrocode}
\if@twoside \rightnotemarginwidth{0.5} \fi

%    \end{macrocode}
% \begin{macro}{\exs@process@noteragged}
% The noteragged option takes one of the following values:
% \texttt{left}, \texttt{right}, \texttt{center}, \texttt{justify} or \texttt{twoside}.
%
% |\marginpar| with optional parameter makes the job for a two side document.
% We then use |\noteraggedleft| and |\noteraggedright| instead of |\noteragged|.
% % Commands |\RaggedLeft|, |\RaggedRight|, |\Centering| and |\justifying|
% come from the \textsf{ragged2e} package by Martin Schröder.
% They give better results as standard commands
% |\raggedleft|, |\raggedright| (or |\centering|).
% The default \LaTeX\ setting for marginal notes is justifying.
%    \begin{macrocode}
\newcommand{\noteragged}{}
\newcommand{\noteraggedleft}{}
\newcommand{\noteraggedright}{}

\def\exs@process@noteragged{
    \ifthenelse{\equal{\exesheet@noteragged}{left}}{
        \if@twoside
            \renewcommand{\noteraggedleft}{\RaggedLeft}
            \renewcommand{\noteraggedright}{\RaggedLeft}
        \else
            \renewcommand{\noteragged}{\RaggedLeft}
        \fi
    }{% else if
    \ifthenelse{\equal{\exesheet@noteragged}{right}}{
        \if@twoside
            \renewcommand{\noteraggedleft}{\RaggedRight}
            \renewcommand{\noteraggedright}{\RaggedRight}
        \else
            \renewcommand{\noteragged}{\RaggedRight}
        \fi
    }{% else if
    \ifthenelse{\equal{\exesheet@noteragged}{center}}{
        \if@twoside
            \renewcommand{\noteraggedleft}{\Centering}
            \renewcommand{\noteraggedright}{\Centering}
        \else
            \renewcommand{\noteragged}{\Centering}
        \fi
    }{% else if
    \ifthenelse{\equal{\exesheet@noteragged}{justify}}{
          \renewcommand{\noteraggedleft}{\justifying} % equiv to nothing
          \renewcommand{\noteraggedright}{\justifying}
          \renewcommand{\noteragged}{\justifying}
    % justify is the default LaTeX setting
    }{% else  if
    \ifthenelse{\equal{\exesheet@noteragged}{twoside}}{
        \if@twoside
            \renewcommand{\noteraggedleft}{\RaggedLeft}
            \renewcommand{\noteraggedright}{\RaggedRight}
        \else
            \PackageWarning{exesheet}{Invalid option `noteragged=twoside'
             when the document \MessageBreak is not in two side mode}
        \fi
    }{% else
    \PackageWarning{exesheet}{Value `\exesheet@noteragged'
         is not supported by option `noteragged'}
    }}}}}
}

%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\exs@process@checkpts}
% The scale control option is based on length calculus.
% By default these calculus are local but we need to make them global,
% therefore the two first macros |\gsetlength| and |\gaddtolength|.
% In them we must avoid to produce a too large space at the place
% where |\marginpar| is called, therefore all \% symbols at end of lines.
%
% For each question, points assigned will be added in |\sum@pts|
% and, for each exercise, points are accumulated in |\sum@exe|.
% These lengths are compared to |\exe@total| and |\sheet@total|.
% |\exe@check| is called at the beginning of each exercise 
% (when macro |\points|, |\totalexe| or |\totalpoints| is called)
% to check the previous one,
% and also in the |\exs@process@checkpts| at end of document
% to check the last exercise.
%    \begin{macrocode}
\newlength{\sheet@total}
\newlength{\sum@exe}
\newlength{\exe@total}
\newlength{\sum@pts}
\def\exe@label{none}
\newboolean{scale@valid}
\setboolean{scale@valid}{true}

\gdef\gsetlength#1#2{% to get global length values
    \begingroup
        \setlength\skip@{#2}% local assignment to a scratch register
        \global#1=\skip@%     global assignment to #1
    \endgroup               % \skip@ is restored by end of group
}

\gdef\gaddtolength#1#2{% percent symbol necessary here !
    \begingroup
        \setlength\skip@{#1}%
        \addtolength\skip@{#2}%
        \global#1=\skip@%
    \endgroup
}

\def\exe@check#1{
    \ifthenelse{\lengthtest{\sum@pts = 0pt}\or\equal{\exe@label}{none}}{
    % do not check, no \pts or first exercise begins
    }{
        \ifthenelse{\lengthtest{\exe@total = \sum@pts}}{
            \PackageWarningNoLine{exesheet}{\exe@label:
                scale \the\exe@total\space is valid}
        }{
        \PackageWarningNoLine{exesheet}{\exe@label:
            sum of points is 
            \the\sum@pts\space instead of \the\exe@total}
        \setboolean{scale@valid}{false}
        }
        \gsetlength{\sum@pts}{0pt}
    }
    \def\exe@label{#1} % for the next exercise
}

\def\exs@process@checkpts{
    \ifexesheet@checkpts
        \ifthenelse{\lengthtest{\sheet@total = 0pt}}{
            \PackageWarningNoLine{exesheet}{Option checkpts is true;
                \MessageBreak
                but you didn't use \string\totalsheet\space
                in the preamble. \MessageBreak
                See the documentation for more information}
        }{}
        \gsetlength{\sum@exe}{0pt}
        \gsetlength{\exe@total}{0pt}
        \gsetlength{\sum@pts}{0pt}
        \AtEndDocument{
            \ifthenelse{\equal{\exe@label}{none}}{
                \ifthenelse{\lengthtest{\sheet@total = \sum@pts}}{
                    \PackageWarningNoLine{exesheet}{Sum of points
                        is valid: \the\sheet@total}  
                }{
                    \PackageWarningNoLine{exesheet}{Inconsistent 
                        sum of points: 
                        \the\sum@pts\space instead of \the\sheet@total}
                    \setboolean{scale@valid}{false}
                }
            }{
                \exe@check{end}
                \ifthenelse{\lengthtest{\sheet@total = \sum@exe}}{
                    \PackageWarningNoLine{exesheet}{Sum of points
                        is valid: \the\sheet@total}
                }{
                    \PackageWarningNoLine{exesheet}{Inconsistent
                        sum of points:
                        \the\sum@exe\space instead of \the\sheet@total}
                    \setboolean{scale@valid}{false}
                }
            }
            \ifthenelse{\boolean{scale@valid}}{
                \PackageWarningNoLine{exesheet}{Scale is valid}
            }{
                \PackageWarningNoLine{exesheet}{Scale is NOT valid ! 
                    See above}
            }
        }
    \fi
}

%    \end{macrocode}
% \end{macro}
%
% \subsection{Margin notes commands}
%
% \begin{macro}{\points}
%    \begin{macrocode}
\definecolor{pointscolor}{named}{red}
\newcommand{\pointsstyle}{%
    \small\mdseries\sffamily\color{pointscolor}\fbox}
\newcommand*{\exesheet@points}[1]{\hfill
    \pointsstyle{#1~%
        \ifthenelse{\lengthtest{#1pt < 2pt}}{\pointname}{\pointsname}}
    \ifexesheet@checkpts\gaddtolength{\sum@exe}{#1pt}\fi%
}
\newcommand*{\points}[1]{%
    \ifthenelse{\boolean{exesheet@questions}}{\exesheet@points{#1}}{}}

%    \end{macrocode}
% Percent symbols are necessary to avoid spaces between the
% |\fbox| and its inner text.
% Without |\lengthtest|, the test |#1 < 2| doesn't work with decimal numbers
% but it works with lengths.
% \end{macro}
% \DescribeMacro{\pts}
%    \begin{macrocode}
\definecolor{ptscolor}{named}{red}
\newcommand{\ptsstyle}[1]{%
    \footnotesize\centering\sffamily\color{ptscolor} (#1)}
\newcommand*{\ptsmark}[1]{%
    \ifthenelse{\lengthtest{#1pt < 2pt}}{#1 \ptname}{#1 \ptsname}}
\newcommand*{\pts}[1]{%
    \ifexesheet@pts%
        \mbox{}%
        \marginpar{\hspace{0pt}\ptsstyle{\ptsmark{#1}}}%
        \ifexesheet@checkpts%
            \gaddtolength{\sum@pts}{#1pt}%
        \fi%
    \fi%
    \ignorespaces
}

%    \end{macrocode}
%
% \begin{macro}{\totalexe}
% In the following macros using
% |\marginpar|, percent symbols and |\ignorespaces| are necessary 
% to avoid an enlarged blank space in the text (or the margin)
% where these macros are inserted.
%    \begin{macrocode}
\definecolor{markingcolor}{named}{red}
\newcommand{\markingstyle}[1]{\footnotesize\sffamily% 
    \centering\color{markingcolor}\textbf{#1}}
    % inner arguments allow boxed styles
\newlength{\ptsboxlength}
\setlength{\ptsboxlength}{3.1em}
\cornersize{1}
\newcommand*{\totalexe}[1]{%
    \ifexesheet@pts%
        \mbox{}%
        \marginpar{\hspace{0pt}\markingstyle{\ovalbox{%
            \makebox[\ptsboxlength]{\ptsmark{#1}}}}}%
    \fi%
    \ifexesheet@checkpts%
        \gsetlength{\exe@total}{#1pt}%
        \gaddtolength{\sum@exe}{#1pt}%
    \fi%
    \ignorespaces
}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\totalsheet}
%    \begin{macrocode}
\newcommand*{\totalsheet}[1]{
    \gsetlength{\sheet@total}{#1pt}
}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\note} 
% Boolean \texttt{exesheet@pts} and \texttt{exesheet@notes} control
% the display of marginal notes. If \texttt{exesheet@pts} is \texttt{false},
% \DescribeMacro{\note*}
% \texttt{exesheet@notes} will be ignored.
% |\noindent| is necessary when using |\justifying| from the \textsf{ragged2e}
% package.
% Inside the |\note@marginpar| macro, double braces around |\markingstyle|
% avoid some unattended style in the mandatory argument of |\note|. 
% A vicious error occur when using |\if| \ldots |\fi| structure inside
% the |\note@marginpar| macro instead of |\ifthenelse| 
% (but only if |@twoside| is \texttt{true}).
%    \begin{macrocode}
\definecolor{notecolor}{rgb}{0.0, 0.4, 0.0} % kind of dark green  
\newcommand{\notestyle}[1]{\footnotesize\sffamily\color{notecolor} #1}
\newcommand{\note@marginpar}[1]{%
    \if@twoside%
        \marginpar[\noteraggedleft #1]{\noteraggedright #1}%
    \else%
        \marginpar{\noteragged #1}%
    \fi%
}
\newcommand{\@note}[2][]{%
    \ifexesheet@pts%
        \mbox{}%
        \note@marginpar{%
            \ifthenelse{\equal{#1}{}}{}{{%
                \noindent\hspace{0pt}\markingstyle{#1}\\}}%
            \ifthenelse{\boolean{exesheet@notes}}{%
                \noindent\hspace{0pt}\notestyle #2%
            }{}%
        }%
    \fi%
    \ifexesheet@checkpts%
        \ifthenelse{\equal{#1}{}}{}{%
            \gaddtolength{\sum@pts}{#1pt}}%
    \fi%
    \ignorespaces
}
\newcommand{\@@note}[1]{%
    \ifexesheet@pts%
        \mbox{}%
        \marginpar{\noindent\hspace{0pt}\markingstyle{#1}}%
    \fi%
    \ifexesheet@checkpts%
        \gaddtolength{\sum@pts}{#1pt}%
    \fi%
    \ignorespaces
}
\newcommand{\note}{\@ifstar{\@@note}{\@note}}

%    \end{macrocode}
% \end{macro}
% \begin{macro}{\totalpoints}
%    \begin{macrocode}
\newcommand{\totalpoints}{%
    \ifthenelse{\boolean{exesheet@pts}}{\totalexe}{\points}}

%    \end{macrocode}
% \end{macro}
%
% \subsection{The \texttt{correct} option and other (deprecated) commands}
%
% \begin{macro}{\exs@process@correct}
%    \begin{macrocode}
\def\exs@process@correct{     
    \ifthenelse{\equal{\exesheet@correct}{false}}{
        % do nothing
    }{% else
    \@ifpackageloaded{schooldocs}{
        \ifthenelse{\equal{\exesheet@correct}{true}}{
            \correct
        }{% else
        \ifthenelse{\equal{\exesheet@correct}{conditional}}{
            \ifexesheet@answers \correct \fi
        }{}}
    }{
        \PackageWarningNoLine{exesheet}{Package `schooldocs' must be loaded
            \MessageBreak
            to use the `correct' option}
    }}
}

%    \end{macrocode}
% \end{macro}
%
% The following macros are maintained for now
% only for compatibility reasons.
%    \begin{macrocode}
\newcommand{\questionsonly}{
    \PackageWarning{exesheet}{Command \string\questionsonly\space 
        is deprecated, \MessageBreak
        use `output=questions' as package option instead}
    \renewcommand\exesheet@output{questions}
    \exs@process@output
}
\newcommand{\answersonly}{
    \PackageWarning{exesheet}{Command \string\answersonly\space 
        is deprecated, \MessageBreak
        use `output=answers' as package option instead}
    \renewcommand\exesheet@output{answers}
    \exs@process@output
}
\newcommand{\displaypts}{%
    \PackageWarning{exesheet}{Command \string\displaypts\space 
        is deprecated, \MessageBreak
        use `display=pts' as package option instead}
    \renewcommand\exesheet@display{pts}
    \exs@process@display
}
\newcommand{\displaypoints}{%
    \PackageWarning{exesheet}{Command \string\displaypoints\space 
        is deprecated, \MessageBreak
        use `display=pts' as package option instead}
    \renewcommand\exesheet@display{pts}
    \exs@process@display
}
\newcommand*{\displaynotes}[1][\RaggedLeft]{%
    % \renewcommand{\noteragged}{#1} no effect now!
    \PackageWarning{exesheet}{Command \string\displaynotes\space 
        is deprecated, \MessageBreak
        use `display=notes' as package option instead}
    \renewcommand\exesheet@display{notes}
    \exs@process@display
    \renewcommand{\noteragged}{#1}
}
\newcommand*{\displaynotesright}[1][\RaggedRight]{%
    % \renewcommand{\noteragged}{#1} no effect now!
    \PackageWarning{exesheet}{Command \string\displaynotes\space 
        is deprecated, \MessageBreak
        use `display=notes, margin=right' as package options instead}
    \renewcommand\exesheet@display{notes}
    \exs@process@display
    \renewcommand\exesheet@margin{right}
    \renewcommand{\noteragged}{#1}
}

\PackageInfo{exesheet}{Environment `tablenum' is deprecated \MessageBreak
    and replaced by `tablenum1'. \MessageBreak
    Options `notoc' and `nosetlist' \MessageBreak
    are no longer supported\@gobble} 
    % gobble allow to suppress line number
%</package>
%    \end{macrocode}
%
% \Finale
\endinput