summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/chess-problem-diagrams/diagram.dtx
blob: 8213e7b45321ae028f10402a77679bd085320aae (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
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
% \iffalse meta-comment
%%  File 'diagram.dtx'
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version
%% 1.2 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.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%%
%%
% \fi
% \def\fileversion{v1.12}
% \def\docdate{2016/01/06}
% \CheckSum{4288}
% \changes{v0.1}{15 Februar 2004}{First Version}
% \changes{v0.2}{23 Februar 2004}{Added the documentation for the
% {\itshape information collecting} macros which may be used
% inside a environment.}
% \changes{v0.3}{21 May 2004}{Added list of commands which should
% not be indexed.}
% \changes{v0.4}{11 May 2005}{Added most missing user documentation.}
% \changes{v0.5}{25 May 2007}{Fixed wrong piece count when using
% imitators}
% \changes{v0.6}{01 June 2007}{Changed errneous code to parse given
% piececount.}
% \changes{v1.5}{09 March 2008}{Added license meta-comment to
% publish package on ctan.}
% \changes{v1.5.1}{08 Jun 2010}{Fixed font problem when writing
% producing piececounter in small diagrams.}
% \changes{v1.5.2}{13 Jun 2010}{Added some percent signs at line
% ends in @start@diagram and enddiagam to avoid accidently added
% spaces.}
% \changes{v1.5.3}{04 Oct 2010}{Changed switch, which is used to
% decide, whether infomration about computer proof is displayed
% to use standard boolean syntax. Symbols about computer
% proof are now created by standard commands and may
% therefore be changed by users.}
% \changes{v1.5.4}{03 Jun 2011}{Defined 2 different versions of
% @writename command, to be able to change it in other
% stylefiles for the part over the diagram without influencing
% the one used for the solution. Added commands to set white,
% black and neutral Circles within text.}
% \changes{v1.5.5}{01 July 2011}{Changed amount of lowering
% figurine pieces.}
% \changes{v1.5.6}{09 August 2011}{Added new command
% 'solpar' to allow use
% of 'putsol' inside a window environment.}
% \changes{v1.6}{30 April 2012}{Added boolean showcity and code
% to suppress display of city, when showcity is false. Added
% commands for academic titles, which allow to suppress their
% display.}
% \changes{v1.6.1}{24 September 2012}{Added new command piecedefs specify names
% of fairy pieces for rotated pieces.}
% \changes{v1.6.2}{11 November 2012}{Added boolean for allwhite problems.}
% \changes{v1.6.3}{12 November 2012}{Added boolean for board with switched field colors.}
% \changes{v1.6.4}{12 November 2012}{Added convenience command for 'allwhite' and 'switchcolors' booleans.}
% \changes{v1.6.5}{21 June 2013}{As suggested by Torsten Lin{\ss} and Thomas Brand added support for Equihopper and turned Equihopper (X)}
% \changes{v1.6.6}{06 July 2013}{Introduced new command to switch to the default diagram size.}
% \changes{v1.6.7}{17 August 2013}{Fixed issue '19a' with allwhite on quadratic fields.}
% \changes{v1.7.0}{17 August 2013}{Implemented Issue '32c': the command diagnum now allows to specify a prefix to be used for the following diagrams.}
% \changes{v1.8.0}{27 November 2013}{Implemented issue '03f/f2a': Added code to display a legend around the board, controlled by the boolean 'legend'.}
% \changes{v1.8.1}{17 August 2014}{Implemented issue '03f/83c': changed tex boolean solafterdiagram to latex boolean.}
% \changes{v1.9}{10 Januar 2015}{Implemented issue '03f/932': Renamed boardfont to cpd@boardfont due to a naming collision with another chess package. Changed all font definitions to newcommand instead of def.}
% \changes{v1.10}{26 January 2015}{Fixed issue: 03f/658:om: diagram.sty:
% evaluation of options 11pt and 12pt does not work.}
% \changes{v1.11}{30 January 2015}{Fixed issue 03f/e20:om: diagram.sty:
% piecedefs should be written after twins and before remarks.}
% \changes{v1.11.1}{16 March 2015}{Fixed issue 03f/b31:om: diagram.sty: label and ref don't respect diagnum prefix or diagnumbering setting.}
% \changes{v1.12}{06 January 2016}{Implemented issue: 03f/fc0:om: diagram.dtx: change  def x to  newcommand.\\
% Changed name of internal commands ds@left, ds@right, ds@upsidedown due to a naming collising with options from eurosym.sty.}
%
% \DoNotIndex{\@arabic,\def,\@idxitem,\@ifnextchar,\@ifstar,
% \@ne,\@ptsize,\ ,\advance,\AtEndOfPackage,\begin,\begingroup,
% \bfseries,\bgroup,\boolean,\box,\char,\chardef,\closeout,
% \count,\csname,\DeclareOption,\DocInput,\documentclass,
% \egroup,\else,\end,\endcsname,\endgroup,\endinput,\errmessage,
% \exhyphenpenalty,\expandafter,\fi,\font,\fonddimen,\gdef,\global,
% \hangafter,\hangindent,\hbox,\hfill,\hrule,\hsize,\hskip,\hss,\if,
% \ifcase,\ifdim,\iffalse,\ifmmode,\ifnum,\ifodd,\ifthenelse,
% \ifvmode,\ifx,\immediate,\index,\input,\itshape,\kern,\label,\let,
% \llap,\long,\loop,\lower,\mbox,\medskip,\multiply,\newboolean,\newbox,
% \newcount,\newcounter,\newdimen,\newif,\newindex,\newline,\newtoks,
% \newwrite,\noexpand,\noindent,\openout,\OptionNotUsed,\or,\p@,\par,
% \parindent,\parskip,\penalty,\printindex,\ProcessOptions,\ProvidesFile,
% \ProvidesPackage,\raise,\RecordChanges,\ref,\refstepcounter,\relax,
% \repeat,\RequirePackage,\rmfamily,\setboolean,\setbox,\setlength,
% \the,\textwidth,\unhbox,\usepackage,\vbox,\vfil,\vrule,\vskip,
% \vss,\vtop,\wd,\write,\xdef,\z@}
% 
% \title{Creating diagrams for chess problems\\{\large Version~\fileversion}}
% \author{Thomas Brand\\Bornheim\and Stefan H\"oning\\Neuss}
% \date{\docdate}
%
% \maketitle
%
% \begin{abstract}
% It have been more than ten years now, since we last published a documented
% version of the {\ttfamily diagram.sty}, which is mainly intended to
% be used for typesetting chess problems. Since 1994 I (Stefan H"oning) made a
% couple of enhancements to the sourcecode of the style, without publishing and
% putting this into the documentation. We also needed to upgrade to \LaTeXe.
% The major change is the documentation language, which is english now.
%
% The style itself tries to collect very detailed information
% about a chess problem by providing a lot of commands,
% which you may use to specify the necessary information. There
% are different reasons for this.  One idea was to enable people
% to read \LaTeX-diagrams into databases with information as
% detailed as possible. Otherwise it should be easy to change the
% layout of a diagram by applying a changed style - not by
% changing the source.
% \end{abstract}
%
% \newpage
% \tableofcontents
% \newpage
%
% \newcommand{\explained}[1]{{\itshape#1}}
% \newcommand{\magazine}[1]{{\bfseries\itshape #1}}
% \newcommand{\Schwalbe}{\magazine{Die Schwalbe}}
%
% \section{Creating diagrams}
% \subsection{An introductary example}
% Let us first take a look at a simple example which should only
% show what you have to type into your \LaTeX-code to get nice
% looking diagrams.
%
% \bigskip
% %
% \begin{diagram}
%  \label{BSP1}
%  \author{Brand, Thomas}
%  \source{Problemkiste} \year{1992}
%  \dedic{Elmar Bartel gew.}
%  \pieces[2+3]{wKd1, wBe2, sKh8, sBe4, sTa4}
%  \stip{h\#7}
%  \sol{1.Ta3 Kc2!, 2.Tf3 e\x f3, 3.e3 f4, 4.e2 f5, 5.e1T f6, 
%       6.Th1! (Te7?) f7, 7.Th7 f8D\#}
% \end{diagram}
% \hfill
% \begin{diagram}
%  \label{BSP2}
%  \setboolean{legend}{true}
%  \author{Brand, Thomas}
%  \source{Problemkiste} \year{1992}
%  \pieces[3+2]{wKa4, wLb5, wSh3, sKb7, sBh4}
%  \stip{h\#5}
%  \sol{1.Ka8 Sg1, 2.h3 Ka5, 3.h2 Kb6, 4.h\x g1L+ Kc7, 5.La7 Lc6\#}
% \end{diagram}
%
% \putsol
%
% \bigskip
% To use the package you have to make it available to \LaTeX\ using 
% \verb+\usepackage{diagram}+ inside the preamble of your document.
%
% Then you may use the {\ttfamily diagram} environment to create
% the diagrams. For the above example I had to type the
% following:
%
% \begin{verbatim}
% \begin{diagram}
%  \author{Brand, Thomas}
%  \source{Problemkiste} \year{1992}
%  \dedic{Elmar Bartel gew.}
%  \pieces[2+3]{wKd1, wBe2, sKh8, sBe4, sTa4}
%  \stip{h\#7}
%  \sol{1.Ta3 Kc2!, 2.Tf3 e\x f3, 3.e3 f4, 4.e2 f5, 5.e1T f6, 
%       6.Th1! (Te7?) f7, 7.Th7 f8D\#}
% \end{diagram}
%%
% \hfill
%%
% \begin{diagram}
%  \setboolean{legend}{true}
%  \author{Brand, Thomas}
%  \source{Problemkiste} \year{1992}
%  \pieces[3+2]{wKa4, wLb5, wSh3, sKb7, sBh4}
%  \stip{h\#5}
%  \sol{1.Ka8 Sg1, 2.h3 Ka5, 3.h2 Kb6, 4.h\x g1L+ Kc7, 5.La7 Lc6\#}
% \end{diagram}
%
% \putsol
% \end{verbatim}
%
% \DescribeEnv{diagram}
% Any information which belongs to a problem should be put
% between \verb+\begin{diagram}+ and \verb+\end{diagram}+. The
% above examples contains information for \explained{authors,
% source, year of publication, stipulation, solution} and (in
% diagram \ref{BSP1}) a \explained{dedication}.
%
% This information is shown around a chessboard except the
% solution, which is collected and put into the output using the
% \verb+\putsol+ command.
%
% \subsection{Elements of a diagram}
% This section describes the elements which may be used inside a 
% {\ttfamily diagram} environment. For most of these elements
% there is no sense using them between \verb+\begin{diagram}+ and
% \verb+\end{diagram}+. Some of them will not work outside of the
% environment (like |\author|). In case you use these switches
% anywhere outside you will specify the information for all
% problems in your surrounding environment (which may be the
% complete document).
%
% \subsubsection{Collecting the problem information}
% \MakeShortVerb{\|}
% The following information is typically given with a problem:
% \begin{itemize}
% \item \DescribeMacro{\author}
% With the |\author| tag you specify one author or a list of authors.
% If you specify more than one author, you must separate them
% with ";~". Normally an author is given as \explained{"sirname,
% givenname"}. You may change the way, how the name is
% interpreted by \LaTeX\ using |\normalnames| and
% |\reversednames|. This \verb+\author+ command does only
% overwrite the default behaviour when used inside a diagram
% environment.
% \item \DescribeMacro{\Dr} \DescribeMacro{\Prof}
% \DescribeMacro{\ProfDr}
% Within the Authors command you should use the commands |\Dr|,
% |\Prof| and |\ProfDr| to specify these academic titles. So one
% may switch off the display of these titles --- like it is
% generally done inside \Schwalbe.
% \item \DescribeMacro{\pieces}
% With |\pieces| you specify the position to be displayed on the
% board. For each kind of piece you may specify a list of fields.
% Different lists of fields are separated by ",~". So the general
% syntax for specifying the position of a specific piece
% is:\newline
% [color][piece]\{rotation of piece\}[list of squares];\newline
% e.\,g. {\ttfamily wTa1h1} should be clear, {\ttfamily nKa4} is
% a neutral king on a4\newline
% {\bfseries w s n} may be used to specify the color of the
% piece.\newline
% {\bfseries K D T L S B C E X} may be used to specify the piece. A {\bfseries
% C} is used for an imitator, {\bfseries E} for an equihopper and {\bfseries X}
% for a rotated equihopper. You may {\itshape not} use an optional rotation
% with {\bfseries C, E} and {\bfseries X}.\newline
% {\bfseries R U L} may be used to specify an optional rotation:
% right, upside-down, left. So you may use {\ttfamily sDUc7} for
% a grashopper on c7 --- displayed as an upsidedown
% queen.\newline The characters used to specify color, piece and
% rotation may be changed using the |\DefinePieces| command.
%
% You may also optionally specify the number of pieces in your
% diagram, which then will be used to control your input
% automatically.
%
% There is also support for an imitator, which is typically
% displayed as a black filled circle. So {\ttfamily sCf4} will
% produce the symbol of an imitator. This is shown in
% diagram~\ref{bigdia}.
% \item \DescribeMacro{\stipulation} \DescribeMacro{\stip}
% is used to specify the stipulation of the problem, e.\,g.\ 
% |\stipulation{\#2}| may be used to specify a \explained{mate in
% two}. There is also an abbreviation |\stip| for this macro.
% \item \DescribeMacro{\city}
% may be used to specify the city and country, where the author
% or the authors live. I use this inside the original section of 
% \Schwalbe. You should separate multiple cities (for multiple
% authors) with ";~". There is also a boolean switch |showcity|,
% which contols, whether this information is displayed.
% \item \DescribeMacro{\specialdiagnum}
% May be used to suppress the default diagram numbering (which
% uses a counter) and instead directly providing a diagram
% "number" which may be an arbritary text.
% \item \DescribeMacro{\sourcenr}
% May be used to specify the number which was used for the
% problem inside an originals section.
% \item \DescribeMacro{\source}
% May be used to specify the book or magazine where the problem
% was issued first.
% \item \DescribeMacro{\issue}
% May be used to specify e.\,g.\ the issue of a magazine where
% the problem was issued.
% \item \DescribeMacro{\pages}
% May be used to specify the page (or pages) where the problem
% was issued.
% \item \DescribeMacro{\day}
% \DescribeMacro{\month}\DescribeMacro{\months}
% \DescribeMacro{\year}
% May be used to specify the different parts of the date of
% publication of the problem. (E.\,g.\ for problems issued in the
% german magazine \Schwalbe\ you will typically only specify the
% |\month| and the |\year|. For problems issued in
% \magazine{feenschach} you may specify a period of months like 
% |\months{7-10}|.)
% \item \DescribeMacro{\tournament}\DescribeMacro{\award}
% May be used to specify an award and a tournament for the
% problem.
% \item \DescribeMacro{\dedication}\DescribeMacro{\dedic}
% May be used to specify a dedication which was given by the 
% author of the problem.
% \item \DescribeMacro{\condition}\DescribeMacro{\cond}
% May be used to specify the fairy conditions of a problem.
% Different conditions should be separated with ";~".
% \item \DescribeMacro{\twins}
% May be used to specify the different twins of a problem.
% Different twins should be separated with ";~".
% \item \DescribeMacro{\remark}\DescribeMacro{\rem}
% May be used to specify remarks to the problem. I typically use
% this to explain fairy pieces on the board. You may also use the 
% abbreviation |\rem|.
% \item \DescribeMacro{\piecedefs}
% May be used to explain rotated pieces. An example:\newline
% \verb+\piecedefs{{ws}{TL}{Turm-L\"aufer-J\"ager}; {wn}{SU}{Nachtreiter}}+
% will create\newline
% \hbox{\wTL\sTL = Turm-L\"aufer-J\"ager}\newline
% \hbox{\wSU\nSU = Nachtreiter}\newline
% under the diagram.
% \item \DescribeMacro{\solution}\DescribeMacro{\sol}
% |\solution| may be used to specify the solution of the problem.
% Normally this information is not used while displaying the
% board but it is only collected and may be put into your text
% using |\putsol|. There is also an abbreviation |\sol|.
% \item \DescribeMacro{\judgement}
% May be used to describe the judgement given for a problem,
% e.\,g. when you are working on an award or when you are
% selecting problems for a "best of \dots{}" book.
% \item \DescribeMacro{\comment}
% May be used to specify some comment on the problem (e.\,g. the
% authors original comment.)
% \item \DescribeMacro{\themes}
% May be used to specify themes displayed in the problem.
% Different themes should be separated with ";~". When creating a 
% theme index, the themes will automatically be used to create
% the register.
% \end{itemize}
%
% There are some commands which not only collect information but
% normally direct result in a change of the diagram. These are:
%
% \begin{itemize}
% \item \DescribeMacro{\verticalcylinder}
% does not display the outer vertical lines to symbolize a
% verticalcylindric board.
% \item \DescribeMacro{\horizontalcylinder}
% does not display the outer horizontal lines to symbolize a
% horizontalcylindric board.
% \item \DescribeMacro{\noframe}
% does completely suppress the outer frame e.\,g.\ to symbolize a
% torus board.
% \item \DescribeMacro{\noinnerframe}
% sometimes you need to suppress the inner frame instead of the
% outer frame which is achieved by using |\noinnerframe|. You may
% not use this together with |\noframe|.
% \item \DescribeMacro{\gridchess}
% displays lines to seperates fieldsections for gridchess.
% \end{itemize}
%
% \subsubsection{Modifying the layout of the diagram (and the
% solution)}
% There are a couple of switches which control the layout of
% the diagrams. These are typically used more generally, so you
% may specify these switches outside the {\ttfamily diagram}
% environment or use them in your own style, which depends on
% {\ttfamily cpd.sty}.
%
% There are some switches which control the layout of the
% information which is displayed above a diagram:
% \begin{itemize}
% \item \DescribeMacro{\diagleft}
% displayes the information left aligned
% \item \DescribeMacro{\diagcenter}
% displayes the information centered
% \item \DescribeMacro{\diagright}
% displayes the information right aligned
% \item \DescribeMacro{\widedias}
% is like |\diagcenter| but the information shown above the
% diagram may span the whole width of the page. So \LaTeX\ will
% not wrap long author names.
% \end{itemize}
%
% \DescribeMacro{\dianamestyle}
% \DescribeMacro{\solnamestyle}
% Using |\dianamestyle| (or |\solnamestyle|) you may specify how
% authornames are written above the boards (or before the
% solutions). You may use this only if you use |\reversednames|
% (which is the default). Otherwise it is not possible to
% distuingish between firstname and sirname. You must specify one
% of the following options as parameter to |\dianamestyle| (or
% |\solnamestyle|):
% \begin{description}
% \item[fullname]
% Writes the authorname as {\itshape firstname sirname}. This is
% the default.
% \item[sirname]
% Writes the {\itshape sirname} only.
% \item[short]
% Writes an abbreviation of the {\itshape firstname} and the
% {\itshape sirname}. The abbreviation is calculated as follows:
% \begin{itemize}
% \item The first letter of the {\itshape firstname} will be
% used.\newline
% |\author{Brand, Thomas}| will be displayed as {\bfseries T.
% Brand}
% \item When there is a combined {\itshape firstname} separated
% with a hyphen, each first letter will be used. (see
% below)\newline
% |\author{Reich, Hans-Peter}| will be displayed as {\bfseries
% H.-P. Reich}
% \item When specifying the author name, you may provide the
% abbreviation for the firstname using the form {\itshape
% sirname, firstname/abbreviation}.\newline
% |\author{Brand, Thomas/Th.}| will be displayed as {\bfseries
% Th.~Brand}
% \end{itemize}
% \item[noname]
% displayes nothing
% \end{description}
%
% \DescribeMacro{\diagnumbering}
% The same way you may specify |\pagenumbering| you may specify
% the format the diagrams are numbered using |\diagnumbering|
% and |\pagenumbering| you may specify {\ttfamily arabic, Roman, roman,
% Alph or alph}. The default used is {\ttfamily arabic}.
% This command also switches the display for diagram numbers on.
%
% \DescribeMacro{\setmonthstyle}
% You may also specify the way a month is displayed using
% |\setmonthstyle|.
%
% There are some boolean switches, which control whether a specific
% information is displayed. These are as follows:
% \begin{itemize}
% \item \DescribeMacro{piececounter}
% This is a \LaTeX\ boolean, which is used to specify whether the
% number of pieces is displayed below the board. So you may
% change its value using |\setboolean{piececounter}{true}| or
% |\setboolean{piececounter}{false}|.
% \item
% \DescribeMacro{showcomputer}
% \DescribeMacro{\nocomputer}\DescribeMacro{\showcomputer}
% There is a boolean value |computer|, which controls whether the
% infomration about a computer proof is displayed or not.  This
% value may be changed using |\setboolean{showcomputer}{true}| or
% |\setboolean{showcomputer}{false}| For backwards compatiblity
% we support the macros |\nocomputer| and |\showcomputer|.
% \item \DescribeMacro{showcity}
% This is a boolean switch, which controls whether the informated
% gathered using the |\city| command is displayed. The default of
% this value is |false|.
% \item \DescribeMacro{showacademictitle}
% This is a boolean switch, which controls whether academic
% titles |\Dr|, |\Prof| or |\ProfDr| --- typically used within
% the |\author| command --- are displayed. The default is |true|.
% \item \DescribeMacro{legend}
% This boolean controls whether a legend is displayed.  The default
% value of this value is |false|. When legends are displayed the
% distance between inner and outer frame is automatically adjusted.
% \end{itemize}
%
% \DescribeMacro{\notcomputerproofedsymbol}
% \DescribeMacro{\computerproofedsymbol}
% You may specify the text, which is used indicate, whether a
% problem is proofed by a computer. To specifiy the symbol for a
% problem, which is proofed, is created by
% |\computerproofedsymbol|.  To specifiy the symbol for a
% problem, which is not computer proofed, is created by
% |\notcomputerproofedsymbol|. You may redefine these commands by
% standard \LaTeX\ means (|\renewcommand|).

%
% \DescribeMacro{\selectelchfont}
% You may specify which font is used for the chesspieces. There
% are two possible fonts:
% \begin{description}
% \item[pk] for the font which was originally used in the german
% magazine \magazine{Problemkiste}
% \selectelchfont{pk}\hbox{\wK\wD\wT\wL\wS\wB\sK\sD\sT\sL\sS\sB}
% \item[fs] for the font which was first used (and was created
% for) the magazine \magazine{feenschach}
% \selectelchfont{fs}\hbox{\wK\wD\wT\wL\wS\wB\sK\sD\sT\sL\sS\sB}
% \end{description}
%
% \DescribeMacro{\diagramx}
% \DescribeMacro{\diagramxi}
% \DescribeMacro{\diagramxii}
% In analogy to the defaults for fontsizes of a document you may
% specify sizes of the fonts used in a diagram. The default will
% be set according to the fontsize specified as the
% |\documentclass| option.
% 
% \subsubsection{Other commands}
% \begin{itemize}
% \item \DescribeMacro{\label}
% This overrides the normal |\label| definition such that the 
% diagram number is displayed when using |\ref| instead of the 
% page number.
% \item \DescribeMacro{\diagnum} 
% This macro expects a number as a parameter. The number will be used to
% (re-)initialize the diagram number counter. With this command the output of
% diagram numbers also is switched on. It must be used outside the {\ttfamily
% diagram} environment.  As an optional parameter you may specify something,
% which will be used as prefix before the automatically updated diagram numbers.
% E.\,g.\ the command \verb+\diagnum[T-]{4}+ will produce the following diagram numbers for the
% following diagrams: \textbf{T-4}, \textbf{T-5}, \textbf{T-6}, \dots{}
% \end{itemize}
%
%
% \subsection{Special boards}
% \subsubsection{Changing the boardsize}
% \DescribeEnv{diagram[]}
% Instead of using a boardsize of $8\times8$ some fairy problems
% need smaller or larger boards. This can be achieved by
% specifying the rows and columns as an optional parameter to the
% |\begin{diagram}| environment. You first have to specify the
% lines and then the rows as the following examples shows.
%
% \bigskip
% \begin{diagram}[17x11]
% \label{bigdia}
% \pieces{wKUi{11}, sKRj9, sCc5b4}
% \end{diagram}
% \hspace{2em}
% \begin{minipage}[t]{7cm}
% \vspace*{-5cm}
% is created by
%
% \bigskip
% \begin{verbatim}
% \begin{diagram}[17x11]
% \label{bigdia}
% \pieces{wKUi{11}, sKRj9, sCc5b4}
% \end{diagram}
% \end{verbatim}
% \end{minipage}
%
% As you can see in the example, pieces are set using the
% |\pieces| macro. When using boards with more than 8 lines you
% have to continue with charachters {\bfseries i, j, k, \dots}\@
% In a board with more than 9 rows you have to specify the rows
% in curly braces \{ \} as shown in the example.
%
% \subsubsection{Stereo- and Space-Chess-Diagrams}
% \DescribeEnv{stereodiagram}
% \DescribeEnv{spacediagram[]}
% Other boards which are used from time to time are stereochess
% or spacechess boards (although there are quite few people which
% really have such boards!). To create these boards you just have
% to use either the |stereodiagram| or |spacediagram| environment
% instead of the normal |diagram| environment. Here is an
% example:
%
%
% \begin{stereodiagram}
% \author{Jensch, Gerhard W.}
% \sourcenr{3104.}
% \source{feenschach}
% \year{1980}
% \award{Preis}
% \pieces{wKf3, wTf6d5A, wLe3, wSf4A, sKe5, sTc4D, sLc4C, sSc6, sBb6c4A}
% \stip{\#9}
% \end{stereodiagram}
% \hfill
% \begin{spacediagram}
% \author{Dawson, T. R.}
% \sourcenr{6595.}
% \source{Fairy Chess Review}
% \month{12}
% \year{1945}
% \pieces{wKc1A, wLe1A, sKa1A, sBa2Aa1Ba2Bd3Be4Bd2Ce2D}
% \stip{\#2}
% \end{spacediagram}
%
% These diagrams have been produced by the following code:
%
% \begin{verbatim}
% \begin{stereodiagram}
% \author{Jensch, Gerhard W.}
% \sourcenr{3104.}
% \source{feenschach}
% \year{1980}
% \award{Preis}
% \pieces{wKf3, wTf6d5A, wLe3, wSf4A, sKe5, sTc4D, sLc4C, sSc6, sBb6c4A}
% \stip{\#9}
% \end{stereodiagram}
% \hfill
% \begin{spacediagram}
% \author{Dawson, T. R.}
% \sourcenr{6595}.
% \source{Fairy Chess Review}
% \month{12}
% \year{1945}
% \pieces{wKc1A, wLe1A, sKa1A, sBa2Aa1Ba2Bd3Be4Bd2Ce2D}
% \stip{\#2}
% \end{spacediagram}
% \end{verbatim}
%
% The main change is within the notation of the pieces, but
% people knowing space- or stereo-chess problems see that the
% notation is just one would expect.
%
% \DescribeMacro{\spacelayout}
% Sometimes one would like show the different planes of a
% space diagram from left to right. This may be switched using
% the |\spacelayout| command, which takes one parameter:
%
% \begin{description}
% \item[vertical] for planes organized bottom up
% \item[horizontal] for planes organized left to right
% \end{description}
%
% \noindent\begin{spacediagram}[4x2x3]
% \spacelayout{horizontal}
% \end{spacediagram}
% \hfill%
% \hbox{\vbox{%
% \hsize6cm
% Is produced by
%
% \begin{verbatim}
% \begin{spacediagram}[4x2x3]
% \spacelayout{horizontal}
% \end{spacediagram}
% \end{verbatim}
% }}
%
% \subsubsection{Cylindric boards / suppressing frames}
% \noindent\hbox{}%
% \DescribeMacro{\horizontalcylinder}
% \DescribeMacro{\verticalcylinder}
% \DescribeMacro{\noframe}
% \DescribeMacro{\noinnerframe}
% To stylize a cylindric board one typically does not show parts
% of the frame. When using |\verticalcylinder| the horizontal
% lines of the outer frame will not be drawn.
% |\horizontalcylinder| suppresses the drawing of the vertical
% lines of the outer frame. Using |\noframe| completely supresses
% the outer frame. |\noinnerframe| suppresses the innerframe. 
% In case of stereo- or space-chess-diagrams |\verticalcylinder|,
% |\horizontalcylinder| and |\noframe| suppresses the inner
% frame.
%
% \subsection{Change the coloring of the fields}
% \DescribeMacro{\allwhite}
% The \verb+allwhite+ boolean can be used to have all white squares.  Therefore
% dotted lines are produced to separate the squares.  For convenience we
% provide a command \verb+allwhite+ which switches the value of the
% \verb+allwhite+ boolean to true.
%
% \bigskip
% \begin{diagram}
% \allwhite
% \pieces{wKe1, wDd1, wTa1h1, wLf1c1, wSb1g1, sKe8, sDd8, sTa8h8, sLf8c8, sSb8g8}
% \end{diagram}
% \hfill
% \begin{minipage}[b]{7cm}
% \vspace*{-3cm}
% This was produced by:
%
% \begin{verbatim}
% \begin{diagram}
% \allwhite
% \pieces{wKe1, wDd1, wTa1h1, wLf1c1, wSb1g1, %
%     sKe8, sDd8, sTa8h8, sLf8c8, sSb8g8}
% \end{diagram}
% \end{verbatim}
% \end{minipage}
%
% \DescribeMacro{\switchcolors}
% The boolean \verb+switchcolors+ may be used to switch the coloring of white
% and black fields.  For convenience we provide a command \verb+switchcolors+
% which switches the value of the \verb+switchcolors+ boolean to true.
% 
% \bigskip
% \begin{diagram}
% \switchcolors
% \end{diagram}
%
%
% \subsubsection{figurine Notation}
% \DescribeEnv{figurine}
% Instead of using the |diagram|, |stereodiagram| or
% |spacediagram| environment one may use the |figurine|
% environment. This suppresses the diagram output and produces a
% figurine notation inside the current text.
%
% \subsubsection{Changes within the board}
% \DescribeMacro{\nofields}
% \DescribeMacro{\nosquares}
% You may remove single fields by using the |\nofields| or
% |\nosquares| command. Using this command does make sense for 
% empty black fields only. This command expects a list of squares
% separated by "',~"'. You may also use this command within a
% stereo- or space-diagram. In this case you must specify the
% fields the same way you do it inside the |\pieces| command.
%
% \DescribeMacro{\fieldframe}
% You may specify single fields, which should be surrounded by a
% frame. This is possible using the |\fieldframe| command. You
% must specify the list of fields which should have frames the
% same way you specify fields within the |\nofields| command.
%
% \DescribeMacro{\gridlines}
% A more general form of lines within diagrams is possible by
% using the |\gridlines| command. You may specify a list of
% horizontal or vertical lines within the diagram. Different
% lines should be separated by "',~"'. A single line must be
% specified as:
%
% [plane](v or h)(x-coordinate)(y-coordinate)(length in squares)
%
% You must specify a plane in case of stereo- or space-chess
% only. For a vertical line starting at the lower left corner of
% "'c2"' ending at the upper left corner of "'c8"' the command to
% use is: |\gridlines{v217}|\@. Concerning the coordinates and
% length specifications you should pay attention to put values
% greater 9 in curly braces \{ \}.
%
% \DescribeMacro{\fieldtext}
% Sometimes you need to show text on some squares. This is done
% using the |\fieldtext| command. The syntax for a single text
% is: \{Text\}(x-coordinate)(y-coordinate)
%
% Now an example how to use |\gridlines|, |\nofields| and
% |\fieldtext| to create some "'{\itshape Letter-Board}"' with text
% inside.
%
% \bigskip
% \begin{diagram}[9x7]
% \label{Buchstabenbrett}
% \noinnerframe
% \nofields{a2, b2, c2, a3, b3, c3, %
%  b5, c5, d5, b6, c6, d6, %
%  e1, e2, e3, e4, e5, e6, e7, %
%  g1, h1, h2, h2, g3, h3, g5, h5, g6, h6, g7, h7}
% \gridlines{h004, h013, h033, h143, h163, h074, %
%  v001, v034, v142, v312, v404, v461, %
%  h501, h571, h632, h642, h801, h871, %
%  v507, v603, v643, v803, v843, v907}
% \fieldtext{{It ...}c5, {works}b2}
% \end{diagram}
% \hfill
% \begin{minipage}[b]{10cm}
% \begin{verbatim}
% \begin{diagram}[9x7]
% \noinnerframe
% \nofields{a2, b2, c2, a3, b3, c3, %
%  b5, c5, d5, b6, c6, d6, %
%  e1, e2, e3, e4, e5, e6, e7, %
%  g1, h1, h2, h2, g3, h3, g5, h5, g6, h6, g7, h7}
% \gridlines{h004, h013, h033, h143, h163, h074, %
%  v001, v034, v142, v312, v404, v461, %
%  h501, h571, h632, h642, h801, h871, %
%  v507, v603, v643, v803, v843, v907}
% \fieldtext{{It ...}c5, {works}b2}
% \end{diagram}
% \end{verbatim}
% \end{minipage}
%
% 
% \subsection{Misc}
% \subsubsection{Chess pieces within normal text}
% Sometimes you may need symbols of chess pieces within your
% normal text, e.\,g. to show the {\itshape
% Viele-V\"ater-Stellung} {\wK}c8, {\wB}b6, {\sK}a8, {\sB}a7.
% This is possible by |{\wK}c8, {\wB}b6, {\sK}a8, {\sB}a7|.
% Additionally you may use some of these symbols:
% \begin{description}
% \item[\swL]
% \DescribeMacro{\swL}
% a white bishop on a black square
% \item[\ssL]
% \DescribeMacro{\ssL}
% a black bishop on a black square
% \item[\wNr]
% \DescribeMacro{\wNr}
% a white nightrider
% \item[\nNr]
% \DescribeMacro{\nNr}
% a neutral nightrider
% \item[\sNr]
% \DescribeMacro{\sNr}
% a black nightrider
% \item[\wGh]
% \DescribeMacro{\wGh}
% a white grashopper
% \item[\nGh]
% \DescribeMacro{\nGh}
% a neutral grashopper
% \item[\sGh]
% \DescribeMacro{\sGh}
% a black grashopper
% \item[\Imi]
% \DescribeMacro{\Imi}
% an imitator, you may also use the {\bfseries Circle} notation:
% \item[\wC]
% \DescribeMacro{\wC}
% a white circle
% \item[\nC]
% \DescribeMacro{\nC}
% a neutral circle
% \item[\sC]
% \DescribeMacro{\sC}
% a black circle
% \item[\wE]
% \DescribeMacro{\wE}
% a white equihopper
% \item[\sE]
% \DescribeMacro{\sE}
% a black equihopper
% \item[\nE]
% \DescribeMacro{\nE}
% a neutral equihopper
% \item[\wX]
% \DescribeMacro{\wX}
% a white rotated equihopper
% \item[\sX]
% \DescribeMacro{\sX}
% a black rotated equihopper
% \item[\nX]
% \DescribeMacro{\nX}
% a neutral rotated equihopper
% \end{description}
% \subsubsection{Other often used symbols}
% The style also defines commands for other symbols, which are
% often used within the declaration of twins or when writing a
% solution:
% \begin{description}
% \item[\set]
% \DescribeMacro{\set}
% setplay
% \item[\ra]
% \DescribeMacro{\ra}
% a left to right arrow
% \item[\lra]
% \DescribeMacro{\lra}
% a double ended arrow
% \item[\OO]
% \DescribeMacro{\OO}
% king side castling
% \item[\OOO]
% \DescribeMacro{\OOO}
% queen side castling
% \item[\x]
% \DescribeMacro{\x}
% for "'takes"'
% \item[\any]
% \DescribeMacro{\any}
% for any move (you may not simply use a \any\ within your
% text because \TeX\ handles this as a protected space)
% \end{description}
% \subsubsection{Internationalization}
% \DescribeMacro{\DefinePieces}
% This part is relevant for people who do not like the german
% notation for pieces and therefore want to change this within
% their sources. Using the german notation, you specify the color
% of a piece as {\bfseries w}, {\bfseries s} or {\bfseries n},
% the type of a piece as {\bfseries K}, {\bfseries D}, {\bfseries T},
% {\bfseries L}, {\bfseries S}, {\bfseries B} and a possible
% rotation of a piece as {\bfseries L}, {\bfseries R} or
% {\bfseries U}. To use another notation you may use the
% |\DefinePieces| command which takes 3 parameters. 
% \begin{enumerate}
% \item the letters used to specify the colors of the pieces
% using the order white, black, neutral
% \item the letters used to specify the type of a piece using the
% order king, queen, rook, bishop, knight, pawn. You may not
% use the characters {\bfseries C, E} and {\bfseries X}, because these are
% used for Circle, Equihopper and rotated Equihopper.
% \item the letters used to specify an optional rotation using
% the order left-turned, right-turned, upside-down. You must use
% capital letters for this.
% \end{enumerate}
%
% When using a |\DefinePieces| command, the commands are changed
% to its next usage (or to the end of the document). The command
% not only changes the pieces you may use within the |\pieces|
% command but also defines commands to be used within normal
% text, as the following example shows:
%
% \noindent|\DefinePieces{wbn}{KQRBNP}{LRU}|\newline
% |\wDU\bKR\bwB|\newline
% \DefinePieces{wbn}{KQRBNP}{LRU}
% creates \wDU\bKR\bwB
%
% \subsubsection{When writing books}
% \DescribeMacro{\develop}
% To simplify your writings you may use the macro
% |\develop|. This will create the following additional information during
% developement:
% \begin{itemize}
% \item when you use |\label| in your diagrams the label will be
% shown at the left upper corner of the diagram.
% \item The given label will also be shown inside the solution
% and also in any register entry.
% \item when you have specified a |\judgement| this information
% will be put into the solution.
% \end{itemize}
%
% Most books on chessproblems contain registers for authors,
% sometimes also on themes and sources. As you already collect
% all these information very detailed within the |diagram|
% environment the generation of registers is very simple.
%
% \DescribeMacro{\makeaindex}
% \DescribeMacro{\authorindex}
% To create a registers of authors you need to put the
% |\makeaindex| command inside the preamble of your document.
% This instructs latex to write an intermediate file containing
% information about authors and the numbers of the
% diagrams.\footnote{Normally registers contain page numbers but
% with chess problems normally people refer to the diagram
% numbers.} After a first \LaTeX\ run on your document, you need
% to convert the intermediate file. This may be done with the
% |makeindex| program, which will typically called like
%
% \noindent|makeindex -o <filename>.and <filename>.adx|
%
% The resulting register may be put into your document using the
% |\authorindex| command.
% 
%
% \DescribeMacro{\makesindex}
% \DescribeMacro{\sourceindex}
% \DescribeMacro{\maketindex}
% \DescribeMacro{\themeindex}
% Like an index for authors you may also create indices for
% sources and/or themes. For an source register you need to put
% |\makesindex| into your document preamble; for a theme register
% the command is |\maketindex|. The conversion commands for the
% intermediate files are
%
% \noindent|makeindex -o <filename>.snd <filename>.sdx|
% \newline for the source register and
%
% \noindent|makeindex -o <filename>.tnd <filename>.tdx|
% \newline for the theme register.
%
% The source register is inserted into the text using
% |\sourceindex| and the theme register using |\themeindex|.
%
% \subsubsection{Other useful stuff}
% \DescribeMacro{\solpar}
% In some environments --- like \verb+window+ --- the use of \verb+\par+ leads to unwanted
% effects. Therefore we use the command \verb+\solpar+ inside the
% definition of \verb+\@dia@solution+, which is used to display
% a single solution when using \verb+\putsol+. You may use
% \verb+\renewcommand{\solpar}+ to provide another definition of
% \verb+\solpar+ in such situations.
%
% \StopEventually{\PrintIndex\PrintChanges}
%
% \section{The documentation driver}
% The following code will generate the documentation. Since it is
% the first piece of code in the file, the documentation can be
% obtained by simply processing the file with \LaTeXe.
%    \begin{macrocode}
%<*driver>
\documentclass[a4paper]{article}
\usepackage{doc}
\usepackage{diagram}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
\DocInput{diagram.dtx}
\end{document}
%</driver>
%    \end{macrocode}
%
% \section{The implementation of the style}
% Specifies the preamble of our style file.
%    \begin{macrocode}
%<*style>
\ProvidesPackage{diagram}[2016/01/06]
%    \end{macrocode}
%
% \begin{macro}{\DefaultDiagramSize}
% The \verb+\DefaultDiagramSize+ may be used in code to switch to the
% default diagram size. As this depends on the documents default font
% size we use the same option and execute \textit{10pt} as default.
%    \begin{macrocode}
\newcommand*{\DefaultDiagramSize}{}
\DeclareOption{10pt}{\renewcommand*{\DefaultDiagramSize}{\diagramx}}
\DeclareOption{11pt}{\renewcommand*{\DefaultDiagramSize}{\diagramxi}}
\DeclareOption{12pt}{\renewcommand*{\DefaultDiagramSize}{\diagramxii}}
\ExecuteOptions{10pt}
%    \end{macrocode}
% \end{macro}

%    \begin{macrocode}
\ProcessOptions
\AtBeginDocument{\DefaultDiagramSize}
%    \end{macrocode}
%
%    \begin{macrocode}
\RequirePackage{ifthen}
\RequirePackage{calc}
\RequirePackage{pstricks}
%    \end{macrocode}
%%
%%
%%
% Now we declare some constants to unify its usage within the
% style file.
%    \begin{macrocode}
\chardef\f@ur=4
\chardef\@ight=8
\newcount\elchfont

\chardef\@pkelch=0
\chardef\@fselch=1

\newcount\dia@type

\newboolean{@textproblem}
\setboolean{@textproblem}{false}
\def\textproblem{\setboolean{@textproblem}{true}\let\@dia@stipulation=\relax}

\newboolean{@solafterdiagram}
\setboolean{@solafterdiagram}{false}
\def\solafterdiagram{\setboolean{@solafterdiagram}{true}\ignorespaces}

\newif\if@vframe\@vframetrue
\newif\if@hframe\@hframetrue
\newif\if@leaveOuter\@leaveOutertrue

\newif\if@shortform

\newif\ifspace@vertical
\def\spacehorizontal{\space@verticalfalse}

\newif\ifdi@no
\newcounter{board@nr}
\renewcommand{\theboard@nr}{\thediag}
% \newif\iffigcnt
\newboolean{piececounter}
\newcount\r@w
\newcount\lin@
\newcount\pl@ne
\newcount\current@plane

\newcount\w@cnt
\newcount\b@cnt
\newcount\n@cnt
\newboolean{showcity}
\setboolean{showcity}{false}
\newboolean{showacademictitle}
\setboolean{showacademictitle}{true}
\newboolean{legend}
\setboolean{legend}{false}

\newcount\@blackfield
\newboolean{allwhite}
\setboolean{allwhite}{false}
\newcommand{\allwhite}{\setboolean{allwhite}{true}}
\newcounter{field@border}
\newcount\@whitefield
\newboolean{switchcolors}
\setboolean{switchcolors}{false}
\newcommand{\switchcolors}{\setboolean{switchcolors}{true}}
%    \end{macrocode}
%
% We have counters for each color to count the pieces on the
% board.
%    \begin{macrocode}
\newboolean{cpd@checkPieceCounts}
\newcounter{cpd@defWhitePieces}
\newcounter{cpd@defBlackPieces}
\newcounter{cpd@defNeutralPieces}

\newcounter{cpd@whitePieces}
\newcounter{cpd@blackPieces}
\newcounter{cpd@neutralPieces}

\newcommand{\cpd@stepcounterWhite}{\stepcounter{cpd@whitePieces}}
\newcommand{\cpd@stepcounterBlack}{\stepcounter{cpd@blackPieces}}
\newcommand{\cpd@stepcounterNeutral}{\stepcounter{cpd@neutralPieces}}
\global\let\cpd@stepcounterPieces\relax

\newcount\help@a
\newcount\help@b

\newbox\dia@box
\newbox\@cnt@box
\newdimen\@cnt@wd
\newbox\@stip@box

\newdimen\topdist\topdist\z@
\newbox\@test@box
\newdimen\@test@dimen
\newif\if@left

\newcount\brd@ff

\newdimen\dia@lineskip

\newdimen\board@width
\newdimen\bd@width
\newdimen\head@width
\newdimen\sq@width

\newdimen\grid@width
\newdimen\inner@frame
\newdimen\outer@frame
\newdimen\space@frame
\newdimen\v@frame@dist
\newdimen\h@frame@dist
\newdimen\space@frame@dist
\newdimen\v@space@dist
\newdimen\h@space@dist

\newbox\sq@box
\newbox\plane@box
%    \end{macrocode}
%
% We need a lot of token registers to register the information
% from within the |diagram| environment. These token registers
% are defined here. Initially each token register is defined to
% contain |\relax|, which serves as an {\itshape end-marker} when
% parsing lists.
%    \begin{macrocode}
\newtoks\typis@tk\typis@tk={\relax}
\newtoks\label@tk\label@tk={\relax}
\newtoks\sol@tk\sol@tk={\relax}
\newtoks\number@tk\number@tk={\relax}
\newtoks\aut@tk\aut@tk={\relax}
\newtoks\city@tk\city@tk={\relax}
\newtoks\sourcenr@tk\sourcenr@tk={\relax}
\newtoks\source@tk\source@tk={\relax}
\newtoks\day@tk\day@tk={\relax}
\newcount\from@month\from@month=\z@
\newcount\to@month\to@month=\z@
\newtoks\year@tk\year@tk={\relax}
\newtoks\issue@tk\issue@tk={\relax}
\newtoks\pages@tk\pages@tk={\relax}
\newtoks\tournament@tk\tournament@tk={\relax}
\newtoks\award@tk\award@tk={\relax}
\newtoks\after@tk\after@tk={\relax}
\newtoks\version@tk\version@tk={\relax}
\newtoks\correction@tk\correction@tk={\relax}
\newtoks\dedic@tk\dedic@tk={\relax}
\newtoks\fidealbum@tk\fidealbum@tk={\relax}
\newtoks\theme@tk\theme@tk={\relax}
\newtoks\twins@tk\twins@tk={\relax}
\newtoks\judgement@tk\judgement@tk={\relax}
\newtoks\comment@tk\comment@tk={\relax}
\newtoks\computer@tk\computer@tk={-}
\newtoks\nofields@tk\nofields@tk={\relax}
\newtoks\fieldframe@tk\fieldframe@tk={\relax}
\newtoks\gridlines@tk\gridlines@tk={\relax}
\newtoks\pieces@tk\pieces@tk={\relax}
\newtoks\fieldtext@tk\fieldtext@tk={\relax}
\newtoks\text@tk\text@tk={\relax}
\newtoks\stipulation@tk\stipulation@tk={\relax}
\newtoks\condition@tk\condition@tk={\relax}
\newtoks\remark@tk\remark@tk={\relax}
\newtoks\piecedefs@tk\piecedefs@tk={\relax}
%    \end{macrocode}
%
% To remember, which information has been specified, we define
% \TeX-booleans for each command.
%    \begin{macrocode}
\newif\if@label\@labelfalse
\newif\if@number\@numberfalse
\newif\if@special\@specialfalse
\newif\ifauth@r\auth@rfalse
\newif\if@city\@cityfalse
\newif\if@sourcenr\@sourcenrfalse
\newif\if@source\@sourcefalse
\newif\if@date\@datefalse
\newif\if@day\@dayfalse
\newif\if@year\@yearfalse
\newif\if@issue\@issuefalse
\newif\if@pages\@pagesfalse
\newif\if@tournament\@tournamentfalse
\newif\if@award\@awardfalse
\newif\if@after\@afterfalse
\newif\if@version\@versionfalse
\newif\if@correction\@correctionfalse
\newif\if@dedication\@dedicationfalse
\newif\if@fidealbum\@fidealbumfalse
\newif\if@twins\@twinsfalse
\newif\if@theme\@themefalse
\newif\if@computer\@computerfalse
\newif\if@judgement\@judgementfalse
\newif\if@comment\@commentfalse
\newif\if@pieces\@piecesfalse
\newif\if@fieldtext\@fieldtextfalse
\newif\if@nofields\@nofieldsfalse
\newif\if@gridlines\@gridlinesfalse
\newif\if@fieldframe\@fieldframefalse
\newif\if@stdgrid\@stdgridfalse
\newboolean{showcomputer}\setboolean{showcomputer}{true}%
\newcommand*{\computerproofedsymbol}{C+}
\newcommand*{\notcomputerproofedsymbol}{C-}
% \newif\if@show@computer\@show@computertrue
\newif\if@stipulation\@stipulationfalse
\newif\if@condition\@conditionfalse
\newif\if@remark\@remarkfalse
\newif\if@piecedefs\@piecedefsfalse
\newif\if@typis\@typisfalse
\newif\if@widedias\@widediasfalse
\newif\ifx@twins\x@twinsfalse
\newif\ifx@cond\x@condfalse
\newif\ifimitator\imitatorfalse
\newif\ifnormal@names\normal@namesfalse
\newif\ifs@lu
\newif\if@develop\@developfalse
\newif\if@notfirst
\newif\if@first
%    \end{macrocode}
%    \begin{macrocode}
\newwrite\s@lfd
\let\below@newline=\relax
% These are used by the "old" board creating mechanism
\newcount\@lines
\newcount\@rows
\newcount\lines@max
\newcount\rows@max
\newcount\planes@max
%    \end{macrocode}
%
% The following counters are used when creating the diagram
% itself.
%    \begin{macrocode}
\newcounter{cpd@rowsmax}
\newcounter{cpd@linesmax}
\newcounter{cpd@current@row}
\newcounter{cpd@current@line}
\newcounter{cpd@maxsquare}
\newcounter{cpd@helper}
\newcounter{cpd@current@square@index}
\newcounter{cpd@current@square@value}
%    \end{macrocode}
%
% Some boolean \TeX-switches used whithin stereo- or spacechess
% diagrams.
%    \begin{macrocode}
\newif\if@stereo\@stereofalse
\newif\if@space\@spacefalse
%    \end{macrocode}
%
% These boolean switches are used to control the output of
% registers.
%    \begin{macrocode}
\newif\if@aindex\@aindexfalse
\newif\if@sindex\@sindexfalse
\newif\if@tindex\@tindexfalse
\newif\ifds@label
%    \end{macrocode}
%
% \begin{macro}{\diagram}
% \begin{macro}{\@diagram}
% Defines the code executed in |\begin{diagram}|. In case no
% optional size is given, a normal 8$\times$8 board is generated.
%    \begin{macrocode}
\def\diagram{%
   \begingroup%
   \@ifnextchar [{\@diagram}{\@diagram[\@ight x\@ight]}%
}

\def\@diagram[#1x#2]{%
   \lines@max=#1%
   \rows@max=#2%
   \setcounter{cpd@linesmax}{#1}%
   \setcounter{cpd@rowsmax}{#2}%
   \setcounter{cpd@maxsquare}{\value{cpd@rowsmax}*\value{cpd@linesmax}}%
   \pl@ne=\z@%
   \current@plane=\z@%
   \let\put@sqs=\put@sqs@normal%
   \let\read@plane=\read@plane@normal%
   \@start@diagram%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%    \begin{macrocode}
\def\stereodiagram{%
   \begingroup%
   \@stereotrue%
   \let\put@sqs=\put@sqs@stereo%
   \let\read@plane=\read@plane@stereo%
   \@start@diagram%
}
\def\spacediagram{%
   \begingroup%
   \@spacetrue%
   \@ifnextchar [{\@spacediagram}{\@spacediagram[5x5x5]}%
}

\def\@spacediagram[#1x#2x#3]{%
   \lines@max=#1%
   \rows@max=#2%
   \planes@max=#3%
   \let\put@sqs=\put@sqs@space%
   \let\read@plane=\read@plane@space%
   \@start@diagram%
}
\def\@start@diagram{%
   \init@vars%
   \let\author=\ds@author%
   \let\day=\ds@day%
   \let\month=\ds@month%
   \let\year=\ds@year%
   \let\label=\ds@label%
   \ignorespaces%
}

\def\showtypis#1{%
   \@typistrue%
   \typis@tk={#1}%
   \ignorespaces%
}

\def\enddiagram{%
   \let\author=\orig@author%
   \let\day=\orig@day%
   \let\month=\orig@month%
   \let\year=\orig@year%
   \let\label=\orig@label%
   \if@number%
   \else%
      \refstepcounter{board@nr}% so \label and \ref work properly
   \fi%
   %
   % Now \label@tk should be set, if wanted, so
   % we can generate the index entries
   %
   \@aindex%
   \@sindex%
   \@tindex%
   %
   % Now \@currentlabel will be set right, so we can use
   % the original label
   \if@label%
      \expandafter\@set@label\the\label@tk;%
   \fi%
   %
   % Now we know, if we have frames so we can setup our dimensions
   %
   \global\sq@width=\fontdimen\tw@\chessfont%
   \if@stereo%
      \bd@width=\@ight\sq@width%
      \board@width=\@ight\sq@width%
      \ifdim\h@frame@dist<\sq@width%
         \h@frame@dist=\sq@width%
      \fi%
      % We do already skip with \v@space@dist
      % So we use the additional skip \space@frame@dist here
      \v@frame@dist=\space@frame@dist%
      \ifdim\space@frame>\outer@frame%
         \outer@frame=\space@frame%
      \fi%
      \advance\bd@width\tw@\inner@frame%
      \advance\board@width\tw@\inner@frame%
      \advance\board@width\tw@\h@frame@dist%
      \advance\board@width\tw@\outer@frame%
   \else\if@space%
      \ifdim\h@frame@dist<1.5\sq@width%
         \h@frame@dist=1.5\sq@width%
      \fi%
      % We do already skip with \v@space@dist
      % So we use the additional skip \space@frame@dist here
      \v@frame@dist=\space@frame@dist%
      \ifdim\space@frame>\outer@frame%
         \outer@frame=\space@frame%
      \fi%
      \ifspace@vertical%
         \bd@width=\lines@max\sq@width%
         \board@width\bd@width%
         \advance\bd@width\tw@\inner@frame%
         \advance\board@width\tw@\inner@frame%
         \advance\board@width\tw@\h@frame@dist%
         \advance\board@width\tw@\outer@frame%
      \else%
         \bd@width=\lines@max\sq@width%
         \advance\bd@width\tw@\inner@frame%
         \ifdim\h@space@dist<1.5\sq@width%
            \h@space@dist=1.5\sq@width%
         \fi%
         %\h@space@dist=0.7\sq@width%
         % Now we can compute the width of the complete board
         \board@width\bd@width%
         \advance\board@width\h@space@dist%
         \multiply\board@width\planes@max%
         \advance\board@width\h@space@dist%
         \advance\board@width\tw@\outer@frame%
      \fi%
   \else%
      \ifthenelse{\boolean{legend}}{\v@frame@dist=1.5em\h@frame@dist=1.5em}{}%
      \bd@width=\lines@max\sq@width%
      \ifnum\lines@max>\@ight%
         % Make the board wider
         \board@width=\lines@max\sq@width%
      \else%
         % Make a normal width
         \board@width=\@ight\sq@width%
      \fi%
      \advance\bd@width\tw@\inner@frame%
      \advance\board@width\tw@\inner@frame%
      \advance\board@width\tw@\h@frame@dist%
      \advance\board@width\tw@\outer@frame%
   \fi\fi%
   \if@widedias%
      \head@width=\textwidth%
   \else%
      \head@width=\board@width%
   \fi%
   %
   % Now we should build the diagram itself
   %
   \ifthenelse{\boolean{@textproblem}}{%
      % Put the stipulation into the \sq@box
      \setbox\sq@box=\hbox{\vbox to \board@width{\hsize\board@width%
         \stipfont%
         \raggedright%
         \sloppy%
         \the\stipulation@tk%
         \vfil%
      }}%
   }{%
      \put@sqs% This builds up the \sq@box
      % Check, if the given number of pieces is reached
      \ifthenelse{\boolean{cpd@checkPieceCounts}}{%
        \ifthenelse{\value{cpd@defWhitePieces}=\value{cpd@whitePieces}}{}%
            {\errmessage{Wrong number of white pieces}}%
        \ifthenelse{\value{cpd@defBlackPieces}=\value{cpd@blackPieces}}{}%
            {\errmessage{Wrong number of black pieces}}%
         \ifthenelse{\value{cpd@defNeutralPieces}=\value{cpd@neutralPieces}}{}%
             {\errmessage{Wrong number of neutral pieces}}%
      }{}%
   }%
   %
   \global\setbox\dia@box=\hbox{\vbox{%
      \parindent\z@%
      \parskip\z@%
      \baselineskip11\p@\advance\baselineskip\dia@lineskip%
      \hsize\head@width%
      \centering%
      % diagram header
      \vskip\topdist%
      \vbox{\hsize\board@width\hbox{%
         \if@develop\if@label%
            \noindent\raggedright\llap{\labelfont\the\label@tk\ }%
         \fi\fi%
         \vbox{%
            \he@dpos\dia@above%
         }%
      }}%
      \vskip\tw@\p@%
      % diagram itself
      \vtop{\hsize\board@width%
         \hbox to \head@width{\hss\vbox{%
            \hsize\board@width%
            \ifthenelse{\boolean{@textproblem}}{%
               \box\sq@box%
            }{%
               \outer@henbox{\box\sq@box}%
            }%
         }\hss}%
         % diagram trailer
         \hbox to \head@width{\hss\vtop{%
            \hsize\board@width%
            \parskip\z@%
            \raggedright%
            \put@count%
            \dia@below%
         }\hss}%
      }%
   }}% End of \dia@box
   \do@dia@job%
   \endgroup%
}

\def\do@put@count{%
   \ \ (\arabic{cpd@whitePieces}+\arabic{cpd@blackPieces}%
   \ifthenelse{\value{cpd@neutralPieces}>0}{+\arabic{cpd@neutralPieces}}{})%
}

\def\put@count{%
   % First we build the box with the figure count
   \ifthenelse{\boolean{showcomputer}\OR\boolean{piececounter}}{%
     \global\setbox\@cnt@box=\hbox{%
        \stipfont%
        \ifthenelse{\boolean{showcomputer}}{%
           \ \ \if@computer\computerproofedsymbol\else\notcomputerproofedsymbol\fi%
        }{}%
        \ifthenelse{\boolean{piececounter}}{%
           \do@put@count%
        }{}%
      }%
      \@cnt@wd=\wd\@cnt@box%
      \hangindent-\@cnt@wd%
      \hangafter\m@ne%
      \noindent%
      \hbox to \z@{%
        \hbox to \board@width{\hfil\unhbox\@cnt@box}\hskip -\board@width%
      }%
   }{}%
}

\let\endstereodiagram=\enddiagram
\let\endspacediagram=\enddiagram
\def\figurine{%
   \begingroup%
   \init@vars%
   \let\author=\ds@author%
   \let\day=\ds@day%
   \let\month=\ds@month%
   \let\year=\ds@year%
   \let\label=\ds@label%
}

\def\endfigurine{%
   \let\author=\orig@author%
   \let\day=\orig@day%
   \let\month=\orig@month%
   \let\year=\orig@year%
   \let\label=\orig@label%
   \if@number%
   \else%
      \refstepcounter{board@nr}% so \label and \ref work properly
   \fi%
   %
   % Now \label@tk should be set, if wanted, so
   % we can generate the index entries
   %
   \@aindex%
   \@sindex%
   \@tindex%
   %
   % Now \@currentlabel will be set right, so we can use
   % the original label
   %
   \if@label%
      \expandafter\@set@label\the\label@tk;%
   \fi%
   %
   \@show@figurine%
   \endgroup%
}
%
\gdef\selectelchfont#1{%
   \global\elchfont\csname @#1elch\endcsname\defaultelchfont%
}
%    \end{macrocode}
%
% Here we define commands to change fonts used for text above
% and below the diagram. You may redefine to adjust the fonts to
% your needs.
% \begin{macro}{\authorfont}
% \begin{macro}{\cityfont}
% \begin{macro}{\sourcefont}
% \begin{macro}{\awardfont}
% \begin{macro}{\dedicfont}
% \begin{macro}{\stipfont}
% \begin{macro}{\remfont}
% \begin{macro}{\labelfont}
% \begin{macro}{\cpd@boardfont}
% \begin{macro}{\legendfont}
%    \begin{macrocode}
\newcommand*{\authorfont}{\bfseries}
\newcommand*{\cityfont}{\slshape}
\newcommand*{\sourcefont}{\bfseries\itshape}
\newcommand*{\awardfont}{\itshape}
\newcommand*{\dedicfont}{\itshape}
\newcommand*{\stipfont}{\rmfamily}
\newcommand*{\remfont}{\rmfamily}
\newcommand*{\labelfont}{\rmfamily}
\newcommand*{\cpd@boardfont}{\rmfamily}
\newcommand*{\legendfont}{\sffamily}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% We have three different default sizes for diagrams. 
% The following commands switch fontsizes used for the chessfonts
% to typeset the diagrams.
% \begin{macro}{\diagramx}
% \begin{macro}{\diagramxi}
% \begin{macro}{\diagramxii}
%    \begin{macrocode}
\newcommand*{\diagramx}{
   \ifcase\elchfont\relax%
      \font\chessfont=pkelch12
      \font\chtextfont=pkelch10
   \else%
      \font\chessfont=fselch12
      \font\chtextfont=fselch10
   \fi%
   \dia@lineskip\z@
   \dia@type\z@
}

\newcommand*{\diagramxi}{
   \ifcase\elchfont\relax%
      \font\chessfont=pkelch14
      \font\chtextfont=pkelch11
   \else%
      \font\chessfont=fselch14
      \font\chtextfont=fselch11
   \fi%
   \dia@lineskip\@ne\p@
   \dia@type\@ne
}

\newcommand*{\diagramxii}{
   \ifcase\elchfont\relax%
      \font\chessfont=pkelch16
      \font\chtextfont=pkelch12
   \else%
      \font\chessfont=fselch16
      \font\chtextfont=fselch12
   \fi%
   \dia@lineskip\tw@\p@
   \dia@type\tw@
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\defaultelchfont}
% |\defaultelchfont| is used to define the fontsize used to
% typeset the diagrams depending on the documentsize.
%    \begin{macrocode}
\def\defaultelchfont{%
   \ifcase\@ptsize\relax%
      \diagramx\or%
      \diagramxi\or%
      \diagramxii%
   \fi%
}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\def\dianamestyle#1{\def\@dianame{\csname @#1\endcsname}}
\def\solnamestyle#1{\def\@solname{\csname @#1\endcsname}}
\newcommand*{\diagnum}[2][]{%
   \renewcommand*{\@dianumber@prefix}{#1}%
   \setcounter{board@nr}{#2}%
   \addtocounter{board@nr}{\m@ne}}
%    \end{macrocode}
%
% \begin{macro}{\ra}
% \begin{macro}{\lra}
% \begin{macro}{\rla}
% \begin{macro}{\x}
% \begin{macro}{\set}
% \begin{macro}{\OO}
% \begin{macro}{\OOO}
% \begin{macro}{\any}
% \begin{macro}{\further}
% Now we define a couple of abbreviations and special symbols
% often used when setting problem chess documents.
%    \begin{macrocode}
\def\ra{\mbox{$\rightarrow$}}
\def\lra{\mbox{$\leftrightarrow$}}
\let\rla=\lra
\newcommand{\x}{\mbox{\ifmmode\times\else$\times$\fi}}
\def\set{\kern -.05em\raise .1ex\hbox{*}}
\def\@O{0\raise.25ex\hbox{-}\kern -.1em\relax}
\def\OO{\@O0}
\def\OOO{\@O\@O0}
\def\any{\ifmmode\sim\else$\sim$\fi}
\def\further{\ifmmode\Rightarrow\else$\Rightarrow$\fi\ \ignorespaces}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
\def\spacelayout#1{\csname space@#1\endcsname}
\def\nodiagnumbering{\global\di@nofalse}
\newcommand*{\@dianumber@prefix}{}
\def\diagnumbering#1{%
   \di@notrue\diagnum{\@ne}%
   \gdef\thediag{\@dianumber@prefix\csname @#1\endcsname\c@board@nr}%
}
%    \end{macrocode}
%
% \begin{macro}{\diagcenter}
% \begin{macro}{\diagleft}
% \begin{macro}{\diagright}
% The macros |\diagcenter|, |\diagleft| and |\diagright| simply
% define the macro |\he@dpos| to the corresponding paragraph
% alignment.
%    \begin{macrocode}
\def\diagcenter{\def\he@dpos{\centering}}
\def\diagleft{\def\he@dpos{\raggedright}}
\def\diagright{\def\he@dpos{\raggedleft}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\setmonthstyle}
% The implementation of |\setmonthstyle| does |\diagnumbering|
% define a command which uses the given parameter as a part of
% the command name.
%    \begin{macrocode}
\def\setmonthstyle#1{\def\write@month{\csname @#1\endcsname}}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\def\specialdiagnum#1{%
   \@specialtrue%
   \number@tk={#1}\@numbertrue\def\thediag{#1}\def\@currentlabel{#1}%
   \ignorespaces%
}
%    \end{macrocode}
%
% \begin{macro}{\ds@label}
% \begin{macro}{\ds@author}
% The macros |\ds@label| and |\ds@author| are defined internally
% and are made public within |\begin{diagram}|. This is because
% the macros |\label| and |\author| are normal \LaTeX-macros and
% I want to avoid to redefine these globally.
%    \begin{macrocode}
\def\ds@label{%
   \@ifstar{\ds@labelfalse\ds@xlabel}{\ds@labeltrue\ds@xlabel}%
}
\def\ds@author#1{%
   \aut@tk={#1}\auth@rtrue%
   \ignorespaces%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\ds@academictitle}
% \begin{macro}{\Dr}
% \begin{macro}{\Prof}
% \begin{macro}{\ProfDr}
%    \begin{macrocode}
\def\ds@academictitle#1{\ifthenelse{\boolean{showacademictitle}}{#1~}{}\ignorespaces}
\newcommand{\Dr}{\ds@academictitle{Dr.}}
\newcommand{\Prof}{\ds@academictitle{Prof.}}
\newcommand{\ProfDr}{\ds@academictitle{Prof.\,Dr.}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
\def\city#1{%
   \city@tk={#1}\@citytrue%
   \ignorespaces%
}
\def\sourcenr#1{%
   \sourcenr@tk={#1}\@sourcenrtrue%
   \ignorespaces%
}
\def\source#1{%
   \source@tk={#1}\@sourcetrue%
   \ignorespaces%
}
\def\ds@day#1{%
   \day@tk={#1}\@daytrue\@datetrue%
   \ignorespaces%
}
\def\ds@month#1{%
   \from@month=#1\@datetrue%
   \ignorespaces%
}
\def\months#1{%
   \@months#1;%
   \ignorespaces%
}
\def\ds@year#1{%
   \year@tk={#1}\@yeartrue\@datetrue%
   \ignorespaces%
}
\def\issue#1{%
   \issue@tk={#1}\@issuetrue%
   \ignorespaces%
}
\def\pages#1{%
   \pages@tk={#1}\@pagestrue%
   \ignorespaces%
}
\def\tournament#1{%
   \tournament@tk={#1}\@tournamenttrue%
   \ignorespaces%
}
\def\award#1{%
   \award@tk={#1}\@awardtrue%
   \ignorespaces%
}
\def\version#1{%
   \version@tk={#1}\@versiontrue%
   \ignorespaces%
}
\def\after#1{%
   \after@tk={#1}\@aftertrue%
   \ignorespaces%
}
\def\correction#1{%
   \correction@tk={#1}\@correctiontrue%
   \ignorespaces%
}
\def\dedication#1{%
   \dedic@tk={#1}\@dedicationtrue%
   \ignorespaces%
}
\def\fidealbum#1{%
   \fidealbum@tk={#1}\@fidealbumtrue%
   \ignorespaces%
}
\def\pieces{%
   \@ifnextchar[%
   {\x@pieces}%
   {\@pieces}%
}
\def\x@pieces[#1]{%
   % We should parse the given piececounts
   \setboolean{cpd@checkPieceCounts}{true}%
   \@parseWhiteAndBlackCount#1+\e@list
   \@pieces%
}
\def\@parseWhiteAndBlackCount#1+#2+{%
   \setcounter{cpd@defWhitePieces}{#1}%
   \setcounter{cpd@defBlackPieces}{#2}%
   \futurelet\n@xt\cpd@checkNeutral%
}
\let\cpd@nextproc=\relax%
\def\cpd@checkNeutral{%
    \if\n@xt\relax%
        \let\cpd@nextproc=\relax%
    \else%
        \let\cpd@nextproc=\@parseNeutralCount%
    \fi%
    \cpd@nextproc%
}
\def\@parseNeutralCount#1+{%
   \setcounter{cpd@defNeutralPieces}{#1}%
}
\def\@pieces#1{%
   \pieces@tk={#1}\@piecestrue%
   \ignorespaces%
}
\def\fieldtext#1{%
   \fieldtext@tk={#1}\@fieldtexttrue%
   \ignorespaces%
}
\def\nofields#1{%
   \nofields@tk={#1}\@nofieldstrue%
   \ignorespaces%
}
\let\nosquares\nofields
\def\gridlines#1{%
   \gridlines@tk={#1}\@gridlinestrue%
   \ignorespaces%
}
\def\fieldframe#1{%
   \fieldframe@tk={#1}\@fieldframetrue%
   \ignorespaces%
}
\def\stipulation#1{%
   \stipulation@tk={#1}\@stipulationtrue%
   \ignorespaces%
}
\def\condition{%
   \@ifstar{\x@condtrue\@condition}{\@condition}%
}
\def\@condition#1{%
   \condition@tk={#1}\@conditiontrue%
   \ignorespaces%
}
\def\twins{%
   \@ifstar{\x@twinstrue\@twins}{\@twins}%
}
\def\@twins#1{%
   \twins@tk={#1}\@twinstrue%
   \ignorespaces%
}
\def\remark#1{%
   \remark@tk={#1}\@remarktrue%
   \ignorespaces%
}
\def\piecedefs#1{%
   \piecedefs@tk={#1}\@piecedefstrue%
   \ignorespaces%
}
% \def\@piecedef#1{\csname#1\x@piecedef\endcsname\l@@klist}
% \newcommand{\piecedef}[3][ws]{%
%     \def\x@piecedef{#2}%
%     \let\@action=\@piecedef%
%     \hbox{\l@@klist#1\e@list%
%     \ = #3}%
% }
\def\Co#1{%
   \ifx#1+\@computertrue\computer@tk={+}\fi%
   \ignorespaces%
}
\long\def\solution#1{%
   \sol@tk={#1}\global\s@lutrue%
   \ignorespaces%
}
\def\themes#1{%
   \theme@tk={#1}\@themetrue%
   \ignorespaces%
}
\long\def\comment#1{%
   \comment@tk={#1}\@commenttrue%
   \ignorespaces%
}
\long\def\judgement#1{%
   \judgement@tk={#1}\@judgementtrue%
   \ignorespaces%
}
\def\noframe{%
   \@vframefalse\@hframefalse%
   \ignorespaces%
}
\def\noinnerframe{%
   \@leaveOuterfalse\@vframefalse\@hframefalse%
   \ignorespaces%
}
\def\verticalcylinder{%
   \@vframefalse%
   \ignorespaces%
}
\def\horizontalcylinder{%
   \@hframefalse%
   \ignorespaces%
}
\def\stdgrid{%
   \@stdgridtrue%
   \ignorespaces%
}
%    \end{macrocode}
%
% \begin{macro}{\gridchess}
% \begin{macro}{\magic}
% \begin{macro}{\tourn}
% \begin{macro}{\dedic}
% \begin{macro}{\stip}
% \begin{macro}{\cond}
% \begin{macro}{\rem}
% \begin{macro}{\sol}
% Here we define some abbreviations and synonyms for other
% macros.
%    \begin{macrocode}
\let\gridchess=\stdgrid
\let\magic=\fieldframe
\let\tourn=\tournament
\let\dedic=\dedication
\let\stip=\stipulation
\let\cond=\condition
\let\rem=\remark
\let\sol=\solution
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
\def\develop{%
   \@developtrue%
   \ignorespaces%
}
\def\showcomputer{%
   \setboolean{showcomputer}{true}%
   \ignorespaces%
}
\def\nocomputer{%
   \setboolean{showcomputer}{false}%
   \ignorespaces%
}
\def\putsol{\immediate\closeout\s@lfd\input\jobname.sol\cl@arsol}
\def\widedias{\@widediastrue\diagcenter}
\def\nowidedias{\@widediasfalse}
\def\normalnames{\normal@namestrue}
\def\reversednames{\normal@namesfalse}
\def\makeaindex{%
   \@dia@index%
   \newindex[thediag]{author}{adx}{and}{Autorenverzeichnis}%
   \@aindextrue\reversednames%
}

\def\makesindex{%
   \@dia@index%
   \newindex[thediag]{source}{sdx}{snd}{Quellenregister}%
   \@sindextrue%
}

\def\maketindex{%
   \@dia@index%
   \newindex[thediag]{theme}{tdx}{tnd}{Themenregister}%
   \@tindextrue%
}

\def\authorindex{{\let\@idxitem\@aidxitem\printindex[author]}}
\def\sourceindex{\printindex[source]}
\def\themeindex{\printindex[theme]}
\def\DefinePieces#1#2#3{%
   \@setPieceColor#1\@setPieceSpec#2\@setPieceRotation#3%
   \loop@rotation%
   \expandafter\xdef\csname\ds@black\ds@white\ds@bishop\endcsname{%
      \noexpand\ch@fig{20}%
   }%
   \expandafter\xdef\csname\ds@black\ds@black\ds@bishop\endcsname{%
      \noexpand\ch@fig{32}%
   }%
   \expandafter\xdef\csname\ds@white F\endcsname{{\chessfont\ }}
   \expandafter\xdef\csname\ds@black F\endcsname{{\chessfont\char144}}
   \expandafter\xdef\csname\ds@white Nr\endcsname{%
      \noexpand\ch@fig{109}%
   }%
   \expandafter\xdef\csname\ds@neutral Nr\endcsname{%
      \noexpand\ch@fig{115}%
   }%
   \expandafter\xdef\csname\ds@black Nr\endcsname{%
      \noexpand\ch@fig{121}%
   }%
   \expandafter\xdef\csname\ds@white Gh\endcsname{%
      \noexpand\ch@fig{112}%
   }%
   \expandafter\xdef\csname\ds@neutral Gh\endcsname{%
      \noexpand\ch@fig{118}%
   }%
   \expandafter\xdef\csname\ds@black Gh\endcsname{%
      \noexpand\ch@fig{124}%
   }%
   \expandafter\xdef\csname\ds@white C\endcsname{%
      \noexpand\ch@fig{145}%
   }%
   \expandafter\xdef\csname\ds@neutral C\endcsname{%
      \noexpand\ch@fig{151}%
   }%
   \expandafter\xdef\csname\ds@black C\endcsname{%
      \noexpand\ch@fig{157}%
   }%
}
\def\Imi{\ch@fig{157}}
\def\wE{\ch@fig{216}}
\def\nE{\ch@fig{222}}
\def\sE{\ch@fig{228}}
\def\wX{\ch@fig{180}}
\def\nX{\ch@fig{186}}
\def\sX{\ch@fig{192}}

%    \end{macrocode}
%
% \begin{macro}{\dia@above}
% The content of the box above a diagram is controlled by the
% macro |\dia@above|. It just delegates the information to a
% couple of other macros, which then generate the displayed
% information above the diagram.
%    \begin{macrocode}
\newboolean{above@newline}
\newcommand{\above@newline}{\ifthenelse{\boolean{above@newline}}{\linebreak}{\setboolean{above@newline}{true}}}
\def\dia@above{%
   \setboolean{above@newline}{false}%
   \@dia@number%
   \@dia@authors%
   \@dia@city%
   \@dia@after%
   \@dia@version%
   \@dia@source%
   \@dia@correction%
   \@dia@tournament%
   \@dia@award%
   \@dia@dedic%
   \@dia@fidealbum%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\dia@below}
% As before, the macro |\dia@below| creates the displayed
% information below the chessboard - forwarding to a couple of other
% macros.
%    \begin{macrocode}
\def\dia@below{%
   \bgroup%
   \if@stipulation%
      \@dia@stipulation%
   \fi%
   \ifx@cond\else%
      \@dia@condition%
   \fi%
   \ifx@twins\else%
      \@dia@twins%
   \fi%
   \@dia@piecedefs%
   \@dia@remark%
   \ifthenelse{\boolean{@solafterdiagram}}{%
      \below@newline%
      \the\sol@tk%
   }{}%
   \noindent\hbox{}\newline\hbox{}%
   \egroup%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@dia@number}
% The |\@dia@number| macro simply creates the diagram number in a
% single paragraph.
%    \begin{macrocode}
\def\@dia@number{%
   \ifdi@no\above@newline{\authorfont\thediag}\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@dia@authors}
% This macro is used to create the list of authors specified
% within the |\author| macro inside the |diagram| environment.
% Depending on the \TeX-boolean |normal@names| we either simply
% display the registered author or parse the list of authors by
% using the generic |\@parseTokenList| macro.
%    \begin{macrocode}
\def\@dia@authors{%
   \ifauth@r%
      \ifnormal@names%
         \above@newline
         {\authorfont\the\aut@tk}%
      \else%
         \let\@action=\@dia@writename% Parse the list of authors
       \@parseTokenlist\aut@tk;
      \fi%
   \fi%
}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\def\@show@city#1;{\if@notfirst\ \slash\ \else\@notfirsttrue\fi#1}

\def\p@rsecity#1; {\@show@city#1;\l@@klist}

\def\@dia@city{%
   \ifthenelse{\boolean{showcity}}{%
       \if@city%
          \above@newline%
          \bgroup%
          \cityfont\@notfirstfalse%
          \let\@action=\p@rsecity\@parseTokenlist\city@tk;%
          \egroup%
       \fi%
   }{}%
}

\def\@dia@after{%
   \if@after%
      \bgroup%
      \above@newline%
      \dedicfont\the\after@tk%
      \egroup%
   \fi%
}

\def\@dia@version{%
   \if@version%
      \above@newline%
      \bgroup%
      \dedicfont\the\version@tk%
      \egroup%
   \fi%
}

\def\@dia@date{%
   \ifnum\from@month>\z@%
      \if@day%
         \the\day@tk.\write@month\from@month%
      \else%
         \write@month\from@month%
      \fi%
      \ifnum\to@month>\z@--\write@month\to@month\fi%
      \if@day.\else/\fi%
   \fi%
   \if@year\the\year@tk\fi%
}

\def\@dia@source{%
   \if@source%
      \above@newline%
      \bgroup%
      \sourcefont%
      \if@sourcenr\the\sourcenr@tk\ \fi
      \the\source@tk%
      \if@date\ \ \fi\@dia@date%
      \if@issue\ \ \the\issue@tk\fi%
      \if@pages ,\ \the\pages@tk\fi%
      \egroup%
   \else%
      \if@tournament\else\if@date%
         \above@newline%
         \bgroup%
         \sourcefont%
         \@dia@date%
         \egroup%
      \fi\fi%
   \fi%
}

\def\@dia@correction{%
   \if@correction%
      \above@newline%
      \bgroup%
      \dedicfont\the\correction@tk%
      \egroup%
   \fi%
}

\def\@dia@tournament{%
   \if@tournament
      \above@newline%
      \bgroup%
      \awardfont%
      \the\tournament@tk
      \if@source\else\if@date%
         \ \ \@dia@date%
      \fi\fi%
      \egroup%
   \fi%
}

\def\@dia@award{%
   \if@award%
      \above@newline%
      \bgroup%
      \awardfont\the\award@tk%
      \egroup%
   \fi%
}

\def\@dia@dedic{%
   \if@dedication%
      \above@newline%
      \bgroup%
      \dedicfont\the\dedic@tk%
      \egroup%
   \fi%
}

\def\@show@album#1/#2;{#1 FIDE-Album #2}

\def\@dia@fidealbum{%
   \if@fidealbum%
      \above@newlne%
      {\expandafter\@show@album\the\fidealbum@tk;}%
   \fi%
}

\def\@twinskip{\ \ }

\def\@dia@stipulation{%
   \if@stipulation%
      \bgroup%
      \stipfont%
      \the\stipulation@tk%
      \ifx@twins%
         \let\below@newline\@twinskip%
         \@dia@twins%
      \else\ifx@cond%
         \let\below@newline\@twinskip%
         \@dia@condition%
      \fi\fi%
      \egroup%
      \let\below@newline\newline%
   \else%
      \x@twinsfalse%
      \x@condfalse%
      \let\below@newline\relax%
   \fi%
}

\def\x@write@twin#1; {%
   \hskip1em#1%
   \@lefttrue\let\below@newline\newline%
   \let\@action\write@twins%
   \l@@klist%
}

\def\write@twins#1; {%
   \setbox\@test@box=\hbox{#1\if@left~~\fi}%
   \ifdim\wd\@test@box>4\sq@width%
      \below@newline%
      \@lefttrue%
      #1%
   \else%
      \if@left%
         \below@newline%
      \fi%
      \noindent\hbox to 4\sq@width{#1\hfil}%
      \if@left%
         \@leftfalse%
      \else%
         \@lefttrue%
      \fi%
   \fi%
   \let\below@newline\newline%
   \l@@klist%
}

\def\@dia@twins{%
   \if@twins%
      \bgroup%
      \@lefttrue%
      \remfont%
      \ifx@twins%
         \let\@action=\x@write@twin%
      \else%
         \let\@action=\write@twins%
      \fi%
      \@parseTokenlist\twins@tk;%
      \egroup%
      \let\below@newline\newline%
   \fi%
}

\def\@dia@condition{%
   \if@condition%
      \bgroup%
      \@lefttrue%
      \remfont%
      \ifx@cond%
         \let\@action=\x@write@twin%
      \else%
         \let\@action=\write@twins%
      \fi%
      \@parseTokenlist\condition@tk;%
      \egroup%
      \let\below@newline\newline%
   \fi%
}

\def\check@piecedef{%
    \ifx\next@piecedef\relax%
        \let\col@action=\relax%
    \else%
        \let\col@action=\@@piecedef%
    \fi%
    \col@action%
}
\def\@@piecedef#1{\csname#1\x@piecedef\endcsname\parse@piecedef}

\def\parse@piecedef{\futurelet\next@piecedef\check@piecedef}

\def\@piecedef#1#2#3{%
   \def\x@piecedef{#2}%
   \below@newline%
   \hbox{%
   \parse@piecedef#1\relax%
   \ = #3}%
}

\def\write@piecedefs#1; {%
   \@piecedef#1%
   \l@@klist%
}

\def\@dia@piecedefs{%
   \if@piecedefs%
      \bgroup%
      \@lefttrue%
      \let\below@newline\newline%
      \remfont\let\@action=\write@piecedefs%
      \@parseTokenlist\piecedefs@tk;%
      \egroup%
   \fi%
}

\def\@dia@remark{%
   \if@remark%
      \bgroup%
      \@lefttrue%
      \remfont\let\@action=\write@twins%
      \@parseTokenlist\remark@tk;%
      \egroup%
      \let\below@newline\newline%
   \fi%
}

\def\parse@params#1{%
   \ifcase\help@a\relax
      \label@tk={#1}\ifx\relax#1\else\@labeltrue\fi\or%
      \number@tk={#1}\ifx\relax#1\else\@numbertrue\fi\or%
      \aut@tk={#1}\ifx\relax#1\else\auth@rtrue\fi\or%
      \city@tk={#1}\ifx\relax#1\else\@citytrue\fi\or%
      \sourcenr@tk={#1}\ifx\relax#1\else\@sourcenrtrue\fi\or%
      \source@tk={#1}\ifx\relax#1\else\@sourcetrue\fi\or%
      \day@tk={#1}\ifx\relax#1\else\@daytrue\fi\or%
      \from@month=#1\or%
      \to@month=#1\or%
      \year@tk={#1}\ifx\relax#1\else\@yeartrue\fi\or%
      \issue@tk={#1}\ifx\relax#1\else\@issuetrue\fi\or%
      \pages@tk={#1}\ifx\relax#1\else\@pagestrue\fi\or%
      \tournament@tk={#1}\ifx\relax#1\else\@tournamenttrue\fi\or%
      \award@tk={#1}\ifx\relax#1\else\@awardtrue\fi\or%
      \after@tk={#1}\ifx\relax#1\else\@aftertrue\fi\or%
      \version@tk={#1}\ifx\relax#1\else\@versiontrue\fi\or%
      \correction@tk={#1}\ifx\relax#1\else\@correctiontrue\fi\or%
      \dedic@tk={#1}\ifx\relax#1\else\@dedicationtrue\fi\or%
      \theme@tk={#1}\ifx\relax#1\else\@themetrue\fi\or%
      \twins@tk={#1}\ifx\relax#1\else\@twinstrue\fi\or%
      \computer@tk={#1}\or%
      \comment@tk={#1}\ifx\relax#1\else\@commenttrue\fi\or%
      \judgement@tk={#1}\ifx\relax#1\else\@judgementtrue\fi\or%
      \sol@tk={#1}%
   \fi%
   \advance\help@a \@ne%
   \l@@klist%
}

\def\split@param#1{%
   \@labelfalse\@numberfalse\auth@rfalse\@cityfalse%
   \@sourcenrfalse\@sourcefalse\@dayfalse\@yearfalse%
   \@issuefalse\@pagesfalse\@tournamentfalse\@awardfalse%
   \@afterfalse\@versionfalse\@correctionfalse\@dedicationfalse%
   \@themefalse\@twinsfalse\@commentfalse\@judgementfalse%
   \help@a=\z@%
   \let\@action=\parse@params\l@@klist#1\e@list%
}
\newcommand{\solpar}{\par}
\def\@dia@solution{%
   \bgroup%
   \parindent\z@%
   \parskip\tw@\p@%
   {\bfseries%
      \noindent\if@label\showlabel{\the\label@tk}\fi%
      \the\number@tk) %
      \ifauth@r%
         \ifnormal@names%
            \the\aut@tk%
         \else%
            {\@notfirstfalse% We are the first one
            \def\name@sep{, }%
            \let\@action=\@sol@writename%
            \@parseTokenlist\aut@tk;}:%
         \fi%
         \newline%
      \fi%
   }%
   \if@develop\if@judgement\the\judgement@tk\solpar\fi\fi%
   \the\sol@tk\solpar%
   \if@comment\the\comment@tk\solpar\fi%
   \egroup%
}
\grid@width=0.6\p@
\inner@frame=0.6\p@
\outer@frame=1.2\p@
\space@frame=\outer@frame
\v@frame@dist=\tw@\p@%
\h@frame@dist=\tw@\p@%
\space@frame@dist=\z@
\v@space@dist=1em
\def\@show@figurine{%
   \noindent%
   \@figurine@number%
   \@figurine@author%
   \@figurine@city%
   \@figurine@after%
   \@figurine@correction%
   \@figurine@version%
   \@figurine@source%
   \@figurine@tournament%
   \@figurine@award%
   \@figurine@dedic%
   \@figurine@pieces%
   \@figurine@stip%
   \@figurine@twins%
   \@figurine@conditions%
   \@figurine@remarks%
   \@figurine@computer%
}
\def\@figurine@number{{\authorfont\thediag)}}

\def\p@rseauthor@figurine#1,#2; {%
   \if@notfirst, \else\@notfirsttrue\fi#2 #1%
   \l@@klist%
}

\def\@figurine@author{%
   {\ifauth@r%
      \authorfont\@notfirstfalse%
      \let\@action=\p@rseauthor@figurine%
      \@parseTokenlist\aut@tk;%
      \ \ %
   \fi}%
}

\def\@figurine@city{%
   {\if@city%
      \cityfont\@notfirstfalse%
      \let\@action=\p@rsecity\@parseTokenlist\city@tk;%
      \ \ \ %
   \fi}%
}

\def\@figurine@after{\if@after{\dedicfont\ \ \the\after@tk}\fi}

\def\@figurine@correction{%
   \if@correction{\dedicfont\ \ \the\correction@tk}\fi%
}

\def\@figurine@version{%
   \if@version{\dedicfont\ \ \the\version@tk}\fi%
}

\def\@figurine@source{%
   {\if@source%
      \sourcefont%
      \if@sourcenr\the\sourcenr@tk\ \fi%
      \the\source@tk%
      \if@year%
         \ \ %
         \if@day%
            \ifnum\from@month>\z@%
               \the\day@tk.%
               \write@month\from@month%
               \ifnum\to@month>\z@%
                  -\write@month\to@month%
               \fi%
               .%
            \fi%
         \else%
            \write@month\the\from@month%
            \ifnum\to@month>\z@%
               -\write@month\the\to@month%
            \fi%
            /%
         \fi%
         \the\year@tk%
      \fi%
      \if@issue , \the\issue@tk\fi%
      \if@pages , \the\pages@tk\fi%
   \fi}%
}

\def\@figurine@tournament{%
   \if@tournament{\awardfont\ \ \the\tournament@tk}\fi%
}

\def\@figurine@award{%
   \if@award{\awardfont\ \ \the\award@tk}\fi%
}

\def\@figurine@dedic{%
   \if@dedication{\awardfont\ \ \the\dedic@tk}\fi%
}
\def\show@squares#1\e@list{\ch@fig{\the\help@a}#1, }

\def\@figurine@pieces{%
   {\if@pieces%
      \let\@action=\p@rsepieces%
      \let\piece@job\show@squares%
      \@parseTokenlist\pieces@tk,%
   \fi}%
}
\def\@figurine@stip{%
   \if@stipulation{\stipfont\ \ \the\stipulation@tk}\fi%
}

\def\@figurine@conditions{%
   \if@condition{\remfont\ \ \the\condition@tk}\fi%
}

\def\@figurine@twins{%
   \if@twins{\remfont\ \ \the\twins@tk}\fi%
}

\def\@figurine@computer{%
   \ifthenelse{\boolean{showcomputer}}{%
      \if@computer\ \computerproofedsymbol\fi%
   }{}%
}

\def\@figurine@remarks{%
   \if@remark{\stipfont\ \ \the\remark@tk}\fi%
}
\def\do@dia@job{\@write@sol\ifvmode\noindent\fi\unhbox\dia@box}
\def\solhead#1{{\split@param{#1}\@dia@solution}}
\def\@write@sol{%
   \ifs@lu%
      \immediate\write\s@lfd{%
         \noexpand\solhead{%
            {\the\label@tk}%
            {\thediag}%
            {\the\aut@tk}%
            {\the\city@tk}%
            {\the\sourcenr@tk}%
            {\the\source@tk}%
            {\the\day@tk}%
            {\the\from@month}%
            {\the\to@month}%
            {\the\year@tk}%
            {\the\issue@tk}%
            {\the\pages@tk}%
            {\the\tournament@tk}%
            {\the\award@tk}%
            {\the\after@tk}%
            {\the\version@tk}%
            {\the\correction@tk}%
            {\the\dedic@tk}%
            {\the\theme@tk}%
            {\the\twins@tk}%
            {\the\computer@tk}%
            {\the\comment@tk}%
            {\the\judgement@tk}%
            {\the\sol@tk}%
         } %end of \solhead
      }%
   \fi
}
\def\@months#1-#2;{\from@month=#1\to@month=#2\@datetrue}
\def\@dia@writename#1; {\above@newline{\authorfont\@dianame#1; }\l@@klist}
\def\@sol@writename#1; {\sep@names\@dianame#1; \l@@klist}
\def\name@sep{,\ }
\def\sep@names{\if@notfirst\name@sep\else\@notfirsttrue\fi}
\def\@checkshort#1/#2#3;{%
   \@shortformtrue%
   \ifx#2\e@list\relax%
      \@shortformfalse%
   \fi%
}
\def\short@christian#1#2-{%
   \if@notfirst -\else\@notfirsttrue\fi%
   #1.%
   \l@@klist%
}

\def\@write@christian#1/#2;{#1}

\def\write@christian#1;{%
   \@checkshort#1/\e@list;%
   \if@shortform\@write@christian#1;\else#1\fi%
}

\def\@write@short#1/#2;{#2}

\def\write@short#1;{%
   \@checkshort#1/\e@list;%
   \if@shortform%
      \@write@short#1;%
   \else%
      {\@notfirstfalse\let\@action\short@christian\l@@klist#1-\e@list}%
   \fi%
}
\def\@fullname#1, #2; {\write@christian#2; #1}
\def\@sirname#1, #2; {#1}
\def\@short#1, #2; {\write@short#2;\ #1}
\def\@noname#1, #2; {}
\def\@normalname#1; {#1}
\def\space@vertical{\space@verticaltrue}
\def\space@horizontal{\space@verticalfalse}
\def\cl@arsol{\immediate\openout\s@lfd=\jobname.sol}
\def\getc@lor#1{%
   \if#1\ds@white%
     \help@a\z@\global%
     \let\cpd@stepcounterPieces\cpd@stepcounterWhite%
   \else\if#1\ds@neutral%
     \help@a=6\global%
     \let\cpd@stepcounterPieces\cpd@stepcounterNeutral%
   \else\if#1\ds@black%
     \help@a=12\global%
     \let\cpd@stepcounterPieces\cpd@stepcounterBlack%
   \else\errmessage{invalid color!}%
   \fi\fi\fi%
   \getpi@ce%
}

\def\get@text#1{\text@tk={#1}\read@square}

\def\getpi@ce#1{\if#1B\relax\else
   \if#1\ds@knight\advance\help@a\@ne%
   \else\if#1\ds@bishop\advance\help@a\tw@%
   \else\if#1\ds@rook\advance\help@a\thr@@%
   \else\if#1\ds@queen\advance\help@a\f@ur%
   \else\if#1\ds@king\advance\help@a 5%
   \else\if#1C%
      % An imitator should not count for any color.
      \let\cpd@stepcounterPieces\relax
      \advance\help@a 145%
   \else\if#1E%  Equihopper
      \advance\help@a 216%
   \else\if#1X%  Equihopper senkrecht
      \advance\help@a 180%
   \else%
      \errmessage{invalid piece!}%
   \fi\fi\fi\fi\fi\fi\fi\fi\fi%
   \futurelet\r@tate\chkr@tate%
}

\def\chkr@tate{%
   \if\r@tate \ds@rotation@upsidedown\advance\help@a 108\let\nextpr@c=\skipr@t\else%
   \if\r@tate \ds@rotation@left\advance\help@a 36\let\nextpr@c=\skipr@t\else%
   \if\r@tate \ds@rotation@right\advance\help@a 72\let\nextpr@c=\skipr@t\else%
   \let\nextpr@c\piece@job\fi\fi\fi\nextpr@c%
}
\def\skipr@t#1{\piece@job}
\def\l@@k{\futurelet\whatsnext\parsefi@lds}
\def\parsefi@lds{%
   \if\whatsnext\e@list%
      \let\nextpr@c\relax%
   \else
      \let\nextpr@c\read@square%
   \fi%
   \nextpr@c%
}

\def\set@current@square@index#1#2{%
  \setcounter{cpd@current@square@index}{#1+\value{cpd@linesmax}*#2}%
}
\def\set@current@square@value#1{%
  \expandafter%
    \xdef\csname cpd@square@\roman{cpd@current@square@index}\endcsname{#1}%
}
\def\get@current@square@value{%
  \setcounter{cpd@current@square@value}%
    {\csname cpd@square@\roman{cpd@current@square@index}\endcsname}%
}
\def\set@piece{%
   \ifnum\pl@ne=\current@plane%
      \cpd@stepcounterPieces%
      \set@current@square@index\lin@\r@w%
      \get@current@square@value%
      \ifthenelse{\value{cpd@current@square@value}=\m@ne}
        {\set@current@square@value{\the\help@a}}%
        {\ifthenelse{\value{cpd@current@square@value}=144}%
          {\set@current@square@value{\the\help@a+18}}%
          {\errmessage{Trying to set a piece to an occupied square}}}%
   \fi%
   \l@@k%
}
\def\set@nofield, {%
   \ifnum\pl@ne=\current@plane%
      \set@current@square@index\lin@\r@w%
      \get@current@square@value%
      \ifthenelse{\value{cpd@current@square@value}=\m@ne}%
        {}% This is an empty white square, nothing to do
        {\ifthenelse{\value{cpd@current@square@value}=144}%
          {\set@current@square@value{\m@ne}}%
          {\errmessage{Trying to set a piece to an occupied square}}}%
   \fi%
   \l@@klist%
}
\def\set@frame, {%
   \ifnum\pl@ne=\current@plane%
      \@vGrid{\the\lin@}{\the\r@w}\@ne%
      \@hGrid{\the\lin@}{\the\r@w}\@ne%
      \advance\lin@\@ne%
      \@vGrid{\the\lin@}{\the\r@w}\@ne%
      \advance\lin@\m@ne\advance\r@w\@ne%
      \@hGrid{\the\lin@}{\the\r@w}\@ne%
   \fi%
   \l@@klist%
}
\def\e@list{\relax}
\def\l@@klist{\futurelet\nextlist\ch@cklst}
\def\ch@cklst{%
   \ifx\nextlist\e@list%
      \let\nextpr@c=\relax%
   \else%
      \let\nextpr@c=\@action%
   \fi%
   \nextpr@c%
}
\def\p@rsepieces#1, {\getc@lor#1\e@list\l@@klist}
\def\p@rsetext#1, {\get@text#1\e@list\l@@klist}
\def\set@text{%
   \ifnum\pl@ne=\current@plane%
      \raise\r@w\sq@width\hbox to \z@{%
         \hskip\lin@\sq@width%
         \vbox to \sq@width{\vss%
         \hbox to \sq@width{%
           \hss%
           {\the\text@tk}%
           \hss%
         }\vss}%
         \hss%
      }%
   \fi%
   \l@@klist%
}
\def\p@rseauthor#1; {\sh@wauthor#1;\l@@klist}
\def\read@square#1#2{%
   \lin@=`#1\advance\lin@ by -`a\relax%
   \r@w=#2\advance\r@w by \m@ne%
   \read@plane%
}
\def\read@plane@normal{\plane@job}

\def\read@plane@stereo{\futurelet\plane@char\get@plane@stereo}

\def\get@plane@stereo{%
   \if\plane@char A%
      \pl@ne=\@ne\advance\r@w-\tw@\advance\lin@-\tw@%
      \let\@plane@job=\skip@plane%
   \else\if\plane@char B%
      \pl@ne=\tw@\advance\r@w-\tw@\advance\lin@-\tw@%
      \let\@plane@job=\skip@plane%
   \else\if\plane@char C%
      \pl@ne=\thr@@\advance\r@w-\tw@\advance\lin@-\tw@%
      \let\@plane@job=\skip@plane%
   \else\if\plane@char D%
      \pl@ne=\f@ur\advance\r@w-\tw@\advance\lin@-\tw@%
      \let\@plane@job=\skip@plane%
   \else%
      \pl@ne=\z@\let\@plane@job=\plane@job%
   \fi\fi\fi\fi%
   \@plane@job%
}

\def\skip@plane#1{\plane@job}

\def\read@plane@space#1{\pl@ne=`#1\advance\pl@ne by -`A\relax\plane@job}
\def\@vGrid#1#2#3{%
   \raise#2\sq@width\hbox to \z@{%
      \hskip#1\sq@width\hskip-.5\grid@width%
      \vrule height#3\sq@width width\grid@width\hss%
   }%
}

\def\@hGrid#1#2#3{%
   \raise#2\sq@width\hbox to \z@{%
      \hskip#1\sq@width%
      \vrule width#3\sq@width height .5\grid@width depth%
      .5\grid@width\hss%
   }%
}
\def\@selGrid#1#2, {%
   \ifnum\pl@ne=\current@plane%
      \if#1h%
         \@hGrid#2%
      \else\if#1v%
         \@vGrid#2%
      \else%
         \errmessage{Wrong GridSelector #1}%
      \fi\fi%
   \fi%
   \l@@klist%
}
\def\@stdgrid{%
   \setbox\plane@box=\vbox{\hbox{%
      \help@a=\tw@%
      \loop%
         \ifnum\help@a<\lines@max%
         \@vGrid{\the\help@a}{0}{\the\rows@max}%
         \advance\help@a\tw@%
      \repeat%
      \help@a=\tw@%
      \loop%
         \ifnum\help@a<\rows@max%
            \@hGrid{0}{\the\help@a}{\the\lines@max}%
            \advance\help@a\tw@%
      \repeat%
      \box\plane@box
   }}%
}
\def\ds@xlabel#1{%
   \label@tk={#1}\@labeltrue%
}

\def\@set@label#1;{\ifds@label\label{#1}\fi}
\def\init@vars{%
   \global\s@lufalse
   \setboolean{cpd@checkPieceCounts}{false}%
   \setcounter{cpd@defWhitePieces}{\z@}%
   \setcounter{cpd@defBlackPieces}{\z@}%
   \setcounter{cpd@defNeutralPieces}{\z@}%
   \setcounter{cpd@whitePieces}{\z@}%
   \setcounter{cpd@blackPieces}{\z@}%
   \setcounter{cpd@neutralPieces}{\z@}%
   \lin@\z@
}

\def\clear@board{%
   \ifthenelse{\boolean{allwhite}\and\boolean{switchcolors}}%
      {\errmessage{'allwhite' and 'switchcolors' do not make sense used together.}}%
      {\@whitefield=\m@ne\@blackfield=144}%
   \ifthenelse{\boolean{allwhite}}{\@blackfield=\m@ne}{}%
   \ifthenelse{\boolean{switchcolors}}{\@whitefield=144\@blackfield=\m@ne}{}%
   \setcounter{cpd@current@row}{0}%
   \whiledo{\value{cpd@current@row}<\value{cpd@rowsmax}}{%
      \setcounter{cpd@current@line}{0}%
      \whiledo{\value{cpd@current@line}<\value{cpd@linesmax}}{%
         \set@current@square@index{\value{cpd@current@line}}{\value{cpd@current@row}}%
         \setcounter{cpd@helper}{\the\current@plane+\value{cpd@current@line}+\value{cpd@current@row}}%
         \ifthenelse{\isodd{\value{cpd@helper}}}%
           {\set@current@square@value{\@whitefield}}%
           {\set@current@square@value{\@blackfield}}%
        \addtocounter{cpd@current@line}{\@ne}%
      }%
      \addtocounter{cpd@current@row}{\@ne}%
   }%
}

\def\put@row#1{%
   \lin@\z@%
   \help@b=#1%
   \advance\help@b\brd@ff%
   \hbox{%
      \ifthenelse{\boolean{legend}}{{%
         \advance\@rows`1%
         \llap{\raise .25\sq@width\hbox{\legendfont \char\@rows\ \ }}%
      }}{}%
      \if@stereo%
         \ifnum\current@plane>\z@%
            \ifnum\@rows=12%
               \llap{\raise .5\sq@width\hbox{\cpd@boardfont c6\ }}%
            \fi%
         \fi%
      \fi%
      \hbox to \z@{\vbox to \sq@width{}}%
      \set@current@square@index{\lin@}{#1}%
      \loop%
         \get@current@square@value%
         \ifthenelse{\value{cpd@current@square@value}=\m@ne}%
          {\wF}%
          {\char\value{cpd@current@square@value}}%
         % \ifnum\count\help@b=\m@ne\wF%
         % \else\char\count\help@b\fi%
         \advance\lin@\@ne%
         \addtocounter{cpd@current@square@index}{1}%
         % \advance\help@b\@ne%
      \ifnum\lin@<\lines@max\repeat%
   }%
}
% \def\put@line#1{%
%    \lin@\z@%
%    \help@b=#1%
%    \advance\help@b\brd@ff%
%    \hbox{%
%       \if@stereo%
%          \ifnum\current@plane>\z@%
%             \ifnum\@rows=12%
%                \llap{\raise .5\sq@width\hbox{\cpd@boardfont c6\ }}%
%             \fi%
%          \fi%
%       \fi%
%       \hbox to \z@{\vbox to \sq@width{}}%
%       \loop%
%          \ifnum\count\help@b=\m@ne\wF%
%          \else\char\count\help@b\fi%
%          \advance\lin@\@ne\advance\help@b\@ne%
%       \ifnum\lin@<\lines@max\repeat%
%    }%
% }
\def\@parseTokenlist#1#2{\expandafter\l@@klist\the#1#2 \e@list}
\def\@addToPlane#1{%
   \setbox\plane@box=\vbox{\hbox{%
      \@parseTokenlist#1,%
      \box\plane@box%
   }}%
}
\def\put@plane{%
   % We might want gridchess
     \if@stdgrid%
        \@stdgrid%
     \fi%
   % Let us first set the fieldframes
   \if@fieldframe%
      \let\@action\read@square%
      \let\plane@job\set@frame%
      \@addToPlane\fieldframe@tk%
   \fi%
   % Now we set text to all squares which are given using \fieldtext
   \if@fieldtext%
      \let\@action\p@rsetext%
      \let\plane@job\set@text%
      \@addToPlane\fieldtext@tk%
   \fi%
   % Then we should add the gridlines
   \if@gridlines%
      \let\@action\read@plane%
      \let\plane@job\@selGrid%
      \@addToPlane\gridlines@tk%
   \else%
      \if@stereo%
        \stereo@center%
     \fi%
   \fi%
   % In an 'allwhite' diagram we display dotted lines
   \ifthenelse{\boolean{allwhite}}{%
       \setbox\plane@box=\vbox{\hbox{%
           \psset{unit=\sq@width,linewidth=.4pt,linestyle=dotted,dotsep=.125}%
           \setcounter{field@border}{1}%
           \whiledo{\value{field@border}<\lines@max}{%
              \psline(\value{field@border},0)(\value{field@border},\rows@max)%
              \addtocounter{field@border}{\@ne}%
           }%
           \setcounter{field@border}{1}%
           \whiledo{\value{field@border}<\rows@max}{%
              \psline(0,\value{field@border})(\lines@max,\value{field@border})%
              \addtocounter{field@border}{\@ne}%
           }%
           \box\plane@box%
       }}%
   }{}%
   % Now we should clear the board
   \clear@board%
   % Let us now parse the list of pieces
   \if@pieces%
      \let\@action\p@rsepieces%
      \let\piece@job\l@@k\let\plane@job\set@piece%
      \@parseTokenlist\pieces@tk,%
   \fi%
   % Now we clear all fields, which are given using \nofields
   \if@nofields%
      \let\@action\read@square%
      \let\plane@job\set@nofield%
      \@parseTokenlist\nofields@tk,%
   \fi%
   % Now we can put the pieces to the board
   \global\setbox\plane@box=\hbox{%
      \vbox{\rlap{\box\plane@box}}%
      \vbox{%
         \chessfont%
         \baselineskip=\z@\lineskip=\z@%
         \@rows=\rows@max%
         % \multiply\@rows by \lines@max%
         \loop%
            \advance\@rows \m@ne%
            \put@row\@rows%
         \ifnum\@rows>\z@\repeat%
      }%
       % Put a legend if wanted
       \ifthenelse{\boolean{legend}}{%
          \vbox to \z@{%
             \vbox to \z@{\vss}%
             \llap{\hbox{\hspace*{\inner@frame}%
                \lin@\z@%
                \loop%
                   \hbox to \sq@width{\hfill{\advance\lin@`a\legendfont\char\lin@}\hfill}%
                   \advance\lin@\@ne%
                \ifnum\lin@<\lines@max\repeat%
             }}\vss}%
       }{}%
   }%
}
\def\put@sqs@normal{%
   \put@plane%
   \setbox\sq@box=\hbox{%
      \inner@henbox{\box\plane@box}%
   }%
}
\def\put@sqs@stereo{%
   \setbox\sq@box=\hbox{\hfil\vbox{%
      \current@plane=5%
      \vskip\v@space@dist%
      \loop%
         \advance\current@plane\m@ne%
         \ifnum\current@plane=\z@%
            \lines@max=\@ight%
            \rows@max=\@ight%
         \else%
            \lines@max=\f@ur%
            \rows@max=\f@ur%
         \fi%
         % Now we should clear the board
         \begingroup% We need this for inner loops!
            \clear@board%
            \put@plane%
         \endgroup%
         \hbox to \bd@width{%
            \hfil%
            \inner@henbox{\box\plane@box}%
            \ifcase\current@plane\or%
               \rlap{{\cpd@boardfont\ A}}\or%
               \rlap{{\cpd@boardfont\ B}}\or%
               \rlap{{\cpd@boardfont\ C}}\or%
               \rlap{{\cpd@boardfont\ D}}%
            \fi%
            \hfil%
         }%
         \vskip\v@space@dist%
      \ifnum\z@<\current@plane\repeat%
   }\hfil}%
}

\def\stereo@center{%
   \ifnum\current@plane=\z@%
      \setbox\plane@box=\vbox{\hbox{%
         \@hGrid\tw@\tw@\f@ur\@hGrid\tw@ 6\f@ur%
         \@vGrid\tw@\tw@\f@ur\@vGrid6\tw@\f@ur%
         \box\plane@box%
      }}%
   \fi%
}
\def\put@sqs@space@vertical{%
   \setbox\sq@box=\hbox{\hfil\vbox{%
      \current@plane=\planes@max%
      \vskip\v@space@dist%
      \loop%
         \advance\current@plane\m@ne%
         % Now we should clear the board
         \begingroup% We use inner loops!
         \clear@board%
         \put@plane%
         \hbox to \bd@width{%
            \inner@henbox{\box\plane@box}%
            \advance\current@plane`A%
            \rlap{{\cpd@boardfont\ \char\current@plane}}%
         }%
         \endgroup%
         \vskip\v@space@dist%
      \ifnum\z@<\current@plane\repeat%
   }\hfil}%
}

\def\put@sqs@space@horizontal{%
   \setbox\sq@box=\hbox{%
      \current@plane=\z@%
      \hskip\h@space@dist%
      \loop%
         % Now we should clear the board
         \begingroup% We use inner loops!
         \clear@board%
         \put@plane%
         \hbox to \bd@width{%
            \inner@henbox{\box\plane@box}%
            \advance\current@plane`A%
            \rlap{{\cpd@boardfont\ \char\current@plane}}%
         }%
         \endgroup%
         \hskip\h@space@dist%
         \advance\current@plane\@ne%
      \ifnum\planes@max>\current@plane%
      \repeat%
   }%
}

\def\put@sqs@space{%
   \ifspace@vertical%
      \put@sqs@space@vertical%
   \else%
      \put@sqs@space@horizontal%
   \fi%
}
\def\@inner@vframe{%
   \if@vframe%
      \vrule width \inner@frame%
   \else%
      \hskip\inner@frame%
   \fi%
}

\def\@inner@hframe{%
   \if@hframe%
      \hrule height \inner@frame%
   \else%
      \vskip\inner@frame%
   \fi%
}
\def\inner@v@frame@rule{%
   \if@stereo%
      \@inner@vframe%
   \else\if@space%
      \@inner@vframe%
   \else\if@leaveOuter%
      \vrule width \inner@frame%
   \else%
      \@inner@vframe%
   \fi\fi\fi%
}

\def\inner@h@frame@rule{%
   \if@stereo%
      \@inner@hframe%
   \else\if@space%
      \@inner@hframe%
   \else\if@leaveOuter%
      \hrule height \inner@frame%
   \else%
      \@inner@hframe%
   \fi\fi\fi%
}

\def\inner@henbox#1{%
   \hbox{%
      \inner@v@frame@rule%
      \vbox{\inner@h@frame@rule#1\inner@h@frame@rule}%
      \inner@v@frame@rule%
   }%
}
\def\@outer@vrule{\vrule width \outer@frame}

\def\@outer@hrule{\hrule height \outer@frame}
\def\outer@v@frame@rule{%
   \if@stereo%
      \@outer@vrule%
   \else\if@space%
      \@outer@vrule%
   \else\if@leaveOuter%
      \if@vframe\@outer@vrule\else\hskip\outer@frame\fi%
   \else%
      \@outer@vrule%
   \fi\fi\fi%
}

\def\outer@h@frame@rule{%
   \if@stereo%
      \@outer@hrule%
   \else\if@space%
      \@outer@hrule%
   \else\if@leaveOuter%
      \if@hframe\@outer@hrule\else\vskip\outer@frame\fi%
   \else%
      \@outer@hrule%
   \fi\fi\fi%
}

\def\outer@henbox#1{%
   \outer@h@frame@rule%
   \hbox{%
      \outer@v@frame@rule%
      \ifspace@vertical%
         \hskip\h@frame@dist%
      \fi%
      \vbox{%
         \ifspace@vertical%
            \vskip\v@frame@dist%
         \else%
            \vskip\v@space@dist%
         \fi%
         #1%
         \ifspace@vertical%
            \vskip\v@frame@dist%
         \else%
            \vskip\v@space@dist%
         \fi%
      }%
      \ifspace@vertical%
         \hskip\h@frame@dist%
      \fi%
      \outer@v@frame@rule%
   }%
   \outer@h@frame@rule%
}
\def\ch@fig#1{%
   \ifvmode\noindent\fi%
   \hbox{\chtextfont\lower.1\fontdimen\tw@\chtextfont\hbox{\char#1}}%
}
\def\@dia@index{%
   \@ifundefined{newindex}%
   {\errmessage{You should add documentstyle-option 'index'}}{}%
}

\def\showlabel#1{%
   \if@develop%
      \raise1ex\hbox{\labelfont#1}\penalty\exhyphenpenalty%
   \fi%
}

\def\@aidxitem#1, #2, #3{%
   \par\medskip#1, \write@christian#2; \dotfill #3%
}

\def\dia@index#1\@sep#2[#3]{\index[#3]{#2|showlabel{#1}}}

\def\parse@aindex#1; {%
   \expandafter\dia@index\the\label@tk\@sep#1[author]\l@@klist%
}

\def\@aindex{%
   \if@aindex%
      \ifnormal@names%
         \errmessage{Cannot create index entries with normalnames}%
      \else\ifauth@r%
         \let\@action=\parse@aindex\@parseTokenlist\aut@tk;%
      \fi\fi%
   \fi%
}

\def\x@sindex#1\@sep{\expandafter\dia@index\the\label@tk\@sep#1[source]}

\def\@sindex{%
   \if@sindex\if@source%
      \expandafter\x@sindex\the\source@tk\@sep%
   \fi\fi%
}

\def\parse@tindex#1, {%
   \expandafter\dia@index\the\label@tk\@sep#1[theme]\l@@klist%
}

\def\@tindex{%
   \if@tindex\if@theme%
      \let\@action=\parse@tindex\@parseTokenlist\theme@tk,%
   \fi\fi%
}
\def\@setPieceColor#1#2#3{%
   \gdef\ds@white{#1}\gdef\ds@black{#2}\gdef\ds@neutral{#3}%
}

\def\@setPieceSpec#1#2#3#4#5#6{%
   \gdef\ds@king{#1}\gdef\ds@queen{#2}\gdef\ds@rook{#3}%
   \gdef\ds@bishop{#4}\gdef\ds@knight{#5}\gdef\ds@pawn{#6}%
}

\def\@setPieceRotation#1#2#3{%
   \gdef\ds@rotation@left{#1}\gdef\ds@rotation@right{#2}\gdef\ds@rotation@upsidedown{#3}%
}
\def\loop@rotation{%
   \bgroup%
      \n@cnt\z@%
      \help@a\z@%
      \loop%
         \ifcase\n@cnt%
            \def\@theRotation{}%
         \or%
            \def\@theRotation{\ds@rotation@left}%
         \or%
            \def\@theRotation{\ds@rotation@right}%
         \or%
            \def\@theRotation{\ds@rotation@upsidedown}%
         \fi%
         \loop@color%
         \advance\n@cnt\@ne%
         \advance\help@a by 36\relax%
      \ifnum\n@cnt<\f@ur\repeat%
   \egroup%
}

\def\loop@color{%
   \bgroup%
      \w@cnt\z@%
      \loop%
         \ifcase\w@cnt%
            \def\@theColor{\ds@white}%
         \or%
            \def\@theColor{\ds@neutral}%
         \or%
            \def\@theColor{\ds@black}%
         \fi%
         \loop@piece%
         \advance\w@cnt\@ne%
         \advance\help@a by 6%
      \ifnum\w@cnt<\thr@@\repeat%
   \egroup%
}

\def\loop@piece{%
   \bgroup%
      \b@cnt\z@%
      \loop%
         \ifcase\b@cnt%
            \def\@thePiece{\ds@pawn}%
         \or%
            \def\@thePiece{\ds@knight}%
         \or%
            \def\@thePiece{\ds@bishop}%
         \or%
            \def\@thePiece{\ds@rook}%
         \or%
            \def\@thePiece{\ds@queen}%
         \or%
            \def\@thePiece{\ds@king}%
         \fi%
         \expandafter\xdef\csname%
         \@theColor\@thePiece\@theRotation\endcsname{%
            \noexpand\ch@fig{\the\help@a}%
         }
         \advance\b@cnt\@ne%
         \advance\help@a by \@ne%
      \ifnum\b@cnt<6\repeat%
   \egroup%
}
\elchfont\@fselch

\defaultelchfont%
\diagnum{\@ne}
%% \figcnttrue
\setboolean{piececounter}{true}
\def\@dianame{\@fullname}
\def\@solname{\@fullname}
\space@verticaltrue
\diagnumbering{arabic}
\def\write@month{\@arabic}%
\diagleft
\cl@arsol
\let\orig@author=\author
\let\orig@day=\day
\let\orig@month=\month
\let\orig@year=\year
\let\orig@label=\label
\DefinePieces{wsn}{KDTLSB}{LRU}
\newdimen\normalboardwidth
\def\setboardwidth{%
   \normalboardwidth=\@ight\fontdimen\tw@\chessfont%
   \advance\normalboardwidth\tw@\inner@frame%
   \advance\normalboardwidth\tw@\h@frame@dist%
   \advance\normalboardwidth\tw@\outer@frame%
}

\setboardwidth

%</style>
%    \end{macrocode}
%
% \Finale