summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/beamersubframe/beamersubframe.dtx
blob: d6698dd3cafa8e1e507031203cedc58f046cef3b (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
% \iffalse meta-comment
%
% Package beamersubframe
% Copyright (c) 2011 Mike Kaufmann, all rights reserved
%
% This program is provided under the terms of the
% LaTeX Project Public License distributed from CTAN
% archives in directory macros/latex/base/lppl.txt.
%
% Author: Mike Kaufmann
%         m.km@gmx.de
% \fi
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
% \CheckSum{922}
%
% \iffalse meta-comment
%
%<*package>
%% 
\def\fileversion{0.2}
\def\filedate{2011/08/07}

%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{hypdoc}
\usepackage{graphicx}
%\usepackage[pdfborder=0,colorlinks,linkcolor=blue]{hyperref}
\usepackage[all]{hypcap}
\setcounter{IndexColumns}{2}
\EnableCrossrefs
\CodelineIndex
%\RecordChanges
%\OnlyDescription
\makeatletter
% new, like ...Env... commands from doc.sty)
\let\PrintDescribeOpt\PrintDescribeEnv
\let\PrintOptName\PrintEnvName
\def\DescribeOpt{\leavevmode\@bsphack\begingroup\MakePrivateLetters
    \Describe@Opt}
