1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
|
% \iffalse
% makeindex -s gglo.ist -o insdljs.gls insdljs.glo
% makeindex -s gind.ist -o insdljs.ind insdljs.idx
%<*copyright>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% insdljs.sty package, %%
%% Copyright (C) 2001-2021 D. P. Story %%
%% dpstory@uakron.edu %%
%% %%
%% This program can redistributed and/or modified under %%
%% the terms of the LaTeX Project Public License %%
%% Distributed from CTAN archives in directory %%
%% macros/latex/base/lppl.txt; either version 1 of the %%
%% License, or (at your option) any later version. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%</copyright>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{insdljs}
%<package> [2021/06/19 v2.5.5 Insert Document Level JavaScripts (dps)]
%<*driver>
\documentclass{ltxdoc}
\usepackage[colorlinks,hyperindex=false]{hyperref}
\usepackage{fancyvrb}
\makeatletter
\let\@latex@warning@no@line\@gobble
\renewcommand{\paragraph}{\@startsection{paragraph}{4}{0pt}{6pt}{-3pt}{\bfseries}}
\makeatother
\usepackage{makeidx}
\makeindex
\def\EXPT{!}
\pdfstringdefDisableCommands{\let\\\textbackslash}%
% \OnlyDescription % comment out for implementation details
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\gdef\darg#1{\texttt{\char123\relax#1\char125\relax}}
\let\env\texttt
\let\opt\texttt
\let\app\textsf
\let\pkg\textsf
\let\uif\textsf
\def\visispace{\symbol{32}}
\def\ameta#1{\ensuremath{\langle\textit{\texttt{#1}}\rangle}}
\def\meta#1{\textsl{\texttt{#1}}}
\def\SUB#1{\ensuremath{{}_{\mbox{\scriptsize\ttfamily#1}}}}
\InputIfFileExists{aebdocfmt.def}{\PackageInfo{insdljs}{Inputting aebdocfmt.def}}
{\def\IndexOpt{\DescribeMacro}\def\IndexKey{\DescribeMacro}\let\setupFullwidth\relax
\PackageInfo{insdljs}{aebdocfmt.def cannot be found}}
\begin{document}
\GetFileInfo{insdljs.sty}
\title{The \texttt{insDLJS} Package}
\author{D. P. Story\\
Email: \texttt{dpstory@uakron.edu}}
\date{processed \today}
\maketitle
\tableofcontents
\let\Email\texttt
\let\pkg\textsf
\DocInput{insdljs.dtx}
\IfFileExists{\jobname.ind}{\newpage\setupFullwidth\PrintIndex}{\paragraph*{Index} The index goes here.\\Execute
\texttt{makeindex -s gind.ist -o insdljs.ind insdljs.idx} on the command line and recompile
\texttt{insdljs.dtx}.}
\IfFileExists{\jobname.gls}{\PrintChanges}{\paragraph*{Change History} The list of changes goes here.\\Execute
\texttt{makeindex -s gglo.ist -o insdljs.gls insdljs.glo} on the command line and recompile
\texttt{insdljs.dtx}.}
\end{document}
%</driver>
% \fi
%
% \InputIfFileExists{aebdonotindex.def}{\PackageInfo{insdljs}{Inputting aebdonotindex.def}}
% {\PackageInfo{insdljs}{aebdonotindex.def cannot be found}}
%
% \section{Introduction}
% This package defines a new environment, \texttt{insDLJS}, used
% for inserting Acrobat JavaScript into a PDF file created from a
% \LaTeX{} source. This package works correctly for users of
% \textsf{pdftex} or \textsf{dvipdfm}. For those that use the
% \textsf{Acrobat Distiller} (specifically, those that use either
% \textsf{dvips} or \textsf{dvipsone} to produce a postscript file,
% which is then distilled), you are required to have Acrobat~5.0 (or
% later).
% \changes{v2.5.1}{2021/02/04}{Updated \string\texttt{aeb\_man.tex} and
% \string\texttt{eformman.tex} to reflect additional security restriction
% on \string\app{Acrobat}.}
%
% \section{Features of the \textsf{insdljs} package}
% We present a few of the several features of the package to get some feel for its
% purpose.
%
% \subsection{The \texttt{insDLJS} Environment}
%
% The following is a quick illustration of the use of the new environment.
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={!~@},codes={\catcode`\%=9}]
%\documentclass{article}
%\usepackage{hyperref}
%\usepackage{insdljs}
%\newcommand\tugHello{Welcome to TUG 2001!}
%\begin{insDLJS}[HelloWorld]{mydljs}{My Private DLJS}
%function HelloWorld(){app.alert("\tugHello", 3);}
%\end{insDLJS}
%\begin{document}
%\begin{Form} !%!textsf~ needed for !cs~PushButton@@
%
%\section{Test of the \textsf{insDLJS} Package}
%
%!%!textsf~ use the built-in form button of hyperref@
%Push \PushButton[name=myButton,onclick={HelloWorld();}]{Button}
%
%\end{Form}
%\end{document}
%\end{Verbatim}
% This environment takes three parameters, the first of which is required
% for users of \texttt{dvips} and \texttt{dvipsone} and optional otherwise.
% Within the environment, `|\|', is the escape character, and `|%|' is the comment
% character, as they are in \TeX{} and \LaTeX.
% See the documentation preceding the definition of the
% \texttt{\hyperlink{insDLJS}{insDLJS}} environment.
%
% \subsection{Debugging}
%
% Another feature of this package is the ability to place debugging markers
% within the JavaScript. When the \texttt{debug} option is used, the markers
% show up in the document level JavaScript; otherwise, they are not written
% to the PDF document. Here is a simple example,
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={*~@},codes={\def\1{\quad}\catcode`\%=9}]
%\begin{insDLJS}{mydljs}{My Private DLJS}
%function HelloWorld() {
%*1app.alert("\tugHello", 3);
%*1var x = "\\";
%\db console.println("Entered HelloWorld function and x = " + x);\db!%
%}
%\end{insDLJS}
%\end{Verbatim}
% The last line of the function will appear in the DLJS if compiled under
% the \texttt{debug} option; otherwise, it is removed. Additional discussion
% of this debugging device is given below.
%
% \subsection{Open Action}
%
% This package also defines an \cs{OpenAction} command to introduce actions that are
% executed when the PDF document is opened on page~1. The open action command only
% applies to page~1.
%\paragraph*{Usage}
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%codes={\catcode`\%=9}]
%\OpenAction{/S/JavaScript/JS(app.alert("Hello World!");)}
%\end{Verbatim}
% The package defines a \cs{JS} command that takes one argument. The code |\JS{#1}| expands to
% |/S/JavaScript/JS (#1)|, and so the above example may be written as,
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%codes={\catcode`\%=9}]
%\OpenAction{\JS{app.alert("Hello World!");}}
%\end{Verbatim}%
% Multiple JavaScript commands can be entered. For nice formatting use \cs{r}
% and \cs{t} for carriage return and tab, respectively.
%\goodbreak
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={*~@},codes={\def\1{\quad}\catcode`\%=9}]
%\OpenAction{\JS{*%
%*1app.alert("Hello World!");\r
%*1app.alert("Good Day to You!");
%}}
%\end{Verbatim}
% The open actions are placed in a token list. Additional actions are added to the token list, so
% you say
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={*~@},codes={\def\1{\quad}\catcode`\%=9}]
%\OpenAction{\JS{app.alert("Hello World!");}}
%\OpenAction{\JS{app.alert("Good Day to You!");}}
%\end{Verbatim}
% the two messages will appear each time you open page~1 of the document.
%
% In the case of users of the distiller, \textsf{insdljs} uses this mechanism to
% define an open action. To avoid overwriting this definition, the \cs{OpenAction}
% command is necessary in insert additional actions.
%
% See \Nameref{openaction} for more details.
%
% \subsection{How \textsf{insdljs} Works}
%
% Let me describe in rough terms what goes on behind the scenes. In the discussion
% below, the following example will be used:
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={*~@},codes={\def\1{\quad}\catcode`\%=9}]
%\newcommand\tugHello{"Hello World!"}
%\begin{insDLJS}{mydljs}{My Private DLJS}
%function HelloWorld(){
%*1app.alert("\tugHello", 3);
%}
%\end{insDLJS}
%\end{Verbatim}
%
% \subsubsection{For the \texttt{pdftex} and \texttt{dvipdfm} Options}
%
% Both \texttt{pdftex} and \texttt{dvipdfm} have primitives/macros for inserting
% JavaScript at the document level into the PDF document. The work of the package,
% in this case, is to take the JavaScript and place it into the correct form
% for the application (\textsf{pdftex} or \textsf{dvipdfm}).
%
% Material within the \texttt{insDLJS} environment is written verbatim to a file.
% The name of this file is \texttt{mydljs.djs}. The file base name comes from the
% first required parameter of the \texttt{insDLJS} environment, see example above.
% The file extension \texttt{.djs} stands for ``define javascript''.
%
% At begin document, the file \texttt{mydljs.djs} is input back into the document after
% special definitions have already been read. These special definitions are the content
% of the file \texttt{dljscc.def}. The script is placed in the appropriate construct
% for insertion by the application at the document level.
%
% For more information about \texttt{dljscc.def}, see documentation given in the Section~\ref*{dljscc},
% \Nameref{dljscc}.
%
% \subsubsection{For the \texttt{dvipsone} and \texttt{dvips} Options}
%
% When you use the \texttt{dvipsone} or \texttt{dvips}, this means you are going to convert
% your document to postscript and distill it to create a PDF document. There is no \texttt{pdfmark}
% construct for inserting document level JavaScripts; however, the recent release of Acrobat~5.0
% gives postscript users an avenue for inserting DLJS.
%
% The material within the \texttt{insDLJS} environment is written verbatim to the file
% \texttt{mydljs.djs}, as above. It is input back into the document where macros are allowed
% to expand, then written back out to another file. The name of this new file is \texttt{mydljs.fdf}.
% The file base name comes from the first required parameter of the \texttt{insDLJS} environment.
% The file extension \texttt{.fdf} stands for ``forms data format''. This is an extension defined
% and recognized by the Acrobat line of products.
%
% The file \texttt{mydljs.fdf} contains the document level JavaScript in a form that
% the Acrobat application (version~5.0 or later) can import. Part of the work of the package
% is to define an open page action. When the PDF document is opened for the first time in
% Acrobat, the JavaScript is imported. Usually, you open the document following distillation.
% After the \texttt{.fdf} file(s) have been imported, you need to save the document, usually using
% the ``SaveAs'' file option, this saves the JavaScript code with the file. (There is no need for the
% \texttt{.fdf} file(s) at this point.)
%
% \subsection{Comments on JavaScript}
% A few words on JavaScript.
%
% \subsubsection{What is Document Level JavaScript?}
% The document level is a location in the PDF document where script can be stored.
% When the PDF document is opened, the document level functions are scanned, and any
% ``exposed script'' is executed.
%
% Normally, the type of scripts you would place at the document level are
% general purpose JavaScript functions, functions that are called repeatedly or large special
% purpose functions. Functions at the document level
% are known throughout the document, so they can be called by links, form buttons, page open
% actions, etc.
%
% Variables declared within a JavaScript function have local scope, they are not known outside
% that function. However, if you can declare variables and initialize them at the document level outside
% of a function, these variables will have document wide scope. Throughout the document, the values of these
% global variables are known. For example
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={*~@},codes={\def\1{\quad}\catcode`\%=9}]
%\begin{insDLJS}{mydljs}{My Private DLJS}
%var myVar = 17; //*textsf~ defined outside a function, global scope@
%function HelloWorld(){
%*1var x = 3; //*textsf~ defined inside a function, local scope@
%*1app.alert("\tugHello", 3);
%}
%\end{insDLJS}
%\end{Verbatim}
% Both the function \texttt{HelloWorld()} and the variable \texttt{myVar} are known throughout
% the document. The function \texttt{HelloWorld()} can be called by a mouse up button action;
% some form field, executing some JavaScript, may access the value of \texttt{myVar} and/or
% change its value. The variable \texttt{x} is not known outside of the \texttt{HelloWorld()} function.
%
% \subsubsection{Access and Debugging}
% For those who do not have \textsf{Acrobat}, the application,
% unless you are writing very simple code, writing and debugging
% JavaScript will be very difficult. From the Acrobat Reader,
% there is not access to the document level JavaScript. You will be
% pretty much writing blind. You can use the debug feature of
% \textsf{insdljs} and insert some debugging code to try to give you
% some insight into what is going wrong. Even so, debugging will be a problem.
%
% Normally, I develop the JavaScript from within Acrobat. The GUI editor does check for
% syntax errors, giving you a chance to correct some simple errors as you go. After I am satisfied
% with my code, I copy it from the editor and paste it into a \texttt{insDLJS} environemnt. This is
% how the JavaScript code of \textsf{exerquiz} was developed.
%
% In my opinion, if you want to develop rather complicated code, having the full Acrobat product
% is a must. (This implies that the Windows or Mac platform is needed!)
%
% \subsubsection{JavaScript References}
% The JavaScript used by Acrobat consists of the core JavaScript plus Acrobat's JavaScript extensions.
% Acrobat~5.0 uses core JavaScript~1.5, see
%\begin{quote}
% \footnotesize\url{https://developer.mozilla.org/en/JavaScript}
%\end{quote}
% and documentation of the Acrobat extensions can be found in the ``JavaScript for Acrobat API Reference,''
% see
%\begin{quote}
%\href{http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat9_HTMLHelp&file=JS_API_AcroJSPreface.87.1.html}
%{JavaScript for Acrobat API Reference}
%\end{quote}
%
% \subsection{The \textsf{execJS} Environment}
% This is an environment useful to PDF developers who want to tap into the power of JavaScript.
% To use this environment, the developer needs Acrobat~5.0 or higher, or Acrobat Approval~5.0
% or higher. \textsf{pdftex} or \textsf{dvipdfm} can be used to produce the PDF document, but one of the
% applications (not the Reader) listed above is needed for this environment to do anything.
%
% The \texttt{execJS} is used primarily for post-distillation processing (post-creation processing, in the case of
% \textsf{pdftex} and \textsf{dvipdfm}). The \texttt{execJS} environment can be used, for example, to automatically import
% named icons into the document, which can, in turn, be used for an animation.
%
% The \textsf{execJS} is an environment in which you can write verbatim JavaScript code. This environment
% is a variation on \textsf{insdljs}, it writes a couple of auxiliary files to disk; in particular, the
% environment creates an \texttt{.fdf} file. When the newly produced PDF is loaded for the first time
% into the viewer (Acrobat or Approval, not Reader), the \texttt{.fdf} file generated by the \textsf{execJS}
% environment is imported, and the JavaScript executed. This JavaScript is \emph{not} saved with
% the document.
%
% The environment takes one required argument, the base name of the auxiliary files to be generated.
%
%
% For more details on this environment, see
% \Nameref{execJS}. Also, see the demo file \texttt{execjstst.tex} and \texttt{execjstst.pdf} for
% a short tutorial on the \texttt{execJS} environment, and an animation example, built entirely from
% {\LaTeX} commands.
%
% \paragraph*{Security Note:} Executing arbitrary
%JavaScript through a menu is potentially a security hole. If a
%malicious hacker knows that you have a menu item with the name of
%\texttt{MenuProc}, and that you use the variable
%\texttt{\_MenuProc} in the way described above, the hacker could
%distribute a PDF that executes (security restricted) JavaScript
%through the menu in this way. Therefore, you should select
%\texttt{private names} for \texttt{MenuProc} and \texttt{\_MenuProc}.
%
% \subsection{The \textsf{defineJS} Environment}
%
%When you create a form element (button, text field, etc.), you sometimes want to attach
%JavaScript. The \textsf{defineJS} environment aids you in writing your Field level JavaScript.
%It too is a verbatim environment, however, this environment does not write to this, but
%saves the contents in a token register. The contents of the register are used in defining
%a macro that expands to the verbatim listing.
%
% The \textsf{defineJS} environment takes two parameters, the first optional.
% the required parameter is the cmd name of the command you want to define.
% You can use the optional first parameter to modify the verbatim environment,
% as illustrated. The \textsf{defineJS} is a complete verbatim environment: no escape,
% and no comment characters are defined. You can use the optional parameter to create
% an escape character. You can pretty much use any character you wish, \emph{except}
% the usual one `\verb+\+', backslash.
%
% The following environment, defines a command \cs{myCmd} what expands to the verbatim
% contents of the environment.
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={!()},codes={\catcode`\%=9}]
%\begin{defineJS}{\myCmd}
%...
%!ameta(JavaScript code)
%...
%\end{defineJS}
%\end{Verbatim}
%
% There is also a \textsf{localJS} environment that makes any definitions within the
% environment local.
%
%The following examples uses some macros from the \textsf{eforms} package:
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={*~$},codes={\def\1{\quad}\catcode`\%=9}]
%*%*uif~ Define a text macro that will be expanded from within$
%*%*uif~ the *env~defineJS$ environment$
%\def\HelloWorld{Hello World}
%*%*uif~ Now define some JavaScript to execute with a button to be created.$
%*%*uif~ We enclose the *env~defineJS$ and the *cs~pushButton$ in the *env~localJS$ environment$
%*%*uif~ That way, the macro definitions, *cs~JSA$, *cs~JSAAE$, *cs~JSAAX$ will be local to$
%*%*uif~ this group$
%\begin{localJS}
%*%*uif~ Make @ the escape so we can demonstrate the optional parameter.$
%\begin{defineJS}[\makeesc\@]{\JSA}
%var sum = 0;
%for (var i = 0; i < 10; i++)
%{
%*1sum += i;
%*1console.println("@HelloWorld i = " + i );
%}
%console.println("sum = "+sum);
%\end{defineJS}
%\begin{defineJS}{\JSAAE}
%console.println("Enter the button area");
%\end{defineJS}
%\begin{defineJS}{\JSAAX}
%console.println("Exiting the button area");
%\end{defineJS}
%\pushButton[*%
%*1\A{\JS{\JSA}}
%*1\AA{\AAMouseEnter{\JS{\JSAAE}}
%*1*1 \AAMouseExit{\JS{\JSAAX}}
%*1}
%]{myButton}{30bp}{15bp}
%\end{localJS}
%\end{Verbatim}
%
% See the section \Nameref{defineJS} for details of these two environments.
% \section{Package Options and Requirements}
%
% \subsection{Package Options}
%
% The options are \texttt{dvipsone}, \texttt{dvips}, \texttt{pdftex} and
% \texttt{dvipdfm}. The default is \texttt{dvipsone}/\texttt{dvips}.
% \changes{v2.3g}{2017/09/03}{Added ifluatex package}
% \begin{macrocode}
%<*package>
\usepackage{xkeyval}
\RequirePackage{ifpdf}[2006/02/20]
\RequirePackage{ifxetex}[2006/08/21]
\RequirePackage{ifluatex}
% \end{macrocode}
%
% Standard driver options.\par\medskip\noindent
% \textbf{Those using Distiller}
% \IndexOpt{dvips}
% \IndexOpt{dvipsone}
% \IndexOpt{textures}
% \begin{macrocode}
\DeclareOptionX{dvipsone}{\def\dljs@drivernum{0}%
\AtBeginDocument{\dvips@marker}}
\DeclareOptionX{dvips}{\def\dljs@drivernum{0}%
\AtBeginDocument{\dvips@marker}}
\DeclareOptionX{textures}{\def\dljs@drivernum{0}%
\AtBeginDocument{\dvips@marker}}
% \end{macrocode}
%\textbf{Those not using Distiller}
% \IndexOpt{pdftex}
% \IndexOpt{luatex}
% \IndexOpt{dvipdfm}
% \IndexOpt{dvipdfmx}
% \IndexOpt{xetex}
% \changes{v2.3g}{2017/09/03}{Added luatex option}
% \begin{macrocode}
\DeclareOptionX{pdftex}{\def\dljs@drivernum{1}}
\DeclareOptionX{luatex}{\def\dljs@drivernum{1}}
\DeclareOptionX{dvipdfm}{\def\dljs@drivernum{2}}
\DeclareOptionX{dvipdfmx}{\def\dljs@drivernum{2}}
\DeclareOptionX{xetex}{\def\dljs@drivernum{2}}
% \end{macrocode}
% Set the default value of the driver: assume the distiller is used.
% \begin{macrocode}
%\def\dljs@drivernum{0}
% \end{macrocode}
% Some switch definitions
% \begin{macrocode}
\let\dl@YES=y \let\dl@NO=n
\let\dl@One=1 \let\dl@Zero=0
\let\dljs@YES=y \let\dljs@NO=n
\edef\dl@restoreCats{%
\catcode`\noexpand\"=\the\catcode`\"\relax
\catcode`\noexpand\'=\the\catcode`\'\relax
\catcode`\noexpand\,=\the\catcode`\,\relax
\catcode`\noexpand\(=\the\catcode`\(\relax
\catcode`\noexpand\!=\the\catcode`\!\relax
\catcode`\noexpand\_=\the\catcode`\_\relax
}
\@makeother\"\@makeother\'\@makeother\,%
\@makeother\(\@makeother\!\@makeother\_
% \end{macrocode}
% \leavevmode\DescribeMacro{\dlpkgInfo} A command to identify package date
% from within document level Javascript
%\changes{v2.4.7}{2019/10/23}{Added \string\cs{dlkgInfo} to identify version}
% \begin{macrocode}
\def\dlpkgInfo{\@nameuse{ver@\@currname.\@currext}}
\def\dlSetPkgInfo{%
\edef\dlpkgInfoExpd{\dlpkgInfo}%
\expandafter\dlparsePkgInfo\dlpkgInfoExpd\@nil}
\def\dlparsePkgInfo#1 #2 #3:#4\@nil{%
\def\dlPkgInfoDate{#1}%
\def\dlPkgInfoVer{#2}%
\def\dlPkgInfoPkg{#3}%
\def\dlPkgInfoDesc{#4}}
% \end{macrocode}
% When using pdfmarks, the open action is initiated by the document JavaScript code,
% when there was not document JavaScript, the open action did not get executed.
% This was a bad idea, here is a work around. When the \texttt{insDLJS} environment is used,
% we |\let\dljspresent=y|, and if at the beginning of the document, \cs{dljspresent} is still
% \texttt{n}, we'll issue a special execution of \cs{@OAction}.
% \begin{macrocode}
\def\dvips@marker{\ifx\dljspresent\dl@NO\@OAction\fi}
% \end{macrocode}
% This command sequence will mark the passing of the first open event that is defined. The rest of the open events,
% if any, will be in a \texttt{Next} dictionary.
% \begin{macrocode}
\let\isOpenAction\dl@NO
% \end{macrocode}
% \leavevmode\IndexOpt{nodljs}^^A
% Option to cancel the insertion of DLJS, useful for a document meant to be
% printed only, or one that does not use the \texttt{shortquiz} or
% \texttt{quiz} environments, for example.
% \begin{macrocode}
\DeclareOptionX{nodljs}{\let\importdljs\dl@NO}
\let\importdljs\dl@YES
% \end{macrocode}
% Need to place certain code only once. This switch will make sure of that.
% \begin{macrocode}
\let\firstdljs\dl@YES
\let\dljspresent\dl@NO
% \end{macrocode}
% \leavevmode\IndexOpt{debug}^^A
% Use this option to help debug DLJS.
% \begin{macrocode}
\DeclareOptionX{debug}{\let\dljs@debug\dl@YES}
\let\dljs@debug\dl@NO
% \end{macrocode}
% If the option \IndexOpt{execJS}\opt{execJS} is taken, then the JavaScript code for any \env{execJS} environment
% will be executed following PDF creation (\app{Acrobat} required). The default is no.
% More recently (2019/08/06) \DescribeMacro\execJSOn\cs{execJSOn} and \DescribeMacro\execJSOff\cs{execJSOff}
% were added to turn on (or off) execution of JS in this way. Useful when \pkg{insdljs} is loaded by other
% packages and you cannot access the optional arguments of \cs{usepackage}. These commands are only effective
% in the preamble.
% \changes{v2.4.6}{2019/08/06}{Added \string\cs{execJSOn} and \string\cs{execJSOff}}
% \begin{macrocode}
\DeclareOptionX{execJS}{\execJSOn}
\def\execJSOn{\let\execjs\dl@YES}
\def\execJSOff{\let\execjs\dl@NO}
\execJSOff
\DeclareOptionX{nopro}{\let\dl@gopro\dl@NO}
\let\dl@gopro\dl@YES
% \end{macrocode}
% We set the driver, according to the following algorithm.
% \begin{macrocode}
\@ifpackageloaded{web}{%
\ExecuteOptionsX{\eq@driver@name}%
}{%
\@ifpackageloaded{eforms}{%
\ExecuteOptionsX{\ef@driver}%
}{%
\ifpdf\ExecuteOptionsX{pdftex}\else
\ifxetex\ExecuteOptionsX{xetex}\else
\@ifundefined{l@tex@@@@driver}{\ExecuteOptionsX{dvips}}
{\ExecuteOptionsX{dvipsone}}\fi\fi
}%
}
% \end{macrocode}
% \leavevmode\IndexOpt{reqjs}^^A
% Beginning with PDF 1.7, a document can specify requirements, here we declare
% the document uses JavaScripts. The option \texttt{reqjs} is taken by default,
% that is, JavaScripts are required for this document
% \medskip\par\noindent
% \DescribeMacro{!reqjs}^^A
% The option \texttt{!reqis} turns off this feature; that is, there is no notification
% via the \textsf{YMB} (\textsf{Yellow Message Bar}) that Javascripts are used in the document, and the
% document may not function as designed.
% \changes{v2.2d}{2016/04/06}{Added \string\texttt{reqjs} and \string\texttt{{\string\EXPT}reqjs} options.}
% \begin{macrocode}
\DeclareOptionX{reqjs}{\let\dl@reqJS\dl@YES}
\let\dljs@reqJS\dl@YES
\DeclareOptionX{!reqjs}{\let\dl@reqJS\dl@NO}
% \end{macrocode}
% The \texttt{usealtadobe} option\IndexOpt{usealtadobe} defined alternate names
% for some of Adobe's formatting functions. This is useful only if the document
% author has the Adobe application and know how to use its form edit capabilities.
% The name of each of the selected function begins with `\texttt{AF}', the name of the new
% function is the same, but begins with `\texttt{EF}'. For example, the keystroke function
% \texttt{AFNumber\_Keystroke} is also known under the name of \texttt{EFNumber\_Keystroke}.
% See \hyperref[s:AltAdbFncs]{Section~\ref*{s:AltAdbFncs}} for the list of functions.
% \changes{v2.4.6}{2019/08/06}{Added switch \string\cs{usedAdbFuncs} to help detect
% the usealtadobe option}
% \begin{macrocode}
\DeclareOptionX{usealtadobe}{\let\usedAdbFuncs\dl@YES
\def\inputAltAdbFncs{\InputIfFileExists{altadbfncs.def}
{\PackageInfo{insdljs}{Inputting code for usealtadobe option}}
{\PackageWarning{insdljs}{Cannot find altadbfncs.def.\MessageBreak
Reinstall or refresh your file name database.}}}}
\let\usedAdbFuncs\dl@NO
\let\inputAltAdbFncs\relax
% \end{macrocode}
% \textbf{Process the package options}
% \begin{macrocode}
\ProcessOptionsX
% \end{macrocode}
% This package uses the double quote as a double quote, other packages the make double quote
% an active character.
% \begin{macrocode}
\edef\dl@dquoteCat{\the\catcode`\"}
\catcode`\"=12\relax
% \end{macrocode}
% Issue a package error if there is no driver specified or implied.
% \begin{macrocode}
\@ifundefined{dljs@drivernum}{\PackageError{insdljs}%
{You have not specified dvips, dvipsone, pdftex,\MessageBreak
dvipdfm, dvipdfmx, or xetex in the option list
\MessageBreak of the insdljs package}
{Place one of the drivers dvips, dvipsone, pdftex, dvipdfm,
dvipdfmx, or xetex
\MessageBreak in the option list of the insdljs package.}
}{}
% \end{macrocode}
% \subsection{Required Packages}
% We need \texttt{hyperref} to provide some fundamental code for the
% various drivers and \texttt{verbatim} to help write verbatim code
% to a file.
% \changes{v2.2h}{2016/06/09}{Added \string\cs{ifpdfmarkup} to easily detect
% use of pdfmarks}
% \begin{macrocode}
\@ifundefined{ifpdfmarkup}{\newif\ifpdfmarkup}{}\pdfmarkupfalse
\ifpdf\else\ifxetex\else\pdfmarkuptrue\fi\fi
\RequirePackage{hyperref}
% \end{macrocode}
% LuaTeX v0.85 has made some changes to primitives, the definition below follows
% the pattern of \texttt{hluatex.def} of \textsf{hyperref}.
% \changes{v2.3}{2016/06/09}{Fixed \string\cs{pdfnames} corresponding to
% changes in primitives of LuaTeX v0.85}
% \changes{v2.3a}{2016/07/31}{Added luatex85 definition of \string\cs{pdfpageref}}
% \begin{macrocode}
\ifpdf\ifx\pdfextension\@undefined\else
\protected\def\pdfcatalog{\pdfextension catalog } % l3
\protected\def\pdfnames{\pdfextension names }
\protected\def\pdfobj{\pdfextension obj } % l3
\protected\def\pdflastobj{\numexpr\pdffeedback lastobj\relax} % l3
\def\pdfpageref{\pdffeedback pageref}\fi\fi
% \end{macrocode}
% The critical JavaScript files are no longer distributed with this package,
% but are distributed by the \pkg{acrotex-js} package. This package must be
% installed, and the instructions in the \texttt{docs} folder followed to
% propery install the critical JavaScript file \texttt{aeb.js}.
% \changes{v2.5.5}{2021/06/19}{Require acrotex-js when dvips is used}
% \begin{macrocode}
\ifpdfmarkup
\IfFileExists{acrotex-js.sty}{\let\reqpkg\relax}
% \end{macrocode}
% If the style file \texttt{acrotex-js.sty} is detected, we assume the document
% author has correctly installed \texttt{aeb.js}, if not, we require
% this package, which may be automatically installed on some {\TeX} systems.
% \begin{macrocode}
{\PackageWarningNoLine{insdljs}{%
The acrotex-js package is required.\MessageBreak
Before continuing, install this package,\MessageBreak
read the documentation, and place\MessageBreak
aeb.js in the expected folder
}\def\reqpkg{\usepackage{acrotex-js}[2021/06/19]}
}
\expandafter\reqpkg\fi
\RequirePackage{verbatim}
% \end{macrocode}
%\changes{v2.4.1}{2019/02/11}{Save \string\cs{comment}\space as \string\cs{dlcomment}}
% \begin{macrocode}
\let\dlcomment\comment
\let\enddlcomment\endcomment
% \end{macrocode}
% (2017/01/03) The \pkg{insdljs} package does not use \pkg{conv-xkv} but
% is fundamental to other packages (\pkg{eforms}, \pkg{aeb\_pro}) that require
% \pkg{insdljs} and \pkg{conv-xkv}.
% \changes{v2.3c}{2017/01/03}{Require \string\pkg{conv-xkv}}
% \begin{macrocode}
\usepackage{conv-xkv}[2017/01/03]
% \end{macrocode}
% Last minute adjustments in the driver.
% \begin{macrocode}
\@ifundefined{dljs@drivernum}{%
\@ifundefined{eq@drivernum}{%
\PackageWarning{insdljs}
{No driver specified, will check for pdftex.}
\@ifundefined{pdfoutput}{%
\@ifundefined{@pdfm@mark}{\def\eq@drivernum{2}%
\def\dljs@drivernum{1}\let\isOpenAction\dl@NO
\PackageWarning{insdljs}{No pdftex, but detected dvipdfm}}%
{\PackageWarning{insdljs}{Neither pdftex nor dvipdfm,
assuming dvips/dvipsone.}%
\def\eq@drivernum{0}\def\dljs@drivernum{0}%
\let\isOpenAction\dl@YES}
}{%
\ifcase\pdfoutput
\def\eq@drivernum{1}\def\dljs@drivernum{1}%
\let\isOpenAction\dl@NO
\PackageInfo{insdljs}{Pdftex detected.}%
\else
\def\eq@drivernum{0}\def\dljs@drivernum{0}%
\let\isOpenAction\dl@YES
\PackageWarning{insdljs}{Pdftex engine detected,
but is outputting dvi. Assuming dvips as the driver.}%
\fi
}%
}{%
\begingroup
\count0=\eq@drivernum
\xdef\dljs@drivernum{\ifcase\count0 0\or1\or2\or0\else0\fi}
\ifnum\dljs@drivernum=0\global\let\isOpenAction\dl@YES
\else\global\let\isOpenAction\dl@NO\fi
\endgroup
}%
}{}
% \end{macrocode}
% I've always had problems with the pdftex option and inserting open page actions.
% The problem is that the open page action, which is defined using the token list
% \cs{pdfpageattr} appears not only on the first page, but every page thereafter.
% To solve this problem, I've used \textsf{everyshi}, a nice and useful package by
% Martin Schr\"oder, to set the open page action with \cs{AtNextShipout}.
% This approach seems to work.
% \begin{macrocode}
\ifnum\dljs@drivernum=1\relax
\RequirePackage{everyshi}
\fi
% \end{macrocode}
% If \texttt{reqjs} is in effect, we execute the following code, otherwise, we
% do not. The \textbf{\textsf{Requirements}} dictionary goes in the document \textbf{\textsf{Catalog}}.
% \changes{v2.2d}{2016/04/06}{Code to support \string\texttt{reqjs} and \string\texttt{{\string\EXPT}reqjs} options.}
% \begin{macrocode}
\def\AEB@psMrk{[%]
\space}
\ifx\dl@reqJS\dl@YES
\def\dl@@reqJS{/Requirements[<</Type/Requirement/S/EnableJavaScripts>>]}
\ifpdf\pdfcatalog{\dl@@reqJS}\else
\ifxetex\immediate\special{pdf:put @catalog <<\dl@@reqJS>>}\else
\literalps@out{\AEB@psMrk{Catalog} <<\dl@@reqJS>> /PUT\space pdfmark}\fi\fi
\fi
% \end{macrocode}
% Added switch to mark whether djs is inserted
% \changes{v2.4}{2018/07/21}{Added switch}{Added \string\cs{ifthereisdjs}}
% \begin{macrocode}
\newif\ifthereisdjs \thereisdjsfalse
\def\applydljs#1{\ifthereisdjs\else#1
\global\thereisdjstrue\fi}
% \end{macrocode}
%
% \section{Main Code}
%
% Before we begin, we need to document the problems that need to be addressed by this package.
%
% \subsection{Complications}
%
% There is a complication with writing JavaScript and \TeX{} together; they both use
% the backslash character, `|\|', as the escape character. The following two tables
% list escaped characters that have special meanings in different situations. These two tables
% were taken from the book \textsl{JavaScript, The Definitive Guide}, by David Flanagan, 4th Edition,
% O'Reilly publishers.
%
%\begin{flushleft}
%\begin{minipage}{\linewidth}
% \textbf{Escape Sequences in String Literals}
%
% \begin{tabular}{@{}ll@{}}
% Sequence & Character represented \\
% \cs{0} & the NULL character (\cs{u0000}) \\
% \cs{b} & backspace (\cs{u0008}) \\
% \cs{t} & horizontal tab (\cs{u0009}) \\
% \cs{n} & newline (\cs{u000A}) \\
% \cs{v} & vertical tab (\cs{u000B}) \\
% \cs{f} & form feed (\cs{u000C}) \\
% \cs{r} & carriage return (\cs{u000D}) \\
% \cs{"} & double quote (\cs{u0022}) \\
% \cs{'} & apostrophe or single quote (\cs{u0027}) \\
% |\\| & backslash (\cs{u005C})\\
% \cs{xXX} & the Latin-1 character specified by the two hexadecimal digits \texttt{XX} \\
% \cs{uXXXX}& the unicode character specified by the four hexadecimal digits \texttt{XXXX} \\
% \cs{XXX} & the Latin-1 character specified by the octal digits \texttt{XXX}, between \\
% & $1$ and $377$. \\
% \end{tabular}
%\end{minipage}
%\end{flushleft}
%
%\begin{flushleft}
%\begin{minipage}{\linewidth}
% \textbf{Regular Expression Literal characters}
%
% \begin{tabular}{ll}
% Character & Matches \\
% Alphanumeric & Itself \\
% \cs{0} & the NULL character (\cs{u0000}) \\
% \cs{t} & horizontal tab (\cs{u0009}) \\
% \cs{n} & newline (\cs{u000A}) \\
% \cs{v} & vertical tab (\cs{u000B}) \\
% \cs{f} & form feed (\cs{u000C}) \\
% \cs{r} & carriage return (\cs{u000D}) \\
% \cs{xXX} & the Latin-1 character specified by the two hexadecimal\\
% & digits \texttt{XX} \\
% \cs{uXXXX}& the unicode character specified by the four hexadecimal\\
% & digits \texttt{XXXX} \\
% \cs{cXX} & the control character |^X|
% \end{tabular}
%\end{minipage}
%\end{flushleft}
%
% Again, both JavaScript and \TeX, certain punctuation marks have special meaning; in the case of
% JavaScript, punctuation has a special meaning within regular expressions:
%\paragraph*{Special Punctuation in Regular Expressions}
%\begin{verbatim}
% ^ $ . * + ? = ! : | \ / ( ) [ ] { }
%\end{verbatim}
% Complications continued. The distiller method (the \texttt{dvipsone} or the
% \texttt{dvips} option), and the \textsf{pdftex}/\textsf{dvipdfm} applications
% handle the backslash differently. The following example illustrates the problem.
% {\small
%\begin{verbatim}
%dvips
%LaTeX Source As appears in PDF
%var x = "\"; --> var x = "\"; (SyntaxError: Unterminated string literal)
%var x = "\\"; --> var x = "\\"; (Correct)
%\end{verbatim}}
% When we type \texttt{"\string\"}, we are beginning a string (with the first
% double quotes, but then we have a literal \texttt{\string\"}, so we have not
% closed the opening string, hence the error message. We have to type
% `\verb+\\+' to get the single backslash.
% {\small
%\begin{verbatim}
%pdftex/xetex
%LaTeX Source As appears in PDF
%var x = "\"; --> var x = ""; (\" is the literal ")
%var x = "\\"; --> var x = "\"; (SyntaxError: Unterminated string literal)
%var x = "\\\\"; --> var x = "\\"; (Correct)
%\end{verbatim}}
% These applications write raw PDF code to the \texttt{.pdf} file.
% All special characters need to be escaped. You can see, that \textsf{pdftex}
% and \textsf{dvipdfm} require extra backslashs.
%
% The solution to this problem---the problem of how distiller and the two applications
% handle backslashes---is to define control sequences for all the sequences JavaScript uses
% and to adjust their definitions depending on the driver option. As a result, of these
% background definitions, the JavaScript writer does not worry too much about these details,
% for example
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={*~@},codes={\def\1{\quad}\catcode`\%=9}]
%\begin{insDLJS}{mydljs}{My Private DLJS}
%function HelloWorld()
%{
%*1app.alert("\tugHello", 3);
%*1var x = "\\";
%*1app.alert("x = " + x);
%}
%\end{insDLJS}
%\end{Verbatim}
% So much for the complication.
%
%\subsection{Begin Code}
%
% Some control sequences that are useful for various
% actions. All appear within the \cs{A} key, eg, |\A{\JS{var x=17;}}|. Note the arguments
% of some are delimited by parentheses, others by braces. Sorry for the inconsistency,
% but these evolved over a period of years. Some keys require additional arguments which
% are typically inserted in raw form; eg, |\A{\GoToR(|\ameta{dest}|)/F(example.pdf)}|.
% \begin{macro}{\JS}\hskip-\marginparsep\texttt{\darg{\ameta{code}}}
% A convenience command for writing a JavaScript action
% \begin{macrocode}
\providecommand\JS[1]{/S/JavaScript/JS(#1)}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\Named}\hskip-\marginparsep\texttt{\darg{\ameta{name}}}
% A named action, eg, |\A{\Named{NextPage}}|
% \begin{macrocode}
\providecommand{\Named}[1]{/S/Named/N/#1}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\GoTo}\hskip-\marginparsep\texttt{(\ameta{name})}
% A go-to-action; eg, |\A{\GoTo(|\ameta{dest}|)}|. The argument can actually be a name
% (enclosed in parentheses), a byte string, or an array.
% \begin{macrocode}
\providecommand{\GoTo}{/S/GoTo/D}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\GoToD}\hskip-\marginparsep\texttt{(\ameta{name})}
% A go-to-action destination; eg, |\A{\GoToD(|\ameta{dest}|)}| (same as \cs{GoTo})
% \begin{macrocode}
\providecommand{\GoToD}{/S/GoTo/D}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\GoToR}\hskip-\marginparsep\texttt{(\ameta{name})/F(\ameta{file-spec})} A go-to-remote action,
% where \ameta{name} is the destination in the remote file \ameta{file-spec}; eg, |\A{\GoToR(|\ameta{dest}|)/F(example.pdf)}|
%
% \begin{macrocode}
\providecommand{\GoToR}{/S/GoToR}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\Thread}\hskip-\marginparsep\texttt{\darg{\ameta{thread-title}}}
% \changes{v2.4.9}{2020/07/09}{Added \string\cs{Thread}}
% A thread action; this command is used in the \pkg{artthreads} package.
% \begin{macrocode}
\providecommand{\Thread}[1]{/S/Thread/D(#1)}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\URI}\hskip-\marginparsep\texttt{\darg{\ameta{string}}}
% A URI action, eg, |\A{\URI{http://www.example.com}}|
% \begin{macrocode}
\providecommand{\URI}[1]{/S/URI/URI(#1)}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\Launch}\hskip-\marginparsep\texttt{\darg{\ameta{file-spec}}}
% \changes{v2.5}{2020/12/20}{Added \string\cs{Launch}}
% A launch action
% \begin{macrocode}
\providecommand{\Launch}[1]{/S/Launch/F(#1)}
% \end{macrocode}
% \end{macro}
% \begin{macrocode}
\def\previewMiKTeX{\def\jsR{\string\r}\def\jsT{\string\t}}
{\obeylines %
\gdef\js@@R{\noexpand
}}
% \end{macrocode}
% We define space\DescribeMacro\pdfSp, left\DescribeMacro\pdfLBr, and right \DescribeMacro\pdfRBr
% braces in pdf (PDFDocEncoding); these are also defined
% in \pkg{exerquiz} but under different names (\cs{eqSP}, \cs{eqLBr}, and \cs{eqRBr}).
% \changes{v2.4.2}{2019/03/16}{Added \string\cs{pdfSP}, and others, and \string\cs{dl@sp@ce}}
% \changes{v2.4.10}{2020/11/28}{\string\cs{pdfSpacesOn} on by default,
% only for \string\app{dvips}; otherwise, \string\cs{pdfSpacesOff}}
% \begin{macrocode}
\def\pdfSPDef{\string\040}
\def\dl@sp@ce{ }
% \end{macrocode}
% Beginning with \pkg{insdljs} dated 2019/03/16, we solve an age-old problem with \app{dvips}: This problem
% is that is wraps code around to the next line, according to some unknown algorithm. Normally this is not
% a problem, but occasionally it will wrap some JavaScript code that breaks the code. Solve this problem,
% we make the space character active, and replace it with \cs{pdfSP} (\cs{040}), which is octal for the space
% character. Now there are no free spaces for \app{dvips} to break the line at in the PS file. The feature
% is turned on by default, and may be turned off with \DescribeMacro\pdfSpacesOff\cs{pdfSpacesOff}
% and back on by \DescribeMacro\pdfSpacesOn\cs{pdfSpacesOn}.
% \begin{macrocode}
\newif\ifpdfspaces\pdfspacesfalse
\def\pdfSpacesOn{\global\pdfspacestrue\let\pdfSP\pdfSPDef}
\def\pdfSpacesOff{\global\pdfspacesfalse\let\pdfSP\dl@sp@ce}
\pdfSpacesOff
\ifpdf\else\ifxetex\else\pdfSpacesOn\fi\fi
\def\pdfLBr{\string\173}
\def\pdfRBr{\string\175}
% \end{macrocode}
% \DescribeMacro\dl@restorespcs restores the obey spaces space to its default,
% saved earlier. This command is placed at the end of each of the form field
% commands to reverse the earlier change to \cs{pdfSP}.
% \begin{macrocode}
\bgroup\obeyspaces
\gdef\dl@restorespcs{\global\let =\dl@sp@ce}\egroup
% \end{macrocode}
% \cs{dljstfor} is used in the \texttt{cc4js} segment.
% \begin{macrocode}
\let\dljstfor\@tfor
% \end{macrocode}
% \leavevmode\DescribeMacro{\dfnJSCR}\hskip-\marginparsep\texttt{\darg{\ameta{eol}}}
% A help macro to define \cs{dfnJSR} in a convenient way; \cs{dfnJSR} is
% used in the \env{defineJS} environment.
% \changes{v2.5}{2020/12/20}{Helper commands \string\cs{dfnJSCR} to define
% \string\cs{defineJSjsR} and \string\cs{dfnJSCRDef} to set default.}
% \begin{macrocode}
\def\dfnJSCR#1{\gdef\dfnJSR{#1}\gdef\defineJSjsR{#1}}
\def\dfnJSCRDef{\dfnJSCR{\string\r\eqbs^^J}}
\dfnJSCRDef
\def\jsR{\string\r\string\n}
% \end{macrocode}
% \cs{r} is recognized by hyperref when \cs{pdfstringdef} is used. Hyperref
% then modifies the expansion of \cs{r}. So, we'll use \cs{n} in those situations.
% \changes{v2.0l}{2012/11/10}{Added \string\cs{jsN}}
% \begin{macrocode}
\def\jsN{\string\n}
{\catcode`\^^I\active %
\gdef^^I{\noexpand^^I}%
\gdef\js@@T{\noexpand^^I}%
}% end of \catcode`\^^I
\let\jsT=\js@@T
% \end{macrocode}
% Need to write to files. This stream will be used for that purpose.
% \begin{macrocode}
\newwrite\js@verbatim@out
\def\iwvo#1{\immediate\write\js@verbatim@out{#1}}
% \end{macrocode}
% \paragraph*{Convenience command\DescribeMacro{\dl@EForAF4} that support \opt{usealtadobe} option.} This helper
% command make it convenient to switch from the `AF' to the `EF' versions.
% \changes{v2.5.3}{2021/05/10}{Added \string\cs{dl@EForAF4}}
% \changes{v2.5.4}{2021/05/13}{Added \string\cs{dl@EForAFMergeChange}}
% \begin{macrocode}
\def\dl@EForAF4#1_{\ifx\usedAdbFuncs\dl@YES EF\else AF\fi#1_}
\def\dl@EForAFMergeChange{%
\ifx\usedAdbFuncs\dl@YES EF\else AF\fi MergeChange}
% \end{macrocode}
% \subsection{Some JavaScript Support}
%
% \begin{macro}{\flJSStr}
% \begin{macro}{\dlJSStr}
%
% A simple command for creating JavaScript strings that recognize unicode escape
% sequences \cs{uXXXX}. This command defines a macro with name contained in \texttt{\#1},
% the first argument, the second argument \texttt{\#2} is the JavaScript string. Enclosing
% the string with double quotes is not necessary, this is done automatically. Any expandable
% commands within string are expanded at define time, unless they are protected with \cs{protect}.
% The string can be formatted using \cs{r} and \cs{t}. Also, \verb!\\! expands to a backslash
% should the need arise.
%\changes{v2.0b}{2008/06/19}
%{
% A simple command for creating JS strings with unicode \string\cs{uXXXX}.
%}
% \changes{v2.0m}{2013/12/23}{Added \string\cs{jscsDflt} and \string\cs{jscsDLJS}, incorporated into \string\cs{dl@defJSStr}.}
% Added \string\cs{jscsDflt} and \string\cs{jscsDLJS}, incorporated them into \string\cs{dl@defJSStr}.
% \begin{macrocode}
\def\dl@lparen{(}\def\dl@rparen{)}
\def\genericNL{^^J}
\def\defjsLB{\gobiv}
\def\genericLB{\eqbs\eqbs^^J}
\def\pdfmarkLB{\eqbs^^J}
\def\jscsDflt{\let\protect\noexpand\let\jslit\string
\let\~\dl@tilda\let\^\dl@sup
\def\\{\eqbs\eqbs}\def\cs##1{\\\\##1}%
\def\r{\\r}\def\t{\\t}\def\n{\\n}%
\let\{\dl@lBrace\let\}\dl@rBrace
\ifx\jsstr@useUni\dl@One\def\Uni{\\u}\else\def\u{\\u}\fi
\ifx\jsstr@parens\dl@One\let\l@paren\dl@lparen
\let\r@paren\dl@rparen\else
\let\l@paren\@empty\let\r@paren\@empty\fi
\dl@paramlocal\let\LB\genericLB\let\NL\genericNL
}
\def\jscsDLJS{\let\protect\noexpand\let\jslit\string
\let\~\dl@tilda\let\^\dl@sup
\ifxetex\def\\{\eqbs\eqbs}\else\def\\{\eqbs}\fi\def\cs##1{\\\\##1}%
\def\r{\\r}\def\t{\\t}\def\n{\\n}%
\let\{\dl@lBrace\let\}\dl@rBrace
\ifx\jsstr@useUni\dl@One\def\Uni{\\u}\else\def\u{\\u}\fi
\ifx\jsstr@parens\dl@One\let\l@paren\dl@lparen
\let\r@paren\dl@rparen\else
\let\l@paren\@empty\let\r@paren\@empty\fi
\ifpdfmarkup\let\LB\pdfmarkLB\else
\let\LB\genericLB\fi
\let\NL\genericNL
}
\ifpdf\let\jscsDLJS\jscsDflt\fi
\let\dl@JSCS\jscsDflt
% \end{macrocode}
% \DescribeMacro{\flJSStr} This form is designed for writing literal strings
% at the field level.
% When the \texttt{*}-form is used, \texttt{\#2} is passed through \cs{pdfstringdef},
% needed if there are some latex to pdf strings to be converted.
% \changes{v2.4.2}{2019/03/16}{Implement tex to pdf spacing}
% \begin{macrocode}
\bgroup\obeyspaces
\gdef\flJSStr{\bgroup\global\let =\pdfSP
\let\dl@JSCS\jscsDflt
\obeyspaces\@ifstar{\def\isStar{*}\dl@defJSStr}%
{\let\isStar\relax\dl@defJSStr}}\egroup
\let\fieldJSStr\flJSStr
% \end{macrocode}
% For backward compatibility, we \cs{let} \cs{defineJSStr} to \cs{flJSStr}.
% \begin{macrocode}
\let\defineJSStr\flJSStr
% \end{macrocode}
% \DescribeMacro{\dlJSStr} This form is designed for writing strings to the document
% level JavaScript, as embedded using the \texttt{insDLJS} environment.
% When the \texttt{*}-form is used, \texttt{\#2} is passed through \cs{pdfstringdef},
% needed if there are some latex to pdf strings to be converted.
% \begin{macrocode}
\newcommand{\dlJSStr}{\bgroup
\@ifstar{\def\isStar{*}\let\dl@JSCS\jscsDLJS\dl@defJSStr}
{\let\isStar\relax\let\dl@JSCS\jscsDLJS\dl@defJSStr}}
% \end{macrocode}
% Some simple key-values for both commands above. Both commands, by default,
% insert double quotations marks at the beginning and end of the string as a convenience.
% \IndexKey{quotes}\texttt{quotes} option just affirms that default; it need not be specified.
% The \IndexKey{noquotes}\texttt{noquotes} option signals \textsf{eforms} not to
% insert said double quotation marks. The other option, \texttt{useUni} is implemented, but not
% documented publicly, to change the command for unicode from \cs{u} to \cs{Uni} in case there
% is a clash of definitions with some accents, \u{a} (\verb!\u{a}!), for example. Hyperref has a
% \cs{u} command defined in the PU encoding, but \cmd{\flJSStr} and \cmd{\dlJSStr} through
% \cmd{\dl@defJSStr} sets \cmd{\Hy@unicodefalse} to support PD1 encoding only. The user can
% access the full range of unicode glyphs through \cs{u}.
% \begin{macrocode}
\define@key{jsstr}{quotes}[]{\let\jsstr@quotes\dl@One}
\define@key{jsstr}{noquotes}[]{\let\jsstr@quotes\dl@Zero}
\define@key{jsstr}{parens}[]{\let\jsstr@parens\dl@One}
\define@key{jsstr}{noparens}[]{\let\jsstr@parens\dl@Zero}
\let\jsstr@quotes\dl@One\let\jsstr@parens\dl@Zero % noparens the default
\define@key{jsstr}{useUni}[]{\let\jsstr@useUni\dl@One}
\let\jsstr@useUni\dl@Zero
% \end{macrocode}
% The common part to both \cs{flJSStr} and \cs{dlJSStr}.
% \changes{v2.4.2}{2019/03/16}{Implement tex to pdf spacing. Remove the use of
% parentheses in \string\cs{dl@defJSStr}.}
% \begin{macrocode}
\newcommand{\dl@defJSStr}[3][quotes]{\def\dl@argi{#1}\ifx\dl@argi\@empty
\else\ifx\dl@JSCS\jscsDLJS\let\jsstr@parens\dl@Zero\fi
\setkeys{jsstr}{#1}\fi\dl@JSCS
\ifx\jsstr@quotes\dl@One
\xdef#2{\l@paren"#3"\r@paren}\else
\xdef#2{\l@paren#3\r@paren}\fi
\if\isStar*\gdef\dl@afterAction{{\Hy@unicodefalse\expandafter
\pdfstringdef\expandafter#2\expandafter{#2}}}\else
\global\let\dl@afterAction\relax\fi
\aftergroup\dl@afterAction\egroup\dl@restorespcs}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\dlTC}\hspace{-\marginparsep}\thinspace
% \darg{\ameta{code}} A convenience command to insert a \texttt{try/catch} pair around
% \ameta{code} with no error report.
% \changes{v2.3e}{2017/02/27}{Added convenience command \string\cs{dlTC}}
% \begin{macrocode}
\def\dlTC#1{try{#1}catch(e){}}
% \end{macrocode}
% \end{macro}
%
% \subsection{A Macro for Debugging JS}
% \begin{macro}{\db}\hskip-\marginparsep{\,\texttt{...\cs{db}}}
% The \cs{db} macro can be used within the \texttt{insDLJS} to insert
% addition JS commands to help debug the code. Usage:
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={*~@},codes={\def\1{\quad}\catcode`\%=9}]
%\db console.println("myVal = " + myVal);\db*%
%\end{Verbatim}
% Any material (on one line) that is between the two \verb+\db+ will either be
% written to the DLJS (if \cmd{\dljs@debug} expands to \texttt y), or be removed from
% the final output (if \cmd{\dljs@debug} does not expand to \texttt y).
%
% Note that the comment character (|%|) following the terminating \verb+\db+.
% This comment keeps a carriage return from being invoked; if \cmd{dljs@debug} is false
% then this will not create an empty line in your JavaScript.
% \begin{macrocode}
\def\js@R{\ifcase\dljs@drivernum^^J\else\jsR\fi}
% \end{macrocode}
% The three spaces (\cs{space}) is meant to align the debug statement, since |\db| takes
% up three spaces.
% \begin{macrocode}
\def\db#1\db{\ifx\dljs@debug\dl@YES\space\space\space#1\js@R\fi}
% \end{macrocode}
% \end{macro}
% Acrobat (and Reader) expect the JavaScript code will be listed in the JavaScript
% array in sorted form. \texttt{pdftex} and \texttt{dvipdfm} do not sort this array
% and it would be difficult for \TeX{} to do the sorting; therefore a workaround.
% Each set of DLJS will be numbered in the order in which they are defined. This puts
% them naturally in proper sorted order. The following counter, numbers the JS.
% \begin{macrocode}
\newcounter{dljs@cnt}
\newcounter{dljssegs}\setcounter{dljssegs}{2}
% \end{macrocode}
% \subsection{Some Verbatim Write Environments}
% Here is a verbatim write environment, based on an example in the
% \texttt{verbatim} package. One modification: The output stream is
% not opened by this environment, this must be done prior. This is necessary
% to write some other stuff prior to the verbatim write.
%
% This verbatim is used internally to write the \texttt{.djs} files, containing
% the JavaScript.
% \begin{macrocode}
\newenvironment{js@verbatimwrite}{% writes to current \js@verbatim@out
\@bsphack
\let\do\@makeother\dospecials\catcode`\^^M\active
\def\verbatim@processline{\immediate
\write\js@verbatim@out{\the\verbatim@line}}\verbatim@start
}{\@esphack}
% \end{macrocode}
% Unlike the example of verbatimwrite in the \texttt{verbatim} package, we do not
% automatically close the stream when we finish out \texttt{js@verbatimwrite} environment.
% We need to write more to this file, so we have an explicit close.
% \begin{macrocode}
\def\closejs@verbatim@out{\immediate\closeout\js@verbatim@out}
% \end{macrocode}
% Same as above, except we expand the line with an \cmd{\edef}.
%
% For the case of \texttt{dvipsone/dvips}, which use the pdfmark operator, we have
% a couple of definitions for escape (esc). It turns out, I find it convenient to have
% two versions, a \cs{eqesc}, and a \cs{eqesci}, the latter one is only used once, the former
% one is used numerous times, see the \texttt{\hyperref[dljscc]{dljscc.def}} file.
% \begin{macrocode}
\begingroup
\catcode`\@=0 @catcode`@\=12
@gdef@eqbs{\}
@gdef@ccpdfmark{@gdef@eqesc{\}@gdef@eqesci{}}
@endgroup
% \end{macrocode}
% Here's a definition of left and right braces that will be used in writing JavaScript code.
% \begin{macrocode}
\begingroup
\catcode`<=1 \catcode`\>=2 \@makeother\{ \@makeother\}
\gdef\definebraces<\def\{<\eqesc{>\def\}<\eqesc}>>
\endgroup
% \end{macrocode}
% My own special dos and don'ts. Preserve |\| and \texttt{\%}
% \begin{macrocode}
\def\eqdospecials{\do\ \do\{\do\}\do\$\do\&%
\do\#\do\^\do\_\do\~}
% \end{macrocode}
% The \texttt{jsexpverbatimwrite} environment is used to write a quasi-verbatim
% file. We keep original default definitions of |\| and |%| (they are not included in the
% \cs{eqdospecials} above). The code for \texttt{jsexpverbatimwrite} is based on that found
% in the \texttt{verbatim} package. The trouble is, this package assumes that |\| has been changed
% to catcode 12, other. Consequently, I had a devil of a time trying to stop the verbatim write
% with |\| as an escape rather than other. I finally decided it was necessary to rewrite some of
% the main macros in \texttt{verbatim} so they would properly stop. Below are the modifications
% designed to stop when \texttt{*end} encountered rather than \cs{end}. These changes seem to
% work o.k.
% \begin{macrocode}
\begingroup
\catcode`\~=\active \lccode`\~=`\^^M
\lowercase{\endgroup
\def\eqverbatim@#1~{\verbatim@@#1*end\@nil}%
\def\eqverbatim@@#1*end{%
\verbatim@addtoline{#1}%
\futurelet\dl@next\eqverbatim@@@}%
\def\eqverbatim@@@#1\@nil{%
\ifx\dl@next\@nil
\verbatim@processline
\verbatim@startline
\let\dl@next\eqverbatim@
\else
\def\@tempa##1*end\@nil{##1}%
\@temptokena{*end}%
\def\dl@next{\expandafter\verbatim@test\@tempa#1\@nil~}%
\fi\dl@next}%
}%
\def\jsexpverbatimwrite
{% writes to current \js@verbatim@out
\@bsphack
\ccpdfmark
\catcode`\<=12 \catcode`\>=12
\input{dljscc.def}%
% Attempt to redefine some macros from the verbatim package
\let\verbatim@=\eqverbatim@
\let\verbatim@@=\eqverbatim@@
\let\verbatim@@@=\eqverbatim@@@
% end redefine of verbatim package
\let\do\@makeother\eqdospecials%
\catcode`\^^M=\active\catcode`\^^I=12%
\def\verbatim@processline{%
\edef\expVerb{\the\verbatim@line}%
\immediate\write\js@verbatim@out{\expVerb}}%
\verbatim@start%
}
\def\endjsexpverbatimwrite{\immediate\closeout\js@verbatim@out\@esphack}
% \end{macrocode}
% \begin{macro}{\insPath}
% Set this macro in the \textbf{preamble} of your document to
% direct (almost) all auxiliary files of insDLJS to the specified
% path. The macro takes one parameter, a path on your local hard
% disk. Usage:
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={*~@},codes={\def\1{\quad}\catcode`\%=9}]
%\insPath{c:/temp/}
%\end{Verbatim}
% Be sure to use only forward slashes, and don't forget to finish
% the string with a final forward slash, as illustrated above.
%
% All \texttt{*.fdf} files are written to this folder. The
% \texttt{.djs} files of any \texttt{insDLJS} environments created
% after the \cmd{\insPath} will also be written to the path. Any
% \texttt{.djs} created by packages loaded earlier (such as
% \textsf{exerquiz}) will be written to the current directory.
%
% This macro may be useful for users of Distiller~5.0, and is of marginal
% value to users of \textsf{pdftex/dvipdfm}.
% \begin{macrocode}
\let\js@Path\@empty
\def\insPath#1{\def\js@Path{#1}}
% \end{macrocode}
% \end{macro}
% \DescribeMacro{\makeJSspecials}
% This command is typically executed at the beginning of each field
% or link (see \cs{eq@setButtonProps} and \cs{eq@setWidgetProps}).
% They are used for formatting JavaScript code. The command
% \cs{makespecialJS} is defined in \textsf{insdljs}.
% \changes{v2.1}{2015/06/15}{Moved \string\cs{makeJSspecials} from \string\textsf{eforms}
% to here.}
% \begin{macrocode}
\begingroup
\catcode`\{=12 \catcode`\}=12 \catcode`\<=1 \catcode`\>=2
\gdef\dl@lBrace<\string\{> \gdef\dl@rBrace<\string\}>
\gdef\dl@tilda<\string~> \gdef\dl@sup<\string^>
\endgroup
\def\makeJSspecials{%
\def\\{\eqbs\eqbs}% % define \\ to be \\
\let\jslit\string
% \end{macrocode}
% \changes{v2.0n}{2014/05/20}{Remake the definition of \string\cs{\char`\{} and \string\cs{\char`\}}}
% In an attempt to avoid the use of \verb~\jslit\{~ and \verb~\jslit\}~, we remake
% the definition of \verb~\{} and \verb~\}~.
% \begin{macrocode}
\let\{\dl@lBrace\let\}\dl@rBrace
% \end{macrocode}
% \changes{v2.1}{2015/07/12}{\string\cs{let} \string\cs{u} to \string\cs{@empty}.}
% \cs{let} \cs{u} to \cs{@empty}.
% \begin{macrocode}
\let\u\@empty
\def\({\eqbs(}\def\){\eqbs)}%
\makespecialJS % make \r=\jsR and \t=\jsT
}
% \end{macrocode}
% \subsection{Open Document Actions}\label{opendocactions}
% Early in the process of opening a document, the `\texttt{/OpenAction}' event occurs, where
% various action-types may be executed. These actions occur before the document JavaScripts
% are read and before any pages are opened. We give support for this event, originally part
% of the \textsf{aeb\_pro} package.
%\changes{v2.1}{2015/06/15}{Moved definition of \string\cs{addToDocOpen} from
% \textsf{aeb\_pro} to \textsf{insdljs}, added support for \string\texttt{pdftex} and \string\texttt{xetex}
% options.}
% \paragraph*{Page views}
% The view can be set when the page key is used. Possible values are
% \texttt{fitpage}, \texttt{actualsize}, \texttt{fitwidth},
% \texttt{fitvisible}, and \texttt{inheritzoom}. These terms correspond
% to Acrobat's UI. When jumping to a destination, the view is set by the
% destination code.
% \begin{macrocode}
\def\dl@fitpage{/Fit}
\def\dl@actualsize{/XYZ null null 1.0} %{/XYZ -32768 -32768 1.0}
\def\dl@fitwidth{/FitH null} %{/FitH -32768}
\def\dl@fitheight{/FitV null} %{/FitV -32768}
\def\dl@fitvisible{/FitBH null} %{/FitBH -32768}
\def\dl@inheritzoom{/XYZ 0 0 0}
\def\dl@mag#1{/XYZ null null #1}
\edef\dl@Page#1{\ifcase\dljs@drivernum
{Page#1}\or\noexpand\pdfpageref#1\space\space 0 R\or
@page#1\fi}
\def\dl@preProcDefns{\let\Page\dl@Page\let\mag\dl@mag
\let\fitpage\dl@fitpage\let\actualsize\dl@actualsize
\let\fitwidth\dl@fitwidth\let\fitheight\dl@fitheight
\let\fitvisible\dl@fitvisible\let\inheritzoom\dl@inheritzoom
}
\let\aeb@additionalOpenAction\@empty
\let\aeb@addActionCode\@empty
\let\addActionObj\@empty
\let\aebpopentoks\@empty
\let\aebpFA\dl@NO
\def\aebp@rightDelimiters{}
% \end{macrocode}
% The argument of \DescribeMacro\addToDocOpen\cmd{\addToDocOpen} is an action-type, usually
% \textbf{JavaScript} or a \textbf{GoTo}. The command is accumulative, it can be invoked several types
% with different action-types. Must be executed in the preamble or it has no effect.
% It populates the value of the key \textbf{/OpenAction} in the \textbf{Catalog} of the
% PDF file.
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={*~@},codes={\def\1{\quad}\catcode`\%=9}]
%\addToDocOpen{\JS{console.println("Open the doc!");}}
%\addToDocOpen{/S/GoTo/D[\Page{2}\fitpage]}
%\end{Verbatim}
% \begin{macrocode}
\newcommand{\addToDocOpen}[1]{%
\ifx\aebpFA\dl@NO
\g@addto@macro\aebpopentoks{#1}%
\def\aeb@additionalOpenAction{/Next {pubAddToDocOpen}}%
\ifpdf
\def\aeb@addActionCode{\immediate\pdfobj{<<
\aebpopentoks\aebp@rightDelimiters >>}%
\edef\addActionObj{\the\pdflastobj\space 0 R}}%
\else\ifxetex
\def\aeb@addActionCode{\immediate
\special{pdf:obj @objAddActionObj
<< \aebpopentoks\aebp@rightDelimiters >> }}%
\def\addActionObj{@objAddActionObj}%
\else % postscript
\def\aeb@addActionCode{\literalps@out{%
\AEB@psMrk/_objdef {pubAddToDocOpen}
/type/dict /OBJ pdfmark^^J%
\AEB@psMrk{pubAddToDocOpen} <<
\aebpopentoks\aebp@rightDelimiters >> /PUT pdfmark}}%
\def\addActionObj{{pubAddToDocOpen}}%
\fi\fi
\global\let\aebpFA\dl@YES
\let\@pdfstartview\@empty
\else
\edef\aebp@dljstmp{\aebp@rightDelimiters}%
\xdef\aebp@rightDelimiters{\aebp@dljstmp >> }%
\g@addto@macro\aebpopentoks{/Next << #1 }%
\fi
}
\def\dljs@OpenActions{/OpenAction \addActionObj}
\def\dljs@setOpenActions{\bgroup\makeJSspecials\dl@preProcDefns
\aeb@addActionCode
\ifpdf\pdfcatalog{\dljs@OpenActions}\else
\ifxetex\immediate
\special{pdf:put @catalog <<\dljs@OpenActions>>}\else
\literalps@out{\AEB@psMrk
{Catalog} <<\dljs@OpenActions>> /PUT pdfmark}\fi\fi\egroup}
% \end{macrocode}
% If \textsf{aeb\_pro} is not loaded, we set the open actions. If \textsf{aeb\_pro}
% is loaded, we do nothing for \textsf{aeb\_pro} has its own contributions to the
% PDF \textbf{Catalog}.
% \changes{v2.3d}{2017/01/08}{Use \string\cs{aebpFA} to detect open actions}
% \begin{macrocode}
\@ifpackageloaded{aeb_pro}{}
{\AtBeginDocument{\ifx\aebpFA\dl@YES\expandafter
\dljs@setOpenActions\fi}}
% \end{macrocode}
%
% \subsection{Open Page Actions}\label{openaction}
%
% In order to get automatic insertion of DLJS using Distiller~5.0 or greater, it is necessary
% to use a ``Page Open Action'' for page 1 of the document. This section contains some commands
% for defining an open page action. Originally, these macros were defined only for Distiller
% users (\textsf{dvips} and \textsf{dvipsone} users), later, I extended their use to
% \textsf{pdftex} and \textsf{dvipdfm}.
%
%\subsubsection{\texorpdfstring{\cs{OpenAction}}{\textbackslash{OpenAction}}}
%
% Here are the macros that actually place the open page action into the PDF document. One for
% the \textsf{Distiller}, one for \textsf{pdftex}, and one for \textsf{dvipdfm}.
% \begin{macrocode}
\let\@CloseAction\@empty
\def\@OAction@pdfmark{\literalps@out{%
\AEB@psMrk{ThisPage} << /AA << /O << \theFirstAction\space
\opentoks\@rightDelimiters >> \@CloseAction >> >> /PUT pdfmark}}
\def\@POAction@pdfmark{\literalps@out{%
\AEB@psMrk{ThisPage} << /AA << \@thisOpenAction
\@thisCloseAction >> >> /PUT pdfmark}%
}
\def\@OAction@pdftex{%
\ifx\isOpenAction\dl@YES
\xdef\pdftexOAction{/AA << /O << \theFirstAction\space
\opentoks\@rightDelimiters >> \@CloseAction >>}%
\AtNextShipout{\pdfpageattr=\expandafter{\pdftexOAction}}\fi
}
\def\@POAction@pdftex{%
\xdef\thisPageActionpdftex{/AA << \@thisOpenAction
\@thisCloseAction >>}%
\AtNextShipout{\pdfpageattr=\expandafter{\thisPageActionpdftex}}%
}
% \end{macrocode}
% For \textsf{dvipdfm}
% \begin{macrocode}
\def\@OAction@dvipdfm{\ifx\isOpenAction\dl@YES
\special{pdf:put @thispage << /AA << /O << \theFirstAction\space
\opentoks\@rightDelimiters >> \@CloseAction >> >>}\fi
}
\def\@POAction@dvipdfm{%
\special{pdf:put @thispage << /AA << \@thisOpenAction
\@thisCloseAction >> >>}%
}
% \end{macrocode}
% Now we choose the one appropriate to the user's driver option.
% \begin{macrocode}
\ifcase\dljs@drivernum
\let\@OAction\@OAction@pdfmark
\let\@POAction\@POAction@pdfmark
\gdef\theFirstAction{/S/JavaScript/JS (\the\importfdftoks)}
\let\isOpenAction\dl@YES
\or
\let\@OAction\@OAction@pdftex
\let\@POAction\@POAction@pdftex
\AtBeginDocument{\@OAction@pdftex}
\or
\let\@OAction\@OAction@dvipdfm
\let\@POAction\@POAction@dvipdfm
\AtBeginDocument{\@OAction@dvipdfm}
\fi
% \end{macrocode}
% \begin{macro}{\OpenAction}
% In order for the DLJS to be inserted, \texttt{insdljs} places an open page action
% on the first page. If the document author wants his/her own open page action, inserting
% it with the pdfmark operator may lead to unpredictable results. For the uses of the
% Distiller (dvipsone and dvips users of the distiller), if additional open page action
% is needed on the first page, you can insert this action using the \cmd{\nextOAction} command.
%
%\paragraph*{Usage}
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={*~@},codes={\def\1{\quad}\catcode`\%=9}]
%\OpenAction{\JS{app.beep(-1); app.alert("Welcome to my Page!",3);}}
%\end{Verbatim}
% The macro takes two parameters, the \cmd{\Next} followed by the desired action, in this
% case it is a JavaScript action.
%
% From the code below, you can see that \cmd{\nextOAction} ends calling itself. If the next token
% is a \cmd{\Next}, additional code is entered into the open page action. Thus, for example, the
% following code is effectively the same as the above example, but the individual lines are
% listed separately in the GUI action dialog of Acrobat.
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={*~@},codes={\def\1{\quad}\catcode`\%=9}]
%\OpenAction{\JS{app.beep(-1);}}
%\Next{\JS{app.alert("Welcome to my Page!",3);}}
%\end{Verbatim}
% In the above example, several open page actions are ``chained'' together.
%
% You are not restricted to JavaScript actions, for example, you can perform a \texttt{Named}
% action:
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={*~@},codes={\def\1{\quad}\catcode`\%=9}]
%\OpenAction{/S/Named/N/Open}
%\end{Verbatim}
% There is a |\Named| command that expands to |/S /Named /N#1|, so the above
% example can be written
%\begin{verbatim}
% \OpenAction{\Named{Open}}
%\end{verbatim}
%\cs{opentoks} accumulates the ``action''.
% \begin{macrocode}
\def\opentoks{}
% \end{macrocode}
% The open action is really not meant for anything too fancy, such as searching using regular
% expressions. Of the special characters, we include only \cs{r} and \cs{t} for formatting
% purposes. If you want to use a regular expression in the open page action (not likely),
% put it at the document level as a JavaScript function, and call that function from the
% open page action.
% \begin{macrocode}
\def\makespecialJS{%
\let\r\jsR\let\t\jsT\let\n\jsN}
\def\@rightDelimiters{}
% \end{macrocode}
% If the next token is \cs{Next} then we gobble it up, and begin \cs{@OpenAction}
% otherwise we begin \cs{@OpenAction}. This allows the ``chaining'' as illustrated above.
% \begin{macrocode}
\def\OpenAction{\@ifnextchar\Next
{\expandafter\@OpenAction\@gobble}{\@OpenAction}}
% \end{macrocode}
% \cs{@OpenAction}: This is the macro that actually does the work. We differentiate between whether the
% current argument \texttt{\#1} is the first of all open actions, or not. If the former,
% we define it as \cs{theFirstAction}, and reset \cs{isOpenAction}, which keeps track of
% whether there has been a \textit{prior} open action defined. If the latter, we place it in
% the \cs{opentoks} token register.
% \begin{macrocode}
\def\@OpenAction#1{%
\ifx\isOpenAction\dl@NO
{\makespecialJS\xdef\theFirstAction{#1}}%
\global\let\isOpenAction\dl@YES
\else
\edef\dljstmp{\@rightDelimiters}%
\xdef\@rightDelimiters{\dljstmp >> }%
{\makespecialJS\xdef\dljstmp{\opentoks /Next << #1 }}%
\xdef\opentoks{\dljstmp}%
\fi
\@nextOpenAction
}
% \end{macrocode}
% As its last act, \cs{@OpenAction} calls \cs{@nextOpenAction}, which is nearly identical to
% \cs{OpenAction}, except if there is no \cs{Next} token, the macro terminates.
% \begin{macrocode}
\def\@nextOpenAction{\@ifnextchar\Next{\expandafter
\@OpenAction\@gobble}{}}
% \end{macrocode}
% \end{macro}
% Here is a last example that uses the \texttt{insDLJS} environment and the \cs{OpenAction} command. This code
% will cause the following action: Ten seconds after the document is opened, an annoying
% message is placed on the screen. The annoying message appears only \texttt{once}, otherwise,
% it would really be annoying. Reader (Acrobat)~5.0 is required for this code.
%\begin{verbatim}
%\begin{insDLJS}[DoIt]{doit}{DoIt}
%var timeout;
%var didIt = false;
%var myWelcome="Welcome to your PDF Page!\r\r You can remove this annoying"
% +" message by sending \u00A3100 to my Swiss bank account!"
%function startToDoIt()
%{
% if(!didIt) timeout = app.setInterval("DoIt();", 10000);
%}
%function DoIt()
%{
% app.beep(-1);
% app.alert(myWelcome,1);
% app.clearInterval(timeout);
% didIt = true;
%}
%\end{insDLJS}
%\OpenAction{/S /JavaScript /JS(startToDoIt();)}
%\end{verbatim}
% See the ``Acrobat JavaScript Object Specification'' for the definitions of some
% of these JavaScript methods.
%
%\subsubsection{\texorpdfstring{\cs{thisPageAction}}{\textbackslash{thisPageAction}}}
% \DescribeMacro{\thisPageAction} places page actions on the current page.
% The first argument is on open page action, the second one is a closed page action.
% \begin{macrocode}
\def\protectJSCtrls{\def\r{\string\r\string\n}%
\def\t{\string\t}\def\n{\string\n}}
\def\dljs@tstlp{\@ifnextchar\bgroup
{\let\dljs@multi\dl@YES\dljs@tstlpi}%
{\let\dljs@multi\dl@NO\dljs@tstlpi}}
\def\dljs@tstlpi#1\@nil{}%
% #1=arg, #2=O|C, #3=cmd
\def\dljs@bldScript#1#2#3{\bgroup
\dljs@tstlp#1\@nil
\ifx\dljs@multi\dl@NO{\protectJSCtrls\xdef#3{/#2<<#1>>}}\else
\toks0={}\let\dljs@rAngles\@empty\count0=0
\@tfor\dljs@arg:=#1\do{%
\ifnum\count0=0
\toks0=\expandafter{\dljs@arg}\else
\toks2=\expandafter{\dljs@arg}%
\edef\holdtokstmp{\the\toks0
/Next<<\the\toks2 }%
\edef\dljs@rAngles{\dljs@rAngles\space>>}%
\toks0=\expandafter{\holdtokstmp}%
\fi
\advance\count0by\@ne
}{\protectJSCtrls\xdef#3{/#2<<\the\toks0 \dljs@rAngles>>}%
\xdef#3{#3}}%
\fi
\egroup}
\newcommand{\thisPageAction}[2]{%
\let\@CloseAction\@empty
\let\@thisOpenAction\@empty
\let\@thisCloseAction\@empty
\def\dljs@argi{#1}\def\dljs@argii{#2}%
% \end{macrocode}
% On the first page, \cs{OpenAction} is used to process the open action
% \begin{macrocode}
\ifnum\value{page}=1\relax
\ifx\dljs@argii\@empty\else
\dljs@bldScript{#2}{C}{\@CloseAction}\fi
\ifx\dljs@argi\@empty\else\dljs@tstlp#1\@nil
\ifx\dljs@multi\dl@NO\OpenAction{#1}\else
\@tfor\dljs@arg:=#1\do{\expandafter
\OpenAction\expandafter{\dljs@arg}%
}\fi\fi
\else
% \end{macrocode}
% If this is not the first page, we just populate the \texttt{/O} dictionary
% \begin{macrocode}
\ifx\dljs@argi\@empty\else
\dljs@bldScript{#1}{O}{\@thisOpenAction}\fi
\ifx\dljs@argii\@empty\else
\dljs@bldScript{#2}{C}{\@thisCloseAction}\fi
\@POAction
\fi
}
% \end{macrocode}
% \subsection{The \texttt{insDLJS} Environments}
%
% \begin{macro}{insDLJS}\hypertarget{insDLJS}{}
% \begin{macro}{insDLJS*}
% This is the main environment defined by this package. These environments
% first set some global variables, then set the program flow to driver-dependent
% environments. There are two forms of this environment, the \texttt{insDLJS} and the
% \texttt{insDLJS*}.
%
% The \texttt{insDLJS} is the simplest of the two environments. Any material
% within the environment, eventually ends up in the DLJS section of the
% PDF document
%
% The environment takes the \texttt{\ameta{base\_name}} and writes the
% file \texttt{\ameta{base\_name}.djs}. This file contains a verbatim
% listing of the JS within the environment, plus some changing of
% catcodes. This file is then input back into the document at
% \cmd{\AtBeginDocument} with the necessary code for
% \textsf{pdftex} and \textsf{dvipdfm} properly place the JS.
%
% The case of \textsf{dvipsone} and \textsf{dvips} is a little different. A
% \texttt{\ameta{base\_name}.djs} is written and input back, and a second file
% \texttt{\ameta{base\_name}.fdf} is written. This second file is later input
% into the PDF document after distillation.
%
% The syntax of usage for this environment, which takes three
% arguments, is given next.\goodbreak
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={!()},codes={\def\1{\quad}\catcode`\%=9}]
%\begin{insDLJS}[!ameta(function)]{!ameta(base_name)}{!ameta(script_name)}
%!1!ameta(JavaScript functions or exposed code)
%\end{insDLJS}
%\end{Verbatim}
% where,
% \begin{description}
% \item[\texttt{\#1:}] This optional legacy parameter, its use is discouraged.
% Its value must be the name of
% one of the functions defined in the environment. This is used to
% detect whether the DLJS has already be loaded by Acrobat. This parameter
% is now automatically created.
% \item[\texttt{\#2}:] This parameter, \ameta{base\_name}, is an
% alphabetic word with no spaces and limited to eight characters. It
% is used to build the names of auxiliary files and to build the
% names of macros used by the environment.
% \item[\texttt{\#3}:] The \ameta{script\_name} of your JavaScript.
% This title will appear in the document-level JavaScript dialog of
% Acrobat.
% \end{description}
% Within the insDLJS environment, there are two types of comment characters:
% (1) a \TeX{} comment (|%|) and (2) a JavaScript comment. The JavaScript
% comments are `\texttt{//}', a line comment, and `\texttt{/*...*/}' for more
% extensive commenting. These comments will survive and be placed into the
% PDF file. In JavaScript the `|%|' is used as well, use |\%| when you want to use
% the percent character in a JavaScript statement, for example
% |app.alert("\%.2f", 3.14159);|, this statement will appear within your JavaScript
% code as |app.alert("%.2f", 3.14159);|.
% \changes{v2.2c}{2015/11/13}{Turned \string\cs{Hy@unicodefalse} so unicode is not written
% in the name of the script.}
% \begin{macrocode}
\let\insdljsloadVar\@empty
\newenvironment{insDLJS}[3][]
{%
\gdef\detectdljs{#1}\gdef\dljsBase{#2}%
\ifxetex{\def\1{\string\1}\def\2{\string2}%
\def\3{\string\3}\xdef\dljsName{#3}}\else
\Hy@unicodefalse\pdfstringdef{\dljsName}{#3}\fi
% \end{macrocode}
% If the optional argument is not passed,
% we generate one for the user.
%\changes{v2.0k}{2012/06/21}{If the optional argument is not passed,
% we generate one for the user.}
% \begin{macrocode}
\ifx\detectdljs\@empty
\stepcounter{dljs@cnt}%
\xdef\detectdljs{_bInsdljsload\arabic{dljs@cnt}}%
\edef\insdljsloadVar{var \detectdljs=true;}%
\addtocounter{dljs@cnt}{-1}%
\fi
\global\let\multisegments\dl@NO\setcounter{dljssegs}{2}%
\global\dljsobjtoks={}\expandafter
\ifx\csname dljs\dljsBase\endcsname\relax
\else\@insjserrDuplicate\fi
\ifcase\dljs@drivernum
\let\insert@DLJS\insert@DLJS@pdfmark
\let\endinsDLJS\endinsert@DLJS@pdfmark
\let\newsegment\newsegment@pdfmark
\let\endnewsegment\endnewsegment@pdfmark
\or
\let\insert@DLJS\insert@DLJS@pdftex
\let\endinsDLJS\endinsert@DLJS@pdftex
\let\newsegment\newsegment@pdftex
\let\endnewsegment\endnewsegment@pdftex
\or
\let\insert@DLJS\insert@DLJS@dvipdfm
\let\endinsDLJS\endinsert@DLJS@dvipdfm
\let\newsegment\newsegment@dvipdfm
\let\endnewsegment\endnewsegment@dvipdfm
\fi
\insert@DLJS
}{}
% \end{macrocode}
%
% The \texttt{insDLJS*} environment can be used to better organize,
% edit and debug your JavaScript. If you have the full Acrobat
% product, you can open the DLJS edit dialog. There you will see a
% listing of all DLJS contained in the document. When you double
% click on one of the \textsl{script names}, you enter the edit
% window, where you can edit all JavaScript contained under that
% name. Each \texttt{insDLJS} environment creates a new listing
% within this DLJS dialog; and, each environment creates a
% `\texttt{.djs}' file and possibly a \texttt{.fdf}' file. Each
% \texttt{insDLJS*} environment also creates a `\texttt{.djs}' file
% and possibly a `\texttt{.fdf}' file too, but within the
% \texttt{insDLJS*} environment you can create JavaScript under
% different \textsl{script names}.
%
% The syntax is
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={!()},codes={\def\1{\quad}\catcode`\%=9}]
%\begin{insDLJS*}[!ameta(function)]{!ameta(base_name)}
%\begin{newsegment}{!ameta(script_name)}
%!1!ameta(JavaScript functions or exposed code)
%\end{newsegment}
%\begin{newsegment}{!ameta(script_name)}
%!1!ameta(JavaScript functions or exposed code)
%\end{newsegment}
%...
%...
%\begin{newsegment}{<script_name>}
%!1!ameta(JavaScript functions or exposed code)
%\end{newsegment}
%\end{insDLJS*}
%\end{Verbatim}
% where,
% \begin{description}
% \item[\texttt{\#1:}] This optional parameter, \texttt{<function>},
% is \emph{required} for the \texttt{dvipsone} and \texttt{dvips}
% options; otherwise it is ignored. Its value must be the name of
% one of the functions defined in the environment. This is used to
% detect whether the DLJS has already be loaded by Acrobat.
% \item[\texttt{\#2}:] This parameter, \texttt{<base\_name>}, is an
% alphabetic word with no spaces and limited to eight characters. It
% is used to build the names of auxiliary files and to build the
% names of macros used by the environment.
% \item[\texttt{\#3}:] The \texttt{<script\_name>} of your JavaScript.
% This title will appear in the Document level JavaScript dialog of
% Acrobat.
% \end{description}
% \begin{macrocode}
\newenvironment{insDLJS*}[2][]
{%
\gdef\detectdljs{#1}\gdef\dljsBase{#2}%
% \end{macrocode}
% If the optional argument is not passed,
% we generate one for the user.
%\changes{v2.0k}{2012/06/21}{If the optional argument is not passed,
% we generate one for the user.}
% \begin{macrocode}
\ifx\detectdljs\@empty
\stepcounter{dljs@cnt}%
\xdef\detectdljs{_bInsdljsload\arabic{dljs@cnt}}%
\edef\insdljsloadVar{var \detectdljs=true;}%
\addtocounter{dljs@cnt}{-1}%
\fi
\global\let\multisegments\dl@YES\setcounter{dljssegs}{2}%
\global\dljsobjtoks={}%
\expandafter\ifx\csname dljs\dljsBase\endcsname\relax
\else\@insjserrDuplicate\fi
\ifcase\dljs@drivernum
\let\insert@DLJS\insert@DLJS@pdfmark\expandafter
\let\csname endinsDLJS*\endcsname\endinsert@DLJS@pdfmark
\let\newsegment\newsegment@pdfmark
\let\endnewsegment\endnewsegment@pdfmark
\or
\let\insert@DLJS\insert@DLJS@pdftex\expandafter
\let\csname endinsDLJS*\endcsname\endinsert@DLJS@pdftex
\let\newsegment\newsegment@pdftex
\let\endnewsegment\endnewsegment@pdftex
\or
\let\insert@DLJS\insert@DLJS@dvipdfm\expandafter
\let\csname endinsDLJS*\endcsname\endinsert@DLJS@dvipdfm
\let\newsegment\newsegment@dvipdfm
\let\endnewsegment\endnewsegment@dvipdfm
\fi
\insert@DLJS
}{}
\def\@insjserrDuplicate{%
\typeout{^^J! insdljs Package error.}
\typeout{! insDLJS environment: On line number \the\inputlineno,}
\typeout{! the base name `\dljsBase' has already been chosen.}
\typeout{! A DLJS earlier defined has been overwritten!}
\typeout{! Choose another name for the first required argument}
\typeout{! of the insDLJS environment.^^J}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \subsection{The \texttt{execJS} Environment}\label{execJS}
% This environment works only for those document authors using Acrobat 5.0 or
% Acrobat Approval. The \texttt{execJS} environment writes a verbatim \texttt{.djs} and
% \texttt{.fdf} files using the same scheme as \texttt{insDLJS} environment.
% The \texttt{.fdf} file is imported into the newly created PDF document and the JavaScript contained
% within the environments are executed.
%
% In order for the JavaScript to be imported and executed, the \texttt{execJS} must be used. The
% JavaScript is executed once, when the document is first opened in Acrobat.
%
% This feature is potentially useful for developmental purposes.
% \begin{macrocode}
\newif\ifisdljs \isdljsfalse
\begingroup
\catcode`\~=12 \catcode`\#=12
\gdef\efdlspecials{\catcode`\~=12 \catcode`\#=12}
\endgroup
\def\ckivspace#1{\if\noexpand#1\space\else\expandafter#1\fi}
% \end{macrocode}
% \changes{v2.2b}{2015/08/03}{Added a hook \string\cs{DLspecialDefs} into the DJS file}
% (2015/08/03) Added the \string\cs{DLspecialDefs} hook into the DJS file, used in
% \textsf{aeb\_pro}.
% \begin{macrocode}
\let\DLspecialDefs\@empty
\def\fdfAfterheader#1{%
\iwvo{\string\begingroup\string\efdlspecials}
\iwvo{\string\DLspecialDefs\string#1}
\iwvo{\string\isdljstrue}
\iwvo{\string\makeatletter}
\iwvo{\string\immediate\string\openout\string
\js@verbatim@out=\string\js@Path\space\dljsBase.fdf}%
\iwvo{\string\begin{jsexpverbatimwrite}}
\iwvo{\string\firstFDFline}
\iwvo{1 0 obj}
\iwvo{<< /FDF << /JavaScript << /Doc 2 0 R /After 3 0 R >> >> >> }
\iwvo{endobj}
\iwvo{2 0 obj}
% \end{macrocode}
% When a non-Distiller workflow, ensure \env{execJS}s are listed first.
% \changes{v2.2h}{2016/06/09}{When a non-Distiller workflow, ensure \string\env{execJS}s are listed first}
% \begin{macrocode}
\let\x\@empty
\applydljs{\def\x{^^Jvar _thereisdjs=true;}}%
\ifpdfmarkup
\iwvo{[ (ExecJS \dljsBase) (var _\dljsBase\space = true;\x) ] }\else
\iwvo{[ (00 ExecJS \dljsBase) (var _\dljsBase\space = true;\x)] }\fi
\iwvo{endobj}
\iwvo{3 0 obj}
\iwvo{<<>>}
\iwvo{stream}
}
% \end{macrocode}
% \begin{environment}{execJS}
% \hskip-\marginparsep\texttt{[\ameta{\cs{cmd}}]\darg{\ameta{base-name}}}
% The parameter \texttt{\#2} (\ameta{base-name}) is the base name for this environment.
% The base name will be used to create a filename to save the \texttt{.fdf} file under.
% \begin{macrocode}
% \end{macrocode}
% Added \DescribeMacro\restoreDLspecialsDefs\cs{restoreDLspecialsDefs} to restore
% \DescribeMacro\DLspecialDefs\cs{DLspecialDefs} to its default of \cs{@empty}.
% \changes{v2.4.4}{2019/07/14}{Added \string\cs{restoreDLspecialsDefs}}
% The \env{execJS} environment now has an optional argument, the optional argument must be
% a command (\ameta{\cs{cmd}}) that is then passed on to \cs{fdfAfterheader}, which then writes it to
% \cs{dljsBase.djs}. The purpose is to make special definitions at the time the script
% is expanded.
% \changes{v2.4.5}{2019/07/15}{\string\env{execJS} now has an optional argument}
% \begin{macrocode}
\def\restoreDLspecialDefs{\let\DLspecialDefs\@empty}
\newenvironment{execJS}[2][\relax]
{%
\def\x{#1}\ifx\x\@empty\def\x{\relax}\fi
\gdef\detectdljs{\string_#2}\gdef\dljsBase{#2}%
\global\dljsobjtoks={}%
\expandafter\gdef\csname dljs\dljsBase\endcsname{}%
\ifx\importdljs\dl@YES\ifx\execjs\dl@YES
\ifx\dl@gopro\dl@YES
\ifnum\dljs@drivernum=0\relax
\addImportAnFDF\importAnFDFTemplate
\else
\OpenAction{/S/JavaScript/JS (\importAnFDFTemplate)}%
\fi\fi
\fi\fi
\immediate\openout \js@verbatim@out \js@Path\dljsBase.djs
\expandafter\fdfAfterheader\expandafter{\x}%
\js@verbatimwrite
}{%
\fdfendstreamobj
\endjs@verbatimwrite
\fdftrailer
% \end{macrocode}
% Added \cs{restoreDLspecialsDefs} to restore \cs{DLspecialDefs} to its default of \cs{@empty}.
% \changes{v2.4.4}{2019/07/14}{Added \string\cs{restoreDLspecialsDefs}}
% \begin{macrocode}
\iwvo{\string\restoreDLspecialDefs}%
\closejs@verbatim@out
\expandafter\xdef\csname\dljsBase OBJ\endcsname{\the\dljsobjtoks}%
\edef\@dljstmp{\noexpand\AtBeginDocument{%
\noexpand\input{\js@Path\dljsBase.djs}}}\@dljstmp
% \end{macrocode}
%\changes{v2.2g}{2016/05/11}{Removed \string\cs{AtBeginDocument} code
%from the \string\texttt{execJS} environment. This causes problems with
%the order of \string\texttt{execJS} and \string\texttt{insDLJS}.}
%(2016/05/11) Remove the following code, seens to cause problems with
%the order of \texttt{execJS} and \texttt{insDLJS}.
%\begin{verbatim}
% \ifx\firstdljs\dl@YES
% \AtBeginDocument{\importAnFDF}%
% \global\let\firstdljs\dl@NO
% \fi
%\end{verbatim}
% \begin{macrocode}
}
% \end{macrocode}
% \end{environment}
% \subsection{The \texttt{defineJS} Environment}\label{defineJS}
% When we create a form field that has a JavaScript action attached, it would be nice
% to be able to write verbatim JavaScript code into the action. Due to the limitations
% of \TeX, this is not possible. The other possibility is to create an environment for
% writing JavaScript. This section introduced a couple of environments, the
% \texttt{defineJS} and \texttt{localJS} environments.
% \begin{environment}{defineJS}
% The \texttt{defineJS} environment takes two parameters, the first one optional.
%\begin{description}
%\item[\ttfamily\#1 = ] This optional parameter can be used to change catcodes
% before the verbatim read begins.
%\item[\ttfamily\#2 = ] The command to be defined.
%\end{description}
% The material within the environment is read verbatim and a new command by the name of \#2
% is defined.
% \changes{v2.4.2}{2019/03/16}{Changed space token to \string\cs{pdfSP} in \string\env{defineJS}}
% \begin{macrocode}
\newtoks\JStoks
% \end{macrocode}
% \leavevmode\DescribeMacro{\bParams}\hskip-\marginparsep\texttt{\darg{\ameta{token\SUB1}}\darg{\ameta{token\SUB2}}...\darg{\ameta{token\SUB{n}}}\cs{eParams}}
% The \env{defineJS} environments do not
% have parameters/arguments as a normal environment (or command) do. To enable the ability
% to modify the JavaScript code within the environment of \env{defineJS}, we introduce
% the \cs{bParams}/\allowbreak\cs{eParams} construct. When you use one of the \env{defineJS} environments
% to define field level JavaScript, you can include parameters \cs{p(1)}, \cs{p(2)}, etc., within the body
% of the environment. (Note, within the body, there is no escape character unless you change catcode of another character
% within the optional argument of the \env{defineJS} environments.)
%\begin{verbatim}
% \begin{defineJS}[\makeesc\!]{\myCode}
% var p1=!p(1), p2=!p(2);
% app.alert("p1 + p2 = " + Number(p1+p2) );
% \end{defineJS}
%\end{verbatim}
% The substitution of the parameter values does not take place until the code is expanded (\cs{myCode})
%\begin{verbatim}
% \bParams{1}{16}\eParams
% \pushButton[\A{\JS{\myCode}}]{pbfld1}{.5in}{11bp}
%\end{verbatim}
%When the button is pressed, an alert box appears and states that `\texttt{p1 + p2 = 17}'. The same code
%can be used later in another button, for example,
%\begin{verbatim}
% \bParams{77}{11}\eParams
% \pushButton[\A{\JS{\myCode}}]{pbfld2}{.5in}{11bp}
%\end{verbatim}
%Using the (new) \cs{cmd} key for \pkg{eforms}, all these declarations can be made locally:
%\begin{verbatim}
% \pushButton[\cmd{\bParams{77}{11}\eParams}
% \A{\JS{\myCode}}]{pbfld3}{.5in}{11bp}
%\end{verbatim}
% The definitions of the parameters are made using an \cs{edef} (using a control
% name, \cs{p@r@m\ameta{cnt}}, that is probably not otherwise used). This last
% command is generally accessed through \DescribeMacro\dl@param\cs{dl@param}.
% Within all
% the form fields, as defined in \pkg{eforms},
% \DescribeMacro\dl@paramlocal\cs{dl@paramlocal} is expanded within a group; it is
% also expanded within \cs{flJSStr}. Expansion of \cs{dl@paramlocal} \cs{let}s
% \cs{p} to \cs{dl@param}; hence, \cs{p(1)}, \cs{p(2)}, etc., are defined. Great
% care must be used in managing the use of this feature; if you are not careful
% an earlier definition of a parameter is used when it was not meant to be so;
% or a \cs{p(n)} is not defined.
% \begin{macrocode}
\def\dl@param(#1){\csname p@r@m#1\endcsname}
\def\dl@paramlocal{\let\p\dl@param}
% \end{macrocode}
% This command uses the counter \texttt{dljs@cnt} and the token register
% \cs{JStoks}, both of which are used elsewhere in this package; however,
% there should be no conflict in using them here.
% \begin{macrocode}
\let\eParams\relax
% \end{macrocode}
% When there is only one token, the braces, if any, get lost. To avoid
% this, we determine how many tokens there are: one or more. If only one, we
% handle separately, otherwise, we pass the flow on to \cs{bParams@i}.
% \begin{macrocode}
\def\bParams#1{\def\p@r@m{p@r@m}\c@dljs@cnt\z@
\@ifnextchar\eParams{\expandafter
\def\csname\p@r@m1\endcsname{#1}}
{\bParams@i{#1}}}
% \end{macrocode}
% The main definition of \cs{bParams}, we \cs{def\cs{p@r@m}\ameta{cnt}\darg{\ameta{token}}}
% \begin{macrocode}
\def\bParams@i#1\eParams{\@tfor\x:=#1\do{\advance\c@dljs@cnt\@ne
\JStoks=\expandafter{\x}\expandafter
\edef\csname\p@r@m\the\c@dljs@cnt\endcsname{\the\JStoks}}}
% \end{macrocode}
% \DescribeMacro{\dlcombine}\hskip-\marginparsep\texttt{(\#1)(\#2)}
% (In this discussion, it is assumed `\texttt{@}' is the escape character
% within \env{defineJS}.)
% Within the \env{defineJS} environment, spaces are obeyed; at times, we want to say
% \verb*|@currQuiz MyField|, for example, which within \env{defineJS} gets expanded to
% \verb*|q1 MyField|, not \texttt{q1MyField} as it should be. To solve this and other
% problems like it, use \verb|@dlcombine(@currQuiz)(MyField)| which does expand
% to the intended expression.
% \changes{v2.4.3}{2019/06/27}{Added \string\cs{dlcombine}}
% \begin{macrocode}
\def\dlcombine(#1)(#2){#1#2}
% \end{macrocode}
% \DescribeMacro{\dlcontig}\hskip-\marginparsep\texttt{(\#1)} Perhaps a better method than
% just described (\cs{dlcombine}) is to have a single argument delimited by parentheses.
% Thus |@currQuiz@dlcontig(MyField)| also produces \texttt{q1MyField}.
% \begin{macrocode}
\def\dlcontig(#1){#1}
% \end{macrocode}
% When you declare a character to be an escape within the optional argument of \env{defineJS},
% that character may be needed in the code; for example if we declare |\makeesc\!|, and
% within the JavaScript code we have \texttt{if (x != 0 )...}, the JavaScript
% code is broken. As a fix for this problem, you can declare \DescribeMacro\escIs|\escIs{!}|,
% which in turn defines \DescribeMacro\Eschr\cs{Eschr} to expand to `\texttt!'. The above code
% may then be written as \texttt{if (x !Eschr= 0 )...}; messy, but it works. The lines
% below are the recommended method of declaring \cs{escIs}:
%\begin{verbatim}
% \pushButton[\cmd{\escIs{!}\bParams{77}{11}\eParams}
% \A{\JS{\myCode}}]{pbfld2}{.5in}{11bp}
%\end{verbatim}
% These declarations make everything local to the group within which the button is built.
% \begin{macrocode}
\def\escIs#1{\def\Eschr{#1}}
% \end{macrocode}
% \DescribeMacro\makeesc\hskip-\marginparsep\texttt{\cs{\ameta{char}}}
% \cs{dl@makeesc} is a helper command that sets the escape character,
% Within the \env{defineJS} environments, it is \cs{let} to \cs{makeesc};
% eg, |\makeesc\!|.
% \changes{v2.4.3}{2019/06/27}{Added \string\cs{dl@makeesc}}
% \begin{macrocode}
\def\dl@makeesc#1{\catcode`#1=0\relax}
% \end{macrocode}
% \DescribeMacro\makecmt\hskip-\marginparsep\texttt{\cs{\ameta{char}}} Likewise,
% you can conviently declare the comment character, if any; eg, |\makecmt\%|.
% \changes{v2.4.10}{2020/11/28}{Added \string\cs{dl@makecmt}}
% \begin{macrocode}
\def\dl@makecmt#1{\catcode`#1=14\relax}
% \end{macrocode}
% \paragraph*{Incorporating {\LaTeX} conditionals in \env{defineJS}.} {\LaTeX} conditionals
% need to be handled carefull so as not to produce any specious spaces. Normally, there is
% a comment character declared (|\makecmt\%|). Use the comment character to suppress the beginning
% of a new line until it is known whether there is content on that next line. Eg,
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={!()},codes={\def\1{\quad}\catcode`\%=9}]
%\begin{defineJS}[\makeesc\*\makecmt\!%]{\X}
%var w=1;!%
%*ifx*Y*@empty*else
%var x=1;
%var y=1;*fi
%var z=1;
%\end{defineJS}
%\end{Verbatim}
%When \cs{Y} is empty, the content expands to,
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={!()},codes={\def\1{\quad}\catcode`\%=9}]
%var w=1;
%var z=1;
%\end{Verbatim}
%and when \cs{Y} is nonempty, it expands to,
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%commandchars={!()},codes={\def\1{\quad}\catcode`\%=9}]
%var w=1;
%var x=1;
%var y=1;
%var z=1;
%\end{Verbatim}
% The following two commands are no longer used by this package.
% \changes{v2.4.8}{2019/10/30}{Added \string\cs{dlgobToFi} to help format
% \string\env{defineJS} code}
% \begin{macrocode}
\def\dlgobToFi#1\fi{\fi\defjsLB}
\let\gobiv\@gobblefour
% \end{macrocode}
% \textbf{Typesetting content with the \cs{typeset} keyword macro.}
% To aid typesetting the contents of a \env{defineJS} environment,
% the keyword macro \DescribeMacro{\typeset}\cs{typeset}, which is defined only within the environment,
% can be used. Pass \cs{typeset} to \env{defineJS} through the optional argument.
% \changes{v2.5}{2020/12/20}{Added the command \string\cs{typeset} to typeset the
% contents of the \string\env{defineJS} environment}
% \begin{macrocode}
\newif\ifdlfortypeset \dlfortypesetfalse
% \end{macrocode}
% The macro \cs{dl@typesetthis} defined here, is the external version of the local command
% \cs{typeset}. It globally sets the switch \cs{ifdlfortypeset} to true and defines the value
% of \cs{dfnJSR} and the legacy command \cs{defineJSjsR}. For \cs{dfnJSCR}, we use only {\TeX}
% primitives to maintain compatibility with the now defunct YandY System, which I still use.
% \begin{macrocode}
\def\dl@typesetthis{\global\dlfortypesettrue
\dfnJSCR{\hfil\break\null}}
% \end{macrocode}
% Next, we define some components common to all define-js environments. First, we initialize
% the environment with several \cs{let}s.
% \begin{macrocode}
\def\@initdfnJS{\let\jsFrstLne\dl@One\let\makeesc\dl@makeesc
\let\makecmt\dl@makecmt\let\typeset\dl@typesetthis}
% \end{macrocode}
% (2020/12/20) Insert \cs{defineJSJsR} (an alias of \cs{dfnJSR}) at the \emph{beginning} of the second line
% onward. This gives better formatting of the code within the editor, without
% an empty final line.
% \changes{v2.5}{2020/12/20}{Modified \string\cs{verbatim@line} in \string\env{defineJS}}
% \begin{macrocode}
\def\@vrbsetupdfnJS{\def\verbatim@processline{\ifx\jsFrstLne\dl@One
\let\jsFrstLne\dl@Zero
\xdef\JS@temp{\the\JStoks\the\verbatim@line}\else
\xdef\JS@temp{\the\JStoks\defineJSjsR\the\verbatim@line}\fi
\global\JStoks=\expandafter{\JS@temp}}%
\let\do\@makeother\dospecials\catcode`\^^M\active}
% \end{macrocode}
% We \cs{let} \cs{space} to \cs{pdfSP}, and declare \cs{obeyspaces}, in this way, the space
% character is active and is equal to \cs{040} (space). Start the verbatim environment.
% We expand \cs{obeyspaces} only if \cs{pdfSpacesOn} is in effect.
% \changes{v2.5.2}{2021/02/07}{Modify \string\cs{b@vrbdfnJS}, remove \string\cs{global}
% on \string\cs{let}}
% \begin{macrocode}
\def\b@vrbdfnJS#1{\ifpdfspaces\let\space\pdfSP
\makeatletter\obeyspaces\fi%
% \end{macrocode}
% Pass the first argument here. If this environment is for typesetting,
% initialize the tokens \cs{JStoks} to be in a group, and such. The insertion
% of \cs{dl@paramlocal} is to support the \cs{bParams}/\allowbreak\cs{eParams} construct.
% \begin{macrocode}
#1\ifdlfortypeset%
\global\JStoks={\bgroup\leavevmode\dl@paramlocal}\fi%
\verbatim@start}
% \end{macrocode}
% The end of the environment code
% \begin{macrocode}
\def\e@vrbdfnJS{\gdef\eq@JStemp{\ifdlfortypeset\global
\JStoks=\expandafter{\the\JStoks\egroup}\fi\expandafter
\edef\defineJSArg{\the\JStoks}\global
\dlfortypesetfalse}\global\let\space\dl@sp@ce\aftergroup\eq@JStemp}
% \end{macrocode}
% Finally, we get to the definition of \env{defineJS}, and its compatriates.
% \begin{macrocode}
\newenvironment{defineJS}[2][]{\@initdfnJS
\expandafter\@ifundefined\expandafter{%
\expandafter\@gobble\string#2}{}{\PackageWarning{insdljs}
{The command \string#2 already defined}}%
\gdef\defineJSArg{#2}\global\JStoks={}%
\@vrbsetupdfnJS
\b@vrbdfnJS{#1}}{\e@vrbdfnJS}
% \end{macrocode}
% \end{environment}
% \begin{environment}{@defineJS}
% Silent version of \texttt{defineJS}, can repeatedly be used to redefine the same
% macro. Note: |\makeesc\@| cannot be declared with the \env{@defineJS} environment.
% \begin{macrocode}
\newenvironment{@defineJS}[2][]{\@initdfnJS
\gdef\defineJSArg{#2}\global\JStoks={}%
\@vrbsetupdfnJS
\b@vrbdfnJS{#1}}{\e@vrbdfnJS}
% \end{macrocode}
% \end{environment}
% \begin{environment}{defineJS*}
% A silent public version of \env{defineJS}.
% The \env{defineJS*} environment cannot use |\makeesc\*| in its optional argument.
% \changes{v2.4.2}{2019/03/16}{define \string\env{defineJS*} a public version of \string\env{@defineJS}}
% \begin{macrocode}
\newenvironment{defineJS*}[2][]{\@initdfnJS
\gdef\defineJSArg{#2}\global\JStoks={}%
\@vrbsetupdfnJS
\b@vrbdfnJS{#1}}{\e@vrbdfnJS}
% \end{macrocode}
% \end{environment}
% An author might want these definitions to be local in definition, so the
% \texttt{localJS} environment is supplied.
% \begin{environment}{localJS}
% This environment does nothing more than to enclose the material
% in \cs{begingroup} and \cs{endgroup}.
% \begin{macrocode}
\newenvironment{localJS}[1][]{}{\ifvmode\else\unskip\fi}
% \end{macrocode}
% \end{environment}
%
% \subsection{Set Document Actions}
% We provide simple environments for writing document actions.
% \begin{environment}{willClose}
% Execute a script just before closing the document.
% \begin{environment}{willSave}
% Execute script just before a save.
% \begin{environment}{didSave}
% Execute a script just after a save
% \begin{environment}{willPrint}
% Execute a script just before a print job
% \begin{environment}{didPrint}
% Execute a script just after a print job
% \begin{macrocode}
\newenvironment{willClose}[1][]
{\@defineJS[#1]{\will@Close}}
{\end@defineJS}
\let\will@Close\@empty
\newenvironment{willSave}[1][]
{\@defineJS[#1]{\will@Save}}
{\end@defineJS}
\let\will@Save\@empty
\newenvironment{didSave}[1][]
{\@defineJS[#1]{\did@Save}}
{\end@defineJS}
\let\did@Save\@empty
\newenvironment{willPrint}[1][]
{\@defineJS[#1]{\will@Print}}
{\end@defineJS}
\let\will@Print\@empty
\newenvironment{didPrint}[1][]
{\@defineJS[#1]{\did@Print}}
{\end@defineJS}
\let\did@Print\@empty
\def\dljs@willDidActions{/AA <<
\ifx\test@will@Close\@empty\else/WC <<
\JS{\will@Close} >>\fi
\ifx\test@will@Save\@empty\else/WS <<
\JS{\will@Save} >>\fi
\ifx\test@did@Save\@empty\else/DS <<
\JS{\did@Save} >>\fi
\ifx\test@will@Print\@empty\else/WP <<
\JS{\will@Print} >>\fi
\ifx\test@did@Print\@empty\else/DP <<
\JS{\did@Print} >>\fi
>>
}
\newcommand\dljs@setDocActions{%
\edef\test@will@Close{\will@Close}%
\edef\test@will@Save{\will@Save}%
\edef\test@did@Save{\did@Save}%
\edef\test@will@Print{\will@Print}%
\edef\test@did@Print{\did@Print}%
% \end{macrocode}
% Driver dependent code to put any document actions into the additional actions
% dictionary of the document catalog.
% \begin{macrocode}
\ifpdf\pdfcatalog{\dljs@willDidActions}\else
\ifxetex\immediate
\special{pdf:put @catalog <<\dljs@willDidActions>>}\else
\literalps@out{\AEB@psMrk
{Catalog} <<\dljs@willDidActions>> /PUT pdfmark}\fi\fi
}
\@ifpackageloaded{aeb_pro}{}
{\AtBeginDocument{\dljs@setDocActions}}
% \end{macrocode}
% \end{environment}
% \end{environment}
% \end{environment}
% \end{environment}
% \end{environment}
%
% \subsection{For \texttt{dvipsone}/\texttt{dvips}}
% The method of automatic insertion of document level JavaScript is to
% write an FDF file (Forms Data Format), then import this FDF into the
% document using the JavaScript method \texttt{Doc.importAnFDF()}.
%
% We break the FDF file into three parts: the \cmd{\fdfheader} (the stuff prior
% to the JavaScript code); the JavaScript code itself; and the
% \cmd{\fdftrailer}, the stuff that follows the code.
% \begin{macrocode}
\begingroup
\catcode`\%=12
\gdef\firstFDFline{%FDF-1.2}
\gdef\lastFDFline{%%EOF}
\endgroup
\def\fdfheader
{%
\iwvo{\string\begingroup\string\efdlspecials}
\iwvo{\string\isdljstrue}
\iwvo{\string\makeatletter}
\iwvo{\string\immediate\string\openout\string
\js@verbatim@out=\string\js@Path\space\dljsBase.fdf}%
\iwvo{\string\begin{jsexpverbatimwrite}}
\iwvo{\string\firstFDFline}
\iwvo{1 0 obj}
\iwvo{<< /FDF << /JavaScript << /Doc 2 0 R >> >> >>}
\iwvo{endobj}
\iwvo{2 0 obj}
\iwvo{[ \string\csname\string\@gobble\space\dljsBase%
OBJ\string\endcsname]}
\iwvo{endobj}
}
\def\fdfbeginstreamobj
{%
\iwvo{\thedljssegs\space 0 obj}
\iwvo{<<>>}
\iwvo{stream}
\applydljs{\iwvo{var _thereisdjs=true;}}
% \end{macrocode}
% If the user has not passed the optional
% name, we generated one for him, now we insert it into the \texttt{stream}.
%\changes{v2.0k}{2012/06/21}{If the user has not passed the optional
% name, we generated one for him, now we insert it into the \string\texttt{stream}.}
% \begin{macrocode}
\ifx\insdljsloadVar\@empty\else
\iwvo{\insdljsloadVar}
\global\let\insdljsloadVar\@empty\fi
}
\def\fdfendstreamobj{%
\iwvo{endstream}
\iwvo{endobj}
}
\def\fdftrailer{%
\iwvo{trailer}
\iwvo{<< /Root 1 0 R >>}
\iwvo{\string\lastFDFline}
% \end{macrocode}
% Here we write \texttt{*end{jsexpverbatimwrite}} as a signal for our modified verbatim write
% code to stop.
% \begin{macrocode}
\iwvo{*end{jsexpverbatimwrite}}
\iwvo{\string\endgroup}
}
% \end{macrocode}
% There may be more than one use of the \texttt{insDLJS}
% environment and we need to be able to import each of the resultant
% FDF files. The \cmd{\importfdftoks} accumulates material to be
% used after all chance for the user to insert JS code has been
% exhausted.
% \begin{macrocode}
\newtoks\importfdftoks \importfdftoks={}
\newtoks\dljsobjtoks \dljsobjtoks={}
% \end{macrocode}
% This is a template for detecting whether the DLJS has been imported into
% the document.
% \begin{macrocode}
\def\importAnFDFTemplate{%
if(typeof \detectdljs\space == "undefined")\jsR\jsT
% \end{macrocode}
% Beginning with Acrobat 8.1, the \texttt{Doc.importAnFDF} has additional security. We must call
% it through a trusted function which is in the file aeb.js, which resides in the user JavaScript folder.
%\changes{v2.0h}{2006/10/03}
%{
% Created aeb.js, which must be installed for users of distiller. The importAnFDF method is now called
% through a trusted function.
%}
% \begin{macrocode}
( app.viewerVersion > 8 ) ? %
aebTrustedFunctions( this, aebImportAnFDF, %
"\js@Path\dljsBase.fdf") : %
this.importAnFDF("\js@Path\dljsBase.fdf");\jsR
}
% \end{macrocode}
% Add in another template into \cmd{\importfdftoks}.
% \begin{macrocode}
\def\addImportAnFDF#1{%
\ifx\importdljs\dl@YES
\edef\importAnFDFtmp{\the\importfdftoks#1}%
\global\importfdftoks=\expandafter{\importAnFDFtmp}\fi
}
% \end{macrocode}
% This is used by \texttt{insert@DLJS@pdfmark} and is placed
% \cmd{\AtBeginDocument}.
% \begin{macrocode}
\def\importAnFDF{\ifx\importdljs\dl@YES\@OAction\fi}
% \end{macrocode}
% The \texttt{insert@DLJS@pdfmark} environment writes the \cmd{\dljsBase.djs} file
% which is in turn input back in, and rewritten as \cmd{\dljsBase.fdf}. This is
% necessary to give the user a chance to modify the JavaScript code in an
% authorized way.
% \begin{macrocode}
\newenvironment{newsegment@pdfmark}[1]{%
\addtocounter{dljssegs}{1}\addtocounter{dljs@cnt}{1}%
\Hy@unicodefalse\pdfstringdef{\dljsName}{#1}%
\edef\@dljstmp{\the\dljsobjtoks(\dljsName)
\thedljssegs\space 0 R\space}%
\global\dljsobjtoks=\expandafter{\@dljstmp}%
\fdfbeginstreamobj
\js@verbatimwrite
}{%
\fdfendstreamobj
\endjs@verbatimwrite
}
\def\insert@DLJS@pdfmark{%
\global\let\dljspresent\dl@YES
\expandafter\gdef\csname dljs\dljsBase\endcsname{}%
\ifx\importdljs\dl@YES\ifx\dl@gopro\dl@YES
\addImportAnFDF\importAnFDFTemplate\fi\fi
\immediate\openout \js@verbatim@out \js@Path\dljsBase.djs
\fdfheader
\ifx\multisegments\dl@NO\expandafter
\newsegment\expandafter{\expandafter\dljsName\expandafter}\fi
}
\def\endinsert@DLJS@pdfmark{%
\ifx\importdljs\dl@YES
\ifx\multisegments\dl@NO\expandafter\endnewsegment\fi
\fdftrailer
\closejs@verbatim@out
\expandafter\xdef\csname\dljsBase%
OBJ\endcsname{\the\dljsobjtoks}%
\edef\@dljstmp{\noexpand\AtBeginDocument{%
\noexpand\input{\js@Path\dljsBase.djs}}}%
\@dljstmp
\ifx\firstdljs\dl@YES
\AtBeginDocument{\edef\@dljstmp{\importAnFDF}%
\@dljstmp}\global\let\firstdljs\dl@NO
\fi
\fi
}
% \end{macrocode}
%
% \subsection{For \texttt{pdftex}/\texttt{dvipdfm}}
%
% Again, we break the problem of creating DLJS into four parts: \cmd{\begindljs},
% \cmd{\enddljs}, the code itself, driver dependent material, \cmd{\write@pdftex@obj}
% and \cmd{\write@dvipdfm@obj}.
%
% The following is used by both \texttt{pdftex} and \texttt{dvipdfm}.
% \begin{macrocode}
\begingroup
\catcode`\@=0 @catcode`@\=12
@gdef@ccpdftex{@gdef@eqesc{\\}@gdef@eqesci{\}}
@endgroup
\def\begindljs
{%
\iwvo{\string\begingroup\string\efdlspecials}
\iwvo{\string\isdljstrue}
% \end{macrocode}
%\changes{v2.2f}{2016/05/07}{Include \string\cs{makeletter} in verbatim write}
% \begin{macrocode}
\iwvo{\string\makeatletter}
{\uccode`c=`\%\uppercase{%
\iwvo{\string\obeyspaces\string\obeylines
\string\let\string^\string^M=\string\jsR c}}}
{\escapechar=-1 \lccode`C=`\%\lowercase{%
\iwvo{\string\\catcode`\string\\"=12C}}}
}
\def\beginseg{%
{\lccode`P=`\{\lccode`C=`\%\lowercase{%
\iwvo{\string\gdef\string\dljs\dljsBase\roman{dljssegs}PC}}}%
\applydljs{\iwvo{var _thereisdjs=true;}}%
}
% \end{macrocode}
% With \cs{enddsljs}, we now finish the macro definition with a closing right brace, followed by a
% comment, `\texttt\%, and an end of group.
% \begin{macrocode}
\def\endseg{{\uccode`c=`\%\uccode`p=`\}\uppercase{\iwvo{pc}}}}
\def\enddljs{\iwvo{\string\endgroup}}
% \end{macrocode}
%\changes{v2.0j}{2011/06/27}{made some changes as suggested by Christian Feuersaenger, who reported some
% problem clashes between \string\textsf{babel} (spanish) and \string\textsf{insdljs}.}
% \begin{macrocode}
\def\@roman#1{\romannumeral#1}
\def\write@objs{%
\iwvo{\begingroup}
\iwvo{\string\catcode`\string\<=12 }
\iwvo{\string\catcode`\string\>=12 }
{\lccode`C=`\%\lowercase{\iwvo{\string\ccpdftex C}}}
{\lccode`C=`\%\lowercase{\iwvo{%
\string\input{dljscc.def}C\the\dljsobjtoks}}}
\iwvo{\endgroup}
}
% \end{macrocode}
% \subsubsection{\texttt{pdftex} Specific Code}
% \begin{macrocode}
\newenvironment{newsegment@pdftex}[1]{%
\addtocounter{dljssegs}{1}%
\addtocounter{dljs@cnt}{1}%
\edef\tmp{^^J\string\immediate\string\pdfobj{ << /S/JavaScript/JS%
(\string\dljs\dljsBase\roman{dljssegs}) >> }}%
\edef\@dljstmp{\the\dljsobjtoks\tmp}%
\global\dljsobjtoks=\expandafter{\@dljstmp}%
\edef\tmp{^^J\string\xdef\string\obj\dljsBase\roman{dljssegs}%
{\string\the\string\pdflastobj\string\space 0 R}}%
\edef\@dljstmp{\the\dljsobjtoks\tmp}%
\global\dljsobjtoks=\expandafter{\@dljstmp}%
\edef\curr@Cnt{\ifnum\arabic{dljs@cnt}<10 0\fi\arabic{dljs@cnt}}%
\Hy@unicodefalse\pdfstringdef{\dljsName}{#1}%
\edef\dljspdftextmp
{\the\importfdftoks (\curr@Cnt\space\dljsName)
\noexpand\csname obj\dljsBase\roman{dljssegs}%
\noexpand\endcsname\space}%
\global\importfdftoks=\expandafter{\dljspdftextmp}%
\beginseg
\js@verbatimwrite
}{%
\endjs@verbatimwrite
\endseg
}
% \end{macrocode}
% The main branch of the \texttt{insDLJS} for \texttt{pdftex}. This
% environment writes to the file \cmd{\dljsBase.djs} all the necessary code, then
% is input back into the file using \cmd{\AtBeginDocument}.
% \begin{macrocode}
\newenvironment{insert@DLJS@pdftex}{%
\expandafter\gdef\csname dljs\dljsBase\endcsname{}%
\immediate\openout \js@verbatim@out \js@Path\dljsBase.djs
\begindljs
\ifx\multisegments\dl@NO\expandafter
\newsegment\expandafter{\expandafter\dljsName\expandafter}\fi
}{%
\ifx\multisegments\dl@NO\expandafter\endnewsegment\fi
\enddljs
\write@objs
\endjs@verbatimwrite
\closejs@verbatim@out
\edef\@dljstmp{\noexpand\AtBeginDocument{%
\noexpand\input{\js@Path\dljsBase.djs}}}%
\@dljstmp
\ifx\importdljs\dl@YES
\ifx\firstdljs\dl@YES
\AtEndDocument{\edef\@dljstmp{\setDLJSRef@pdftex}\@dljstmp}
\global\let\firstdljs\dl@NO
\fi
\fi
}
% \end{macrocode}
% This code places the \texttt{/JavaScript} key-value in the \texttt{/Names} dictionary
% of the PDF document. This code is inserted into the document in \texttt{insert@DLJS@pdftex}
% using \cmd{\AtEndDocument}.
% \begin{macrocode}
\def\setDLJSRef@pdftex{\noexpand
\immediate\noexpand\pdfobj {%
<< /Names [\the\importfdftoks] >> }%
\edef\noexpand\objNames{\noexpand\the\noexpand\pdflastobj\space 0 R}%
\pdfnames {/JavaScript \noexpand\objNames}%
}
% \end{macrocode}
% \subsubsection{\texttt{dvipdfm} Specific Code}
% Begin by writing driver-specific code to \cmd{\dljsBase.djs}.
% \begin{macrocode}
\newenvironment{newsegment@dvipdfm}[1]
{%
\addtocounter{dljssegs}{1}\addtocounter{dljs@cnt}{1}%
\edef\tmp{^^J\string\immediate\string
\csname\space @pdfm@mark\string\endcsname
{obj @obj\dljsBase\roman{dljssegs}\space << /S/JavaScript%
/JS(\string\dljs\dljsBase\roman{dljssegs}) >> }}%
\edef\@dljstmp{\the\dljsobjtoks\space\tmp}%
\global\dljsobjtoks=\expandafter{\@dljstmp}%
\edef\curr@Cnt{\ifnum\arabic{dljs@cnt}<10 0\fi\arabic{dljs@cnt}}%
{\def\1{\string\1}\def\2{\string2}%
\def\3{\string\3}\xdef\dljsName{#1}}%
\edef\dljspdftextmp
{\the\importfdftoks (\curr@Cnt\space \dljsName) %
@obj\dljsBase\roman{dljssegs}\space}%
\global\importfdftoks=\expandafter{\dljspdftextmp}%
\beginseg
\js@verbatimwrite
}{%
\endjs@verbatimwrite
\endseg
}
% \end{macrocode}
% This code places the \texttt{/JavaScript} key-value in the \texttt{/Names} dictionary
% of the PDF document. This code is inserted into the document in \texttt{insert@DLJS@dvipdfm}
% using \cmd{\AtEndDocument}.
% \begin{macrocode}
\def\setDLJSRef@dvipdfm
{%
\immediate\special{pdf:obj @objnames %
<< /Names [\the\importfdftoks] >> }%
\special{pdf:put @names %
<< /JavaScript @objnames >> }%
}
% \end{macrocode}
% The main branch of the \texttt{insDLJS} for \texttt{dvipdfm}. This
% environment writes to the file \cmd{dljsBase.djs} all the necessary code, then
% is input back into the file using \cmd{\AtBeginDocument}.
% \begin{macrocode}
\newenvironment{insert@DLJS@dvipdfm}
{%
\expandafter\gdef\csname dljs\dljsBase\endcsname{}%
\immediate\openout \js@verbatim@out \js@Path\dljsBase.djs
\begindljs
\ifx\multisegments\dl@NO\expandafter\newsegment\expandafter{%
\expandafter\dljsName\expandafter}\fi
}{%
\ifx\multisegments\dl@NO\expandafter\endnewsegment\fi
\enddljs
\write@objs
\endjs@verbatimwrite
\closejs@verbatim@out
\edef\@dljstmp{\noexpand\AtBeginDocument{%
\noexpand\input{\js@Path\dljsBase.djs}}}%
\@dljstmp
\ifx\importdljs\dl@YES
\ifx\firstdljs\dl@YES
% \end{macrocode}
% 2012/06/09 Changed positioning of \cmd{\setDLJSRef@dvipdfm}.
% \begin{macrocode}
\AtBeginDocument{\setDLJSRef@dvipdfm}%
\global\let\firstdljs\dl@NO
\fi
\fi
}
\catcode`\"=\dl@dquoteCat
%</package>
% \end{macrocode}
% \begin{macrocode}
%<*cc4js>
% \end{macrocode}
%\section{Command Changes for JavaScript}\label{dljscc}
% Regular expressions are a very important part of JavaScript, but they do present
% some problems for \LaTeX. Ideally, we would like to type JavaScript code into the
% \texttt{insDLJS} environment using standard JavaScript syntax.
% (Whether I am successful remains to be seen.) As a result, some new definitions
% and changes in old definitions are necessary. All definitions take place within a
% group, so they are unknown outside the \texttt{insDLJS} environment.
%
%\subsection{Regular Expressions}
% Regular expressions can be constructed in two ways, by using (1) a literal text format; or (2)
% using the \texttt{RegExp} constructor function. The literal text format:
%\begin{flushleft}
%\texttt/\textsl{pattern}\texttt/\textsl{flags}
%\end{flushleft}
% The \texttt{RegExp} constructor method:
%\begin{flushleft}\ttfamily
%new RegExp("\textsl{pattern}" [, "\textsl{flags}"])
%\end{flushleft}
% For additional details on regular expressions, see
%\begin{flushleft}\small
%\url{http://developer.netscape.com/docs/manuals/js/core/jsref15/regexp.html}
%\end{flushleft}
% There is a further complication when dealing with regular expressions. To quote from the above
% document:\par\medskip\noindent
% \textbf{Description }
% When using the constructor function, the normal string escape rules (preceding special characters with `|\|' when included in a string) are necessary.
% For example, the following are equivalent:
% \begin{flushleft}
% \ttfamily\obeylines
% re = new RegExp("\string\\w+")
% re = /\string\w+/
%\end{flushleft}
%\subsection{Begin Definitions}
% \subsubsection{Handling of Formatting Sequences}
% The macro \cmd{\eqesc} expands to `|\|' in the case of the distiller and to `|\\|' in the
% case of \textsf{pdftex} or \textsf{dvipdfm}. This group of special characters formats the
% output and they require a different definition than most of the others.
%
% The \cs{ckivspace} (``check for space'') macro sees whether the next token is a space,
% if yes, it absorbs it, if not, it replaces it. I implemented this in order to get
% final output identical to the JavaScript. For example, the following is legal JavaScript:
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%codes={\def\1{\quad}\catcode`\%=9}]
%var str = "First line.\r\rSkip a line. // (1)
%\end{Verbatim}
% This is a problem for \TeX. In order to delimit the macro, \TeX{} users need to write the
% above line as,
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%codes={\def\1{\quad}\catcode`\%=9}]
% var str = "First line.\r\r Skip a line. // (2)
%\end{Verbatim}
% which then introduces a spurious space into the JavaScript code. The \cs{ckivspace} solves this
% problem, I hope. With the definition of \cs{r} given below, after expansion of the line (2)
% occurs, we have line (1), the space following the second \cs{r} gets absorbed. Note: (2014/05/20)
% I moved this to the main code thread of \textsf{insdljs}.
% \changes{v2.0n}{2014/05/20}{Moved code for \string\cs{ckivspace} to main code thread of \string\textsf{insdljs}.}
% \begin{macrocode}
%\def\ckivspace#1{\if\noexpand#1\space\else\expandafter#1\fi}
% \end{macrocode}
% \begin{macro}{\r}
% Matches a carriage return.
% \begin{macrocode}
\def\r{\eqesc r\ckivspace}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\t}
% Matches a tab.
% \begin{macrocode}
\def\t{\eqesc t\ckivspace}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\n}
% Matches a linefeed.
% \begin{macrocode}
\def\n{\eqesc n\ckivspace}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\f}
% Matches a form-feed.
% \begin{macrocode}
\def\f{\eqesc f\ckivspace}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\v}
% Matches a form-feed.
% \begin{macrocode}
\def\v{\eqesc v\ckivspace}
% \end{macrocode}
% \end{macro}
% \subsubsection{Matching a Word Boundary or Not}
% \begin{macro}{\b}
% Matches a word boundary, such as a space. (Not to be confused with |[\b]|, which
% matches a backspace.)
% \begin{macrocode}
\def\b{\eqesc b\ckivspace}
% \end{macrocode}
% \end{macro}
% The next group are all defined in the same way, pretty much. The macro \cmd{\eqesc} expands to `|\|'
% in the case of the distiller options, and to `|\\\|' otherwise.
% \begin{macro}{\B}
% Matches a non-word boundary.
% \begin{macrocode}
\def\B{\eqesc B\ckivspace}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\cX}
% Where X is a letter from A - Z. Matches a control character in a string. Doesn't seem to have
% much use in Acrobat JavaScript, will comment this one out. Usage: \cs{cM}
% \begin{macrocode}
% \def\doAlpha{\do A\do B\do C\do D\do E\do F%
% \do G\do H\do I\do J\do K\do K\do M\do N%
% \do O\do P\do Q\do R\do S\do T\do U\do V\do W\do X\do Y\do Z}
% \def\mkDefns#1{\expandafter\def\csname c#1\endcsname{\eqesc c#1}}
% \let\do=\mkDefns\doAlpha
% \end{macrocode}
% \end{macro}
% \subsubsection{Matching Digits or Not}
% \begin{macro}{\d}
% Matches a digit character. Equivalent to \texttt{[0-9]}.
% \begin{macrocode}
\def\d{\eqesc d\ckivspace}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\D}
% Matches any non-digit character. Equivalent to |[^0-9]|.
% \begin{macrocode}
\def\D{\eqesc D\ckivspace}
% \end{macrocode}
% \end{macro}
%\subsubsection{Matching Whitespaces or Not}
% \begin{macro}{\s}
% Matches a single white space character, including space, tab, form feed, line feed.
% Equivalent to |[\f\n\r\t\u00A0\u2028\u2029]|.
% \begin{macrocode}
\def\s{\eqesc s\ckivspace}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\S}
% Matches a single character other than white space.\newline
% Equivalent to |[^ \f\n\r\t\u00A0\u2028\u2029]|.
% \begin{macrocode}
\def\S{\eqesc S\ckivspace}
% \end{macrocode}
% \end{macro}
%\subsubsection{Matching Alphanumeric Characters or Not}
% \begin{macro}{\w}
% Matches any alphanumeric character including the underscore. Equivalent to |[A-Za-z0-9\_]|.
% \begin{macrocode}
\def\w{\eqesc w\ckivspace}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\W}
% Matches any non-word character. Equivalent to |[^A-Za-z0-9_]|.
% \begin{macrocode}
\def\W{\eqesc W\ckivspace}
% \end{macrocode}
% \end{macro}
% \subsubsection{Handling of Character Codes}
% \begin{macro}{\xXX}
% Matches the character with the code \texttt{XX} (two hexadecimal digits).
% The character with the Latin-1 encoding specified by the two hexadecimal digits \texttt{XX}
% between 00 and FF. For example, \cs{xA9} is the hexadecimal sequence for the copyright
% symbol.
%\begin{flushleft}
%\textbf{Usage}
%\begin{verbatim}
%\x9A
%\end{verbatim}
%if the most significant digit is a number \texttt{[0-9]},
%\begin{verbatim}
%\x A9
%\end{verbatim}
%if the most significant digit is a letter \texttt{[a-fA-F]}
%\end{flushleft}
%\changes{v2.3b}{2016/10/13}{JPC reported bug with French-Babel, traced it to this code.}
%To avoid a French-Babel clash (reported by JPC), we change \cs{catcode} of colon (:) to other, enclose in a group
%and do \cs{xdef} instead of \cs{edef}.
% \begin{macrocode}
\begingroup
\catcode`\:=12\relax
\dljstfor\dlhex:={AA}{AB}{AC}{AD}{AE}{AF}%
{BA}{BB}{BC}{BD}{BE}{BF}{CA}{CB}{CC}{CD}{CE}{CF}%
{DA}{DB}{DC}{DD}{DE}{DF}{EA}{EB}{EC}{ED}{EE}{EF}%
{FA}{FB}{FC}{FD}{FE}{FF}\do{%
\expandafter\xdef\csname x\dlhex\endcsname{\noexpand\eqesc x\dlhex}%
}
\endgroup
% \end{macrocode}
% \end{macro}
% \begin{macro}{\uXXXX}
% In a regular expression search, \cs{uXXXX} matches the character
% with unicode character code \texttt{XXXX} (four hexadecimal
% digits). For example, \cs{u00A9} is the Unicode sequence for the
% copyright symbol. See Unicode Escape Sequences. http://www.unicode.org
%\begin{flushleft}
%\textbf{Usage}
%\begin{verbatim}
%\u00A9
%\end{verbatim}
%if the most significant digit is a number \texttt{[0-9]},
%\begin{verbatim}
%\u F0A9
%\end{verbatim}
%if the most significant digit is a letter \texttt{[a-fA-F]}
%\end{flushleft}
% \begin{macrocode}
\def\u{\eqesc u\ckivspace}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\XXX}
% The character with the Latin-1 encoding specified by up to three octal digits \texttt{XXX} between
% 0 and 377. For example, \cs{251} is the octal sequence for the copyright symbol.
%
% Since this goes only up to octal 377, it suffices to make only the following four definitions.
% \begin{macrocode}
\def\0{\eqesc0}
\def\1{\eqesc1}
\def\2{\eqesc2}
\def\3{\eqesc3}
% \end{macrocode}
% \end{macro}
%\subsubsection{Other Special Characters}
% \begin{macro}{braces}
% Braces are a problem when they are unbalanced. In a regular expression, |\{| works properly, but |\\{| works
% for the distiller options but not otherwise. For example, if I wanted to replace every instance
% of \texttt{\{} with \texttt{(}, we can do this by
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%codes={\def\1{\quad}\catcode`\%=9}]
%myString = myString.replace( /\{/, "\(");
%\end{Verbatim}
% This works for all options, even though the braces are not balanced. However, when the constructor
% function is used, we must double-escape:
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%codes={\def\1{\quad}\catcode`\%=9}]
%var re = new RegExp("\\{", "g");
%myString = myString.replace( re, "\(");
%\end{Verbatim}
% This works for the distiller options, but not for \texttt{pdftex/dvipdfm}. The reason |\{| works is that
% it is a control sequence, defined by the \cmd{\definebraces} command below. Where as |\\{| consists
% of the control sequence |\\|, which is defined below, followed by a left brace.
% \TeX{} still requires the braces to be balanced.
%
% If you are searching for balanced braces, there should't be a problem, for example,
% the code
%\begin{verbatim}
% var re = new RegExp("\\{|\\}", "g");
% myString = myString.replace( re, "\(");
%\end{verbatim}
% works correctly.
%
% To continue the discussion of the problem with searching for
% unbalanced braces, one workaround is to balance out the left
% brace with a right brace in the form of a JavaScript comment.
% This ``fools'' \TeX! For example,
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%codes={\def\1{\quad}\catcode`\%=9}]
%var re = new RegExp("\\{", "g"); // }
%myString = myString.replace( re, "\(");
%\end{Verbatim}
% Finally, we have\par\medskip
% \noindent\textbf{The Recommended Workaround:} Use |\\\{| and |\\\}|, e.g.,
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%codes={\def\1{\quad}\catcode`\%=9}]
%var re = new RegExp("\\\{", "g");
%myString = myString.replace( re, "\(");
%\end{Verbatim}
% This is more verbose than needed, but it works for all options! These comments are only for regular expression
% strings within the constructor function. Note the replacement text, |\(|, is only escaped.
%
% Here we make the definitions for left and right braces. See the definition of \cs{definebraces}
% given earlier.
% \begin{macrocode}
\definebraces
% \end{macrocode}
% \end{macro}
% \begin{macro}{parentheses}
% Just as braces can give us problems with \TeX, so too, parentheses can give us problems with
% Acrobat JavaScript interpreter. There seems to be a requirement that parentheses be balanced
% unless they are properly escaped. Generally, we have no problems in the case of distiller options,
% once again \textsf{pdftex} and \textsf{dvipdfm} are causing (me) problems.
%
% No problems when the regular expression uses the literal string format
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%codes={\def\1{\quad}\catcode`\%=9}]
%myString = myString.replace(/\(/g, "\[");
%\end{Verbatim}
% The above code works for all options. However, for the constructor function we have some problems
% in non-distiller options. If we type instead
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%codes={\def\1{\quad}\catcode`\%=9}]
%var re = new RegExp("\\(", "g");
%myString = myString.replace(re, "\[");
%\end{Verbatim}
% The above code works for the distiller folks, but not for the
% others. In the case of \textsf{pdftex}, I cannot access the UI to
% the document level JavaScripts, and the script is undefined. I suspect
% the lack of balanced parentheses is the curprit. For example,
% consider the code
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%codes={\def\1{\quad}\catcode`\%=9}]
%var re = new RegExp("\\(|\\)", "g");
%myString = myString.replace(re, "\[");
%\end{Verbatim}
% works. I can access the UI to the DLJS from Acrobat, and the script is defined. Another
% example, we can fool the JavaScript interpreter as we did the \TeX{} compiler:
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%codes={\def\1{\quad}\catcode`\%=9}]
%var re = new RegExp("\\(", "g"); // )
%myString = myString.replace(re, "\[");
%\end{Verbatim}
% Here I have placed a balancing right parenthesis as a JavaScript comment. Both sets of code
% work correctly.
%\par\medskip
%\noindent\texttt{Recommended Workaround:} As in the case of parentheses, a more verbose version
% of the script works of all options.
%\begin{Verbatim}[xleftmargin=\parindent,fontsize=\small,
%codes={\def\1{\quad}\catcode`\%=9}]
%var re = new RegExp("\\\(", "g");
%myString = myString.replace(re, "\[");
%\end{Verbatim}
% This is only for the case of the constructor function.
% \begin{macrocode}
\def\({\eqesc\eqesci(}
\def\){\eqesc\eqesci)}
% \end{macrocode}
% \end{macro}
% The rest of these definitions are for characters that have a
% special meaning when they appear in a regular expression. See
%\begin{flushleft}\small
%\url{http://developer.netscape.com/docs/manuals/js/core/jsref15/regexp.html}
%\end{flushleft}
% for a description of the meaning for the special characters given below (and above).
% To ``escape'' the special meaning of any character, ``escape'' them.
% \begin{macrocode}
\def\.{\eqesc.}
\def\/{\eqesc/}
\def\[{\eqesc[}
\def\]{\eqesc]}
% \end{macrocode}
% \begin{macrocode}
\def\|{\eqesc|}
\def\+{\eqesc+}
\def\*{\eqesc*}
\def\-{\eqesc-}
\def\?{\eqesc?}
\def\${\eqesc$}
\def\^{\eqesc^}
\def\\{\eqesc\eqesc}
% \end{macrocode}
% The next group of characters have no special meaning in a regular expression, but are using elsewhere
% in JavaScript. These definitions may come in handy.
% \begin{macrocode}
\def\'{\eqesc'}
% \end{macrocode}
% The \texttt{german} package makes doublequotes, |"|, active, so within the \texttt{insDLJS}
% environment, we change its catcode to 12.
% \begin{macrocode}
\catcode`\"=12
\def\"{\eqesc"}
% \end{macrocode}
% We de-activate angle brackets.
% \begin{macrocode}
\catcode`\<=12
\def\<{\eqesc<}
\catcode`\>=12
\def\>{\eqesc>}
% \end{macrocode}
% Here, we define `\texttt{\%}' differently. The percent has no special meaning in regular expressions,
% but is used by the \texttt{util.printf()} method.
% \begin{macrocode}
\catcode`\%=12
\def\%{%}
\catcode`\%=14
% \end{macrocode}
% The `and' symbol has not special meaning for regular expressions, but is used as a logical `and'.
% Probably don't need this escape.
% \begin{macrocode}
\catcode`\& = 12
\def\&{\eqesc&}
% \end{macrocode}
% \begin{macrocode}
%</cc4js>
% \end{macrocode}
% \begin{macrocode}
%<*altadbfncs>
% \end{macrocode}
% \section{Alternate names for some Adobe functions}\label{s:AltAdbFncs}
% (2017/03/02) Added alternate names for some common Adobe functions. Used for
% creating custom keystroke and formatting events.
% \changes{v2.3f}{2017/03/02}{Alternate names for Adobe functions added}
% \begin{macrocode}
\begin{insDLJS}{altadbfncs}{indljs: Alternate Adobe Function Names}
var EFNumber_Keystroke=AFNumber_Keystroke;
var EFNumber_Format=AFNumber_Format;
var EFPercent_Keystroke=AFPercent_Keystroke;
var EFPercent_Format=AFPercent_Format;
var EFDate_Format=AFDate_Format;
var EFDate_Keystroke=AFDate_Keystroke;
var EFDate_FormatEx=AFDate_FormatEx;
var EFTime_Keystroke=AFTime_Keystroke;
var EFTime_Format=AFTime_Format;
var EFTime_FormatEx=AFTime_FormatEx;
var EFDate_KeystrokeEx=AFDate_KeystrokeEx;
var EFSpecial_Keystroke=AFSpecial_Keystroke;
var EFSpecial_Format=AFSpecial_Format;
var EFSpecial_KeystrokeEx=AFSpecial_KeystrokeEx;
var EFRange_Validate=AFRange_Validate;
var EFSimple_Calculate=AFSimple_Calculate;
var EFMergeChange=AFMergeChange;
\end{insDLJS}
%</altadbfncs>
% \end{macrocode}
% \begin{macrocode}
%<*package>
\inputAltAdbFncs
\dl@restoreCats
%</package>
% \end{macrocode}
% \Finale
%\endinput
|