\def\Describe@Opt#1{\endgroup
    \marginpar{\raggedleft\PrintDescribeOpt{#1}}%
    \SpecialOptIndex{#1}\@esphack\ignorespaces}
\def\SpecialOptIndex#1{\@bsphack
    \index{#1\actualchar{\protect\ttfamily#1}
           (option)\encapchar usage}%
    \index{options:\levelchar#1\actualchar{\protect\ttfamily#1}\encapchar
           usage}\@esphack}
% new (like \SpecialEnvIndex from hypdoc.sty)
\let\HDorg@SpecialOptIndex\SpecialOptIndex
\renewcommand*\SpecialOptIndex[1]{%
  \@bsphack
  \begingroup
    \HD@target
    \let\HDorg@encapchar\encapchar
    \edef\encapchar usage{%
      \HDorg@encapchar hdclindex{\the\c@HD@hypercount}{usage}%
    }%
    \HDorg@SpecialOptIndex{#1}%
  \endgroup
  \@esphack
}
% redefinition (from doc.sty)
\def\macro{\begingroup
   \catcode`\\12
   \MakePrivateLetters \m@cro@ \z@}
\def\environment{\begingroup
   \catcode`\\12
   \MakePrivateLetters \m@cro@ \@ne}
% new, environment 'option', like 'environment', but index entries with
% '(option)'
\def\option{\begingroup
   \catcode`\\12
   \MakePrivateLetters \m@cro@ \tw@}
% redefinition (from doc.sty)
\long\def\m@cro@#1#2{\endgroup \topsep\MacroTopsep \trivlist
   \edef\saved@macroname{\string#2}%
  \def\makelabel##1{\llap{##1}}%
  \if@inlabel
    \let\@tempa\@empty \count@\macro@cnt
    \loop \ifnum\count@>\z@
      \edef\@tempa{\@tempa\hbox{\strut}}\advance\count@\m@ne \repeat
    \edef\makelabel##1{\llap{\vtop to\baselineskip
                               {\@tempa\hbox{##1}\vss}}}%
    \advance \macro@cnt \@ne
  \else  \macro@cnt\@ne  \fi
  \edef\@tempa{\noexpand\item[%
     \ifcase #1%
       \noexpand\PrintMacroName
     \or
       \noexpand\PrintEnvName
     \or
       \noexpand\PrintOptName
     \fi
     {\string#2}]}%
 \@tempa
  \global\advance\c@CodelineNo\@ne
   \ifcase #1%
      \SpecialMainIndex{#2}\nobreak
      \DoNotIndex{#2}%
   \or
      \SpecialMainEnvIndex{#2}\nobreak
   \or
      \SpecialMainOptIndex{#2}\nobreak
   \fi
  \global\advance\c@CodelineNo\m@ne
  \ignorespaces}
% new
\let\endoption\endmacro
\def\SpecialMainOptIndex#1{\@bsphack\special@index{%
                                      #1\actualchar
                                      {\string\ttfamily\space#1}
                                         (option)%
                                      \encapchar main}%
    \special@index{options:\levelchar#1\actualchar{%
                   \string\ttfamily\space#1}\encapchar
           main}\@esphack}
\makeatother
\begin{document}
\DocInput{beamersubframe.dtx}
\end{document}
%</driver>
%
%<*package>
% \fi
%
% \DoNotIndex{\^}
% \DoNotIndex{\@auxout}
% \DoNotIndex{\@@end,\@empty}
% \DoNotIndex{\@gobble,\@gobbletwo}
% \DoNotIndex{\@ifclassloaded,\@ifnextchar,\@ifundefined}
% \DoNotIndex{\@makeother}
% \DoNotIndex{\@nameuse}
% \DoNotIndex{\@tempa,\@tempb,\@tempcnta,\@tempcntb}
% \DoNotIndex{\@writefile,\@nameuse}
% \DoNotIndex{\advance,\active,\addtocontents,\addtocounter}
% \DoNotIndex{\AtBeginDocument,\AtEndDocument}
% \DoNotIndex{\begin,\begingroup}
% \DoNotIndex{\beamer@endpageofdocument,\beamer@endpageofframe}
% \DoNotIndex{\beamer@endpageofpart,\beamer@endpageofsection}
% \DoNotIndex{\beamer@endpageofsubsection}
% \DoNotIndex{\beamer@frameendpage,\beamer@framepages,\beamer@framestartpage}
% \DoNotIndex{\beamer@startpageofpart,\beamer@startpageofsection}
% \DoNotIndex{\beamer@startpageofsubsection,\beamer@subsectionstartpage}
% \DoNotIndex{\beamer@partstartpage,\beamer@sectionstartpage}
% \DoNotIndex{\beamer@ifempty,\beamer@notesactions,\beamer@tempcount}
% \DoNotIndex{\c@framenumber,\c@page,\c@part}
% \DoNotIndex{\c@section,\c@subsection,\c@subsectionslide}
% \DoNotIndex{\catcode,\clearpage,\closeout,\csname}
% \DoNotIndex{\DeclareOption,\def,\do,\dospecials}
% \DoNotIndex{\edef,\else,\end,\endgroup,\endcsname,\endinput,\ExecuteOption}
% \DoNotIndex{\expandafter,\ExecuteOptions}
% \DoNotIndex{\fi,\filedate,\fileversion}
% \DoNotIndex{\gdef,\global}
% \DoNotIndex{\headcommand,\hyperlink}
% \DoNotIndex{\if@filesw}
% \DoNotIndex{\if,\ifcase,\ifcat,\ifdim,\ifnum,\ifx,\InputIfFileExists}
% \DoNotIndex{\immediate,\input}
% \DoNotIndex{\insertpartheadnumber,\insertsectionhead,\insertsubsectionhead}
% \DoNotIndex{\insertsectionheadnumber,\insertsubsectionheadnumber}
% \DoNotIndex{\jobname}
% \DoNotIndex{\let,\lastsubsection}
% \DoNotIndex{\MessageBreak}
% \DoNotIndex{\NeedsTeXFormat,\newcommand,\newcount,\newdimen,\newif}
% \DoNotIndex{\newenvironment,\newtoks,\newwrite,\noexpand}
% \DoNotIndex{\openout}
% \DoNotIndex{\PackageError,\PackageWarning,\PackageInfo}
% \DoNotIndex{\ProcessOptions,\ProvidesPackage}
% \DoNotIndex{\protect}
% \DoNotIndex{\relax,\RequirePackage}
% \DoNotIndex{\setcounter,\slideentry,\space,\string}
% \DoNotIndex{\the}
% \DoNotIndex{\verbatim@,\verbatim@line,\verbatim@processline}
% \DoNotIndex{\write}
% \DoNotIndex{\xdef,\z@}
%
% \changes{0.1}{2011/06/29}{initial release}
% \changes{0.2}{2011/08/07}{proper package, manual and documentation}
% \changes{0.2}{2011/08/07}{appendix tested}
% \changes{0.2}{2011/08/07}{fixed navigation bar}
% \changes{0.2}{2011/08/07}{total number of frames not counting appended frames}
% \changes{0.2}{2011/08/07}{new environment lastframe}
% \changes{0.2}{2011/08/07}{subslideentry}
% \changes{0.2}{2011/08/07}{inserttotalframenumberwithsub}
% \changes{0.2}{2011/08/07}{new option nominiframes}
% \changes{0.2}{2011/08/07}{defaults for bsf@sub...page... macros}
% \changes{0.2}{2011/08/07}{checking .sfp file}
%
% \newcommand{\BSF}{\textsf{BeamerSubFrame}}
%
% \title{The \BSF\ Package\\[1ex]
%     Reordering frames in the PDF file without reordering the source}
% \author{Mike Kaufmann\\\href{mailto:m.km@gmx.de}{\texttt{m.km@gmx.de}}}
% \date{\filedate\ (v\fileversion)}
% ^^A--------------------------------------------------------------------------
% \maketitle
% \begin{abstract}
% The \BSF\ package provides a method to reorder frames in the
% PDF file without reordering the source. Mainly, it is meant to embed or
% append frames with details on some subject.
% \end{abstract}
%
% \tableofcontents
%
% ^^A--------------------------------------------------------------------------
% \section{Introduction}
% \subsection{Why this Package}
% Of course, usually a presentation is prepared for one occasion.
% But sometimes a presentation is used more then once, and the audience
% and/or the available time differs.
%
% For me, there are two kinds of audience. The first group are the
% sales people, who for the most part only want to know the features
% of a new product I developed. And the second group are the technicians,
% who want to know everything.
%
% So basically, on one time I have to give a presentation in half an hour,
% covering only the basics. But there might be questions, where I need to
% show some details. In this case it's nice to have the necessary frames.
% And an another time, I have to give a presentation in one hour, covering
% also the details.
%
% In both cases, it would be nice to have a presentation, where normally
% only the cursor keys are needed for navigation, and without the necessity
% of clicking on links.
%
% With Beamer, one would have to create two presentation. One with the
% frames containing details at the end, and another one with the details
% between the other frames.
%
% Now here the \BSF\ package comes in handy. After some changes to the source
% of the presentation with the details embedded, both version can be compiled
% out of the same source. To select the version, only one option must be
% changed.
%
% ^^A---------------------------------------------
% \subsection{A Warning}
% This package is in an early state of development (it's version
% \fileversion). It is already useful, but there are some restrictions (see
% \autoref{sec:restrictions}). And although it's not planned, the user
% interface may change in the future.
%
% ^^A---------------------------------------------
% \subsection{Feeback and Testing}
% Because this package is very new and still under development, any feedback
% is appreciated. A good location for a discussion would be the newsgroup
% \texttt{comp.text.tex} (or \texttt{de.comp.text.tex}).
%
% And since Beamer offers a lot of features and it is hard to test the
% \BSF\ package with all of them, it would be nice, if some people would
% do some additional testing and/or provide some presentation for testing.
%
% ^^A---------------------------------------------
% \subsection{Dependencies}
% The \BSF\ package can only be used with the Beamer class (article mode
% is not supported yet).
%
% Additionally, it needs the |verbatim| package.
%
% ^^A---------------------------------------------
% \subsection{Legal Stuff}
% This program is provided under the terms of the
% \LaTeX\ Project Public License distributed from CTAN
% archives in directory macros/latex/base/lppl.txt.
% 
% ^^A--------------------------------------------------------------------------
% \section{Using the Packages}
% \subsection{Package Options}
% The \BSF\ package has three options.
% 
% \DescribeOpt{embed}
% The option |embed| is used to put frames with details between the other
% frames.
%
% \DescribeOpt{append}
% The option |append| is used to remove the frames with details from the other
% frames and append them at the end of the PDF file.
%
% If none of these two options is given, |embed| is used as default. Both
% options are mutually exclusive. If both are given, the last one wins.
%
% \DescribeOpt{nominiframes}
% In themes with miniframes, there are also frame symbols for appended frames
% with details by default. If the option |nominiframes| is given, these frame
% symbols will disappear. This option has only an effect, if the |append| option
% is given too.
%
% ^^A---------------------------------------------
% \subsection{The \texttt{subframe} Environment}
% \DescribeEnv{subframe}
% For frames which should be embedded or appended contitionally (i.e.\ frames
% with details), the |subframe| environment must be used instead of the |frame|
% environment. Basically, it works the same way as the |frame| environment,
% i.e.\ it has the same options and arguments.
%
% For typesetting, the |frame| environment is used internally. In embed mode
% (i.e.\ the |embed| option is given) it inserts the option |environment=subframe|
% to enable the use of verbatim material in the frames. In append mode the contents
% of the frame is written to a file. Before the contents, |\begin{frame}|, with
% all arguments of the |subframe| environment appended, is inserted. And after
% the contents |\end{frame}| is inserted.
%
% For copying the contents, the |verbatim| package is used. So in append mode
% the |subframe| environment is treated as a |verbatim|
% environment,\footnote{Because of this, the phrase \texttt{\bslash
% end\{subframe\}} cannot be used in a \texttt{subframe} environment.} but
% without typesetting anything.
%
% There should be no parts, sections, or subsections only containing subframes,
% because in append mode, they would have no contents. Since it is not the
% intention of the \BSF\ package, to move parts, sections, or subsections, this
% was not even tested.
%
% ^^A---------------------------------------------
% \subsection{Appending Frames}
% \DescribeMacro\appendsubframes
% To append the subframes, the macro |\appendsubframes| must be called before
% |\end{document}|. In embed mode, the command simply does nothing. In append
% mode it inputs the file written by the |subframe| environments.
%
% The command is only allowed once and it can only appear right before
% |\end{document}|.\footnote{Both restrictions are not tested by the package yet.}
% Disregarding this may lead to some strange errors.
%
% The command can be omitted to remove the subframes from the PDF file in append
% mode. But links to them will then produce warnigs and will lead somewhere else.
% In themes with miniframes, the links of the miniframe symbols for subframes
% will lead to page 1.
%
% ^^A---------------------------------------------
% \subsection{Conditional Execution}
% \DescribeMacro\ifappend
% To execute some macros or insert some text according to the mode of the
% \BSF\ package, the marco |\ifappend| can be used. It has two arguments.
%
% \vspace{1ex}
% |\ifappend{|\meta{material for append mode}|}{|\meta{material for embed mode}|}|
%
% \vspace{1ex}
% \noindent
% The first argument is inserted only in append mode and the second one only in
% embed mode.
%
% The macro is intended for conditional links in frames and subframes. It can
% be used in own macros. To do something only in one mode, the argument for the
% other mode can be left empty.
%
% ^^A---------------------------------------------
% \subsection{The \texttt{lastframe} Environment}
% \DescribeEnv{lastframe}
% Normally, a presentation has a last frame, containing something like ``Thanks
% for listening'' (at least I learned it this way). But using a |frame|
% environmet, the navigation (sidebar, miniframes, and so on) appears as if the
% frame belongs to the last (sub)section.
%
% Using the |lastframe| environment, the navigation has the same appearance as
% on the title frame.
%
% It has the same options and arguments as the |frame| environment, which is
% used internally with all given arguments.. To enable the use of verbatim
% contents, it additionally inserts the option |environment=lastframe|.
%
% The |lastframe| environment must be used only for the last frame (before the
% |\appendsubframes| command), because it sets the counters for parts, sections,
% and subsections to 0. So after a ``lastframe'', sectioning will not work
% properly anymore.
%
% ^^A---------------------------------------------
% \subsection{Inserts}
% \DescribeMacro\inserttotalframenumber
% Beamers |\inserttotalframenumber| was changed. In append mode it now contains
% the number of frames without the subframes. In embed mode it contains the
% number of frames as usual.
%
% \DescribeMacro\inserttotalframenumberwithsub
% Additionally, the insert |\inserttotalframenumberwithsub| is available. It
% inserts the total number of frames including appended subframes in append mode.
% It is also defined in embed mode. Then it just contains the total number of
% frames (so the same as |\inserttotalframenumber|).
%
% ^^A---------------------------------------------
% \subsection{Files written}
% The \BSF\ package writes two files.
% \begin{description}
% \item[\texttt{\bslash jobname.sfr}] contains the contents of all subframes.
%       The package inputs this file before the end of the document with the
%       |\appendsubframes| command. The file is written regardless of |\nofiles|.
% \item[\texttt{\bslash jobname.sfp}] contains the information necessary for
%       miniframes. It is written indirectly, using the |.aux| file. So if
%       |\nofiles| is used, the |.sfp| file is not written too.
% \end{description}
% Both files are only written and used in append mode.
%
% ^^A---------------------------------------------
% \subsection{Warnings and Errors}
% Currently, there is one warning and one error in the \BSF\ package.
%
% When loading the package, it checks, if the Beamer class is loaded. If not,
% an error message will be displayed and the package is not loaded. Disregarding
% this error will therefore lead to additional errors.
%
% The |.sfp| file is checked at the end of the document. If it is missing,
% corrupted or incomplete, a warning is given out. In this case some links of
% miniframe symbols for subframes will lead to page 1. Of course this applies
% only to themes with miniframes.
%
% ^^A---------------------------------------------
% \subsection{Conditional Execution (2)}
% \DescribeMacro\ifsubframe
% This macro is intended to be used in themes, to make things appear differently
% on normal frames and subframes. This could be used to set some marker on
% subframes.\footnote{There is an example in the example file, which can be
% generated from \texttt{beamersubframe.dtx}.} The command works regardless of
% the mode.
%
% \vspace{1ex}
% |\ifsubframe{|\meta{material for subframes}|}{|\meta{material for normal frames}|}|
%
% \vspace{1ex}
% \noindent
% The first argument is inserted only in subframes and the second one only in
% normal frames. An unused argument may be left empty.
%
% ^^A---------------------------------------------
% \subsection{The \texttt{subslideentry}}
% \label{sec:man-subse}
% \DescribeMacro\subslideentry
% This is not a macro for normal users. It may be useful for people who want to
% write their own theme, willing to do more, then defining and using templates.
% If you are not one of these people, just skip this section.
% 
% In append mode, the \BSF\ package writes a |\subslideentry| instead of a
% |\slideentry| for subframes to the |.nav| file. The |\subslideentry| has the
% same arguments as the |\slideentry|. By default, it just passes its arguments
% to |\slideentry|. This way it does the same as |\slideentry|, independent of
% the used theme. By redefining |\subslideentry|, it is possible to, for example,
% make miniframes for subframes appear differently form miniframes for normal
% frames.
%
% ^^A--------------------------------------------------------------------------
% \section{The Look and Feel}
% \subsection{In Embed Mode}
% In embed mode, the frames containing details are between the other frames.
% And navigation (navigation bar, sidebar and so on) behaves the same way, as
% it would without the \BSF\ package. Of course the highlighting of section
% and subsection names is the same too.
%
% ^^A---------------------------------------------
% \subsection{In Append Mode}
% In apend mode, the frames containing details are at the end of the PDF file.
%
% The navigation in the main part (the part of the PDF without the details)
% behaves as if the frames with details are not part of the PDF. And for the
% total number of frames, the frames with details are not counted (leading to
% something like ``41 / 29'' for the subframes in themes with a footline like
% AnnArbor).
%
% In themes with miniframes there are also frame symbols for the frames with
% details. Clicking on the symbols leads to these frames. But if the option
% |nominiframes| is given, the frame symbols will disappear and the symbol for
% the normal frame before the frame with details is highlighted on the frame
% with details.
%
% The navigation bar in the appended part (the part of the PDF with frames
% containing details) behaves as follows
% \begin{description}
% \item[slide and frame symbol:] behave as if the appended frames where at the
%       end of the source, so leading to the next or previous slide or frame in
%       the PDF (arrows), or leading to the last or first slide of a frame.
% \item[section and subsection symbol:] are always leading to the appropriate
%       slides in the main part of the PDF.
% \item[presentation symbol:] leads to the first frame of the presentation or
%       the last frame of the main part (before a possible appendix).
% \item[appendix symbol:] leads to the first or last frame of the appendix.
% \end{description}
%
% The links for sections and subsections in the sidebar and others lead to the
% first slide of the section or subsetion.
%
% In the navigation part of appended frames, the section and subsection names
% are the same and the highlighting is done as if the frames where embedded.
%
% ^^A--------------------------------------------------------------------------
% \section{A practical Approach}
% \subsection{The Order of Frames}
% If a presentation contains details on some items, there are two ways to
% insert them.
% \begin{enumerate}
% \item The details can be inserted right after the according item. This is
%       useful, if it is planned to present the details.
% \item The details can be inserted at the end. This is useful, if it is not
%       planned to present the details, but they might be needed to answer
%       question.
% \end{enumerate}
% 
% In both cases, links can be useful. In the first case, these are links to
% skip the details. And in the second case, these are links to jump to and
% return from the details.
% 
% The first case is shown in \autoref{fig:embed} and the second in
% \autoref{fig:append}. In both pictures the black lines denote the
% transitions using the cursor keys, and the blue lines the transitions
% using links. The dashed black lines are transitions by cursor keys, which
% are normally not needed.
% 
% \begin{figure}[htb]
% \includegraphics[width=\textwidth]{beamersubframe-embed.pdf}
% \caption{Frame Order with Details embedded}\label{fig:embed}
% \end{figure}
% 
% \begin{figure}[htb]
% \includegraphics[width=\textwidth]{beamersubframe-append.pdf}
% \caption{Frame Order with Details appended}\label{fig:append}
% \end{figure}
% 
% Of course, the way the links are arranged in the picuters is only an example.
% There are hundreds of possibilities. And how the links are arranged the best
% way, depends on the presentation \emph{and} on the person giving the
% presentation. For this section, let's consider the links in the pictures
% the ideal way.
%
% To use the \BSF\ package, in the source the frames must be arranged as shown
% in \autoref{fig:embed}. By default, the frames in the PDF file are arranged
% the same way. By just using the option |append|, the frames in the PDF file
% will be arragned as shown in \autoref{fig:append}.
%
% ^^A---------------------------------------------
% \subsection{Basic Changes to the Source}
% To use the \BSF\ package, a few changes to the source of a presentaion must
% be applied. In the example below, the left side shows the source before the
% changes and the right side the source after them.
%
% \noindent
% \begin{minipage}{0.49\textwidth}
% \footnotesize
% \begin{verbatim}
% \begin{frame}{Frame on Foo}
% material on foo
% \end{frame}
% 
% \begin{frame}
%     {Details on Foo Item b}
% details for item b
% \end{frame}
% 
% \begin{frame}{Another Frame}
% other material
% \end{frame}
% 
% \end{document}
% \end{verbatim}
% \end{minipage}
% \hfill
% \begin{minipage}{0.49\textwidth}
% \footnotesize
% \begin{verbatim}
% \begin{frame}{Frame on Foo}
% material on foo
% \end{frame}
% 
% \begin{subframe}
%     {Details on Foo Item b}
% details for item b
% \end{subframe}
% 
% \begin{frame}{Another Frame}
% other material
% \end{frame}
% \appendsubframes
% \end{document}
% \end{verbatim}
% \end{minipage}
% 
% Here, the |frame| environment for the frame with details was changed to the
% |subframe| environment, and the command |\appendsubframes| was inserted
% before |\end{document}|. This is the minimum of changes necessary.
% 
% It is not necessary, to change the arguments of subframes. Also, there is no
% need to change the contents of subframes. Even the |fragile| option (for
% verbatim material) will work, because the |subframe| environment automatically
% adds the option |environment=subframe|.
%
% ^^A---------------------------------------------
% \subsection{Conditional Links}
% \label{sec:clinks}
% How links are used and arranged, it totally up to the user, because this is
% highly individual. But nevertheless, links in embed mode should be different
% from links in append mode. For example, a link on a frame before a subframe
% (or a group of subframes) with details should skip them in embed mode, while
% in append mode the same link should lead to the subframe (or the first
% subframe of the group).
% 
% Let's stay with the examples shown in \autoref{fig:embed} and
% \autoref{fig:append}.
% 
% The link ``Skip Details'' on slide 2 of ``frame on foo'' in embed mode is
% replaced by a link ``Goto Details'' in append mode. In the first case the
% destination is slide 3 of ``frame on foo'' and in the second case it is
% slide 1 of ``details on foo item b''.
% 
% Let's say, ``frame on foo'' has a label ``lfoo'', given as option |label=lfoo|
% to the |frame| environment (this is also necessary, if the \BSF\ package is
% not used). For append mode a label must be added to the subframe ``details
% on foo item b''. Let's call it ``ldfoob''.
% 
% For embed mode the link can be realised with
% \begin{verbatim}
% \uncover<2>{\hyperlink{lfoo<3>}{\beamerskipbutton{Skip Details}}}
% \end{verbatim}
% and for append mode with
% \begin{verbatim}
% \uncover<2>{\hyperlink{ldfoob}{\beamergotobutton{Goto Details}}}
% \end{verbatim}
% 
% In order to make the link work as expected in both modes, without the need to
% change the source, |\ifappend| can be used like this:
% \begin{verbatim}
% \ifappend{\uncover<2>{\hyperlink{ldfoob}%
%                          {\beamergotobutton{Goto Details}}}}%
%          {\uncover<2>{\hyperlink{lfoo<3>}%
%                          {\beamerskipbutton{Skip Details}}}}
% \end{verbatim}
% 
% The link to return from the frames with details can then be done this way:
% \begin{verbatim}
% \ifappend{\uncover<4>{\hyperlink{lfoo<3>}%
%                          {\beamerreturnbutton{Return from Details}}}}{}
% \end{verbatim}
% This has the disatvantage, that in embed mode there is no link, and therefore
% the layout will differ between embed mode and append mode. But this can be
% fixed by adding an invisible button like this:
% \begin{verbatim}
% \ifappend{\uncover<4>{\hyperlink{lfoo<3>}
%                          {\beamerreturnbutton{Return from Details}}}}%
%          {\visible<0>{\beamerreturnbutton{Return from Details}}}
% \end{verbatim}
% 
% Typing all this every time can be a bit exhausting. So let's define some macros.
% 
% For skipping or going to the details, a macro called |\linkdetail| can be
% defined as
% \begin{verbatim}
% \newcommand<>{\linkdetail}[4]{%
%     \ifappend{\uncover#5{\hyperlink{#3}{\beamergotobutton{#4}}}}%
%              {\uncover#5{\hyperlink{#1}{\beamerskipbutton{#2}}}}
% }
% \end{verbatim}
% 
% The command is overlay-aware and it has four arguments:
% \begin{description}
% \item[\texttt{\#1}] is the label for the destination to go to in order to skip
%       the details.
% \item[\texttt{\#2}] is the text for the link to skip the details.
% \item[\texttt{\#3}] is the label for the destination to go to in order to jump
%       to the details.
% \item[\texttt{\#4}] is the text for the link to go to the details.
% \end{description}
% Now the link on the frame before the subframe can be written as
% \begin{verbatim}
% \linkdetails<2>{lfoo<3>}{Skip Details}{ldfoob}{Goto Details}
% \end{verbatim}
% 
% For returning from the details, a macro called |\returndetail| can be
% defined as
% \begin{verbatim}
% \newcommand<>{\returndetail}[2]{%
% \ifappend{\uncover#3{\hyperlink{#1}{\beamerreturnbutton{#2}}}}%
%          {\visible<0>{\beamerreturnbutton{#2}}}
% }
% \end{verbatim}
% 
% The command is also overlay-aware and it has two arguments:
% \begin{description}
% \item[\texttt{\#1}] is the label for the destination to go to in order to return
%       from details.
% \item[\texttt{\#2}] is the text for the link to return from details.
% \end{description}
% And the link on the subframe can be written as
% \begin{verbatim}
% \returndetails<4>{lfoo<3>}{Return from Details}
% \end{verbatim}
% 
% Of course, these are only examples. How links are done, is up to the user.
% And therefore, it is also up to the user, how commands like |\linkdetail| and
% |\returndetail| are defined.
%
% Another example: I like my links to be active only on the slide, they are
% needed. On all other slides, they should be covered and inactive. So I definded
% the macros a bit different:
% \begin{verbatim}
% \newcommand<>{\linkdetail}[4]{%
%     \ifappend{\uncover#5{\alt#5{\hyperlink{#3}{\beamergotobutton{#4}}}%
%                                {\beamergotobutton{#4}}}}%
%              {\uncover#5{\alt#5{\hyperlink{#1}{\beamerskipbutton{#2}}}%
%                                {\beamerskipbutton{#2}}}}
% }
% \newcommand<>{\returndetail}[2]{%
%     \ifappend{\uncover#3{\alt#3{\hyperlink{#1}{\beamerreturnbutton{#2}}}%
%                                {\beamerreturnbutton{#2}}}}{}
% }
% \end{verbatim}
%
% ^^A---------------------------------------------
% \subsection{An Example}
% \subsubsection{Without \BSF}
% As an example, let's realise frames in the order shown in \autoref{fig:embed}
% and \autoref{fig:append}. To show the difference of the source with and
% without using the \BSF\ package, first the order shown in \autoref{fig:embed}
% is realised without \BSF.
% 
% \begin{verbatim}
% \documentclass{beamer}
% \usepackage{lmodern}
% \usepackage[T1]{fontenc}
% 
% \begin{document}
% \begin{frame}{some frame}
% \begin{itemize}[<+->]
% \item there is foo
% \item foo is good
% \item and there is bar
% \item bar is good too
% \end{itemize}
% \end{frame}
% 
% \begin{frame}<1-2>[label=lfoo]{frame on foo}
% \begin{itemize}[<+->]
% \item item a
% \item item b \uncover<2>{\hyperlink{lfoo<3>}%
%                             {\beamerskipbutton{Skip Details}}}
% \item item c
% \item item d
% \end{itemize}
% \end{frame}
% 
% \begin{frame}{details on foo item b}
% \begin{itemize}[<+->]
% \item item b.1
% \item item b.2
% \item item b.3
% \item item b.4
% \end{itemize}
% \end{frame}
% 
% \begin{frame}
% \frametitle{more details on foo item b}
% \begin{itemize}[<+->]
% \item item b.5
% \item item b.6
% \item item b.7
% \item item b.8
% \end{itemize}
% \end{frame}
% 
% \againframe<3->{lfoo}
% 
% \begin{frame}{frame on bar}
% \begin{itemize}[<+->]
% \item item w
% \item item x
% \item item y
% \item item z \uncover<4>{\hyperlink{lother}%
%                             {\beamerskipbutton{Skip Details}}}
% \end{itemize}
% \end{frame}
% 
% \begin{frame}
% \frametitle{details on bar item z}
% \begin{itemize}[<+->]
% \item item z.1
% \item item z.2
% \item item z.3
% \item item z.4
% \end{itemize}
% 
% \vspace{2ex}
% \uncover<4>{\hyperlink{lother}{\beamerskipbutton{Skip further Details}}}
% \end{frame}
% 
% \begin{frame}{more details on bar item z}
% \begin{itemize}[<+->]
% \item item z.5
% \item item z.6
% \item item z.7
% \item item z.8
% \end{itemize}
% \end{frame}
% 
% \begin{frame}[label=lother]{another frame}
% \begin{itemize}[<+->]
% \item conclusion 1
% \item conclusion 2
% \item conclusion 3
% \item conclusion 4
% \end{itemize}
% \end{frame}
% \end{document}
% \end{verbatim}
% 
% ^^A-------------------------
% \subsubsection{With \BSF}
% And now the same order of frames, but this time using the \BSF\ package and
% with some comments. 
% \begin{verbatim}
% \documentclass{beamer}
% \usepackage{lmodern}
% \usepackage[T1]{fontenc}
% \end{verbatim}
% Here, the option |embed| has to be changed to |append|, to get the order as
% shown in \autoref{fig:append}.
% \begin{verbatim}
% \usepackage[embed]{beamersubframe}
% \end{verbatim}
% The two commands, as explained in \autoref{sec:clinks}.
% \begin{verbatim}
% \newcommand<>{\linkdetail}[4]{%
%     \ifappend{\uncover#5{\hyperlink{#3}{\beamergotobutton{#4}}}}%
%              {\uncover#5{\hyperlink{#1}{\beamerskipbutton{#2}}}}
% }
% \newcommand<>{\returndetail}[2]{%
% \ifappend{\uncover#3{\hyperlink{#1}{\beamerreturnbutton{#2}}}}%
%          {\visible<0>{\beamerreturnbutton{#2}}}
% }
% \end{verbatim}
% The next command realises a link with the same destination (argument |#1|) for
% both modes, but different texts (|#2| for embed mode and |#3| for append mode.
% \begin{verbatim}
% \newcommand<>{\linkdifftext}[3]{%
%     \ifappend{\uncover#4{\hyperlink{#1}{\beamergotobutton{#3}}}}%
%              {\uncover#4{\hyperlink{#1}{\beamerskipbutton{#2}}}}
% }
% \end{verbatim}
% The template defined below is an example for the use of |\ifsubframe|. It puts
% the text ``detail'' in the lower left corner of subframes and ``main part'' in
% the lower left corner of normal frames. Careful: it replaces a sidebar, so
% this will not work with themes like Berkeley.
% \begin{verbatim}
% \defbeamertemplate*{sidebar left}{bsf test}[1][50]
% {
%   \vfill%
%   \rlap{\hskip0.1cm\hbox{\color{fg!#1!bg}\tiny{\ifsubframe{detail}{main part}}}}%
%   \vskip2pt%
% }
% 
% \begin{document}
% \begin{frame}{some frame}
% \begin{itemize}[<+->]
% \item there is foo
% \item foo is good
% \item and there is bar
% \item bar is good too
% \end{itemize}
% \end{frame}
% 
% \begin{frame}<1-2>[label=lfoo]{frame on foo}
% \begin{itemize}[<+->]
% \item item a
% \end{verbatim}
% Here, the link was changed.
% \begin{verbatim}
% \item item b \linkdetail<2>{lfoo<3>}{Skip Details}{ldfoob}{Goto Details}
% \item item c
% \item item d
% \end{itemize}
% \end{frame}
% \end{verbatim}
% For the next two frames the environment was changed to |subframe|. And for the
% first, the label |ldfoob| was added.
% \begin{verbatim}
% \begin{subframe}[label=ldfoob]{details on foo item b}
% \begin{itemize}[<+->]
% \item item b.1
% \item item b.2
% \item item b.3
% \item item b.4
% \end{itemize}
% \end{subframe}
% 
% \begin{subframe}
% \frametitle{more details on foo item b}
% \begin{itemize}[<+->]
% \item item b.5
% \item item b.6
% \item item b.7
% \item item b.8
% \end{itemize}
% 
% \vspace{2ex}
% \end{verbatim}
% The link to return from details was added. Because there was no link in the
% version without \BSF\ the layout of the frame is now changed compared to that
% version. But it doesn't change from one mode to the other, because of the way
% |\returndetails| was definded.
% \begin{verbatim}
% \returndetail<4>{lfoo<3>}{Return from Details}
% \end{subframe}
% 
% \againframe<3->{lfoo}
% 
% \begin{frame}{frame on bar}
% \begin{itemize}[<+->]
% \item item w
% \item item x
% \item item y
% \end{verbatim}
% Again, the link was changed here.
% \begin{verbatim}
% \item item z \linkdetail<4>{lother}{Skip Details}{ldbarz}{Goto Details}
% \end{itemize}
% \end{frame}
% \end{verbatim}
% For the next two frames the environment was changed to |subframe| also. And
% for the first, the label |ldbarz| was added.
% \begin{verbatim}
% \begin{subframe}[label=ldbarz]
% \frametitle{details on bar item z}
% \begin{itemize}[<+->]
% \item item z.1
% \item item z.2
% \item item z.3
% \item item z.4
% \end{itemize}
% 
% \vspace{2ex}
% \end{verbatim}
% This link was changed, so the text differs between modes. But it would have
% been possible here, to leave the link unchanged.
% \begin{verbatim}
% \linkdifftext<4>{lother}{Skip further Details}{Return from Details}
% \end{subframe}
% 
% \begin{subframe}{more details on bar item z}
% \begin{itemize}[<+->]
% \item item z.5
% \item item z.6
% \item item z.7
% \item item z.8
% \end{itemize}
% 
% \vspace{2ex}
% \end{verbatim}
% Again, the link was added here, resulting also in a change off layout compared
% to the first version.
% \begin{verbatim}
% \returndetail<4>{lother}{Return from Details}
% \end{subframe}
% 
% \begin{frame}[label=lother]{another frame}
% \begin{itemize}[<+->]
% \item conclusion 1
% \item conclusion 2
% \item conclusion 3
% \item conclusion 4
% \end{itemize}
% \end{frame}
% \end{verbatim}
% And finally, the |\appendsubframes| command was inserted here.
% \begin{verbatim}
% \appendsubframes
% \end{document}
% \end{verbatim}
% 
% The source of the second version is available as example file, which can be
% generated from |beamersubframe.dtx|.
%
% ^^A--------------------------------------------------------------------------
% \section{Restrictions}
% \label{sec:restrictions}
% Since this is an early version of the \BSF\ package, there are some
% restrictions.
%
% \begin{itemize}
% \item The package was only tested with Beamer mode |beamer|. Using other
%       modes may lead to strange errors.
% \item Supporting material, like notes, is not tested yet.
% \item Lectures are not tested yet.
% \item There is no support for subsubsections (not even tested). And it is not
%       planned at all.
% \item There is no |\subframe| command.
% \item There is no |\againsubframe| command.
% \end{itemize}
% 
% ^^A--------------------------------------------------------------------------
% \section{Testing}
% For testing the \BSF\ package the following themes were used:
% \begin{itemize}
% \item Dresden
% \item Darmstadt
% \item Berkeley
% \item Montpellier
% \item Malmoe
% \item AnnArbor
% \end{itemize}
% 
% The themes were used without options. They where choosen to cover all types of
% navigation possible with the themes delivered with Beamer. If I missed
% something and this doesn't work, please let me know. If there are other things
% not working (e.g.\ some inserts), please let me know too. In both cases, a
% file for testing would be nice.
%
% ^^A--------------------------------------------------------------------------
% \section{ToDo}
% Although the \BSF\ package is already useful, there are a lot of things left
% to do:
% \begin{description}
% \item[testing] Beamer has a lot of features, an many of them are still
%       not tested.
% \item[Beamer modes] I have to admit, I didn't even test them.
% \item[notes] The same here.
% \item[lectures] And again, not tested.
% \item[macros] There are commands, which would be nice to have, like
%       |\subframe|, |\againsubframe|, and |\subnote| (to get notes between
%       frames moved too)
% \item[levels] With multiple levels of subframes, it would be possible, to have
%       details on details (on details on \dots). And then, one could embed the
%       first $n$ levels of details, and append the others.
% \end{description}
% 
% The list is not complete. If someone has an item to add, please let me know.
%
% ^^A--------------------------------------------------------------------------
% \StopEventually{\newpage\PrintIndex}
% ^^A \PrintChanges}
%
% ^^A--------------------------------------------------------------------------
% \newpage
% \section{The Code}
% \subsection{The Usual}
% First the usual things.
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamersubframe}[\filedate\space
    v\fileversion\space reordering beamer frames]
%    \end{macrocode}
%
% ^^A---------------------------------------------
% \subsection{Check the Class}
% Since the \BSF\ package only works with the Beamer class and article mode is
% not supported yet, check for the Beamer class. If it is not loaded, throw an
% error message and stop loading the package.
%    \begin{macrocode}
\@ifclassloaded{beamer}{}{%
  \PackageError{beamersubframe}{%
    The package works only with the beamer class,\MessageBreak
    therefore it is not loaded.
  }{%
    The package is not loaded, because it needs the\MessageBreak
    beamer class. Continuing may lead to additional\MessageBreak
    errors because of undefined commands.
  }
  \endinput
}
%    \end{macrocode}
%
% ^^A---------------------------------------------
% \subsection{``Variables''}
% \begin{macro}{\if@bsf@append}
% First there is the main flag to distinguish between append mode and embed mode.
%    \begin{macrocode}
\newif\if@bsf@append
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@bsf@miniframes}
% This flag is true by default. It is set to false by the option |nominiframes|.
%    \begin{macrocode}
\newif\if@bsf@miniframes
\@bsf@miniframestrue
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@bsf@subframe}
% This flag is set to true for subframes in both modes. For normal frames it is
% false.
%    \begin{macrocode}
\newif\if@bsf@subframe
\@bsf@subframefalse
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@bsf@nosfnum}
% This flag is used for checking the |.sfp| file.
%    \begin{macrocode}
\newif\if@bsf@nosfnum
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@bsf@firstline}
% This flag is needed to write |\begin{frame}| in front of the arguments of a
% |subframe| environment to the |.sfr| file in append mode.
%    \begin{macrocode}
\newif\if@bsf@firstline
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@bsf@firstpart}
% This flag is needed by |\bsfrestorepart| to initialize some macros used as
% variables instead of writing the |\bsf@partpages| entry to the |.nav| file.
%    \begin{macrocode}
\newif\if@bsf@firstpart
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@bsf@firstsection}
% This flag is needed by |\bsfrestoresection| to initialize some macros used as
% variables instead of writing the |\bsf@sectionpages| entry to the |.nav| file.
%    \begin{macrocode}
\newif\if@bsf@firstsection
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@bsf@firstsubsection}
% This flag is needed by |\bsfrestoresubsection| to initialize some macros used
% as variables instead of writing the |\bsf@subsectionpages| entry to the |.nav|
% file.
%    \begin{macrocode}
\newif\if@bsf@firstsubsection
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@bsf@nosubsection}
% This flag is used by |\bsfrestoresection| and |\bsfrestoresubsection| to
% determine, if a section contains any subsections.
%    \begin{macrocode}
\newif\if@bsf@nosubsection
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@bsf@prevnosubsection}
% This flag contains the final state of |\if@bsf@nosubsection| for the previous
% section.
%    \begin{macrocode}
\newif\if@bsf@prevnosubsection
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\bsf@frame@param}
% This token register is used to store the first three arguments of the
% |subframe| environment in embed mode, after adding the option
% |environmet=subframe|. The contents is passed to the |frame| environmet as
% its first three arguments.
%    \begin{macrocode}
\newtoks\bsf@frame@param
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\bsf@sfrout}
% The stream used to write the |.sfr| file. It holds the contents of all
% subframes. The file is only written and used in append mode.
%    \begin{macrocode}
\newwrite\bsf@sfrout
%    \end{macrocode}
% \end{macro}
%
% ^^A---------------------------------------------
% \subsection{Options and Packages}
% \begin{option}{embed}
% The options are rather simple. The option |embed| just sets |\if@bsf@append|
% to false.
%    \begin{macrocode}
\DeclareOption{embed}{\@bsf@appendfalse}
%    \end{macrocode}
% \end{option}
% \begin{option}{append}
% And |append| sets |\if@bsf@append| to true.
%    \begin{macrocode}
\DeclareOption{append}{\@bsf@appendtrue}
%    \end{macrocode}
% \end{option}
% \begin{option}{nominiframes}
% The option |nominiframes| sets |\if@bsf@miniframes| to false.
%    \begin{macrocode}
\DeclareOption{nominiframes}{\@bsf@miniframesfalse}
%    \end{macrocode}
% \end{option}
% The default is set and the options are processed.
%    \begin{macrocode}
\ExecuteOptions{embed}
\ProcessOptions*\relax
%    \end{macrocode}
% And the verbatim package is loaded.
%    \begin{macrocode}
\RequirePackage{verbatim}
%    \end{macrocode}

% ^^A---------------------------------------------
% \subsection{Navigation}
% \subsubsection{Sidebar and Headline}
% To get the highlighting of sections and subsections on appened subframes as if
% the frames were embedded, some counters must be restored to the values, they
% had at the point, the subframe appeared in the source. Additionally, for the
% headline some inserts must be restored.
% 
% To achieve this, the |subframe| environment writes a macro with all necessary
% arguments to the |.sfr| file. This is done for each subframe, before its
% contents, embedded in a |frame| environmet, is written to the file (see
% \autoref{sec:code-subframe}).
% 
% \begin{macro}{\bsfrestore}
% The macro is called |\bsfrestore|. It is executed, when the |.sfr| file is
% loaded. It restores the counters for part (|#1|), section (|#2|), and
% aubsection (|#3|). It also restores the counter subsectionslide (|#4|), which
% is needed for miniframes.
% 
% Then |\insertsectionhead| and |\insertsubsectionhead| are restored to their
% meanings at the point, the subframe appeard in the source. These meanings were
% stored to the two macros |\bsf@sectionhead|\meta{part}|.|\meta{section} and
% |\bsf@subsectionhead|\meta{part}|.|\meta{section}|.|\meta{subsection} by the
% |subframe| environment (see \autoref{sec:code-subframe}).
% 
% After that, the inserts for the part, section, and subsection numbers are
% restored.
% 
% The macro is also used by the |lastframe| environment (see
% \autoref{sec:code-lastframe}).
%    \begin{macrocode}
\newcommand{\bsfrestore}[4]{%
  \setcounter{part}{#1}%
  \setcounter{section}{#2}%
  \setcounter{subsection}{#3}%
  \setcounter{subsectionslide}{#4}%
  \expandafter\let\expandafter\insertsectionhead
    \csname bsf@sectionhead\the\c@part.\the\c@section\endcsname
  \expandafter\let\expandafter\insertsubsectionhead
    \csname bsf@subsectionhead\the\c@part.\the\c@section.\the\c@subsection\endcsname
  \def\insertpartheadnumber{#1}%
  \def\insertsectionheadnumber{#2}%
  \def\insertsubsectionheadnumber{#3}%
}
%    \end{macrocode}
% \end{macro}
% 
% ^^A-------------------------
% \subsubsection{Miniframes}
% \label{sec:code-miniframes}
% To typset miniframes, Beamer writes a |\slideentry| with the necessary
% arguments to the |.nav| file. Because miniframes should appear, as if the
% subframes are embedded, the |subframe| environment has to write such an entry
% at the point, the subframe appears in the source. But instead of a
% |\slideentry|, \BSF\ writes a |\subslideentry| (see \autoref{sec:man-subse}).
% 
% Argument |#4| of |\slideentry| contains the start page and the end page of the
% frame. Unfortunately, for subframes these numbers are unknown, until the
% |.sfr| file was loaded by |\appendsubframes|.
% 
% To get around this, for each subframe two macros are used. Their names \linebreak
% are
% |\bsf@substartpage|\meta{part}|.|\meta{section}|.|\meta{subsection}|.|\meta{subsectionslide}
% and \linebreak
% |\bsf@subendpage|\meta{part}|.|\meta{section}|.|\meta{subsection}|.|\meta{subsectionslide}.
% Here \meta{part}, \meta{section} and so on are the numbers.
% 
% Now at the point where the subframe appears in the souce, the |\subslideentry|
% is written. Instead of the unknown frame numbers, it contains the sequence
% |{\bsf@usenum{bsf@substartpage...}/\bsf@usenum{bsf@subendpage...}}| as argument
% |#4|. After a subframe was typeset by loading the |.sfr| file, the necessary
% information is written to the |.sfp| file. In the next \TeX\ run, when loading
% the |.sfp| file at the beginning of the document (see \autoref{sec:code-beginend}),
% these macros are all defined.
% 
% \begin{macro}{\bsf@subnum}
% The first macro involved is just a shortcut to get the numbers.
%    \begin{macrocode}
\def\bsf@subnum{%
  \the\c@part.\the\c@section.\the\c@subsection.\the\c@subsectionslide
}
%    \end{macrocode}
% \end{macro}
% 
% Beamer uses the macro |\beamer@writeslidentry| to write the |\slideentry| and
% the |\beamer@framepages| entry (used for the navigation bar) to the |.nav|
% file. For subframes this is split into two macros.
% 
% \begin{macro}{\beamer@writeslidentry@miniframes}
% The |\subslideentry| is written by |\beamer@writeslidentry@miniframes|. The
% macro is called directly by the |subframe| environment (see
% \autoref{sec:code-subframe}).
%    \begin{macrocode}
\def\beamer@writeslidentry@miniframes{%
  \addtocontents{nav}%
    {\protect\headcommand{%
      \protect\subslideentry{\the\c@section}{\the\c@subsection}%
        {\the\c@subsectionslide}%
        {\protect\bsf@usenum{bsf@substartpage\bsf@subnum}/%
         \protect\bsf@usenum{bsf@subendpage\bsf@subnum}}%
        {\lastsubsection}{\the\c@part}}}%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\beamer@writeslidentry@navbar}
% The |\beamer@framepages| entry is written by |\beamer@writeslidentry@navbar|.
% And it also writes the |\bsfsubframepages| entry to the |.sfp| file.
% 
% This macro is used to replace |\beamer@writeslidentry|, before the |.sfr| file
% is loaded. This is done in |\appendsubframes| (see \autoref{sec:code-appendsub}).
%    \begin{macrocode}
\def\beamer@writeslidentry@navbar{%
  \expandafter\beamer@ifempty\expandafter{\beamer@framestartpage}{}% does not happen normally
  {%else
    \addtocontents{nav}%
      {\protect\headcommand{% 
        \protect\beamer@framepages{\beamer@framestartpage}{\beamer@frameendpage}}}%
    \addtocontents{sfp}{%
      \protect\bsfsubframepages{\the\c@part}{\the\c@section}{\the\c@subsection}%
        {\the\c@subsectionslide}{\beamer@framestartpage}{\beamer@frameendpage}}%
    \clearpage\beamer@notesactions%
  }%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\subslideentry}
% The |\subslideentry| is initialized in a way that it does the same as the
% |\slideentry|. Because |\slideentry| is refedined by some themes, |\let| can
% not be used here.
%    \begin{macrocode}
\def\subslideentry{\slideentry}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\bsfsubframepages}
% The |.sfp| file contains one |\bsfsubframepages| entry for each subframe. The
% arguments are the part number (|#1|), the section number (|#2|), the subsection
% number (|#3|), the subsectionslide number (|#4|), and the first (|#5|) and the
% last page of the subframe (|#6|).
% 
% When the |.sfp| file is loaded, each |\bsfsubframepages| defines two macros
% |\bsf@substartpage...| and |\bsf@subendpage...| used by the |\subslideentry|.
%    \begin{macrocode}
\def\bsfsubframepages#1#2#3#4#5#6{%
  \expandafter\def\csname bsf@substartpage#1.#2.#3.#4\endcsname{#5}%
  \expandafter\def\csname bsf@subendpage#1.#2.#3.#4\endcsname{#6}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\bsf@usenum}
% The macro |\bsf@usenum|, used in the |\subslideentry|, sets a default in case
% the |\bsf@substartpage...| and |\bsf@subendpage...| macros are not defined due
% to a missing, corrupted or incomplete |.sfp| file. Without this, there could
% be errors which would persist on every subsequent run of \TeX.
%    \begin{macrocode}
\def\bsf@usenum#1{%
  \@ifundefined{#1}{1}{\csname #1\endcsname}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\bsf@checksfp}
% In order to warn the user about a missing, corrupted or incomplete |.sfp| file,
% the file is checked. This is done indirectly by checking, if all
% |\bsf@substartpage...| and |\bsf@subendpage...| macros in the current |.nav|
% file are defined. 
% 
% For this all commands in the |.nav| file are executed using Beamers |\dohead|
% command. Because some of the commands would typeset something, they are
% disabled and everything is done in a group to keep the changes local.
% 
% The macro |\bsf@usenum| is also redefined to set the flag |\if@bsf@nosfnum| to
% true in case one of the checked macros is undefined.
%    \begin{macrocode}
\def\bsf@checksfp{%
  \begingroup
    \@bsf@nosfnumfalse
    \def\bsf@usenum##1{%
      \@ifundefined{##1}{\@bsf@nosfnumtrue}{}}
    \def\slideentry##1##2##3##4##5##6{}%
    \def\partentry##1##2{}%
    \def\sectionentry##1##2##3##4##5{}%
    \def\beamer@subsectionentry##1##2##3##4##5{}%
    \def\subslideentry##1##2##3##4##5##6{%
      \bsf@checksfnum(##4)}%
    \dohead
    \if@bsf@nosfnum
      \PackageWarningNoLine{Beamer SubFrame}{%
        Missing, incomplete or corrupted file\MessageBreak
        \jobname.sfp! Links for miniframes of\MessageBreak
        subframes may be wrong. Please run TeX\MessageBreak
        again}
    \fi
  \endgroup
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\bsf@checksfnum}
% The macro |\bsf@checksfnum| is just used by |\bsf@checksfp| to get rid of the
% slash in argument |#4| of the |\subslideentry|.
%    \begin{macrocode}
\def\bsf@checksfnum(#1/#2){#1#2}
%    \end{macrocode}
% \end{macro}
% 
% ^^A-------------------------
% \subsubsection{Navigation Bar}
% Getting the navigation bar right takes some effort. First lets take a look,
% what Beamer does to get the necessary information for the navigation bar.
% 
% \paragraph{How Beamer does it}~\\
% Beamer writes several different entries to the |.nav| file.
% \begin{description}
% \item[\texttt{\bslash beamer@framepages}] with the first and the last page of
%       the frame as arguments. It is written for every frame at its end.
% \item[\texttt{\bslash beamer@subsectionpages}] with the first and the last
%       page of the subsection as arguments. It is written by the |\subsection|
%       command for the previous subsection, as well as by |\section| and
%       |\part| and the end of the document for the last subsection.
% \item[\texttt{\bslash beamer@sectionpages}] with the first and the last page
%       of the section as arguments. It is written by the |\section| command for
%       the previous section, as well as by |\part| and the end of the document
%       for the last section.
% \item[\texttt{\bslash beamer@partpages}] with the first and the last page of
%       the part as arguments. It is written by the |\part| command for the
%       previous part and the end of the document for the last part.
% \item[\texttt{\bslash beamer@documentpages}] with the last page of the
%       documnet as argument. It is written at the end of the document.
% \end{description}
% 
% The macros in the |.nav| file are executed once for every page (i.e.\ slide).
% By this the entry |\beamer@framepages| sets the macro |\beamer@startpageofframe|
% to its first argument and |\beamer@endpageofframe| to its second argument, but
% only if the current page is $\ge$ than the first argument and $\le$ than the
% second one. Similar macros are set the same way by the other entries. 
% 
% The frame icon is then typeset in a way, that
% \begin{itemize}
% \item the left arrow points to page |\beamer@startpageofframe| $-1$,
% \item the left part of the frame symbol points to page |\beamer@startpageofframe|,
% \item the right part of the frame symbol points to page |\beamer@endpageofframe|,
% \item and the right arrow points to page |\beamer@endpageofframe| $+1$.
% \end{itemize}
% The arrows are limited 1 or |\beamer@endpageofdocument| respectively. The icons
% for subsections and sections are typeset in a similar way.
% 
% The right part of the presentation symbol or (if there is an appendix) of the
% appendix symbol will point to page |\beamer@endpageofdocument|.

% \paragraph{How \BSF\ does it}~\\
% The frame icon should point to the previous or next frame or subframe in the
% PDF file. This is simply achieved by writing the |\beamer@framepages| entry
% with |\beamer@writeslidentry@navbar| (see \autoref{sec:code-miniframes}) for
% every subframe.
%
% The section icon should point to the first and last page of the section the
% subframe belongs to in the main part. For this, the first page of the first
% and the last page of the last subframe of a section is needed also. The
% information is stored in two steps.
% \begin{enumerate}
% \item A macro |\bsfrestoresection| is written to the |.sfr| file for each
%       section. Its arguments are the number of the previous section and the
%       first page of the section just started.
% \item When loading the |.sfr| file, the first |\bsfrestoresection| entry
%       initializes some makros (used as variables). All subsequent entries
%       write a |\bsf@sectionpages| entry to the |.nav| file, which has the
%       necessary pages as arguments.
% \end{enumerate}
% For parts and subsections corresponding entries are written to the files. And
% for the last part, section, and subsection |\bsf@...pages| entries are written
% after appending the subframes.
% 
% The |\beamer@...pages| entries written by Beamer at the end of the document
% would mix up the links of the navigation bar. It is not possible to prevent
% writing these entries. Instead they are disabled after appending the subframes.
% Since they would stay disabled for all pages after the first, they are
% reenabled at the beginning of the |.nav| file. Also, these entries have to be
% written before appending the subframes, in order to make the navigation bar
% work correctly for the last section and subsection in the main part.
% 
% Since this is also done for the |\beamer@documentpages| entry, the right
% arrows of the section and subsection icons are limited to the last page of the
% main part, i.e.\ the page before the first subframe. The same applies to the
% right part of the presentation or appendix symbol.
% 
% Unfortunately, this would apply to the right arrows of the slide icon and the
% frame icon too. Therefore the package writes a |\bsf@documentpages| entry to
% the |.nav| file after appending the subframes. Additionally, two macros of
% Beamer are redefined to use this information, instead of the information of
% the |\beamer@documentpages| entry.
%
% \paragraph{The Macros}~\\
% Lets start with the two redefined macros. The originals are defined in
% \textsf{beamerbasenavigation.sty}.
% 
% \begin{macro}{\hyperlinkslidenext}
% The new definition of |\hyperlinkslidenext| uses |\bsf@nextpage| instead of
% |\beamer@nextpage|.
%    \begin{macrocode}
\def\hyperlinkslidenext{%
  \bsf@nextpage\c@page%
  \hyperlink{Navigation\the\beamer@tempcount}}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\hyperlinkframestartnext}
% The new definition of |\hyperlinkframestartnext| also uses |\bsf@nextpage|
% instead of |\beamer@nextpage|.
%    \begin{macrocode}
\def\hyperlinkframestartnext{%
  \bsf@nextpage\beamer@endpageofframe%
  \hyperlink{Navigation\the\beamer@tempcount}}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\bsf@nextpage}
% The macro |\bsf@nextpage| works like |\beamer@nextpage| (from
% \textsf{beamerbasenavigation.sty}), but it uses |\bsf@endpageofdocument| as
% the last page for links, instead of |\beamer@endpageofdocument|.
%    \begin{macrocode}
\def\bsf@nextpage#1{%
  \beamer@tempcount=#1%
  \advance\beamer@tempcount by1\relax%
  \ifnum\beamer@tempcount>\bsf@endpageofdocument%
  \beamer@tempcount=\bsf@endpageofdocument%
  \fi}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\bsf@documentpages}
% The |\bsf@endpageofdocument| is defined by the |\bsf@documentpages| entry of
% the |.nav| file.
%    \begin{macrocode}
\def\bsf@documentpages#1{\def\bsf@endpageofdocument{#1}}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\bsf@endpageofdocument}
% And |\bsf@endpageofdocument| is initialized to reflect the original.
%    \begin{macrocode}
\def\bsf@endpageofdocument{\beamer@endpageofdocument}
%    \end{macrocode}
% \end{macro}
% 
% To disable and reenable the |\beamer@...pages| entries, first
% \begin{macro}{\beamer@partpages@orig}
% the macro |\beamer@partpages|,
%    \begin{macrocode}
\let\beamer@partpages@orig\beamer@partpages
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\beamer@subsectionpages@orig}
% the macro |\beamer@subsectionpages|,
%    \begin{macrocode}
\let\beamer@subsectionpages@orig\beamer@subsectionpages
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\beamer@sectionpages@orig}
% the macro |\beamer@sectionpages|,
%    \begin{macrocode}
\let\beamer@sectionpages@orig\beamer@sectionpages
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\beamer@documentpages@orig}
% and the macro |\beamer@documentpages| are saved.
%    \begin{macrocode}
\let\beamer@documentpages@orig\beamer@documentpages
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\bsf@enablenaventries}
% The command |\bsf@enablenaventries| restores the original meanings of the
% |\beamer@...pages| entries. It is written to the |.nav| file at the beginning
% of the document (see \autoref{sec:code-beginend}).
%    \begin{macrocode}
\def\bsf@enablenaventries{%
  \let\beamer@partpages\beamer@partpages@orig
  \let\beamer@subsectionpages\beamer@subsectionpages@orig
  \let\beamer@sectionpages\beamer@sectionpages@orig
  \let\beamer@documentpages\beamer@documentpages@orig
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\bsf@disablenaventries}
% And |\bsf@disablenaventries| disables the entries by letting them gobble their
% arguments. It is written to the |.nav| file after appending the subframes (see
% \autoref{sec:code-appendsub}).
%    \begin{macrocode}
\def\bsf@disablenaventries{%
  \let\beamer@partpages\@gobbletwo
  \let\beamer@subsectionpages\@gobbletwo
  \let\beamer@sectionpages\@gobbletwo
  \let\beamer@documentpages\@gobble
}
%    \end{macrocode}
% \end{macro}
%
% In order to write the |\bsfrestore...| entries to the |.sfr| file, the
% sectioning commands must be extended. First the originals for
%
% \begin{macro}{\part@orig}
% the macro |\part|,
%    \begin{macrocode}
\let\part@orig\part
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\section@orig}
% the macro |\section|,
%    \begin{macrocode}
\let\section@orig\section
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\subsection@orig}
% and the macro |\subsection| are saved.
%    \begin{macrocode}
\let\subsection@orig\subsection
%    \end{macrocode}
% \end{macro}
% The sectioning macros are only redefined in append mode.
%    \begin{macrocode}
\if@bsf@append
%    \end{macrocode}
% 
% \begin{macro}{\part}
% The new version of |\part| writes the |\bsfrestorepart| entry to the |.sfr|
% file. The original version is called at the end, so its arguments are of no
% concern here. But because of that, |\c@part| still contains the number of the
% previous part. Here, |\c@page| already contains the number of the first page
% of the new part.
%    \begin{macrocode}
  \def\part{%
    \immediate\write\bsf@sfrout{\string\bsfrestorepart{\the\c@part}%
        {\the\c@page}}%
    \part@orig
  }
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\section}
% The new version of |\section| writes the |\bsfrestoresection| entry to the
% |.sfr| file. Besides that, it works like the new |\part| command.
%    \begin{macrocode}
  \def\section{%
    \immediate\write\bsf@sfrout{\string\bsfrestoresection{\the\c@section}%
        {\the\c@page}}%
    \section@orig
  }
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\subsection}
% And the new version of |\subsection| writes the |\bsfrestoresubsection| entry
% to the |.sfr| file. It also works like the new |\part| command.
%    \begin{macrocode}
  \def\subsection{%
    \immediate\write\bsf@sfrout{\string\bsfrestoresubsection{\the\c@subsection}%
        {\the\c@page}}%
    \subsection@orig
  }
\fi
%    \end{macrocode}
% \end{macro}
% 
% The |\bsfrestore...| entries are executed, when loading the |.sfr| file.
% Basically, they write the |\bsf@... pages| entries to the |.nav| file. But
% the first time, they just initialize some macros used as variables, because
% at this point only the first page of the first subframe of a part, section
% or subsection and the first page of the part, section or subsection itself
% are known.
% 
% \begin{macro}{\bsfrestorepart}
% On the first call, |\bsfrestorepart| stores the the first page of the new part
% (|#2|), the number of the previous part (|#1|), and the number of the first
% page of the first subframe belonging to the new part (|c@page|).
%    \begin{macrocode}
\def\bsfrestorepart#1#2{%
  \if@bsf@firstpart
    \@bsf@firstpartfalse
    \def\bsf@partstartpage{#2}%
    \def\bsf@prevpart{#1}%
    \edef\bsf@partfirstsubframepage{\the\c@page}%
  \else
%    \end{macrocode}
% On all subsequent calls, if there is a new part, the last page of the last
% subframe belonging to the previous part (in |\@tempcnta|) and the last page
% of the previous part (in |\@tempcntb|) are calculated. 
%    \begin{macrocode}
    \@tempcnta=\bsf@prevpart\relax
    \ifnum#1>\@tempcnta
      \@tempcnta\c@page\advance\@tempcnta -1\relax
      \@tempcntb=#2\relax\advance\@tempcntb -1\relax
%    \end{macrocode}
% Then the |\bsf@partpages| entry is written to the |.nav| file. Here
% |\addtocontents| can not be used, because it doesn't work, if |\bsfrestorepart|
% appears after the last subframe.
%    \begin{macrocode}
      \if@filesw
        \immediate\write\@auxout{\string\@writefile{nav}%
          {\noexpand\headcommand{%
            \noexpand\bsf@partpages{\bsf@partfirstsubframepage}%
              {\the\@tempcnta}{\bsf@partstartpage}{\the\@tempcntb}}}}%
      \fi
%    \end{macrocode}
% After that, the ``variables'' are reinitialized.
%    \begin{macrocode}
      \def\bsf@partstartpage{#2}%
      \def\bsf@prevpart{#1}%
      \edef\bsf@partfirstsubframepage{\the\c@page}%
    \fi
  \fi
}
%    \end{macrocode}
% Two of the ``variables'' must be initialized, in order to make the package
% work for presentations without sectioning commands.
%    \begin{macrocode}
\def\bsf@partstartpage{1}%
\def\bsf@prevpart{0}%
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\bsfrestoresection}
% The macros |\bsfrestoresection| and |\bsfrestoresubsection| work the same way
% as |\bsfrestorepart|. But additionally, they must keep track of sections
% without subsections. For this, the flags |\if@bsf@nosubsection| and
% |\if@bsf@prevnosubsection| and the macro |\bsf@prevsectionstartpage| are used.
%    \begin{macrocode}
\def\bsfrestoresection#1#2{%
  \if@bsf@firstsection
    \@bsf@firstsectionfalse
    \def\bsf@prevsectionstartpage{#2}%
    \@bsf@nosubsectiontrue
    \@bsf@prevnosubsectionfalse
    \def\bsf@sectionstartpage{#2}%
    \def\bsf@prevsection{#1}%
    \edef\bsf@sectionfirstsubframepage{\the\c@page}%
  \else
    \@tempcnta=\bsf@prevsection\relax
    \ifnum#1>\@tempcnta
%    \end{macrocode}
% When a new section starts, the start page and the |\if@bsf@nosubsection| flag
% of the previous section are stored.
%    \begin{macrocode}
      \edef\bsf@prevsectionstartpage{\bsf@sectionstartpage}%
      \if@bsf@nosubsection
        \@bsf@prevnosubsectiontrue
      \else
        \@bsf@prevnosubsectionfalse
      \fi
%    \end{macrocode}
% The flag |\if@bsf@nosubsection| is set to false, because the new section has
% no subsections yet.
%    \begin{macrocode}
      \@bsf@nosubsectiontrue
%    \end{macrocode}
% And the number of the previous subsection is set to $-1$, because the
% subsection counter will be reset to 0 on the start of each section.
%    \begin{macrocode}
      \def\bsf@prevsubsection{-1}%
      \@tempcnta\c@page\advance\@tempcnta -1\relax
      \@tempcntb=#2\relax\advance\@tempcntb -1\relax
      \if@filesw
        \immediate\write\@auxout{\string\@writefile{nav}%
          {\noexpand\headcommand{%
            \noexpand\bsf@sectionpages{\bsf@sectionfirstsubframepage}%
              {\the\@tempcnta}{\bsf@sectionstartpage}{\the\@tempcntb}}}}%
      \fi
      \def\bsf@sectionstartpage{#2}%
      \def\bsf@prevsection{#1}%
      \edef\bsf@sectionfirstsubframepage{\the\c@page}%
    \fi
  \fi
}
\def\bsf@sectionstartpage{1}%
\def\bsf@prevsection{0}%
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\bsfrestoresubsection}
% The macro |\bsfrestoresubsection| uses the flags |\if@bsf@nosubsection| and
% |\if@bsf@prevnosubsection| and the macro |\bsf@prevsectionstartpage| to set
% the correct range of pages.
%    \begin{macrocode}
\def\bsfrestoresubsection#1#2{%
  \if@bsf@firstsubsection
    \@bsf@firstsubsectionfalse
    \@bsf@prevnosubsectionfalse
    \def\bsf@subsectionstartpage{#2}%
    \def\bsf@prevsubsection{#1}%
    \edef\bsf@subsectionfirstsubframepage{\the\c@page}%
  \else
    \@tempcnta=\bsf@prevsubsection\relax
    \ifnum#1>\@tempcnta
      \@tempcnta\c@page\advance\@tempcnta -1\relax
%    \end{macrocode}
% Since the |\bsf@...pages| entries are written (indirectly) at the point of the
% next part, section or subsection, the entry for let's say subsection 1.3 would
% be written at the point of subsection 3.1, if section 2 has no subsections.
% So if the previous section had no subsection, its start page is used to
% calculate the last page of the last subsection instead of the start page of
% this subsection.
%    \begin{macrocode}
      \if@bsf@prevnosubsection
        \@tempcntb=\bsf@prevsectionstartpage\relax
      \else
        \@tempcntb=#2\relax
      \fi
      \advance\@tempcntb -1\relax
%    \end{macrocode}
% Because |\if@bsf@prevnosubsection| can only be used at the point of the first
% subsection of a new section, it is set to false.
%    \begin{macrocode}
      \@bsf@prevnosubsectionfalse
      \@bsf@nosubsectionfalse
      \if@filesw
        \immediate\write\@auxout{\string\@writefile{nav}%
          {\noexpand\headcommand{%
            \noexpand\bsf@subsectionpages{\bsf@subsectionfirstsubframepage}%
              {\the\@tempcnta}{\bsf@subsectionstartpage}{\the\@tempcntb}}}}%
      \fi
      \def\bsf@subsectionstartpage{#2}%
      \def\bsf@prevsubsection{#1}%
      \edef\bsf@subsectionfirstsubframepage{\the\c@page}%
    \fi
  \fi
}
\def\bsf@subsectionstartpage{1}%
\def\bsf@prevsubsection{0}%
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\bsf@partpages}
% The |\bsf@partpages| macro is similar to the |\beamer@partpages| macro (from
% \textsf{beamerbasenavigation.sty}). But to decide if the first and the last
% page of a part are stored in |\beamer@startpageofpart| and |\beamer@endpageofpart|,
% it uses the first page of the first subframe (|#1|) and the last page of the
% last subframe (|#2|) belonging to the part.
% 
% There may be parts with no subframes. In this case, |#1| is greater then |#2|
% and the first (|#3|) and last page (|#4|) of the part are not stored.
%    \begin{macrocode}
\def\bsf@partpages#1#2#3#4{%
  \ifnum\c@page<#1%
  \else%
    \ifnum\c@page>#2%
    \else%
      \gdef\beamer@startpageofpart{#3}%
      \gdef\beamer@endpageofpart{#4}%
    \fi%
  \fi%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\bsf@sectionpages}
% The macro |\bsf@sectionpages| works the same way as |\bsf@partpages|.
%    \begin{macrocode}
\def\bsf@sectionpages#1#2#3#4{%
  \ifnum\c@page<#1%
  \else%
    \ifnum\c@page>#2%
    \else%
      \gdef\beamer@startpageofsection{#3}%
      \gdef\beamer@endpageofsection{#4}%
    \fi%
  \fi%
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\bsf@subsectionpages}
% And |\bsf@sectionpages| works the same way as |\bsf@partpages| too.
%    \begin{macrocode}
\def\bsf@subsectionpages#1#2#3#4{%
  \ifnum\c@page<#1%
  \else%
    \ifnum\c@page>#2%
    \else%
      \gdef\beamer@startpageofsubsection{#3}%
      \gdef\beamer@endpageofsubsection{#4}%
    \fi%
  \fi%
}
%    \end{macrocode}
% \end{macro}
% 
% ^^A-------------------------
% \subsubsection{Inserts}
% Beamers |\inserttotalframenumber| is changed by simply writing its definition
% a second time to the |.nav| file, thus overwriting Beamers original definition.
% This is done at the end of the document (see \autoref{sec:code-beginend}).
% The necessary frame number is stored in |\bsf@totalframenumber| before
% appending the subframes (see \autoref{sec:code-appendsub}).
% \begin{macro}{\inserttotalframenumberwithsub}
% The new |\inserttotalframenumberwithsub| is written at the end of the documnet
% (see \autoref{sec:code-beginend}), regardless of the mode of \BSF, so it's
% always defined. But to work on the first \TeX\ run, it must be initialized.
%    \begin{macrocode}
\def\inserttotalframenumberwithsub{\inserttotalframenumber}
%    \end{macrocode}
% \end{macro}
%
% ^^A-------------------------
% \subsubsection{The \texttt{subframe} environment}
% \label{sec:code-subframe}
% \begin{environment}{subframe}
% The |subframe| environment is defined differently for the two modes. In append
% mode it is basically a verbatim environment, which writes its contents to the
% |.sfr| file. Here, the verbatim package is used.
% 
% Before writing the contents, it writes the |\bsfrestore| entry for the
% subframe. The latter contains the value of the |subsectionslide| counter as
% fourth argument, which has to be corrected, if miniframes for subframes should
% not appear. The counter needs to be incremented, if miniframes should appear
% for subframes.
%
% The |\bsfrestore| entry also has to restore the section and subsection heads.
% Since they might contain macros and not just the text itself,
% |\insertsectionhead| and |\insertsubsectionhead| can not be used directly.
% Their current meaning is stored in macros, which are later used to restore
% the heads.
%
% The first line of the |subframe| environment, which contains the arguments, is
% treated differently. It is preceded with |\begin{frame}|.
% 
% At the end of the environment, |\end{frame}| is written to the |.sfr| file.
% And the |\subslideentry| is written with |\beamer@writeslidentry@miniframes|,
% but only if miniframes should appear for subframes.
%    \begin{macrocode}
\if@bsf@append
  \newenvironment{subframe}{%
    \@tempcnta\c@subsectionslide
    \if@bsf@miniframes\else \advance\@tempcnta by -1\fi
    \expandafter\global\expandafter\let
      \csname bsf@sectionhead\the\c@part.\the\c@section
        \endcsname\insertsectionhead
    \expandafter\global\expandafter\let
      \csname bsf@subsectionhead\the\c@part.\the\c@section.\the\c@subsection
        \endcsname\insertsubsectionhead
    \immediate\write\bsf@sfrout{\string\bsfrestore{\the\c@part}{\the\c@section}%
        {\the\c@subsection}{\the\@tempcnta}}%
    \if@bsf@miniframes \addtocounter{subsectionslide}{1}\fi
    \@bsf@firstlinetrue
    \let\do\@makeother\dospecials\catcode`\^^M\active
    \def\verbatim@processline{%
      \if@bsf@firstline
        \immediate\write\bsf@sfrout{\string\begin{frame}\the\verbatim@line}%
        \@bsf@firstlinefalse
      \else
        \immediate\write\bsf@sfrout{\the\verbatim@line}%
      \fi
    }%
    \verbatim@}{\immediate\write\bsf@sfrout{\string\end{frame}^^J}%
    \if@bsf@miniframes \beamer@writeslidentry@miniframes \fi
  }
\else
%    \end{macrocode}
% In embed mode, the |subframe| environment is basically a |frame| environment.
% Before calling it, |\if@bsf@subframe| is set to true. And after the |frame|
% environment, |\if@bsf@subframe| is set to false again. This is needed for the
% |\ifsubframe| command.
% 
% The main problem here is adding |environment=subframe| to the options. For
% this, |\bsf@frame| is called with the name of the environment, the optional
% overlay specification (|#2|), and the first optional argument (|#1|).
%    \begin{macrocode}
  \newenvironment<>{subframe}[1][]{%
    \@bsf@subframetrue
    \bsf@frame{subframe}{#2}{#1}}{\end{frame}\@bsf@subframefalse}
\fi
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{\bsf@frame}
% The macro |\bsf@frame| initializes the token register |\bsf@frame@param|, sets
% a default for the second optional argument and then calls |\bsf@@frame|.
%    \begin{macrocode}
\def\bsf@frame#1#2#3{\bsf@frame@param={}%
  \@ifnextchar[{\bsf@@frame{#1}{#2}{#3}}{\bsf@@frame{#1}{#2}{#3}[]}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\bsf@@frame}
% The macro |\bsf@@frame| is called with the name of the new frame environment
% (|#1|), the overlay specification (|#2|), and the first (|#3|) and the second
% (|#4|) optional argument. It stores the arguments in|\bsf@frame@param|,
% thereby adding |environment=|\meta{name of the new frame environment} at the
% appropriate place.
%    \begin{macrocode}
\def\bsf@@frame#1#2#3[#4]{%
  \def\@tempa{#3}
%    \end{macrocode}
% If |#3| is empty, then there are no optional arguments, i.e.\ no default
% overlay specification and no options. In this case, |#4| is empty too.
%    \begin{macrocode}
  \ifx\@tempa\@empty
    \bsf@frame@param={#2[environment=#1]}%
  \else
    \def\@tempb{#4}
%    \end{macrocode}
% If only |#4| is empty, then there is one optional argument. This case is
% handled by |\bsf@@@frame|.
%    \begin{macrocode}
    \ifx\@tempb\@empty
      \bsf@@@frame{#1}{#2}#3\@@end
%    \end{macrocode}
% Otherwhise, both optional arguments are present.
%    \begin{macrocode}
    \else
      \bsf@frame@param={#2[#3][environment=#1,#4]}%
    \fi
  \fi
%    \end{macrocode}
% At the end, |\bsf@frame@| is called with the token register |\bsf@frame@param|
% already expanded.
%    \begin{macrocode}
  \expandafter\bsf@frame@\the\bsf@frame@param\@@end
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\bsf@@@frame}
% The macro |\bsf@@@frame| checks, if the only optional argument is a default
% overlay specification or the list of options. Here |#1| is the name of the new
% frame environment, |#2| is the overlay specification, |#3| is the first
% character of the optional argument and |#4| contains all subsequent characters.
% 
% If |#3| is `|<|', then the optional argument is a default overlay specification.
% Otherwhise, it is the list of options.
%    \begin{macrocode}
\def\bsf@@@frame#1#2#3#4\@@end{%
  \def\@tempa{#3}\def\@tempb{<}%
  \ifx\@tempa\@tempb\relax
    \bsf@frame@param={#2[#3#4][environment=#1]}%
  \else
    \bsf@frame@param={#2[environment=#1,#3#4]}%
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\bsf@frame@}
% The macro |\bsf@frame@| calls |\begin{frame}| with its argument, which
% contains the overlay specification and the default overlay specification if
% present, and the options, containing at least |environment=...|. This includes
% angle brackets and brackets.
%    \begin{macrocode}
\def\bsf@frame@#1\@@end{\begin{frame}#1}
%    \end{macrocode}
% \end{macro}
%
% ^^A-------------------------
% \subsubsection{The \texttt{lastframe} environment}
% \label{sec:code-lastframe}
% \begin{environment}{lastframe}
% The |lastframe| environment also uses |\bsf@frame| to add |environment=lastframe|
% to the options before calling the |frame| environment.
%
% Before that, it uses |\bsfrestore| to reset all sectioning counters. After
% this, the counters are in the same state, as they would be for a title frame
% before all sectioning commands. By this, navigation in the sidebar or headline
% will appear the same way as on the title page.
%    \begin{macrocode}
\newenvironment<>{lastframe}[1][]{%
  \bsfrestore{0}{0}{0}{0}%
  \bsf@frame{lastframe}{#2}{#1}}{\end{frame}}
%    \end{macrocode}
% \end{environment}
%
% ^^A-------------------------
% \subsubsection{Appending Subframes}
% \label{sec:code-appendsub}
% \begin{macro}{\appendsubframes}
% The macro |\appendsubframes| does nothing in embed mode. In append mode it
% first writes |\endinput| to the |.sfr| file and initializes some macros for
% navigation. The page number of the last frame of the main part is stored in
% |\bsf@pagebeforesub|, to be used after loading the |.sfr| file.
%    \begin{macrocode}
\newcommand{\appendsubframes}{%
  \if@bsf@append
    \immediate\write\bsf@sfrout{\string\endinput}%
    \edef\bsf@partfirstsubframepage{\the\c@page}%
    \edef\bsf@sectionfirstsubframepage{\the\c@page}%
    \edef\bsf@subsectionfirstsubframepage{\the\c@page}%
    \@tempcnta\c@page\advance\@tempcnta -1\relax
    \edef\bsf@pagebeforesub{\the\@tempcnta}%
%    \end{macrocode}
% For the navigation in the main part, the |\beamer@...pages| entries are
% written to the |.nav| file.
%    \begin{macrocode}
    \addtocontents{nav}{\protect\headcommand{%
        \protect\beamer@partpages{\the\beamer@partstartpage}{\bsf@pagebeforesub}}}%
    \addtocontents{nav}{\protect\headcommand{%
        \protect\beamer@subsectionpages{\the\beamer@subsectionstartpage}{\bsf@pagebeforesub}}}%
    \addtocontents{nav}{\protect\headcommand{%
        \protect\beamer@sectionpages{\the\beamer@sectionstartpage}{\bsf@pagebeforesub}}}%
    \addtocontents{nav}{\protect\headcommand{%
        \protect\beamer@documentpages{\bsf@pagebeforesub}}}%
%    \end{macrocode}
% The number of the last frame of the main part is stored in |\bsf@totalframenumber|.
% And |\beamer@writeslidentry| is replaced by |\beamer@writeslidentry@navbar|.
%    \begin{macrocode}
    \edef\bsf@totalframenumber{\the\c@framenumber}%
    \let\beamer@writeslidentry\beamer@writeslidentry@navbar
%    \end{macrocode}
% Before loading the |.sfr| file, it is closed and the flags for the navigation
% bar are initialized. The flag for |\ifsubframe| is set to true, because from
% now on there are only subframes.
%    \begin{macrocode}
    \immediate\closeout\bsf@sfrout
    \@bsf@firstparttrue
    \@bsf@firstsectiontrue
    \@bsf@firstsubsectiontrue
    \@bsf@subframetrue
    \input{\jobname.sfr}
%    \end{macrocode}
% After all subframes are typeset, the final |\bsf@...pages| entries are written
% to the |.nav| file.
%    \begin{macrocode}
    \@tempcnta\c@page\advance\@tempcnta -1\relax
    \if@filesw
      \immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\bsf@partpages{\bsf@partfirstsubframepage}%
          {\the\@tempcnta}{\bsf@partstartpage}{\bsf@pagebeforesub}}}}%
      \immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\bsf@sectionpages{\bsf@sectionfirstsubframepage}%
          {\the\@tempcnta}{\bsf@sectionstartpage}{\bsf@pagebeforesub}}}}%
      \immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\bsf@subsectionpages{\bsf@subsectionfirstsubframepage}%
          {\the\@tempcnta}{\bsf@subsectionstartpage}{\bsf@pagebeforesub}}}}%
      \immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\bsf@documentpages{\the\@tempcnta}}}}%
%    \end{macrocode}
% Finally, the command to disable the remaining |\beamer@...pages| entries is
% written to the |.nav| file.
%    \begin{macrocode}
      \immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\bsf@disablenaventries}}}%
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% ^^A-------------------------
% \subsubsection{At Begin and End of the Document}
% \label{sec:code-beginend}
% At the beginning of the document, first the |.sfp| file is loaded. The |.sfr|
% file is only opened in append mode.
%    \begin{macrocode}
\AtBeginDocument{%
  \InputIfFileExists{\jobname.sfp}{}{}%
  \if@bsf@append
    \immediate\openout\bsf@sfrout\jobname.sfr\relax
%    \end{macrocode}
% To reenable the |\beamer@...pages| entries after the first page, the command
% |\bsf@enablenaventries| is written as the first entry to the |.nav| file.
%    \begin{macrocode}
    \if@filesw
      \immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\bsf@enablenaventries}}}%
    \fi
  \fi
}
%    \end{macrocode}
%
% At the end of the document in append mode first the |.sfp| file is checked.
% After that |\bsf@totalframenumber| is initialized if necessary, i.e.\ if
% |\appendsubframes| was omitted in the source.
%    \begin{macrocode}
\AtEndDocument{%
  \if@bsf@append
    \bsf@checksfp
    \@ifundefined{bsf@totalframenumber}{%
      \edef\bsf@totalframenumber{\the\c@framenumber}}{}%
    \if@filesw
%    \end{macrocode}
% The definition for |\inserttotalframenumber| is written to the |.nav| file a
% second time, thus overwriting the first definition written by Beamer. Here it
% contains the number of frames of the main part.
%    \begin{macrocode}
      \immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{%
          \noexpand\def\noexpand\inserttotalframenumber{\bsf@totalframenumber}}}}
%    \end{macrocode}
% A stream for the for the |.sfp| file is defined and the file is opened, so
% \LaTeX\ can write it, when loading the |.aux| file at the end of the document.
%    \begin{macrocode}
      \newwrite\tf@sfp
      \immediate\openout\tf@sfp\jobname.sfp\relax
    \fi
  \fi
%    \end{macrocode}
% Regardless of the mode, the definition of |\inserttotalframenumberwithsub| is
% written to the |.nav| file, so it can be used in themes in both modes.
%    \begin{macrocode}
  \if@filesw
    \immediate\write\@auxout{\string\@writefile{nav}%
      {\noexpand\headcommand{%
        \noexpand\def\noexpand\inserttotalframenumberwithsub{\the\c@framenumber}}}}
  \fi
}
%    \end{macrocode}
%
% ^^A-------------------------
% \subsubsection{Contitional Execution}
% \begin{macro}{\ifappend}
% The macro |\ifappend| simply expands to its first argument in append mode and
% to its second in embed mode.
%    \begin{macrocode}
\newcommand{\ifappend}[2]{\if@bsf@append #1\else #2\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifsubframe}
% The macro |\ifsubframes| simply expands to its first argument in subframes and
% to its second in normal frames.
%    \begin{macrocode}
\newcommand{\ifsubframe}[2]{\if@bsf@subframe #1\else #2\fi}
%    \end{macrocode}
% \end{macro}
%
% \newpage
% \Finale\endinput
%</package>
% ^^A--------------------------------------------------------------------------
% ^^A Now the source of the example
%<*example>
\documentclass{beamer}
\usepackage{lmodern}
\usepackage[T1]{fontenc}

\usepackage[append]{beamersubframe}

\newcommand<>{\linkdetail}[4]{%
    \ifappend{\uncover#5{\hyperlink{#3}{\beamergotobutton{#4}}}}%
             {\uncover#5{\hyperlink{#1}{\beamerskipbutton{#2}}}}
}
\newcommand<>{\returndetail}[2]{%
\ifappend{\uncover#3{\hyperlink{#1}{\beamerreturnbutton{#2}}}}%
         {\visible<0>{\beamerreturnbutton{#2}}}
}
\newcommand<>{\linkdifftext}[3]{%
    \ifappend{\uncover#4{\hyperlink{#1}{\beamergotobutton{#3}}}}%
             {\uncover#4{\hyperlink{#1}{\beamerskipbutton{#2}}}}
}

\defbeamertemplate*{sidebar left}{bsf test}[1][50]
{
  \vfill%
  \rlap{\hskip0.1cm\hbox{\color{fg!#1!bg}\tiny{\ifsubframe{detail}{main part}}}}%
  \vskip2pt%
}

\begin{document}
\begin{frame}{some frame}
\begin{itemize}[<+->]
\item there is foo
\item foo is good
\item and there is bar
\item bar is good too
\end{itemize}
\end{frame}

\begin{frame}<1-2>[label=lfoo]{frame on foo}
\begin{itemize}[<+->]
\item item a
\item item b \linkdetail<2>{lfoo<3>}{Skip Details}{ldfoob}{Goto Details}
\item item c
\item item d
\end{itemize}
\end{frame}

\begin{subframe}[label=ldfoob]{details on foo item b}
\begin{itemize}[<+->]
\item item b.1
\item item b.2
\item item b.3
\item item b.4
\end{itemize}
\end{subframe}

\begin{subframe}
\frametitle{more details on foo item b}
\begin{itemize}[<+->]
\item item b.5
\item item b.6
\item item b.7
\item item b.8
\end{itemize}

\vspace{2ex}
\returndetail<4>{lfoo<3>}{Return from Details}
\end{subframe}

\againframe<3->{lfoo}

\begin{frame}{frame on bar}
\begin{itemize}[<+->]
\item item w
\item item x
\item item y
\item item z \linkdetail<4>{lother}{Skip Details}{ldbarz}{Goto Details}
\end{itemize}
\end{frame}

\begin{subframe}[label=ldbarz]
\frametitle{details on bar item z}
\begin{itemize}[<+->]
\item item z.1
\item item z.2
\item item z.3
\item item z.4
\end{itemize}

\vspace{2ex}
\linkdifftext<4>{lother}{Skip further Details}{Return from Details}
\end{subframe}

\begin{subframe}{more details on bar item z}
\begin{itemize}[<+->]
\item item z.5
\item item z.6
\item item z.7
\item item z.8
\end{itemize}

\vspace{2ex}
\returndetail<4>{lother}{Return from Details}
\end{subframe}

\begin{frame}[label=lother]{another frame}
\begin{itemize}[<+->]
\item conclusion 1
\item conclusion 2
\item conclusion 3
\item conclusion 4
\end{itemize}
\end{frame}

\appendsubframes
\end{document}
%</example>