1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
|
% \iffalse meta-comment
%<*identify>
%
% svg and svg-extract -- Handling SVG pictures in LaTeX documents
%
%% ----------------------------------------------------------------------------
%%
%% Copyright (C) Philip Ilten <philten@cern.ch>, 2012-2016
%% Copyright (C) Falk Hanisch <hanisch.latex@outlook.com>, 2017-2020
%%
%% ----------------------------------------------------------------------------
%%
%% This work may be distributed and/or modified under the conditions
%% of the LaTeX Project Public License, version 1.3c of the license.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of
%% LaTeX 2005/12/01 or later and of this work.
%%
%% This work has the LPPL maintenance status "author-maintained".
%%
%% The current maintainer and author of this work is Falk Hanisch.
%%
%% This work consists of the main source file README.md, LICENSE.md, svg.dtx
%% and the derived documentation svg.pdf as well as the example files
%% svg-example.svg, svg-preamble.tex and root.C (with derived file root.svg).
%%
%% ----------------------------------------------------------------------------
%%
%</identify>
% \fi
%
% \iffalse
%<*dtx>
\ifx\documentclass\undefined
\input docstrip.tex
\keepsilent
\declarepreamble\svgmainpreamble
svg -- Include SVG pictures in LaTeX documents using Inkscape
\endpreamble
\declarepreamble\svgextractpreamble
svg-extract -- Extract independent graphic files from SVG pictures
\endpreamble
\askforoverwritefalse
\usedir{tex/latex/svg}
\generate{%
\usepreamble\svgmainpreamble
\file{svg.sty}{
\from{svg.dtx}{package,identify,main}
\from{svg.dtx}{package,base,main}
\from{svg.dtx}{package,option,main}
\from{svg.dtx}{package,body,main}
}
\usepreamble\svgextractpreamble
\file{svg-extract.sty}{
\from{svg.dtx}{package,identify,extract}
\from{svg.dtx}{package,base,extract}
\from{svg.dtx}{package,option,extract}
\from{svg.dtx}{package,standalone,extract}
\from{svg.dtx}{package,body,extract}
}
% \usepreamble\defaultpreamble
% \file{svg-old.sty}{
% \from{svg.dtx}{package,old}
% }
}
\else
\let\endbatchfile\relax
\fi
\endbatchfile
%</dtx>
% \fi
%
% \iffalse
%<*dtx|package&identify>
\NeedsTeXFormat{LaTeX2e}[2020-02-02]
%<*dtx>
\ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
%</dtx>
\begingroup
\catcode`\@11\relax%
\def\svg@Provides#1#2[#3]{%
\def\@tempa{\def\svg@version{#3}}%
\ifx\svg@version\@undefined\else%
\def\@tempb{#3}%
\ifx\svg@version\@tempb\else%
\def\@tempa{%
\@latex@warning@no@line{%
The version of package `#1' is `#3',\MessageBreak%
but `\svg@version' was expected!\MessageBreak%
You should update the svg bundle%
}%
}%
\fi%
\fi%
\edef\@tempb{%
\endgroup%
%<*dtx>
\noexpand\ProvidesFile%
%</dtx>
%<package&identify> \noexpand\ProvidesPackage%
{#1}[#3\space(#2)]%
%<package&identify&extract> \noexpand\RequirePackage{svg}[#3]%
\unexpanded\expandafter{\@tempa}%
}%
}%
\svg@Provides%
%<*dtx>
{svg.dtx}{source}%
%</dtx>
%<package&identify&main> {svg}{include SVG pictures}%
%<package&identify&extract> {svg-extract}{extract graphics from SVG pictures}%
[2020/06/12 v2.02g]%
\@tempb
%</dtx|package&identify>
% \fi
%
% \iffalse
%<*dtx>
\documentclass[english,xindy]{tudscrdoc}[2017/03/27]
\usepackage{iftex}[2020/03/06]
\iftutex
\usepackage{fontspec}
\else
\usepackage[T1]{fontenc}
\fi
\usepackage{babel}
\KOMAoptions{parskip=half-}
\usepackage{marginnote}
\usepackage{svg}
\usepackage{svg-extract}
\svgpath{{./examples/}}
\svgsetup{extractpreamble=svg-preamble.tex,clean=true}
\usepackage{xpatch}
\ifdefined\includesvg
\xpretocmd{\includesvg}{\MakePercentComment}{}{}
\xapptocmd{\includesvg}{\MakePercentIgnore}{}{}
\fi
\ifdefined\includeinkscape
\xpretocmd{\includeinkscape}{\MakePercentComment}{}{}
\xapptocmd{\includeinkscape}{\MakePercentIgnore}{}{}
\fi
\ifdefined\pdfsuppresswarningpagegroup
\pdfsuppresswarningpagegroup=1
\fi
\usepackage{listings}
\lstset{%
inputencoding=utf8,extendedchars=true,%
literate=%
{ä}{{\"a}}1 {ö}{{\"o}}1 {ü}{{\"u}}1
{Ä}{{\"A}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1
{ß}{{\ss}}1 {~}{{\textasciitilde}}1
{»}{{\guillemetright}}1 {«}{{\guillemetleft}}1
}
\newcommand*\svglstbelowskip{\medskipamount}
\AtBeginDocument{%
\renewcommand*\svglstbelowskip{\glueexpr\medskipamount-\parskip\relax}%
}
\lstdefinestyle{svg}{%
basicstyle=\small\ttfamily,%
columns=flexible,%
frame=single,%
backgroundcolor=\color{yellow!10},%
xleftmargin=\fboxsep,%
xrightmargin=\fboxsep,%
gobble=2,%
escapechar=§,%
belowskip=\svglstbelowskip,%
}
\lstnewenvironment{svgexample}[1][]{%
\lstset{style=svg,#1}%
}{}
\usepackage{enumitem}
\newlist{DescribeValues}{description}{1}
\setlist[DescribeValues]{font=\normalfont\val,style=nextline,noitemsep}
\usepackage{subcaption}
\usepackage{relsize}
\usepackage{bookmark}
\usepackage[babel]{microtype}
%\EnableCrossrefs
\CodelineIndex
\RecordChanges
\GetFileInfo{svg.dtx}
\begin{document}
\title{The packages \pkg{svg} and \pkg{svg-extract}}
\author{%
Philip Ilten (2012--2016)\\%
Falk Hanisch (2017--)\\%
\url{https://github.com/mrpiggi/svg}\\%
\mailto{hanisch.latex@outlook.com}%
}
\date{\fileversion\nobreakspace(\filedate)}
\providerobustcmd*\default[1]{\val{\textit{#1}}}
\maketitle%
\begin{abstract}
\noindent
The \pkg{svg} package is intended for the automated integration of
SVG~graphics into \LaTeX~documents. Therefor the capabilities provided
by \app{Inkscape}---or more precisely its command~line~interface---are used
to export the text within a SVG~graphic to a separate file, which is
then rendered by \LaTeX{}. The two commands \cs{includesvg} and
\cs{includeinkscape} are provided as central user\hbox{-}interface,
which are very similar to the \cs{includegraphics} command of the
\pkg{graphicx} package.
In addition, the package \pkg{svg-extract} allows the extraction of these
graphics into independent files in different graphic formats, exactly as it
is rendered within the \LaTeX~document. For the creation of these graphics
in the well\hbox{-}known formats PDF, EPS and~PS, \LaTeX{} and possibly
conversion tools shipped with the distribution are used. If the graphics
are required in other file formats, either \app{ImageMagick} or
\app{Ghostscript} can be invoked.
\bigskip\noindent%
\fbox{\parbox{\dimexpr\linewidth-(\fboxsep+\fboxrule)*2\relax}{%
The command~line~interface~(CLI) of \app{Inkscape}\,1.0 has changed in
comparison to previous versions. In order to provide a comfortable
user\hbox{-}interface for invoking \app{Inkscape}, the used version is
detected and if necessary switch to the outdated syntax of the CLI. If
this approach fails for some reason, you can set the version of
\app{Inkscape} manually with \opt{inkscapeversion}|=|\val{0} or
\opt{inkscapeversion}|=|\val{1}.
}}%
\end{abstract}
\tableofcontents
\DocInput{\filename}
\end{document}
%</dtx>
% \fi
%
% \changes{v1.0}{2004/11/05}{initial version by Philip Ilten}^^A
% \changes{v2.00}{2016/09/23}{new maintainer: Falk Hanisch}^^A
% \changes{v2.00}{2017/03/27}{re-implementation from scratch}^^A
% \changes{v2.00}{2017/03/27}{package \pkg{subfig} not required anymore}^^A
% \changes{v2.00}{2017/03/27}{support of subfigures stopped due to the huge
% number of packages which deal with this topic and the large variety of
% implementing this functionality; naming exported graphics after their
% consecutive numbering can't be ensured for all variants of subfigures, so
% it's neglected}^^A
% \changes{v2.01}{2017/11/28}{usage of \cs{input}\marg{tex~filename} within
% \app{Inkscape}~graphics locates files in all declared searched folders}^^A
% \changes{v2.02}{2018/09/07}{package \pkg{trimspaces} required}^^A
% \changes{v2.02}{2018/09/07}{multiple dots within file names possible}^^A
% \changes{v2.02}{2018/09/07}{fixed errors with active double quotes from
% \pkg{babel} in path arguments}^^A
% \changes{v2.02a}{2018/10/17}{fix bug for package \pkg{polyglossia} which
% fakes \pkg{babel} poorly}^^A
% \changes{v2.02b}{2018/11/12}{fix bug for package \pkg{tikzscale} which
% changes \cs{includegraphics} globally}^^A
% \changes{v2.02c}{2019/10/10}{fix bugs with kernel (2019/10/01) regarding file
% name parsing}^^A
% \changes{v2.02d}{2019/10/22}{fix bugs with kernel (2019/10/01) regarding file
% name parsing, see \url{https://github.com/mrpiggi/svg/issues/16}}^^A
% \changes{v2.02d}{2019/10/22}{conditional invocation of \app{Inkscape} export
% based on file modification date implemented for Xe\TeX{}}^^A
% \changes{v2.02f}{2020/05/06}{command~line~interface of \app{Inkscape~1.0}
% is supported}^^A
% \changes{v2.02g}{2020/06/12}{fix for mutliple dots in file names (\#27)}^^A
%
%
%
% \part{User documentation}
% \section{Introduction}
%
% The open source program \app{Inkscape} has provided an excellent resource for
% the simple and easy creation of images and diagrams using a graphical
% user\hbox{-}interface. The work by Johan\,B.\,C.~Engelen has further enhanced
% the ability of \app{Inkscape} to split a SVG~file into a text component that
% can be compiled with \LaTeX{}, and an image component that can be imported
% as a PDF~file. For further information see the documentation of
% \hrfn{http://www.ctan.org/pkg/svg-inkscape}{\pkg{svg-inkscape} on CTAN}.
% The procedure described therein is taken up and consistently expanded. Thus,
% it is now possible to include a SVG~file into a \LaTeX~document where the
% text within the SVG~graphic will be rendered natively by \LaTeX{}.
%
% Both packages \pkg{svg} and \pkg{svg-extract} rely heavily upon executing
% commands on shell using the \cs{ShellEscape} command---or respectively the
% old known \cs{write18}---for executing the CLIs of the applications mentioned
% above. So passing flag \file{-{}-shell-escape} to the \LaTeX~engine is
% utterly essential when using package \pkg{svg} and/or \pkg{svg-extract}. The
% executed commands and the possibilities to adapt their invocation with the
% appropriate options are described later on in this documentation. All this is
% done automatically with the \cs{includesvg} command. If you don't want to use
% the \file{-{}-shell-escape} flag, either for security reasons or because
% the export of the SVG~files is done in another way, there's also the command
% \cs{includeinkscape} which includes files already exported by \app{Inkscape}.
%
% An working installation of \app{Inkscape} is required for the automated
% integration of SVG~graphics, whereby the installation path must be
% known to the operating system. This can be checked on shell by typing
% \file{inkscape -V}. Moreover, there are some required packages which are
% loaded by packages \pkg{svg} and \pkg{svg-extract} to provide the
% functionallity. These are:
% \begin{description}[parsep=\glueexpr\smallskipamount/2\relax]
% \item[\pkg{iftex}]
% for flow control depending on the used \LaTeX~engine
% \item[\pkg{scrbase}]
% for the definition and handling of options in key-value-syntax
% \item[\pkg{pdftexcmds}, \pkg{shellesc}]
% to allocate the same primitives independent of the used \LaTeX~engine
% \item[\pkg{ifplatform}]
% to control the file~access depending on the operating system
% \item[\pkg{trimspaces}]
% to remove unwanted spaces in file paths
% \item[\pkg{graphicx}]
% for including the graphic~files after the \app{Inkscape}~export
% \item[\pkg{xcolor}, \pkg{transparent}]
% are possibly needed by the separate \LaTeX~files created by \app{Inkscape}
% \item[\pkg{xr}]
% is used by \pkg{svg-extract} in order to include labels within the
% independent graphic~files
% \end{description}
%
% If you want to pass options to package \pkg{graphicx}, you must either load
% it before package \pkg{svg}
% \begin{svgexample}
% \usepackage§\oarg{options}§{graphicx}
% §\dots§
% \usepackage§\oarg{options}§{svg}
% \end{svgexample}
% or use \cs{PassOptionsToPackage}.
% \begin{svgexample}
% \PassOptionsToPackage§\marg{options}§{graphicx}
% §\dots§
% \documentclass§\oarg{options}\marg{class}§
% §\dots§
% \usepackage§\oarg{options}§{svg}
% \end{svgexample}
% The usage of packages \pkg{xcolor} and \pkg{transparent} can be switched off
% while loading package \pkg{svg}. See the two options \opt{usexcolor} and
% \opt{usetransparent} below.
%
%
%
% \section{Usage of package \pkg{svg}\label{sec:inkscape}}
%
% The purpose of this package is to include standalone SVG~graphics into a
% \LaTeX~document. The command \cs{includesvg} is defined which does all
% necessary steps for this task. It first launches the export of a SVG~file
% to a supported file~format with Inkscape, if necessary, and includes the
% exported graphic~file afterwards. The usage and the syntax is quite similiar
% to the command \cs{includegraphics} from the \pkg{graphicx} package. In fact,
% the inclusion of the exported graphic~file is done with \cs{includegraphics}.
%
% \DescribeOptions{usexcolor,usetransparent,noxcolor,notransparent}^^A
% The packages \pkg{xcolor} and \pkg{transparent} are loaded by default at the
% end of package \pkg{svg}. The listed options are intended to prevent these
% packages from loading. They are the only options which have to be given while
% loading the \pkg{svg} package. All supported boolean values
% (\val{true/on/yes/false/off/no}) can be assinged to \opt{usexcolor} and
% \opt{usetransparent}, while \opt{noxcolor} and \opt{notransparent} don't
% accept any value.
% \begin{svgexample}
% \usepackage§\oarg{options}§{svg}
% \end{svgexample}
%
%
%
% \subsection{General settings}
%
% \DescribeMacro{\svgsetup}^^A
% All other options described in detail below can also be changed after loading
% the package either in the preamble or within the document. They don't have to
% be given as optional argument to \cs{usepackage}\oarg{options}|{svg}| but can
% be set by using macro \cs{svgsetup}\marg{options} where \meta{options} is a
% comma separated list of options. Settings with \cs{svgsetup} are done in the
% current scope which means globally or within the current group.
% \begin{svgexample}
% \svgsetup§\marg{options}§
% \end{svgexample}
% Further, with the optional argument of commands
% \cs{includesvg}\oarg{options}\marg{svg~filename} or
% \cs{includeinkscape}\oarg{options}\marg{graphic~filename}, it's possible to
% reset any setting locally for a certain file.
%
% \DescribeMacro{\svgpath}^^A
% Most likely you want to organize your SVG~files in a separate folder either
% as a subfolder in the working directory or elsewhere in your local folder
% structure. For this purpose, a list of root paths to SVG~files can be
% specified using the \cs{svgpath} command in the same way as \cs{graphicspath}
% is used. Every path has to be given in a group of braces |{}|---even if there
% is only one---and should terminate with a slash. For example:
% \begin{svgexample}
% \svgpath{{svg/}{/usr/local/svg/}}
% \end{svgexample}
% would cause the system to look first in the subdirectory \file{svg/} and
% afterwards in the absolute path \file{/usr/local/svg/}. Further, if no path
% was specified with \cs{svgpath} or the desired file wasn't found, all
% directories given with \cs{graphicspath} are searched too. Please keep in
% mind that the current working directory is browsed first in any case.
% It is recommended to avoid umlauts or any other Non\hbox{-}ASCII characters
% as well as any spaces and/or quotes respectively \cs{dq} both in paths and
% file~names. Especially when DVI~output is active using quotes will certainly
% cause an error.
%
%
%
% \subsection{Options for the invocation of \app{Inkscape}}
%
% \DescribeOption{inkscape}^^A
% This option controls, when the export with \app{Inkscape} is invoked and is
% \default{true} by default.
% \begin{DescribeValues}^^A
% \item[false/off/no]
% \app{Inkscape} won't be invoked in any case, no export is done.
% \item[\default{true}/on/yes/newer/onlynewer]
% The export with \app{Inkscape} will only be done, if the exported
% graphic~file either does not exist or the file~modification date of the
% SVG~file is newer than that of the exported graphic~file. Thus the
% compilation time of the \LaTeX~document can be reduced to the necessary
% minimum.
% \item[forced/force/overwrite]
% The \app{Inkscape}~export will definitely be done, any already existing
% exported file will overwritten regardlessly.
% \end{DescribeValues}
%
% In addition to controlling the export behavior, the option \opt{inkscape} can
% also be used to make additional settings, which then acts as a wrapper for
% the options described below.
%
% \begin{DescribeValues}^^A
% \item[pdf/eps/ps/png]
% see \opt{inkscapeformat}|=|\val{pdf/eps/ps/png}
% \item[latex/nolatex]
% see \opt{inkscapelatex}|=|\val{true/false}
% \item[drawing/page]
% see \opt{inkscapearea}|=|\val{drawing/page}
% \item[\meta{integer}dpi]
% see \opt{inkscapedpi}|=|\val{\meta{integer}}
% \end{DescribeValues}
%
% \DescribeOption{inkscapepath}^^A
% The option \opt{inkscapepath} specifies, where the resulting files of the
% \app{Inkscape}~export should be located. The default setting is
% \default{basesubdir}, which uses the subfolder \file{./svg-inkscape/}
% within the current working directory.
% \begin{DescribeValues}^^A
% \item[svgdir/svgpath]
% The PDF/EPS/PS/PNG~graphic~files as well as the \LaTeX~files generated by
% \app{Inkscape} will be located in the same directory as the corresponding
% SVG~file.
% \item[svgsubdir/svgsubpath]
% Within the folder of the encountered SVG~file, all exported files will be
% located in a subfolder named \file{svg-inkscape/}.
% \item[basedir/basepath/jobdir/jobpath]
% All exported files will be located in the current working directory.
% \item[\default{basesubdir}/basesubpath/jobsubdir/jobsubpath]
% A subfolder named \file{svg-inkscape/} within the current working directory
% will be used for files generated by \app{Inkscape}.
% \item[/path/to/somewhere/]
% It is also possible to give a custom path, either relative to the current
% working directory (\file{./relative/path/}) or as an absolute path.
% \end{DescribeValues}
%
% \DescribeOption{inkscapeexe}^^A
% For including a SVG~file, \app{Inkscape} is used to separate the text and
% image from the SVG~file itself. In order to use the command~line~interface
% on shell, the path where the executable is located has to be known to the
% operating system and its name is assumed to be \val{inkscape} by default.
%
% You can check if the default setting is valid for your system by typing
% \file{inkscape -V} into the terminal. If this fails and nothing is returned,
% you should add the binary directory of \app{Inkscape} to the environment
% variable \file{PATH} on your operating system. If this is not possible or you
% aren't willing to do so, you can alternatively use option \opt{inkscapeexe}
% \emph{within the document preamble} to set the absolute path where the
% executable of \app{Inkscape} is located.
%
% \DescribeOption{inkscapeversion}^^A
% \changes{v2.02f}{2020/05/06}{option {inkscapeversion} for explicitly setting
% \app{Inkscape}-CLI version; automatic detection implemented}^^A
% The command~line~interface of \app{Inkscape} changed slightly from version
% \val{0.9x} to \val{1.x} and makes it necessary to distinguish between the two
% versions. By default, \opt{inkscapeversion}|=|\val{auto} is set and the used
% version is automatically detected. This is done by calling \app{Inkscape}-CLI
% with parameter~\prm{-V} on shell---see option \opt{inkscapeexe} described
% above. The returned result is evaluated by either piping \val{stdout} or
% eventually---if this fails---writing to a temporary file and read this back
% in (pipes with a potentially quoted path can not be used with MiK\TeX).^^A
% \footnote{^^A
% If this fails too, the \app{Inkscape} version is guessed when macro
% \cs{svg@ink@run} is used the very first time.^^A
% }
% It is also possible to switch off the automatic detection routine by setting
% the desired version manually with either \opt{inkscapeversion}|=|\val{0} to
% legacy mode or \opt{inkscapeversion}|=|\val{1} to the current CLI~version.
%
% \DescribeOption{inkscapename}^^A
% The file names of the \app{Inkscape}~export are derived from the name of the
% base SVG~file by default. Nevertheless, the name of the exported file can be
% customized with \opt{inkscapename}|=|\file{\meta{filename}}. It is possible
% to use counters for specifying the name of the exported file. Repeatedly
% specifying the same file name will overwrite previously created files.
%
% \DescribeOption{inkscapeformat}^^A
% With this option, the \app{Inkscape}~export~format can be controlled. Valid
% values are \val{pdf}, \val{eps}, \val{ps} and \val{png}, where a \LaTeX~export
% is not possible for \val{png} and option \opt{inkscapelatex} won't have any
% effect. By default, \opt{inkscapeformat}|=|\val{pdf} is set unless DVI~output
% was detected. In this case \opt{inkscapeformat}|=|\val{eps} is the default
% setting.
%
% \DescribeOption{inkscapelatex}^^A
% If option \opt{inkscapelatex}|=|\val{true} is set, the output is split into
% a seperate PDF/EPS/PS~file (see option \opt{inkscapeformat}) and a
% corresponding \LaTeX~file. This is the default setting. Setting
% \opt{inkscapelatex}|=|\val{false} will result in a single PDF/EPS/PS~file,
% where any contained text won't be rendered by \LaTeX{}.
%
% \DescribeOption{inkscapearea}^^A
% This option controls which area of the SVG~file should be exported,
% \default{drawing} is set by default.
% \begin{DescribeValues}^^A
% \item[\default{drawing}/crop]
% The area exported corresponds to the bounding box of all objects in a
% drawing, including any that are not on the page.
% \item[page/nocrop]
% The area exported will correspond to the defined page~area within the
% SVG~file.
% \end{DescribeValues}
%
% \DescribeOption{inkscapedpi}^^A
% The resolution used either for PNG~export or for fallback rasterization of
% filtered objects when exporting to PDF/EPS/PS~file. For PNG~export it is set
% to 300\,dpi by default, if no value was given. The given value should be a
% positive integer. The default behaviour can be reversed after a given value
% with \opt{inkscapedpi}|=|\val{\cs{relax}}.
%
% \DescribeOption{inkscapeopt}^^A
% You can use this option to pass additional switches to the \app{Inkscape}
% command~line~interface. For further information see the documentation of
% \hrfn{https://inkscape.org/de/doc/inkscape-man.html}{\app{Inkscape}}.
%
% \DescribeOption{svgextension}^^A
% \changes{v2.01}{2017/11/27}{option \opt{svgextension} added in order to
% change the format of files exported by \app{Inkscape} from \file{svg} to
% a custom one}^^A
% The package assumes SVG~files with \file{.svg} extension as source for the
% \app{Inkscape} export. This option can be used to change this behaviour.
% For example, in order to process \file{.dia} files instead of \file{.svg} you
% could use
% \begin{svgexample}
% \includesvg[svgextension=dia,§\meta{additional~options}§]§\marg{filename}§
% \end{svgexample}
%
%
%
% \subsection{Options for the graphic inclusion}
%
% \DescribeOptions{width,height,distort,scale}^^A
% \changes{v2.02}{2018/09/07}{option \opt{distort} (or \opt{keepaspectratio})
% added for distortion of included graphics}^^A
% The width of the included graphic~file can be specified via the \opt{width}
% option and the height by the \opt{height} option. If both the width and
% height are specified, the figure will be scaled such that neither of the
% specified dimensions is exceeded, unless option \opt{distort}|=|\val{true} is
% given.\footnote{to provide compatibility for package \pkg{graphicx}, it's
% possible to use \prm{keepaspectratio}|=|\val{true} as alias for
% \opt{distort}|=|\val{false} and the other way round}
% If \opt{width} and/or \opt{height} once have been set, this can be undone
% by setting them to \val{0pt} or \cs{relax}. If neither \opt{width} nor
% \opt{height} are set, the included graphic~file can also be scaled by setting
% \opt{scale} to a positive real number.
%
% \DescribeOptions{pretex,apptex}^^A
% Commands prior and post to the inclusion of the graphic~file may be desired,
% such as font or color commands. The options \opt{pretex} and \opt{apptex} are
% provided where the \LaTeX~code given to \opt{pretex} is included before the
% graphic~file and \opt{apptex} right afterwards. For example, to change the
% size of the included text one could use:
% \begin{svgexample}
% \includesvg[pretex=\tiny,§\meta{additional~options}§]§\marg{svg~filename}§
% \end{svgexample}
%
% \DescribeOption{draft}^^A
% This option can be used with booelan values and is equal to the identically
% named option of the \pkg{graphicx} package. If the \opt{draft} option is
% given to \pkg{graphicx}, it's activated for \pkg{svg} as well.
%
% \DescribeOption{lastpage}^^A
% A \hrfn{https://bugs.launchpad.net/ubuntu/+source/inkscape/+bug/1417470}{bug}
% concerning the \LaTeX~export has been reported for \app{Inkscape}\,0.91. It
% may happen that within the exported \LaTeX~file, it's attempted to include
% more pages of the PDF~graphics than actually exist. The \pkg{svg} package
% attempts to bypass the resulting error.
%
% Consequently, the total number of pages is read and only existing PDF~pages
% are included, if both options \opt{inkscapeformat}|=|\val{pdf} and
% \opt{lastpage}|=|\val{true} are set. This is the default setting
% (unless DVI~output is active) and can be switched off with
% \opt{lastpage}|=|\val{false}. It's also possible to set the number of the
% last page included of a PDF~graphic manually as optional parameter for
% \cs{includesvg} or \cs{includeinkscape}. For details, see the description of
% the respective commands.
%
%
%
% \subsection{Including SVG~files}
%
% \DescribeMacro{\includesvg}^^A
% The command \cs{includesvg} to include a SVG~file is quite similar to the
% \cs{includegraphics} command provided by the \pkg{graphicx} package.
% \begin{svgexample}
% \includesvg§\oarg{parameters}\marg{svg~filename}§
% \end{svgexample}
%
% \begin{DescribeParameterParent}{Macro}{\includesvg}^^A
% \DescribeParameters{inkscape,inkscapeformat,inkscapelatex,inkscapearea,^^A
% inkscapedpi,inkscapeopt,svgextension,width,height,distort,scale,^^A
% pretex,apptex,draft}^^A
% It is used right in the same way but where \meta{svg~filename} is the
% file~name of the SVG~file, where any given file~extension will be replaced
% with \file{.svg} ruthlessly. In order to change the source file format for
% the \app{Inkscape} export, you have to use parameter \prm{svgextension}.
%
% If the given file is not located in the current working directory but
% elsewhere on your file~system, the command \cs{svgpath} could be used to
% specify this path.
% \ToDo{reference to general note at the very beginning instead}[v2.03]^^A
% It is recommended to avoid umlauts or any other Non\hbox{-}ASCII characters
% as well as any spaces and/or quotes respectively \cs{dq} both in paths and
% file~names. Especially when DVI~output is active using quotes will certainly
% cause an error.
%
% The command \cs{includesvg} is intended to do an automated export with
% \app{Inkscape} at first, where the given SVG~file is exported to a
% PDF/EPS/PS/PNG~file (see~\opt{inkscapeformat}) and perhaps a correlating
% \LaTeX~file (see~\opt{inkscapelatex}). The export with \app{Inkscape} is only
% invoked, if the SVG~file is newer than the exported graphic~file or latter
% doesn't exist at all. Once the export has been done, the graphic~file and
% maybe the \LaTeX~file are included.
%
% All previously described options can also be used as optional parameters to
% \cs{includesvg} and do have the same effect as described before. However, the
% optional parameters specified have an effect only once when \cs{includesvg}
% is executed and remain unchanged afterwards.
%
% \DescribeParameter{lastpage}^^A
% In addition to the use of boolean values, the parameter \prm{lastpage} can
% also be assigned a specific (integer) page number, which defines the last
% used page of a PDF~graphic. This, just like the identically named option, has
% an effect only when \prm{inkscapeformat}|=|\val{pdf} is set.
%
% \DescribeParameters{angle,origin}^^A
% Both parameters correlate to the identically named parameters of the
% \cs{includegraphics} command provided by the \pkg{graphicx} package. However,
% unlike to \cs{includegraphics}, they \prm{angle} and \prm{origin} are
% \emph{always evaluated after} \prm{widht}, \prm{height}, \prm{distort} and
% \prm{scale} by \cs{includesvg}, regardless of the used order of the given
% parameters. This is mainly due to the inclusion of the \LaTeX~files
% corresponding to the graphic~files generated by \app{Inkscape}.
% \end{DescribeParameterParent}
%
%
%
% \subsection{Including already exported SVG~files}
%
% \DescribeMacro{\includeinkscape}^^A
% If you don't want to make use of the automated export with \app{Inkscape} but
% the user\hbox{-}interface provided by the \pkg{svg} package, you can use
% \cs{includeinkscape} instead of \cs{includesvg}.
% \begin{svgexample}
% \includeinkscape§\oarg{parameters}\marg{graphic~filename}§
% \end{svgexample}
%
% \begin{DescribeParameterParent}{Macro}{\includeinkscape}^^A
% \DescribeParameters{inkscapeformat,inkscapelatex,width,height,distort,^^A
% scale,pretex,apptex,draft,lastpage,angle,origin}^^A
% You can use it similar to \cs{includesvg} but \meta{graphic~filename} has to
% be the filename of the already exported graphic file. If a valid
% file~extension (\file{.pdf/.eps/.ps/.png}) is given, the current setting for
% \opt{inkscapeformat} is overwritten. It's even possible to specify a
% file~extension like \file{.pdf\_tex} to activate \opt{inkscapelatex}.
% Furthermore, all optional parameters for \cs{includeinkscape} do have the
% same effect as described before for command \cs{includesvg} once when
% \cs{includeinkscape} is executed and remain unchanged afterwards.
% \end{DescribeParameterParent}
%
%
%
% \section{Usage of package \pkg{svg-extract}}
%
% This package allows the extraction of independent graphic~files out of
% SVG~files which have been included and rendered with \LaTeX{} by the
% \pkg{svg} package. This is particularly useful when attempting to provide
% images to journals or collaborators, and one wishes the image to appear
% exactly as it does within the original \LaTeX~document.
%
% In order to extract to PDF, EPS, or PS~files the programs \file{pstoeps},
% \file{pstopdf} and \file{pdftops} are used which are usually provided by most
% of the \LaTeX~distributions. In additon, the command~line~interfaces of
% \app{ImageMagick} and \app{Ghostscript} can be invoked for converting images
% in formats like PNG, JPG, TIF or something else. It's also possible to create
% PDF, EPS or PS~files with one of the two programs. Therefor the desired
% program---\file{magick} and/or \file{gswin32c}/\file{gswin64c} on Windows
% respectively \file{convert} and/or \file{gs} on unix-like operating
% systems---must be installed. By typing \file{\meta{program}~-{}-version} on
% shell, this can be checked.
%
% If you want to extract independent graphic~files from included SVG~files, you
% only have to load \pkg{svg-extract}. All actions for the extraction process
% will be done by using \cs{includesvg} or \cs{includeinkscape}. Without any
% additional settings, the extraction will render the SVG~file to the specified
% output formats(s) of choice using the same settings as specified within the
% two commands. Consequently, the scale between the image and text in the
% extracted files will remain identical to the scale within the document from
% which the SVG~file was extracted.
%
% In contrast to package \pkg{svg}, the console commands for graphic extraction
% are executed with each LaTeX run by package \pkg{svg-extract} when
% \file{-{}-shell-escape} mode is activated. This behaviour can be switched off
% with option \opt{extract}|=|\val{false}.
%
% \minisec{Important changes}
%
% In version~v1.0 of package \pkg{svg} the extracted files were named like the
% numbering of the current \env{subfig} environment by default. As package
% \pkg{subfig} sometime causes problems and because of the large amount of
% different \LaTeX~packages which all provide the possibility to include
% subfigures with very different implemetations, this feature can't be provided
% reliably by \pkg{svg-extract}. See option \opt{extractname} for further
% information.
%
%
%
% \subsection{General settings}
%
% \DescribeOptions{on,off}^^A
% This options have to be given while loading the \pkg{svg-extract} package and
% are intended to toggle the functionality of this package. As both extracting
% and converting independent graphic~files is invoked with every \LaTeX~run
% when \file{-{}-shell-escape} is activated, the option \opt{off} can be given
% to save compilation time, once the creation of all desired images has been
% done and they no longer need to be re-generated. The option \opt{on} can be
% used to reactivate functionality of this package. This can also be done by
% using \opt{extract}|=|\val{true}/\val{false}.
%
% \DescribeMacros{\svgsetup,\includesvg,\includeinkscape}^^A
% With package \pkg{svg-extract} the applicable options for
% \cs{svgsetup}\marg{options} as well as parameters for the already described
% macros \cs{includesvg}\oarg{parameters}\marg{svg~filename} and
% \cs{includeinkscape}\oarg{parameters}\marg{graphic~filename} are extended.
% They can be used to control the process of graphic extraction and converting.
%
% All option described below can be used togehter with \cs{svgsetup} and are
% then valid in the current scope. There also exist identically named
% parameters for the optional arguments of
% \begin{svgexample}
% \includesvg§\oarg{parameters}\marg{svg~filename}§
% \includeinkscape§\oarg{parameters}\marg{graphic~filename}§
% \end{svgexample}
% These have an effect only once, when the specific command is executed.
%^^A \begingroup^^A
%^^A \newcommand*\parameterlist{}^^A
%^^A \listadd\parameterlist{extract}^^A
%^^A \listadd\parameterlist{extractpreamble}^^A
%^^A \listadd\parameterlist{extractformat}^^A
%^^A \listadd\parameterlist{extractwidth}^^A
%^^A \listadd\parameterlist{extractheight}^^A
%^^A \listadd\parameterlist{extractdistort}^^A
%^^A \listadd\parameterlist{extractscale}^^A
%^^A \listadd\parameterlist{extractangle}^^A
%^^A \listadd\parameterlist{extractpretex}^^A
%^^A \listadd\parameterlist{extractapptex}^^A
%^^A \listadd\parameterlist{extractruns}^^A
%^^A \listadd\parameterlist{latexexe}^^A
%^^A \listadd\parameterlist{latexopt}^^A
%^^A \listadd\parameterlist{latexext}^^A
%^^A \listadd\parameterlist{dvipsopt}^^A
%^^A \listadd\parameterlist{pstoepsopt}^^A
%^^A \listadd\parameterlist{pstopdfopt}^^A
%^^A \listadd\parameterlist{pdftoepsopt}^^A
%^^A \listadd\parameterlist{pdftopsopt}^^A
%^^A \listadd\parameterlist{convert}^^A
%^^A \listadd\parameterlist{convertformat}^^A
%^^A \listadd\parameterlist{convertdpi}^^A
%^^A \listadd\parameterlist{magicksetting}^^A
%^^A \listadd\parameterlist{magickoperator}^^A
%^^A \listadd\parameterlist{gsopt}^^A
%^^A \listadd\parameterlist{gsdevice}^^A
%^^A \listadd\parameterlist{clean}^^A
%^^A \listadd\parameterlist{exclude}^^A
%^^A \def\buffer{}\def\do#1{\buffer\prm{#1}\def\buffer{, }}^^A
%^^A These parameters are: \dolistloop{\parameterlist}.
%^^A \renewcommand*\marginpar[2][]{}^^A
%^^A \def\do#1{\DescribeParameter{#1}}^^A
%^^A \begin{DescribeParameterParent}{Macro}{\includesvg}^^A
%^^A \dolistloop{\parameterlist}^^A
%^^A \end{DescribeParameterParent}^^A
%^^A \begin{DescribeParameterParent}{Macro}{\includeinkscape}^^A
%^^A \dolistloop{\parameterlist}^^A
%^^A \end{DescribeParameterParent}^^A
%^^A \endgroup^^A
%
%
%
% \subsection{Extract independent grahic files\label{sec:extract}}
%
% \DescribeOption{extract}^^A
% This option can be used with boolean values. Using \opt{extract}|=|\val{true}
% activates the functionality for both extracting and converting which is the
% default setting, whereas \opt{extract}|=|\val{false} turns it off completely.
%
% \DescribeOption{extractpath}^^A
% The path where the extracted and converted files are located can be specified
% with option \opt{extractpath}, whereas \default{basesubdir} is set by default.
% \begin{DescribeValues}^^A
% \item[svgdir/svgpath]
% The extracted and converted independent graphic~files are located in the
% same directory as the corresponding SVG~file.
% \item[svgsubdir/svgsubpath]
% Within the folder of the encountered SVG~file, all extracted and converted
% files will be located in a subfolder named \file{svg-extract/}.
% \item[basedir/basepath/jobdir/jobpath]
% All extracted and converted files will be located in the current working
% directory.
% \item[\default{basesubdir}/basesubpath/jobsubdir/jobsubpath]
% A subfolder named \file{svg-extract/} within the current working directory
% will be used for all extracted and converted files.
% \item[/path/to/somewhere/]
% It is also possible to give a custom path, either relative to the current
% working directory (\file{./relative/path/}) or as an absolute path.
% \end{DescribeValues}
%
% \DescribeOption{extractname}^^A
% It's also possible to change the name for extracted and converted files. The
% default setting is \opt{extractname}|=|\val{filenamenumbered}. The appended
% file extension is derived from option \opt{extractformat}.
% \begin{DescribeValues}^^A
% \item[filename/name]
% The name of the exported \app{Inkscape}~file is used and the suffix
% \file{-extract} is attached.
% \item[\default{filenamenumbered}/namenumbered/numberedfilename/numberedname]
% Same as above, but a prefix with the current enumerated count of SVG~files
% is used instead of the suffix.
% \item[numbered/section/numberedsection/sectionnumbered]
% The file name is composed by the current enumerated count of SVG~files and
% the present outline numbering.
% \item[\file{\meta{filename}}]
% You can use any file name. It's possible to use counters for specifying the
% name of the extracted file. Repeatedly specifying the same file name will
% overwrite previously created files.
% \end{DescribeValues}
%
% \DescribeOption{extractformat}^^A
% The included SVG~file can be extracted from the document into an independent
% graphic~file of type PDF, EPS or PS. The option can be used with either a
% single value (\opt{extractformat}|=|\val{pdf}) or a comma separated list.
% For example,
% \begin{svgexample}
% \includesvg[extractformat={pdf,eps,ps}]§\marg{svg~filename}§
% \end{svgexample}
% will extract the SVG~file to both PDF and EPS~formats and generates two
% independent graphic~files. By default, \opt{extractformat}|=|\val{pdf} is set
% unless DVI~output was detected. In this case \opt{extractformat}|=|\val{eps}
% is the default setting.
%
% \DescribeOptions{extractwidth,extractheight,extractdistort,extractscale,^^A
% extractpretex,extractapptex}^^A
% \changes{v2.02}{2018/09/07}{option \opt{extractdistort} added for distortion
% of extracted graphics}^^A
% These options can be used to overwrite the settings given for the appearance
% of a SVG~file within the document. For example, a SVG~file should cover the
% entire text width within the document but be extracted to a fixed width. This
% can be done with:
% \begin{svgexample}
% \includesvg[width=\textwidth,extractwidth=500pt]§\marg{svg~filename}§
% \end{svgexample}
% Assigning the value \val{inherit} to one of these options---which is set by
% default---leads to the usage of the corresponding option of package \pkg{svg}
% (\opt{width}/\opt{height}/\opt{scale}/\opt{pretex}/\opt{apptex}), whereas
% \opt{extract\dots}|=|\val{\cs{relax}} can be used to ignore a parent option
% utterly.
%
% \DescribeOptions{extractpreamble,extractpreambleend}^^A
% Within the included and extracted SVG~files any \LaTeX~macro can be used
% either defined by the user---this should be done in the preamble of the
% \LaTeX~document in which the SVG~file is to be included---or provided by a
% package which is loaded. As the extraction process of the SVG~files needs an
% auxiliary \LaTeX~file all used packages and commands have to be known within
% this file. Consequently, the preamble of the current \LaTeX~document is used
% for the extraction of the SVG~file by default.
%
% However, it is possible to specify a different \emph{preamble~file} with the
% option \opt{extractpreamble} where the file to use as the preamble is given
% as the argument---including maybe path, but file~name and file~extension in
% any case. The given preamble file is searched similar to SVG~files meaning,
% every path given with \cs{svgpath} or \cs{graphicspath} is examined. The
% default definition of \opt{extractpreamble} is \file{\cs{jobname}.tex}---more
% precisely the file~extension given by option \opt{latexext} is used---and
% should suffice for most cases. The preamble up to the line defined by the
% option \opt{extractpreambleend} will be used, which is set to a default with
% \cs{begin}|{document}|.
%
% \DescribeMacros{\svghidepreamblestart,\svghidepreambleend}^^A
% In case, the preamble of the current \LaTeX~document is used, there are maybe
% packages included or some parts within the preamble, which should not be used
% within the separate auxiliary \LaTeX~file. These parts can be excluded if
% they are enclosed by \cs{svghidepreamblestart} and \cs{svghidepreambleend}.
%
% For example, your current \LaTeX~document uses package \pkg{showframe} which
% causes some problems with the extraction of independent graphic~files. So you
% want to get rid of it within the auxiliary \LaTeX~file. This can be done with:
% \begin{svgexample}
% \documentclass§\marg{documentclassname}§
% §\dots§
% \usepackage{svg-extract}
% §\dots§
% \svghidepreamblestart
% \usepackage{showframe}
% \svghidepreambleend
% §\dots§
% \end{svgexample}
%
% \DescribeOption{extractruns}^^A
% When extracting independent grahic~files by compiling the generated auxiliary
% \LaTeX~file, it's maybe necessary to do multiple \LaTeX~iterations on this.
% The number of iterations is controlled with option \opt{extractruns}. It is
% set to \opt{extractruns}|=|\val{2} by default.
%
% \DescribeOptions{latexexe,latexopt,latexext}^^A
% For the extraction of an independent grahic~file, the \LaTeX~program is used
% which is set by the \opt{latexexe} option. Depending on the \LaTeX~engine
% used for the current \LaTeX~document, it is set to either \app{pdflatex},
% \app{lualatex}, \app{xelatex} or \app{latex} by default. It's also possible
% to specify additional flags or switches for the \LaTeX~iterations, which are
% performed during the extraction process by the \opt{latexopt} option. If you
% are used to utilize a different extension for \LaTeX~files than \file{.tex},
% option \opt{latexext} can be used like \opt{latexext}|=|\val{ltx}.
%
% \DescribeOptions{dvipsopt,pstoepsopt,pstopdfopt,pdftoepsopt,pdftopsopt}^^A
% Depending on the used \LaTeX~engine, the file~type of the extracted
% graphic differs. In order to create all formats, requested with option
% \opt{extractformat}, several converting tools provided by most of the
% \LaTeX~distributions are maybe invoked. These are \file{dvips},
% \file{ps2eps}, \file{ps2pdf} and/or \file{pdftops} and can't be changed. It's
% only possible to specify additional switches for every single tool with
% \opt{dvipsopt}, \opt{pstoepsopt}, \opt{pstopdfopt}, \opt{pdftoepsopt} and
% \opt{pdftopsopt}.
%
% \DescribeOption{clean}^^A
% During the extraction process many files are generated for each SVG~file
% extraction. So it's oftentimes desirable to automatically remove these
% temporary files. Using the option \opt{clean}|=|\val{true} will remove any
% generated files created other than the extracted output format(s) requested.
% Setting \opt{clean}|=|\val{false} is useful for debugging and set by default.
% Additionally, it's possible to use option \opt{clean} with a list of
% file~extensions in order to specify auxiliary files generated by package
% \pkg{svg-extract} to be deleted, for example \opt{clean}|=|\val{\{log,aux\}}.
%
% \DescribeOption{exclude}^^A
% Sometimes it may be necessary to extract and/or convert a SVG~file without
% including it. If the flag \opt{exclude} is specified, the SVG~file will not
% be rendered in the current \LaTeX~document, but will be extracted and/or
% converted to the requested output format(s).
%
% \DescribeMacros{\includesvg,\includeinkscape}^^A
% As previously mentioned, for extracting independent graphic files it is
% sufficient to load package \pkg{svg-extract} and afterwards everything
% necassary is done by just using \cs{includesvg} or \cs{includeinkscape}.
%
% \begin{DescribeParameterParent}{Macro}{\includesvg}^^A
% \DescribeParameter{extractangle}^^A
% \begin{DescribeParameterParent}{Macro}{\includeinkscape}^^A
% \renewcommand*\marginpar[2][]{}^^A
% \DescribeParameter{extractangle}^^A
% \changes{v2.02}{2018/09/07}{parameter \prm{extractangle} for \cs{includesvg}
% and \cs{includeinkscape} implemented in order to rotate graphics during
% extractions}^^A
% With this additional parameter the graphic is rotated during the extraction
% process. The value is not inherited from \prm{angle} if it was given by
% default. This can be achieved by setting:
% \begin{svgexample}
% \includesvg[angle=§\meta{angle}§,extractangle=inherit]§\marg{svg~filename}§
% \end{svgexample}
% \end{DescribeParameterParent}
% \end{DescribeParameterParent}
%
%
%
% \subsection{Convert extracted grahic files\label{sec:convert}}
%
% Based on the extraction of independent graphic~files, the \pkg{svg-extract}
% packages also provides the possibility to convert these extracted graphics in
% another format than PDF, EPS or PS with either \app{ImageMagick}---which is
% set by default---or \app{Ghostscript}.
%
% \DescribeOption{convert}^^A
% This option can be used to control the invocation of the conversion process.
% By default, \opt{convert}|=|\val{false} is set. For Windows, there exist two
% different versions of \app{Ghostscript}, either 64\,bit or 32\,bit. If
% it is selected as converting tool the 64\,bit~executable is set by default.
% Please note, that option \opt{extract} has to be activated.
% \begin{DescribeValues}^^A
% \item[\default{false}/off/no]
% No conversion is done.
% \item[true/on/yes]
% The conversion will be done with the current chosen converting tool.
% \item[magick/imagemagick/convert]
% The conversion is activated and \app{ImageMagick} is selected.
% \item[gs/ghostscript]
% The conversion is activated and \app{Ghostscript} is selected.
% \item[gs64/ghostscript64]
% This value activates \app{Ghostscript} as conversion tool and sets
% \opt{gsexe}|=|\val{gswin64c}. On unix-like operating systems, the value for
% \opt{gsexe} remains unchanged.
% \item[gs32/ghostscript32]
% The same as for the latter case applies, only option
% \opt{gsexe}|=|\val{gswin32c} is set on Windows.
% \end{DescribeValues}
%
% \DescribeOption{convertformat}^^A
% With this option, the desired output format(s) can be given. Multiple graphic
% formats can be specified in a list, for example something like
% \opt{convertformat}|=|\val{\{png,jpg,tif\}}. The value specified in
% \opt{extractformat} is used as the source format for the conversion. If
% \opt{extractformat} itself contains a file~list, the first value within this
% list is considered. If \opt{extractformat} is defined empty, the file
% generated anyway during the extraction is used.
%
% \minisec{Settings for specific converting formats}
%
% Maybe it's desired to apply varying settings for different output formats.
% Therefor some options described below can either be set for all converted
% files or for a specific output format. In particular, these are the options
% \opt{convertdpi} as well as \opt{magicksetting}, \opt{magickoperator},
% \opt{gsdevice} and \opt{gsopt}. All these mentioned options can be used like
% either \opt{\meta{option}}|=|\val{\meta{value}} or
% \opt{\meta{option}}|=|\val{\{\meta{outputformat}=\meta{value}\}} and even
% \opt{\meta{option}}|=|\val{\{\meta{outputformat}+=\meta{value}\}} where the
% desired output~format is trailed with |+| as inner key.
%
% The first variant is applied to all output formats in general. If one of
% these mentioned options is evaluated and an output format specific value was
% given like in the second variant, the general setting is overwritten. If the
% general setting should be used and extended by an additional output format
% specific settings, then the third variant is to be used. In this case, no
% output format specific setting (second variant) must not have been used.
%
% If you want to reverse any setting, you only have to use \cs{relax} as a
% value, either for a general option (\opt{\meta{option}}|=|\val{\cs{relax}})
% or a specific one
% (\opt{\meta{option}}|=|\val{\{\meta{outputformat}[+]=\cs{relax}\}}).
%
% \DescribeOption{convertdpi}^^A
% This option controls the used density for all file~formats or a specific one,
% whether \app{ImageMagick} or \app{Ghostscript} is used for the graphic
% conversion. The desired resolution of the converted file is given in dots per
% inch~(DPI) either as a scalar value (e.g.~\opt{convertdpi}|=|\val{600}) or
% with different resolutions in x- and y\hbox{-}direction
% (e.g.~\opt{convertdpi}|=|\val{600x400}).
%
% As described before, it's also possible to declare a specific resolution for
% each desired converting format. For example, you want to set different
% resolution for PNG and JPG~formats and something for all other formats:
% \begin{svgexample}
% \svgsetup{%
% convertdpi={png=600},%
% convertdpi={jpg=150},%
% convertdpi=300%
% }%
% \end{svgexample}
% If a setting for a specific output format is given, any unspecific setting is
% overwritten, when the conversion to this format is done. With
% \opt{convertdpi}|=|\val{\{\meta{outputformat}=\cs{relax}\}} a specific
% setting can be reversed.
%
% Please note that not every graphic format support different resolutions in x-
% and y\hbox{-}direction. So using a value like \opt{convertdpi}|=|\val{600x400}
% may not necessarily lead to the desired result. However, this is then due to
% the used conversion tool and not to the processing of the option.
%
%
%
% \subsubsection{Settings for the invocation of \app{ImageMagick}}
%
% \DescribeOptions{magickexe,magicksetting,magickoperator}^^A
% The conversion with \app{ImageMagick} via the \file{magick} or \file{convert}
% command~line~interface can be controlled with these options. The option
% \opt{magickexe} determines the used executable and is set to \file{magick} on
% Windows and otherwise to \file{convert} by default. Additionally, there are
% the two options \opt{magicksetting} and \opt{magickoperator} which can be
% used to define \emph{settings} and \emph{operators} for the conversion
% process. As described before, the two options \opt{magicksetting} and
% \opt{magickoperator} can be set for all output formats or a \emph{specific}
% one either resetting or extending the general settings. For further
% information see the documentation of
% \hrfn{http://www.imagemagick.org/script/command-line-processing.php}^^A
% {\app{ImageMagick} command~line~interface}.
%
%
%
% \subsubsection{Settings for the invocation of \app{Ghostscript}}
%
% \DescribeOptions{gsexe,gsdevice,gsopt}^^A
% The conversion with \app{Ghostscript} is done with command~line~interface
% \file{gswin64c} or \file{gswin32c} on Windows and \file{gs} on unix-like
% operating systems. The executable can be changed with option \opt{gsexe}.
% Because \app{Ghostscript} requires the specification of a device, there are
% some predefined for the most common output formats. These are:
% \begin{svgexample}
% \svgsetup{%
% gsdevice={png=png16m},gsdevice={jpeg=jpeg},gsdevice={jpg=jpeg},%
% gsdevice={tif=tiff48nc},gsdevice={tiff=tiff48nc},%
% gsdevice={eps=eps2write},gsdevice={ps=ps2write}%
% }%
% \end{svgexample}
% Furthermore, with \opt{gsopt} additional switches for \app{Ghostscript} can
% be set. As described before, both \opt{gsdevice} and \opt{gsopt} can be
% defined in general or for specific output formats. For further information
% see the documentation of
% \hrfn{https://ghostscript.com/doc/current/Use.htm}{\app{Ghostscript}}.
%
%
%
% \cleardoublepage
% \section{Example}
%
% As an minimal example\footnote{The image used here is a slightly modified
% version of the image used in the initial documentation on how to include a
% SVG~file in \LaTeX{} by Johan\,B.\,C.~Engelen available as package
% \href{http://www.ctan.org/pkg/svg-inkscape}{\pkg{svg-inkscape} on CTAN}.}
% take the following lines of code:
% \begin{svgexample}
% \documentclass{article}
% \usepackage[T1]{fontenc}
% \usepackage{svg}
% \usepackage[off]{svg-extract}
% \svgsetup{clean=true}
% %\pdfsuppresswarningpagegroup=1
% \usepackage{relsize}
% \usepackage{subcaption}
% \begin{document}
% \begin{figure}
% \begin{minipage}{\dimexpr\linewidth/2\relax}
% \includesvg[width=\linewidth]{svg-example}%
% \subcaption{This text is too large!}%
% \end{minipage}%
% \begin{minipage}{\dimexpr\linewidth/2\relax}
% \includesvg[width=\linewidth,pretex=\relscale{0.6}]{svg-example}%
% \subcaption{This text fits better.}%
% \end{minipage}
% \caption{An example figure with \LaTeX~support\label{fig:example}}%
% \end{figure}
% \begin{figure}\centering
% \includesvg[%
% width=.5\linewidth,inkscapelatex=false,extractformat={pdf,eps}%
% ]{svg-example}%
% \caption{The same example figure without \LaTeX~support}%
% \end{figure}
% \end{document}
% \end{svgexample}
% \begin{figure}[tb]
% \null\hfill^^A
% \begin{minipage}{\dimexpr\linewidth*9/20\relax}
% \includesvg[width=\linewidth]{svg-example}^^A
% \subcaption{This text is too large!\label{fig:example-tex-a}}^^A
% \end{minipage}\hfill^^A
% \begin{minipage}{\dimexpr\linewidth*9/20\relax}
% \includesvg[width=\linewidth,pretex=\relscale{0.6}]{svg-example}^^A
% \subcaption{This text fits better.\label{fig:example-tex-b}}^^A
% \end{minipage}
% \hfill\null^^A
% \caption{An example figure with \LaTeX~support\label{fig:example-tex}}^^A
% \end{figure}
% \begin{figure}[tb]\centering
% \includesvg[^^A
% width=.5\linewidth,inkscapelatex=false,extractformat={pdf,eps}^^A
% ]{svg-example}^^A
% \caption{^^A
% The same example figure without \LaTeX~support\label{fig:example}^^A
% }^^A
% \end{figure}
%
% The output is shown in \autoref{fig:example-tex} and \autoref{fig:example}.
% Within this example the file \file{svg-example.svg} was included three times
% using the \cs{includesvg} command.
%
% If you are willing to compile the example, there are two aspects to consider.
% First, the included SVG~file \file{svg-example.svg} has to be located in the
% current folder and is located in \file{\meta{texmf}/doc/latex/svg/}. Second,
% you have to run the desired \LaTeX~engine with flag \file{-{}-shell-escape}.
%
% As you can see, \autoref{fig:example-tex-a} is created with default settings,
% except the width specification. The \app{Inkscape}~export with \LaTeX~support
% is done and the extraction of an independent graphic~file in PDF~format as
% the \pkg{svg-extract} package was loaded.
%
% However, the text is slightly overrunning the margins of the image, and so
% \autoref{fig:example-tex-b}---which again uses the same \app{Inkscape}~export
% results---decreases the font size of the text within the image relative
% using the \prm{pretex} option together with the \cs{relscale} command
% provided by the \pkg{relsize} package.
%
% In \autoref{fig:example} the same SVG~file was used but without the export
% of a separate \LaTeX~file containing all text elements.
%
% Feel free to use this given example to try out all the options and
% possibilities described in \autoref{sec:inkscape} for package \pkg{svg}.
% Especially if you want to use package \pkg{svg-extract} for the automated
% extraction of independent graphics (\autoref{sec:extract}) and their
% conversion to different graphic formats with \app{ImageMagick} and/or
% \app{Ghostscript} (\autoref{sec:convert}), this example can be easily used
% for the first steps.
%
%
%
% \section{Troubleshooting and reporting issues}
%
% When using the packages \pkg{svg} and \pkg{svg-extract}, the most likely
% occurring problems will be caused by calling the external programs. For this
% reason, a short package information is written into the log~file right before
% each call of an external program on shell. If a file should have been
% created, both packages check after the external call, whether this file
% exists or not and raise an error or at least a warning, if this file is
% missing. If you got such a message, please check the log~file for lines like:
% \begin{quote}
% |Package svg Info:| or |Package svg-extract Info:|
% \end{quote}
% Right afterwards, there should appear |runsystem(<command>)...excuted.| which
% you should try to execute manually at the terminal in the right directory. In
% most cases, the problem will be an invalid command call. If something goes
% wrong during the extraction/converting process of package \pkg{svg-extract},
% it would make sense to set option \opt{clean}|=|\val{false} to not delete any
% auxiliary files that might be needed.
%
% If you are sure that the problem is not caused by the configuration of your
% operating system, you can send an error report either via email or create a
% new issue on GitHub. Both addresses can be found on the title.
%
% \minisec{When using pdf\LaTeX{} there are a lot of warnings}
%
% It may happen that several warnings like
% \begin{quote}\ttfamily\raggedright^^A
% pdfTeX warning:\,pdflatex.exe(file \meta{filename}.pdf):\,PDF inclusion:
% multiple pdfs with page group included in a single page^^A
% \end{quote}
% occur when including the PDF~graphics exported with \app{Inkscape}. This is
% related to the handling of transparency effects within PDF~files. Since
% pdf\TeX~version 1.40.15 or later, you can get rid of these messages by using
% \cs{pdfsuppresswarningpagegroup}|=|\val{1}. See also the discussion on
% \hrfn{http://tex.stackexchange.com/questions/76273/}{LaTeX Stack Exchange}
% for more information.
%
%
%
% \section{Include SVG files created with \app{ROOT}}
%
% This section was originally written by Philip Ilten. In the hope that since
% then nothing has changed fundamentally in the described procedure. This
% passage remains in the documentation, even if it will almost certainly be
% relevant to experimental particle physicists only, who frequently use the
% analysis package \app{ROOT}.
%
% \app{ROOT} has the ability to export directly to a SVG~file, which means that
% it is possible to completely by-pass all of \app{ROOT}'s internal text
% rendering machinery, and let \LaTeX{} handle the text natively. This means
% that all of the ugly fonts that are rendered by \app{ROOT} can now be
% completely avoided, with the additional bonus of being able to add references
% within plots. So how does one go about using this package with \app{ROOT}?
% \begin{enumerate}
% \item
% Create the plot with \app{ROOT} as normal, but turn off all
% \LaTeX~interpretation of text strings. This is a bit tricky, but can be
% accomplished by setting the font in \app{ROOT} to a precision of zero as
% described in the documentation for
% \hrfn{http://root.cern.ch/root/html/TAttText.html}{\texttt{TAttFill}}.
% Remember that the font is set by using the function
% |(TAttFill*)->SetTextFont(i)| with
% \[\texttt{i}=\textrm{(font type)} \times 10 + \textrm{(font precision)}\]
% In the following lines of code, a |TStyle| is defined which sets the font
% to type ``Courier New'' with a precision of zero.
% \begin{svgexample}[backgroundcolor=\color{red!10}]
% TStyle *style = new TStyle("style","style"); int FONT = 80;
% style->SetTextFont(FONT);
% style->SetLabelFont(FONT,"XYZ");
% style->SetTitleFont(FONT,"XYZ");
% style->SetTitleFont(FONT,"");
% gROOT->SetStyle("style");
% gROOT->ForceStyle();
% \end{svgexample}
% Now, you can just use the well\hbox{-}known standard \LaTeX~syntax for
% creating labels, etc. Note however, that backslashes have to be escaped due
% to interpretation of special characters by \app{C++}.
% \item Print the plot as a SVG~file.
% \begin{svgexample}[backgroundcolor=\color{red!10}]
% gPad->Print("foo.svg");
% \end{svgexample}
% \item Include the SVG~file within the document using this package.
% \begin{svgexample}
% \usepackage{svg}
% \usepackage{svg-extract}
% \svgsetup{clean=true}
% §\dots§
% \includesvg[width=\linewidth]{foo}
% \end{svgexample}
% \end{enumerate}
%
% Consider the following example image produced by \app{ROOT} in
% \autoref{fig:root}. This figure was generated by the \app{ROOT} macro
% \file{root.C}, provided within \file{\meta{texmf}/doc/latex/svg/},
% which produces the file~\file{root.svg} when run. The code used to produce
% this SVG~file from within \app{ROOT} is
% \lstinputlisting[style=svg,backgroundcolor=\color{red!10}]{examples/root.C}
% where the text produced within the \app{ROOT} plot is set to a precision of
% zero.
%
% The plot was then included within this document using the following
% \LaTeX~code
% \begin{svgexample}
% \begin{figure}
% \centering%
% \includesvg[%
% inkscapearea=page,height=6cm,pretex=\tiny,convertformat=png%
% ]{root}%
% \caption{%
% Rendering of a \app{ROOT} plot---no more \emph{Comic CERNs}%
% \label{fig:root}%
% }%
% \end{figure}
% \end{svgexample}
% \begin{figure}
% \centering^^A
% \includesvg[^^A
% inkscapearea=page,height=6cm,pretex=\tiny,convertformat=png^^A
% ]{root}^^A
% \caption{^^A
% Rendering of a \app{ROOT} plot---no more \emph{Comic CERNs}
% \label{fig:root}^^A
% }^^A
% \end{figure}
% which includes the graphic as well as the \LaTeX~file exported by
% \app{Inkscape}, produces the extracted PDF~image~(\file{root.pdf}) and
% converts this to a PNG~image~(\file{root.png}) by using \app{ImageMagick}.
% Enjoy plots from \app{ROOT} with natively rendered \LaTeX{}!
%
% \StopEventually{^^A
% \cleardoublepage\PrintIndex^^A
% \cleardoublepage\PrintChanges^^A
% \cleardoublepage\PrintToDos^^A
% }
%
% \iffalse
%<*package&base>
% \fi
%
%
%
% \cleardoublepage
% \appendix
% \part{Implementation}
% \section{Initialization}
% \subsection{Packages}
%
% The package \pkg{svg} mainly requires \pkg{scrbase} for options processing
% and \pkg{graphicx} for the inclusion of the exported graphic~files.
%
% The packages \pkg{iftex} and \pkg{pdftexcmds} are needed to detect the used
% \LaTeX~engine on the one hand and enabling pdf\TeX{} primitives independent
% of the used \LaTeX~engine on the other hand. Additionally, \pkg{trimspaces}
% is responsible for string manipulation. Both packages \pkg{shellesc} and
% \pkg{ifplatform} are used for engine independent access to systems commands
% and files. The package \pkg{svg-extract} only needs package \pkg{svg} itself,
% which is loaded during initialization.
% \begin{macrocode}
%<*main>
\RequirePackage{iftex}[2020/03/06]
\RequirePackage{scrbase}[2020/04/19]
\RequirePackage{pdftexcmds}[2019/11/24]
\RequirePackage{trimspaces}[2009/09/17]
\RequirePackage{graphicx}[2019/11/30]
\RequirePackage{shellesc}[2019/11/08]
% \end{macrocode}
% In order to do not raise a warning, package \pkg{ifplatform} is only used if
% \file{-{}-shell-escape} flag is enabled.
% \begin{macrocode}
\ifnum\pdf@shellescape=\@ne\relax
\RequirePackage{ifplatform}[2017/10/13]
\fi
%</main>
% \end{macrocode}
%
%
%
% \subsection{Dealing with catcodes}
%
% The catcode for double quotes are temporarily changed and restored at the
% very end of both packages.
% \begin{macrocode}
\edef\svg@catcodecodes@restore{%
\catcode`\noexpand\"\the\catcode`\"\relax%
}
\@makeother\"%
\AtEndOfPackage{\svg@catcodecodes@restore}
% \end{macrocode}
%
% \iffalse
%<*main>
% \fi
%
%
%
% \subsection{General macros}
%
% \begin{macro}{\svg@tempa}
% \begin{macro}{\svg@tempb}
% \begin{macro}{\if@svg@tempswa}
% Internal temporary macros.
% \begin{macrocode}
\newcommand*\svg@tempa{}
\newcommand*\svg@tempb{}
\newif\if@svg@tempswa
% \end{macrocode}
% \end{macro}^^A \if@svg@tempswa
% \end{macro}^^A \svg@tempb
% \end{macro}^^A \svg@tempa
%
%
%
% \subsubsection{Macros for process control}
%
% \begin{macro}{\svg@ifwindowsdetected}
% Do some Windows specific stuff if it was detected.
% \begin{macrocode}
\newcommand*\svg@ifwindowsdetected{\@secondoftwo}
\AfterPackage*{ifplatform}{%
\renewcommand*\svg@ifwindowsdetected{%
\ifwindows%
\expandafter\@firstoftwo%
\else%
\expandafter\@secondoftwo%
\fi%
}%
}
% \end{macrocode}
% \end{macro}^^A \svg@ifwindowsdetected
% \begin{macro}{\svg@ifvalueisrelax}
% For some keys the usage of \val{\cs{relax}} as a value should lead to a
% special reaction, such as restoring to default behavior or reseting the key.
% Therefore, \cs{svg@ifvalueisrelax} checks, whether \val{\cs{relax}} was used
% as value or not.
% \begin{macrocode}
\newcommand*\svg@ifvalueisrelax[1]{%
\begingroup%
\def\svg@tempa{#1}%
\def\svg@tempb{\relax}%
\ifx\svg@tempa\svg@tempb%
\aftergroup\@firstoftwo%
\else%
\aftergroup\@secondoftwo%
\fi%
\endgroup%
}
% \end{macrocode}
% \end{macro}^^A \svg@ifvalueisrelax
%
% \iffalse
%</main>
%<*extract>
% \fi
%
% \begin{macro}{\svgx@ifkeyandval}
% \begin{macro}{\svgx@@ifkeyandval}
% It is checked whether a key was given as \val{\meta{key}=\meta{value}} or
% like \val{\meta{key}=\{\meta{format}=\meta{value}\}}.
% \begin{macrocode}
\newcommand*\svgx@@ifkeyandval{}
\newcommand*\svgx@ifkeyandval[3]{%
\def\svgx@@ifkeyandval##1=##2=##3\@nil{\IfArgIsEmpty{##3}{#3}{#2}}%
\svgx@@ifkeyandval#1==\@nil%
}
% \end{macrocode}
% \end{macro}^^A \svgx@@ifkeyandval
% \end{macro}^^A \svgx@ifkeyandval
%
% \iffalse
%</extract>
%<*main>
% \fi
%
%
%
% \subsubsection{String manipulation}
%
% Both packages \pkg{svg} and \pkg{svg-extract} should be able to handle
% user-defined input and output paths. As there is the possibility for users to
% provide paths with or without quotes to \LaTeX{}, this is taken into account.
%
% \begin{macro}{\svg@deactivate@dq}
% \changes{v2.02}{2018/09/07}{new}^^A
% \changes{v2.02a}{2018/10/17}{bug fix for \pkg{polyglossia}}^^A
% In order to avoid errors concerning file names with package \pkg{babel} and
% it's active double quotes, this command is defined.
% \begin{macrocode}
\newcommand*\svg@deactivate@dq{}
\AfterPackage+{babel}{%
\renewcommand*\svg@deactivate@dq{\bbl@deactivate{"}}%
\providecommand*\bbl@deactivate[1]{}%
}
% \end{macrocode}
% \end{macro}^^A \svg@deactivate@dq
% \begin{macro}{\svg@sanitize@dq}
% \changes{v2.02}{2018/09/07}{new}^^A
% Save expansion of the second argument in the macro from the first argument
% with deactivated double quotes.
% \begin{macrocode}
\newcommand*\svg@sanitize@dq[2]{%
\begingroup%
\svg@deactivate@dq%
\edef\svg@tempa{\endgroup\def\noexpand#1{#2}}%
\svg@tempa%
}
% \end{macrocode}
% \end{macro}^^A \svg@sanitize@dq
% \begin{macro}{\svg@quotes@check}
% \begin{macro}{\svg@quotes@@check}
% \begin{macro}{\if@svg@quotes@found}
% During the treatment of paths, it may be necessary to temporarily remove
% quotes and, if required, add them again later. For this purpose, the switch
% \cs{if@svg@quotes@found} as well as the commands \cs{svg@quotes@check} and
% \cs{svg@quotes@@check}, which controls the switch, are defined. As before,
% the string is passed in a macro to \cs{svg@quotes@check}.
% \begin{macrocode}
\newif\if@svg@quotes@found
\newcommand*\svg@quotes@check[1]{%
\expandafter\svg@quotes@@check#1"\@nil%
}
\newcommand*\svg@quotes@@check{}
\def\svg@quotes@@check#1"#2\@nil{%
\IfArgIsEmpty{#2}{\@svg@quotes@foundfalse}{\@svg@quotes@foundtrue}%
}
% \end{macrocode}
% \end{macro}^^A \if@svg@quotes@found
% \end{macro}^^A \svg@quotes@@check
% \end{macro}^^A \svg@quotes@check
% \begin{macro}{\svg@quotes@remove}
% \changes{v2.02}{2018/09/07}{usage of \cs{svg@sanitize@dq}}^^A
% \changes{v2.02}{2018/09/07}{calling \cs{svg@quotes@check}}^^A
% \begin{macro}{\svg@quotes@@remove}
% These two commands are used to remove all occurring quotes within a string.
% The only argument passed to \cs{svg@quotes@remove} is not the string itself
% but a macro in which a string is stored.
% \begin{macrocode}
\newcommand*\svg@quotes@remove[2][]{%
\begingroup%
\IfArgIsEmpty{#1}{\def\svg@tempb{#2}}{\def\svg@tempb{#1}}%
\svg@sanitize@dq\svg@tempa{\svg@tempb}%
\expandafter\svg@quotes@check\expandafter{\svg@tempa}%
\expandafter\svg@quotes@@remove\svg@tempa""\@nil%
\edef\svg@tempb{%
\endgroup%
\def\noexpand#2{\svg@tempa}%
\if@svg@quotes@found%
\noexpand\@svg@quotes@foundtrue%
\else%
\noexpand\@svg@quotes@foundfalse%
\fi%
}%
\svg@tempb%
}
\newcommand*\svg@quotes@@remove{}
\def\svg@quotes@@remove#1"#2"#3\@nil{%
\IfArgIsEmpty{#2}{%
\edef\svg@tempa{#1}%
}{%
\svg@quotes@@remove#1#2#3""\@nil%
}%
}
% \end{macrocode}
% \end{macro}^^A \svg@quotes@@remove
% \end{macro}^^A \svg@quotes@remove
% \begin{macro}{\svg@remove@leadingchar}
% \changes{v2.02}{2018/09/07}{new}^^A
% This command removes the single character in given with the first argument
% from the expanded macro in the second argument.
% \begin{macrocode}
\newcommand*\svg@remove@leadingchar[2]{%
\begingroup%
\svg@sanitize@dq\svg@tempa{#2}%
\def\svg@tempb{%
\def\svg@tempa####1\@nil{\def\svg@tempa{####1}}%
\kernel@ifnextchar#1%
{\expandafter\svg@tempa\@gobble}%
{\svg@tempa}%
}%
\expandafter\svg@tempb\svg@tempa\@nil%
\edef\svg@tempb{%
\endgroup%
\def\noexpand#2{\svg@tempa}%
}%
\svg@tempb%
}
% \end{macrocode}
% \end{macro}^^A \svg@remove@leadingchar
%
%
%
% \subsubsection{File handling}
%
% \begin{macro}{\svg@filename@parse}
% \changes{v2.02}{2018/09/07}{usage of \cs{svg@sanitize@dq}}^^A
% \changes{v2.02}{2018/09/07}{usage of \cs{svg@remove@leadingchar}}^^A
% \changes{v2.02}{2018/09/07}{usage of \cs{svg@extension@parse}}^^A
% As the internal \LaTeX{} command \cs{filename@parse} is not able to split a
% given file name containing quotes, \cs{svg@filename@parse} is defined to
% resolve this problem. The optional argument can be used to give a specific
% file extension, which should be searched within \cs{filename@ext}. If found
% at the very end, the previous part is appended to \cs{filename@base}.
% \begin{macrocode}
\newcommand*\svg@filename@parse[2][]{%
\begingroup%
% \end{macrocode}
% The given path and file is parsed with \cs{filename@parse}.
% \begin{macrocode}
\svg@sanitize@dq\svg@tempa{#2}%
\expandafter\filename@parse\expandafter{\svg@tempa}%
% If there are quotes in the file path, the closing one will be found as first
% character in \cs{filename@base} as \cs{filename@area} is splitted at the last
% slash. This leading quote is removed from \cs{filename@base} with
% \cs{svg@remove@leadingchar}.
% \begin{macrocode}
\svg@quotes@remove{\filename@area}%
\if@svg@quotes@found%
\edef\filename@area{"\filename@area"}%
\svg@remove@leadingchar"\filename@base%
\fi%
% \end{macrocode}
% The found extension is parsed against the optional argument. If a double quote
% was found within the extension, it actually belongs to \cs{filename@base}.
% \begin{macrocode}
\ifx\filename@ext\relax\else%
\svg@quotes@remove{\filename@ext}%
\svg@extension@parse{#1}%
\if@svg@quotes@found%
\edef\filename@base{\filename@base"}%
\fi%
\fi%
% \end{macrocode}
% Quotes within \cs{filename@base} are normalized.
% \begin{macrocode}
\svg@quotes@remove{\filename@base}%
\if@svg@quotes@found%
\edef\filename@base{"\filename@base"}%
\fi%
% \end{macrocode}
% With \cs{svg@tempa} the group is closed and the results are saved in the
% macros \cs{filename@\dots}.
% \begin{macrocode}
\edef\svg@tempa{%
\endgroup%
\def\noexpand\filename@area{\filename@area}%
\def\noexpand\filename@base{\filename@base}%
\ifx\filename@ext\relax%
\let\noexpand\filename@ext\noexpand\relax%
\else%
\def\noexpand\filename@ext{\filename@ext}%
\fi%
}%
\svg@tempa%
}
% \end{macrocode}
% \end{macro}^^A \svg@filename@parse
% \begin{macro}{\svg@extension@parse}
% \changes{v2.02}{2018/09/07}{new}^^A
% \begin{macro}{\svg@extension@@parse}
% \changes{v2.02}{2018/09/07}{new}^^A
% These macros are used to permit multiple dots in file names. The content of
% \cs{filename@ext} is split at each occurence of \val{.} and the trailing part
% is compared against the content of the argument of \cs{svg@extension@parse},
% which is probably \cs{svg@file@ext}. If they are equal, the previous part is
% appended to \cs{filename@base} and \cs{filename@ext} is set to the content of
% the first argument.
% \begin{macrocode}
\newcommand*\svg@extension@parse[1]{%
\IfArgIsEmpty{#1}{}{%
\@expandtwoargs\Ifstr%
{\detokenize\expandafter{\filename@ext}}{\detokenize\expandafter{#1}}{}{%
\begingroup%
% \end{macrocode}
% Macro \cs{svg@tempa} is used to temporarily store anything before the
% searched extension at the end of \cs{filename@ext} and \cs{svg@tempb} is set
% to the actual searched extension if found.
% \begin{macrocode}
\edef\svg@tempa{%
\def\noexpand\svg@tempa{}%
\let\noexpand\svg@tempb\relax%
\noexpand\svg@extension@@parse%
\filename@ext.\noexpand\@nil#1\noexpand\@nil%
}%
\svg@tempa%
\edef\svg@tempa{%
\endgroup%
% \end{macrocode}
% If the trailing extension was found, \cs{filename@base} and \cs{filename@ext}
% are adopted.
% \begin{macrocode}
\def\noexpand\filename@base{\filename@base\svg@tempa}%
\ifx\svg@tempb\relax%
\let\noexpand\filename@ext\relax%
\else%
\def\noexpand\filename@ext{\svg@tempb}%
\fi%
}%
\svg@tempa%
}%
}%
}
% \end{macrocode}
% Macro \cs{svg@extension@@parse} is recursively called as long as there are
% any dots or the searched extension is found.
% \begin{macrocode}
\newcommand*\svg@extension@@parse{}
\def\svg@extension@@parse#1.#2\@nil#3\@nil{%
\edef\svg@tempa{\svg@tempa.#1}%
\IfArgIsEmpty{#2}{}{%
\Ifstr{\detokenize{#2}}{\detokenize{#3.}}{%
% \end{macrocode}
% If the trailing extension is found, \cs{svg@tempb} is definied.
% \begin{macrocode}
\edef\svg@tempb{#3}%
}{%
\svg@extension@@parse#2\@nil#3\@nil%
}%
}%
}
% \end{macrocode}
% \end{macro}^^A \svg@extension@@parse
% \end{macro}^^A \svg@extension@parse
% \begin{macro}{\svg@iffilenewer}
% \changes{v2.02d}{2019/10/22}{use \cs{filemoddate} with Xe\LaTeX, see
% \url{https://github.com/mrpiggi/svg/issues/12}}^^A
% The macro \cs{svg@iffilenewer} is used to decide, whether the export with
% \app{Inkscape} is necessary due to an updated SVG~file. This can only be
% done, if \cs{pdf@filemoddate} or \cs{filemoddate} is definied.
% \ToDo{\cs{svg@iffilenewer} instead \cs{IfFileExists} to check results}[v2.03]
% \begin{macrocode}
\newcommand*\svg@iffilenewer[2]{\@gobbletwo}
\ifx\pdf@filemoddate\@undefined
\ifx\filemoddate\@undefined\else
\ifx\strcmp\@undefined\else
\renewcommand*\svg@iffilenewer[2]{%
\begingroup%
\edef\svg@tempa{\filemoddate{#1}}%
\edef\svg@tempb{\filemoddate{#2}}%
\ifnum\strcmp{\svg@tempa}{\svg@tempb}>\z@\relax%
\aftergroup\@firstoftwo%
\else%
\aftergroup\@secondoftwo%
\fi%
\endgroup%
}%
\fi
\fi
\else
\ifx\pdf@strcmp\@undefined\else
\renewcommand*\svg@iffilenewer[2]{%
\begingroup%
\edef\svg@tempa{\pdf@filemoddate{#1}}%
\edef\svg@tempb{\pdf@filemoddate{#2}}%
\ifnum\pdf@strcmp{\svg@tempa}{\svg@tempb}>\z@\relax%
\aftergroup\@firstoftwo%
\else%
\aftergroup\@secondoftwo%
\fi%
\endgroup%
}%
\fi
\fi
% \end{macrocode}
% \end{macro}^^A \svg@iffilenewer
% \begin{macro}{\svg@shell@mkdir}
% \begin{macro}{\svg@shell@@mkdir}
% \begin{macro}{\svg@shell@mv}
% \begin{macro}{\svg@shell@@mv}
% \begin{macro}{\svg@shell@rm}
% \begin{macro}{\svg@shell@@rm}
% Finally, platform dependend macros for creating directories as well as
% moving and deleting files are provided.
% \begin{macrocode}
\newcommand*\svg@shell@mkdir[1]{%
\begingroup%
% \end{macrocode}
% A directory should only be created, if it isn't the current working directory.
% \begin{macrocode}
\svg@quotes@remove[{#1}]{\svg@tempa}%
\@svg@tempswatrue%
\Ifstr{\svg@tempa}{}{\@svg@tempswafalse}{%
\Ifstr{\svg@tempa}{./}{\@svg@tempswafalse}{%
}}%
\if@svg@tempswa%
\ShellEscape{\svg@shell@@mkdir{\svg@tempa}}%
\fi%
\endgroup%
}
\newcommand*\svg@shell@mv[2]{%
\ShellEscape{\svg@shell@@mv\space"#1"\space"#2"}%
}
\newcommand*\svg@shell@rm[1]{%
\ShellEscape{\svg@shell@@rm\space"#1"}%
}
% \end{macrocode}
% The platform dependent commands for file access.
% \begin{macrocode}
\svg@ifwindowsdetected{%
\newcommand*\svg@shell@@mkdir[1]{if not exist "#1" mkdir "#1"}%
\newcommand*\svg@shell@@mv{move}%
\newcommand*\svg@shell@@rm{del}%
}{%
\newcommand*\svg@shell@@mkdir[1]{mkdir -p "#1"}%
\newcommand*\svg@shell@@mv{mv}%
\newcommand*\svg@shell@@rm{rm}%
}
% \end{macrocode}
% \end{macro}^^A \svg@shell@@rm
% \end{macro}^^A \svg@shell@rm
% \end{macro}^^A \svg@shell@@mv
% \end{macro}^^A \svg@shell@mv
% \end{macro}^^A \svg@shell@@mkdir
% \end{macro}^^A \svg@shell@mkdir
% \begin{macro}{\svg@normalize@path}
% \changes{v2.02}{2018/09/07}{usage of \cs{svg@deactivate@dq}}^^A
% \begin{macro}{\svg@normalize@@path}
% If any path is given, a trailing slash is needed. These two macros ensure
% that this condition is fulfilled in any case, even if this is not considered
% by the user. As before, a macro containing the path string is passed to
% \cs{svg@normalize@path}.
% \begin{macrocode}
\newcommand*\svg@normalize@path[1]{%
\begingroup%
\svg@quotes@remove[{#1}]{\svg@tempa}%
\ifx\svg@tempa\@empty\relax%
\def\svg@tempa{./}%
\fi%
\expandafter\svg@normalize@@path\svg@tempa//\@nil%
\edef\svg@tempb{%
\endgroup%
\if@svg@quotes@found%
\def\noexpand#1{"\svg@tempa"}%
\else%
\def\noexpand#1{\svg@tempa}%
\fi%
}%
\svg@tempb%
}
\newcommand*\svg@normalize@@path{}
\def\svg@normalize@@path#1/#2/\@nil{%
\IfArgIsEmpty{#2}{%
\IfArgIsEmpty{#1}{\def\svg@tempa{}}{\def\svg@tempa{#1/}}%
}{%
\svg@normalize@@path#2/\@nil%
\edef\svg@tempa{#1/\svg@tempa}%
}%
}
% \end{macrocode}
% \end{macro}^^A \svg@normalize@@path
% \end{macro}^^A \svg@normalize@path
%
% \iffalse
%</main>
%<*extract>
% \fi
%
%
%
% \subsubsection{List handling}
%
% \begin{macro}{\svgx@ifinlist}
% Check, if the first argument is included in a comma-separated list in the
% second argument. Keep in mind that the first argument is not expanded at all,
% the second one exactly once.
% \begin{macrocode}
\newcommand*\svgx@ifinlist[2]{%
\begingroup%
\def\svg@tempa##1,#1,##2\@nil{%
\IfArgIsEmpty{##2}{%
\aftergroup\@secondoftwo%
}{%
\aftergroup\@firstoftwo%
}%
}%
\expandafter\svg@tempa\expandafter,#2,#1,\@nil%
\endgroup%
}
% \end{macrocode}
% \end{macro}^^A \svgx@ifinlist
%
% \iffalse
%</extract>
%</package&base>
%<*package&option>
% \fi
%
%
%
% \section{Including SVG files with package \pkg{svg}}
% \subsection{Options}
%
% All options, which can be set either as package options or with
% \cs{svgsetup}, as well as the optional parameters for both user commands
% \cs{includesvg}\oarg{parameters}\marg{svg~filename} and
% \cs{includeinkscape}\oarg{parameters}\marg{graphic~filename} are defined with
% the interface provided by package \pkg{scrbase}.
% \begin{macrocode}
\DefineFamily{SVG}
\DefineFamilyMember{SVG}
% \end{macrocode}
%
% \iffalse
%</package&option>
%<*package&option&main>
% \fi
%
% \begin{macro}{\svg@deprecated@key}
% With version v2.00 the whole user\hbox{-}interface was renewed. For reasons
% of compatibility, outdated options and parameters from version~v1.0 are also
% provided. If an old key was given, a warning is issued and the valid key is
% used.
% \begin{macrocode}
\newcommand*\svg@deprecated@key[3][svg]{%
\PackageWarning{#1}{%
The option key `#2' is deprecated. \MessageBreak%
It's recommended to use `#3'\MessageBreak%
instead%
}%
\FamilyOptions{SVG}{#3}%
}
% \end{macrocode}
% \end{macro}^^A \svg@deprecated@key
%
% Within the exported \LaTeX~files of \app{Inkscape}, some commands are used
% out of additional packages. But maybe the user doesn't want to load this
% packages anyhow.
%
% \begin{option}{usexcolor}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{option}{noxcolor}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{macro}{\if@svg@use@xcolor}
% \begin{option}{usetransparent}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{option}{notransparent}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{macro}{\if@svg@use@transparent}
% Options for preventing packages \pkg{xcolor} and \pkg{transparent} to be
% loaded.
% \begin{macrocode}
\newif\if@svg@use@xcolor
\FamilyBoolKey{SVG}{usexcolor}{@svg@use@xcolor}
\DeclareOption{noxcolor}{\FamilyOptions{SVG}{usexcolor=false}}
\newif\if@svg@use@transparent
\FamilyBoolKey{SVG}{usetransparent}{@svg@use@transparent}
\DeclareOption{notransparent}{\FamilyOptions{SVG}{usetransparent=false}}
% \end{macrocode}
% They are only available during the loading process of package \pkg{svg}.
% \begin{macrocode}
\AtEndOfPackage{%
\RelaxFamilyKey{SVG}{usexcolor}%
\RelaxFamilyKey{SVG}{usetransparent}%
\if@svg@use@xcolor%
\RequirePackage{xcolor}[2016/05/11]%
\else%
\AfterPackage*{xcolor}{%
\PackageWarning{svg}{Package `xcolor' was loaded anyway}%
}%
\fi%
\if@svg@use@transparent%
\RequirePackage{transparent}[2019/11/29]%
\else%
\AfterPackage*{transparent}{%
\PackageWarning{svg}{Package `transparent' was loaded anyway}%
}%
\fi%
% \end{macrocode}
% There is an issue\footnote{\url{https://github.com/ho-tex/oberdiek/issues/62}}
% with package \pkg{transparent}, which currently implements an \emph{invalid}
% check relying on internal commands of package \pkg{pgfsys}, whereas these
% have changed in the latest version.
% \begin{macrocode}
\AfterPackage*{transparent}{%
\@ifpackagelater{transparent}{2018/11/19}{}{\RequirePackage{pgfsys}}%
}%
}
% \end{macrocode}
% \end{macro}^^A \if@svg@use@transparent
% \end{option}^^A notransparent
% \end{option}^^A usetransparent
% \end{macro}^^A \if@svg@use@xcolor
% \end{option}^^A noxcolor
% \end{option}^^A usexcolor
%
%
%
% \subsubsection{The invocation of \app{Inkscape}}
%
% The Application \app{Inkscape} is used to create includable graphic files in
% a desired format (PDF/EPS/PS/PNG) out of files in SVG~format, whereas the
% support of \LaTeX{} can optionally be used.
%
% \begin{option}{inkscape}
% \changes{v2.00}{2017/02/17}{changed/extended}^^A
% \changes{v2.02}{2018/09/07}{usage of \cs{svg@sanitize@dq}}^^A
% \changes{v2.01}{2017/11/28}{using \cs{trim@spaces}}^^A
% \begin{macro}{\svg@ink@mode}
% The intension of option \opt{inkscape} is to control the running behaviour of
% \app{Inkscape}. It can be switched off at all (\opt{inkscape}|=|\val{false})
% or invoked only if necessary (\opt{inkscape}|=|\val{true}) and even be forced
% with every \LaTeX~run (\opt{inkscape}|=|\val{forced}). Additionally, option
% \opt{inkscape} can be used as wrapper for options \opt{inkscapeformat},
% \opt{inkscapelatex}, \opt{inkscapearea} and \opt{inkscapedpi}, which are
% declared later.
% \begin{macrocode}
\newcommand*\svg@ink@mode{}
\DefineFamilyKey{SVG}{inkscape}[true]{%
\svg@sanitize@dq\svg@tempb{#1}%
\FamilySetNumerical{SVG}{inkscape}{svg@tempa}{%
{false}{0},{off}{0},{no}{0},%
{true}{1},{on}{1},{yes}{1},{auto}{1},{onlynewer}{1},{newer}{1},%
{forced}{2},{force}{2},{overwrite}{2},%
{pdf}{3},{PDF}{3},{eps}{4},{EPS}{4},{ps}{5},{PS}{5},{png}{6},{PNG}{6},%
{drawing}{7},{crop}{7},%
{page}{8},{nocrop}{8},%
{tex}{9},{latex}{9},{exportlatex}{9},{latexexport}{9},%
{notex}{10},{nolatex}{10},{noexportlatex}{10},{nolatexexport}{10},%
{latexnoexport}{10},{raw}{10},{plain}{10},{simple}{10}%
}{\svg@tempb}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
% \end{macrocode}
% Setting the mode for invoking \app{Inkscape}\dots
% \begin{macrocode}
\ifnum\svg@tempa<\thr@@\relax%
\let\svg@ink@mode\svg@tempa%
\else%
% \end{macrocode}
% \dots and the part as wrapper for different options.
% \begin{macrocode}
\ifcase\svg@tempa\relax\or\or\or% pdf
\FamilyOptions{SVG}{inkscapeformat=pdf}%
\or% eps
\FamilyOptions{SVG}{inkscapeformat=eps}%
\or% ps
\FamilyOptions{SVG}{inkscapeformat=ps}%
\or% png
\FamilyOptions{SVG}{inkscapeformat=png}%
\or% drawing
\FamilyOptions{SVG}{inkscapearea=drawing}%
\or% page
\FamilyOptions{SVG}{inkscapearea=page}%
\or% tex
\FamilyOptions{SVG}{inkscapelatex=true}%
\or% notex
\FamilyOptions{SVG}{inkscapelatex=false}%
\fi%
\fi%
% \end{macrocode}
% It's also possible to set the option \opt{inkscapedpi} by passing a number
% followed by \val{dpi} like \opt{inkscape}|=|\val{300dpi}.
% \begin{macrocode}
\else% dpi
\def\svg@tempa##1dpi##2\@nil{%
\Ifstr{##2}{dpi}{\FamilyOptions{SVG}{inkscapedpi=##1}}{}%
}%
\lowercase{\expandafter\svg@tempa\svg@tempb dpi\@nil}%
% \end{macrocode}
% In version~v1.0 the option \opt{inkscape} was used to set both the executable
% and options for \app{Inkscape}. This is taken into account here.
% \begin{macrocode}
\ifx\FamilyKeyState\FamilyKeyStateProcessed\else% legacy option
% \end{macrocode}
% Splitting executable from options with delimitted macros. After calling
% \cs{svg@tempa} with the given value, the part for the executable is stored in
% \cs{svg@tempa} and the option part---which is recognized by the first |-|
% character--- in \cs{svg@tempb}.
% \begin{macrocode}
\svg@quotes@remove[{#1}]{\svg@tempb}%
\def\svg@tempa##1-##2\@nil{%
\IfArgIsEmpty{##2}{\let\svg@tempb\@empty}{%
\def\svg@tempa####1-\@nil{\def\svg@tempb{-####1}}%
\svg@tempa##2\@nil%
}%
\edef\svg@tempa{\trim@spaces{##1}}%
}%
\edef\svg@tempb{%
\noexpand\svg@tempa\svg@tempb-\noexpand\@nil%
}%
\svg@tempb%
\if@svg@quotes@found%
\edef\svg@tempa{"\svg@tempa"}%
\fi%
\PackageWarning{svg}{%
Setting the executable%
\ifx\svg@tempb\@empty\else%
\space and associated options%
\fi%
\MessageBreak%
for Inkscape should be done with options\MessageBreak%
`inkscapeexe=\svg@tempa'%
\ifx\svg@tempb\@empty\else%
\MessageBreak and `inkscapeopt=\svg@tempb'%
\fi.\MessageBreak%
Nevertheless, this was done by now anyway%
}%
\edef\svg@tempa{%
\noexpand\FamilyOptions{SVG}{inkscapeexe=\svg@tempa}%
\ifx\svg@tempb\@empty\else%
\noexpand\FamilyOptions{SVG}{inkscapeopt=\svg@tempb}%
\fi%
}%
\svg@tempa%
\fi%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \svg@ink@mode
% \end{option}^^A inkscape
% \begin{option}{on}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{option}{off}
% \changes{v2.00}{2017/02/24}{new}^^A
% Package options which can be used to switch functionality on or off during
% the loading of package \pkg{svg}.
% \begin{macrocode}
\DeclareOption{on}{\FamilyOptions{SVG}{inkscape=true}}
\DeclareOption{off}{\FamilyOptions{SVG}{inkscape=false}}
% \end{macrocode}
% \end{option}^^A off
% \end{option}^^A on
% \begin{option}{inkscapeversion}
% \changes{v2.02f}{2020/05/06}{new}^^A
% \begin{macro}{\svg@ink@ver}
% \changes{v2.02f}{2020/05/06}{new}^^A
% \begin{option}{inkscapeexe}
% \changes{v2.00}{2017/02/17}{new}^^A
% \changes{v2.02f}{2020/05/06}{only usable in preamble}^^A
% \begin{macro}{\svg@ink@exe}
% \begin{option}{inkscapeopt}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{macro}{\svg@ink@opt}
% With these options, the executed command for invoking \app{Inkscape} as well
% as additional options can be defined.
% \ToDo{rename \cs{svg@ink@ver} > \cs{svg@ink@ver@val} (keep former cs)?}[v2.03]
% \begin{macrocode}
\newcommand*\svg@ink@ver{\m@ne}
\DefineFamilyKey{SVG}{inkscapeversion}[true]{%
\FamilySetNumerical{SVG}{inkscape}{svg@tempa}{%
{true}{0},{on}{0},{yes}{0},{auto}{0},{detect}{0},{determine}{0},{fetch}{0},%
{enquire}{0},{identify}{0},{request}{0},{retrieve}{0},{obtain}{0}%
}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\renewcommand*\svg@ink@ver{\m@ne}%
\else%
\def\svg@tempa##1.##2\@nil{%
\Ifnumber{##1}{%
\renewcommand*\svg@ink@ver{##1}%
\FamilyKeyStateProcessed%
}{}%
}%
\svg@tempa#1.\@nil%
\fi%
}
\newcommand*\svg@ink@exe{inkscape}
\DefineFamilyKey{SVG}{inkscapeexe}{%
\svg@sanitize@dq\svg@ink@exe{#1}%
\FamilyKeyStateProcessed%
}
\newcommand*\svg@ink@opt{}
\DefineFamilyKey{SVG}{inkscapeopt}{%
\renewcommand*\svg@ink@opt{#1}%
\FamilyKeyStateProcessed%
}
% \end{macrocode}
% The two options \opt{inkscapeversion} and \opt{inkscapeexe} can only be used
% within the preamble.
% \begin{macrocode}
\def\svg@tempa#1{%
\AtBeginDocument{%
\DefineFamilyKey[]{SVG}{#1}[]{%
\PackageError{svg}{Option `#1' too late}{%
Option `#1' can only be set within\MessageBreak%
the preamble but you have tried to set it up later.%
}%
\FamilyKeyStateProcessed%
}%
}%
}
\svg@tempa{inkscapeexe}
\svg@tempa{inkscapeversion}
% \end{macrocode}
% \end{macro}^^A \svg@ink@opt
% \end{option}^^A inkscapeopt
% \end{macro}^^A \svg@ink@exe
% \end{option}^^A inkscapeexe
% \end{macro}^^A \svg@ink@ver
% \end{option}^^A inkscapeversion
% \begin{option}{inkscapeformat}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{macro}{\svg@ink@format}
% With option \opt{inkscapeformat} the output format of the \app{Inkscape}
% export function, which is called via \cs{ShellEscape}, can be configured.
% It is set to \val{pdf} or, if dvi output could be detected, to \val{eps}
% during initialization.
% \begin{macrocode}
\newcommand*\svg@ink@format{pdf}
\ifxetex\else\ifpdf\else
\renewcommand*\svg@ink@format{eps}
\fi\fi
\DefineFamilyKey{SVG}{inkscapeformat}{%
\FamilySetNumerical{SVG}{inkscapeformat}{svg@tempa}{%
{pdf}{0},{PDF}{0},{eps}{1},{EPS}{1},{ps}{2},{PS}{2},{png}{3},{PNG}{3}%
}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\ifcase\svg@tempa\relax% latex
\renewcommand*\svg@ink@format{pdf}%
\or% eps
\renewcommand*\svg@ink@format{eps}%
\or% ps
\renewcommand*\svg@ink@format{ps}%
\or% png
\renewcommand*\svg@ink@format{png}%
\fi%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \svg@ink@format
% \end{option}^^A inkscapeformat
% \begin{option}{inkscapelatex}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{option}{latex}
% \changes{v2.00b}{2017/02/28}{new, alternative key for \opt{inkscapelatex}}^^A
% \begin{option}{tex}
% \changes{v2.00b}{2017/03/28}{new, alternative key for \opt{inkscapelatex}}^^A
% \begin{macro}{\svg@ink@latex}
% This option controls whether the \app{Inkscape} export will be invoked with
% or without the generation of a seperate \LaTeX~file.
% \begin{macrocode}
\newif\if@svg@ink@latex
\FamilyBoolKey{SVG}{inkscapelatex}{@svg@ink@latex}
\FamilyBoolKey{SVG}{latex}{@svg@ink@latex}
\FamilyBoolKey{SVG}{tex}{@svg@ink@latex}
% \end{macrocode}
% \end{macro}^^A \svg@ink@latex
% \end{option}^^A tex
% \end{option}^^A latex
% \end{option}^^A inkscapelatex
% \begin{option}{inkscapearea}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{macro}{\svg@ink@area}
% The exported area for an \app{Inkscape} graphic can be set with this option.
% \begin{macrocode}
\newcommand*\svg@ink@area{}
\DefineFamilyKey{SVG}{inkscapearea}{%
\FamilySetNumerical{SVG}{inkscapearea}{svg@tempa}{%
{drawing}{0},{crop}{0},%
{page}{1},{nocrop}{1}%
}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\ifcase\svg@tempa\relax% drawing
\renewcommand*\svg@ink@area{-D}%
\else% page
\renewcommand*\svg@ink@area{-C}%
\fi%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \svg@ink@area
% \end{option}^^A inkscapearea
% \begin{option}{inkscapedpi}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{option}{inkscapedensity}
% \begin{macro}{\svg@ink@dpi}
% A density can be chosen, which is used during export with \app{Inkscape} for
% bitmaps and rasterization of filters.
% \begin{macrocode}
\newcommand*\svg@ink@dpi{}
\let\svg@ink@dpi\relax
\DefineFamilyKey{SVG}{inkscapedpi}{%
\FamilyKeyStateUnknownValue%
\svg@ifvalueisrelax{#1}{%
\let\svg@ink@dpi\relax%
\FamilyKeyStateProcessed%
}{%
\def\svg@tempa##1dpi##2\@nil{\def\svg@tempa{##1}}%
\lowercase{\svg@tempa#1dpi\@nil}%
\Ifnumber{\svg@tempa}{%
\edef\svg@ink@dpi{\svg@tempa}%
\FamilyKeyStateProcessed%
}{}%
}%
}
\DefineFamilyKey{SVG}{inkscapedensity}{\FamilyOptions{SVG}{inkscapedpi=#1}}
% \end{macrocode}
% \end{macro}^^A \svg@ink@dpi
% \end{option}^^A inkscapedensity
% \end{option}^^A inkscapedpi
% \begin{macro}{\svg@ink@cmd}
% \changes{v2.02f}{2020/05/06}{distinguish \app{Inkscape}~CLI versions}^^A
% The actual usage of the \app{Inkscape} command~line~interface.
% \begin{macrocode}
\newcommand*\svg@ink@cmd[2]{%
\svg@ink@exe\space"#1.\svg@file@ext"\space\svg@ink@area\space%
\ifx\svg@ink@dpi\relax\else--export-dpi=\svg@ink@dpi\space\fi%
\if@svg@ink@latex--export-latex\space\fi%
\ifx\svg@ink@opt\@empty\else\svg@ink@opt\space\fi%
\ifnum\svg@ink@ver=\z@%
--without-gui\space%
--export-\svg@ink@format="#2.\svg@ink@format"%
\else%
--export-filename="#2.\svg@ink@format"%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \svg@ink@cmd
%
%
%
% \subsubsection{Setting input folder and file}
%
% \begin{option}{svgpath}
% \changes{v2.00}{2017/02/12}{deprecated}^^A
% In version~v1.0 setting the path to SVG~files was done via option. So
% this method is provided as well.
% \begin{macrocode}
\DefineFamilyKey{SVG}{svgpath}{%
\PackageWarning{svg}{%
The key `svgpath' is deprecated. It's recommended\MessageBreak%
to use `\string\svgpath' instead%
}%
\ifx\svgpath\@undefined%
\AtEndOfPackage{\svgpath{{#1}}}%
\else%
\svgpath{{#1}}%
\fi%
\FamilyKeyStateProcessed%
}
% \end{macrocode}
% \end{option}^^A svgpath
% \begin{option}{svgextension}
% \changes{v2.01}{2017/11/27}{new due to user request}^^A
% \changes{v2.02}{2018/09/07}{usage of \cs{svg@quotes@remove}}^^A
% \changes{v2.02}{2018/09/07}{usage of \cs{svg@remove@leadingchar}}^^A
% \begin{option}{extension}
% \begin{option}{ext}
% \begin{macro}{\svg@file@ext}
% This option modifies the expected extension for the input file which is
% exported with \app{Inkscape}. It is set to \file{svg} by default.
% \begin{macrocode}
\newcommand*\svg@file@ext{svg}
\DefineFamilyKey{SVG}{svgextension}{%
% \end{macrocode}
% The extension should be in lower case letters.
% \begin{macrocode}
\lowercase{\svg@quotes@remove[{#1}]{\svg@file@ext}}%
% \end{macrocode}
% Remove leading dots from the extension.
% \begin{macrocode}
\svg@remove@leadingchar.\svg@file@ext%
}
\DefineFamilyKey{SVG}{extension}{\FamilyOptions{SVG}{svgextension=#1}}
\DefineFamilyKey{SVG}{ext}{\FamilyOptions{SVG}{svgextension=#1}}
% \end{macrocode}
% \end{macro}^^A \svg@file@ext
% \end{option}^^A ext
% \end{option}^^A extension
% \end{option}^^A svgextension
%
%
%
% \subsubsection{Setting output folder and file}
%
% \begin{option}{inkscapepath}
% \changes{v2.00}{2017/02/17}{new}^^A
% \changes{v2.02}{2018/09/07}{usage of \cs{svg@sanitize@dq}}^^A
% \begin{macro}{\svg@out@path}
% The option \opt{inkscapepath} controls, in which folder the results of the
% \app{Inkscape} export will be located.
% \begin{macrocode}
\newcommand*\svg@out@path{}
\DefineFamilyKey{SVG}{inkscapepath}{%
\svg@sanitize@dq\svg@tempb{#1}%
\FamilySetNumerical{SVG}{inkscapepath}{svg@tempa}{%
{svgpath}{0},{svgdir}{0},%
{svgsubpath}{1},{svgsubdir}{1},%
{basepath}{2},{basedir}{2},{jobpath}{2},{jobdir}{2},%
{basesubpath}{3},{basesubdir}{3},{jobsubpath}{3},{jobsubdir}{3}%
}{\svg@tempb}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\ifcase\svg@tempa\relax% svgpath
\renewcommand*\svg@out@path{\svg@file@path}%
\or% svgsubpath
\renewcommand*\svg@out@path{\svg@file@path svg-inkscape/}%
\or% basepath
\renewcommand*\svg@out@path{./}%
\or% basesubpath
\renewcommand*\svg@out@path{./svg-inkscape/}%
\fi%
\else%
\edef\svg@out@path{\svg@tempb}%
\svg@normalize@path{\svg@out@path}%
\FamilyKeyStateProcessed%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \svg@out@path
% \end{option}^^A inkscapepath
% \begin{option}{inkscapename}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{macro}{\svg@out@name}
% \begin{macro}{\svg@out@base}
% With option \opt{inkscapename} the name of the exported file can be changed.
% \begin{macrocode}
\newcommand*\svg@out@name{\svg@file@name\svg@file@suffix}
\newcommand*\svg@out@base{\svg@out@path\svg@out@name.\svg@ink@format}
\DefineFamilyKey{SVG}{inkscapename}{%
\renewcommand*\svg@out@name{#1\svg@file@suffix}%
\FamilyKeyStateProcessed%
}
% \end{macrocode}
% \end{macro}^^A \svg@out@base
% \end{macro}^^A \svg@out@name
% \end{option}^^A inkscapename
%
%
%
% \subsubsection{Options for the inclusion of graphics}
%
% After the graphic export with \app{Inkscape}, the inclusion of those graphics
% can be controlled with the following options.
%
% \begin{option}{width}
% \begin{macro}{\svg@param@width}
% \begin{option}{height}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{macro}{\svg@param@width}
% \begin{option}{distort}
% \changes{v2.02}{2018/09/07}{new}^^A
% \begin{option}{keepaspectratio}
% \changes{v2.02}{2018/09/07}{new}^^A
% \begin{macro}{\if@svg@param@distort}
% \begin{option}{scale}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{macro}{\svg@param@scale}
% These options determine the size of the included graphics. The usage of
% \val{\cs{relax}} as value resets the respective option to the default
% behavior.
% \begin{macrocode}
\newcommand*\svg@param@width{\z@}
\DefineFamilyKey{SVG}{width}{%
\FamilyKeyStateUnknownValue%
\svg@ifvalueisrelax{#1}{%
\renewcommand*\svg@param@width{\z@}%
\FamilyKeyStateProcessed%
}{%
\FamilySetLengthMacro{SVG}{width}{\svg@param@width}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\ifdim\svg@param@width<\z@\relax%
\FamilyKeyStateUnknownValue%
\fi%
\fi%
}%
}
\newcommand*\svg@param@height{\z@}
\DefineFamilyKey{SVG}{height}{%
\FamilyKeyStateUnknownValue%
\svg@ifvalueisrelax{#1}{%
\renewcommand*\svg@param@height{\z@}%
\FamilyKeyStateProcessed%
}{%
\FamilySetLengthMacro{SVG}{height}{\svg@param@height}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\ifdim\svg@param@height<\z@\relax%
\FamilyKeyStateUnknownValue%
\fi%
\fi%
}%
}
\newif\if@svg@param@distort
\FamilyBoolKey{SVG}{distort}{@svg@param@distort}
\DefineFamilyKey{SVG}{keepaspectratio}[true]{%
\FamilySetBool{SVG}{keepaspectratio}{@svg@tempswa}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\if@svg@tempswa%
\FamilyExecuteOptions[.svg.sty]{SVG}{distort=false}%
\else%
\FamilyExecuteOptions[.svg.sty]{SVG}{distort=true}%
\fi%
\fi%
}
\newcommand*\svg@param@scale{1}
\DefineFamilyKey{SVG}{scale}{%
\FamilyKeyStateUnknownValue%
\svg@ifvalueisrelax{#1}{%
\renewcommand*\svg@param@scale{1}%
\FamilyKeyStateProcessed%
}{%
\Ifisdimension{#1\p@}{%
\ifdim\dimexpr#1\p@\relax>\z@\relax%
\renewcommand*\svg@param@scale{#1}%
\FamilyKeyStateProcessed%
\fi%
}{}%
}%
}
% \end{macrocode}
% \end{macro}^^A \svg@param@scale
% \end{option}^^A scale
% \end{macro}^^A \if@svg@param@distort
% \end{option}^^A keepaspectratio
% \end{option}^^A distort
% \end{macro}^^A \svg@param@height
% \end{option}^^A height
% \end{macro}^^A \svg@param@width
% \end{option}^^A width
% \begin{option}{pretex}
% \begin{macro}{\svg@param@pretex}
% \begin{option}{apptex}
% \begin{macro}{\svg@param@apptex}
% \begin{option}{postex}
% \changes{v2.00}{2017/03/02}{deprecated}^^A
% For executing code right before or after the graphic inclusion, two hooks are
% defined.
% \begin{macrocode}
\newcommand*\svg@param@pretex{}
\let\svg@param@pretex\relax
\DefineFamilyKey{SVG}{pretex}{%
\svg@ifvalueisrelax{#1}{%
\let\svg@param@pretex\relax%
}{%
\def\svg@param@pretex{#1}%
}%
\FamilyKeyStateProcessed%
}
\newcommand*\svg@param@apptex{}
\let\svg@param@apptex\relax
\DefineFamilyKey{SVG}{apptex}{%
\svg@ifvalueisrelax{#1}{%
\let\svg@param@apptex\relax%
}{%
\def\svg@param@apptex{#1}%
}%
\FamilyKeyStateProcessed%
}
\DefineFamilyKey{SVG}{postex}{%
\svg@deprecated@key{postex=#1}{apptex=#1}%
}
% \end{macrocode}
% \end{option}^^A postex
% \end{macro}^^A \svg@param@apptex
% \end{option}^^A apptex
% \end{macro}^^A \svg@param@pretex
% \end{option}^^A pretex
% \begin{option}{lastpage}
% \changes{v2.00}{2017/02/20}{new}^^A
% \begin{counter}{svg@param@lastpage}
% For \app{Inkscape}\,0.91 a bug concerning the \LaTeX~export has been reported
% (\url{https://bugs.launchpad.net/ubuntu/+source/inkscape/+bug/1417470}).
% Sometimes the \LaTeX~file created by \app{Inkscape} tries to include more
% pages than actually are present in the PDF~file. To work around this
% problem, a patch is provided. For this purpose, the total page number is read
% from the PDF~file.
% \begin{macrocode}
\newcounter{svg@param@lastpage}
\DefineFamilyKey{SVG}{lastpage}[true]{%
\FamilySetNumerical{SVG}{lastpage}{svg@tempa}{%
{false}{0},{off}{0},{no}{0},{ignore}{0},%
{true}{1},{on}{1},{yes}{1},{auto}{1}%
}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\ifcase\svg@tempa\relax% false
\FamilySetCounter{SVG}{lastpage}{svg@param@lastpage}{\m@ne}%
\or% true
\FamilySetCounter{SVG}{lastpage}{svg@param@lastpage}{\z@}%
\fi%
\fi%
}
% \end{macrocode}
% \end{counter}^^A svg@param@lastpage
% \end{option}^^A lastpage
% \begin{option}{draft}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{macro}{\if@svg@draft}
% The option \opt{draft} has the same effect as the eponymous option of package
% \pkg{graphicx}.
% \begin{macrocode}
\newif\if@svg@draft
\FamilyBoolKey{SVG}{draft}{@svg@draft}
\AfterPackage*{graphicx}{\ifGin@draft\@svg@drafttrue\fi}
% \end{macrocode}
% \end{macro}^^A \if@svg@draft
% \end{option}^^A draft
%
% \iffalse
%</package&option&main>
% \fi
%
%
%
% \subsection{User commands}
% \subsubsection{Optional parameters for user commands}
%
% The family member is defined for both \pkg{svg} and \pkg{svg-extract}.
% \begin{macrocode}
%<*package&body>
\DefineFamilyMember[.param]{SVG}
%</package&body>
% \end{macrocode}
%
% \iffalse
%<*package&main>
%<*body>
% \fi
%
% \begin{macro}{\svg@local@param@def}
% \begin{macro}{\svg@local@param@use}
% \begin{macro}{\svg@local@param@set}
% \changes{v2.02}{2018/09/07}{reasonable value for key \opt{distort}}^^A
% Most of the package options can also be used as optional parameters for
% \cs{includesvg} or \cs{includeinkscape}. Some of them are overloaded for the
% usage as optional argument and there are some keys, which \emph{only} can be
% used as optional parameters. This is realized in such a way that
% \cs{svg@local@param@use} is extended with \cs{svg@local@param@def} by the
% definition of local keys during the loading of package \pkg{svg}.
% \begin{macrocode}
\newcommand*\svg@local@param@use{}
\newcommand*\svg@local@param@def[1]{%
\edef\svg@local@param@use{%
\unexpanded\expandafter{\svg@local@param@use}\unexpanded{#1}%
}%
}
\newcommand*\svg@local@param@set[1]{%
\svg@local@param@use%
\FamilyOptions{SVG}{#1}%
% \end{macrocode}
% As \cs{svg@local@param@set} is always used in a local group, it is possible
% to set \opt{inkscapelatex} to \val{false}, if the output format was set to
% \val{png} with option \opt{inkscapeformat}.
% \begin{macrocode}
\Ifstr{\svg@ink@format}{png}{\FamilyOptions{SVG}{inkscapelatex=false}}{}%
% \end{macrocode}
% Using \opt{distort=true} is only reasonable, if \opt{height} and \opt{width}
% are given.
% \begin{macrocode}
\@svg@tempswatrue%
\ifdim\svg@param@width>\z@\relax\ifdim\svg@param@height>\z@\relax%
\@svg@tempswafalse%
\fi\fi%
\if@svg@tempswa%
\FamilyExecuteOptions[.svg.sty]{SVG}{distort=false}%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \svg@local@param@set
% \end{macro}^^A \svg@local@param@use
% \end{macro}^^A \svg@local@param@def
% \begin{macro}{\svg@deprecated@param}
% This macro checks, if \cs{svgwidth} or \cs{svgscale} are defined. In this
% case, the given values are passed to the correlating parameters and a warning
% is raised.
% \begin{macrocode}
\newcommand*\svg@deprecated@param{%
\@svg@tempswafalse%
\ifx\svgwidth\@undefined\else%
\edef\svg@tempa{\noexpand\FamilyOptions{SVG}{width=\svgwidth}}%
\svg@tempa%
\@svg@tempswatrue%
\fi%
\ifx\svgscale\@undefined\else%
\edef\svg@tempa{\noexpand\FamilyOptions{SVG}{scale=\svgscale}}%
\svg@tempa%
\@svg@tempswatrue%
\fi%
\if@svg@tempswa%
\PackageWarning{svg}{%
You should specify the image size with parameters\MessageBreak%
`width' and `height' or `scale' instead of using\MessageBreak%
`\string\svgscale' or `\string\svgwidth'%
}%
\let\svgwidth\@undefined%
\let\svgscale\@undefined%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \svg@deprecated@param
%
%
%
% \subsubsection{Definition of user commands}
%
% \begin{macro}{\svgsetup}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{macro}{\setsvg}
% \changes{v2.00}{2017/02/17}{deprecated}^^A
% The macro \cs{svgsetup} can be used to change options after loading the
% package \pkg{svg} both in preamble and the document body. For compatibility
% reasons, \cs{setsvg} is also defined.
% \begin{macrocode}
\newcommand*\svgsetup{\FamilyOptions{SVG}}
\newcommand*\setsvg{\FamilyOptions{SVG}}
% \end{macrocode}
% \end{macro}^^A \setsvg
% \end{macro}^^A \svgsetup
% \begin{macro}{\svgpath}
% \changes{v2.00}{2017/02/12}{new}^^A
% \changes{v2.02}{2018/09/07}{parse argument for enclosing braces and provide
% those if necessary}^^A
% \begin{macro}{\svg@input@path}
% With \cs{svgpath} the user can give several root paths to SVG~files in the
% same way as \cs{graphicspath} is used. The only difference is that a missing
% slash is added at the end of the path, if needed.
% \begin{macrocode}
\newcommand*\svg@input@path{}
\let\svg@input@path\input@path
\newcommand*\svgpath[1]{%
\def\svg@tempa##1\@nil{%
\ifx\svg@tempb\bgroup%
\def\svg@input@path{#1}%
\else%
\def\svg@input@path{{#1}}%
\fi%
}%
\futurelet\svg@tempb\svg@tempa#1\@nil%
}
% \end{macrocode}
% \end{macro}^^A \svg@input@path
% \end{macro}^^A \svgpath
% \begin{macro}{\includesvg}
% \changes{v2.00}{2017/02/17}{changes, especially to optional parameters}^^A
% \changes{v2.02}{2018/09/07}{switched to \cs{svg@filename@parse}}^^A
% For the inclusion of SVG~files the command \cs{includesvg} is defined.
% \begin{macrocode}
\newcommand*\includesvg[2][]{%
\begingroup%
% \end{macrocode}
% Checking for deprecated commands \cs{svgwidth} and \cs{svgscale}.
% \begin{macrocode}
\svg@deprecated@param%
% \end{macrocode}
% \begin{parameter}{inkscape}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{parameter}{inkscapeformat}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{parameter}{inkscapelatex}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{parameter}{inkscapearea}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{parameter}{inkscapedpi}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{parameter}{inkscapeopt}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{parameter}{svgextension}
% \changes{v2.01}{2017/11/27}{new}^^A
% \begin{parameter}{width}
% \begin{parameter}{height}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{parameter}{distort}
% \changes{v2.02}{2018/07/09}{new}^^A
% \begin{parameter}{scale}
% \changes{v2.00}{2017/02/17}{new}^^A
% \begin{parameter}{pretex}
% \begin{parameter}{apptex}
% \begin{parameter}{draft}
% \changes{v2.00}{2017/02/17}{new}^^A
% Most of the optional parameters have the same effect as the identically named
% options. Only parameter \prm{lastpage} is extended (see below). Moreover,
% there are some additional parameters, which can only be used as optional
% argument for \cs{includesvg} (\prm{angle} and \prm{origin}) but not as an
% option. Now all parameters are set in local context (within a group).
% \begin{macrocode}
\svg@local@param@set{#1}%
% \end{macrocode}
% \end{parameter}^^A draft
% \end{parameter}^^A apptex
% \end{parameter}^^A pretex
% \end{parameter}^^A scale
% \end{parameter}^^A distort
% \end{parameter}^^A height
% \end{parameter}^^A width
% \end{parameter}^^A svgextension
% \end{parameter}^^A inkscapeopt
% \end{parameter}^^A inkscapedpi
% \end{parameter}^^A inkscapearea
% \end{parameter}^^A inkscapelatex
% \end{parameter}^^A inkscapeformat
% \end{parameter}^^A inkscape
% The file suffix used by both packages \pkg{svg} and \pkg{svg-extract}.
% \begin{macrocode}
\if@svg@ink@latex%
\edef\svg@file@suffix{_\svg@file@ext-tex}%
\else%
\edef\svg@file@suffix{_\svg@file@ext-raw}%
\fi%
\@onelevel@sanitize\svg@file@suffix%
% \end{macrocode}
% Searching all given paths for the relevant SVG~file.
% \begin{macrocode}
\svg@get@path{#2}{}%
\if@svg@file@found%
% \end{macrocode}
% Running the export with \app{Inkscape} (if necessary) and checking the
% required files for graphic inclusion.
% \begin{macrocode}
\svg@ink@run%
\IfFileExists{\svg@out@base}{}{%
\@svg@file@foundfalse%
\svg@file@missing{\svg@out@base}{\svg@file@base.\svg@file@ext}%
}%
\if@svg@ink@latex%
\IfFileExists{\svg@out@base_tex}{}{%
\@svg@file@foundfalse%
\svg@file@missing{\svg@out@base_tex}{\svg@file@base.\svg@file@ext}%
}%
\fi%
% \end{macrocode}
% Include the resulting graphic file and maybe extract independent files.
% \begin{macrocode}
\if@svg@file@found%
\svg@input{\svg@out@base}%
\svg@extract{\svg@out@base}%
\fi%
\else%
% \end{macrocode}
% Raise an error, if the requested SVG~file wasn't found.
% \begin{macrocode}
\svg@file@missing[\svg@file@ext]{\svg@file@base}{}%
\fi%
\endgroup%
}
% \end{macrocode}
% \begin{parameter}{lastpage}
% \changes{v2.00}{2017/02/17}{new}^^A
% In addition to the automatic finding of the last page, which is included, it
% can also be given directly as parameter.
% \begin{macrocode}
\svg@local@param@def{%
\FamilyCounterKey[.param]{SVG}{lastpage}{svg@param@lastpage}%
}
% \end{macrocode}
% \end{parameter}^^A lastpage
% \begin{parameter}{angle}
% \changes{v2.00}{2017/02/17}{new}^^A
% \changes{v2.02}{2018/09/07}{validation of argument}^^A
% \begin{parameter}{origin}
% \changes{v2.00}{2017/02/17}{new}^^A
% The parameters \prm{angle} and \prm{origin} are definied as pendants to the
% keys provided by \cs{includegraphics}.
% \begin{macrocode}
\newcommand*\svg@param@angle{0}
\svg@local@param@def{%
\DefineFamilyKey[.param]{SVG}{angle}{%
\FamilyKeyStateUnknownValue%
\Ifisdimension{#1\p@}{%
\renewcommand*\svg@param@angle{#1}%
\FamilyKeyStateProcessed%
}{}%
}%
}
\newcommand*\svg@param@origin{c}
\svg@local@param@def{%
\DefineFamilyKey[.param]{SVG}{origin}[c]{%
\renewcommand*\svg@param@origin{#1}%
\FamilyKeyStateProcessed%
}%
}
% \end{macrocode}
% \end{parameter}^^A origin
% \end{parameter}^^A angle
% \end{macro}^^A \includesvg
% \begin{macro}{\includeinkscape}
% \changes{v2.00}{2017/02/23}{new}^^A
% \changes{v2.02}{2018/09/07}{usage of \cs{svg@extension@parse}}^^A
% The command \cs{includeinkscape} can be used for including the export results
% of \app{Inkscape}, if this part of the job was done in another way.
% \begin{macrocode}
\newcommand*\includeinkscape[2][]{%
\begingroup%
% \end{macrocode}
% Checking for deprecated commands \cs{svgwidth} and \cs{svgscale}.
% \begin{macrocode}
\svg@deprecated@param%
% \end{macrocode}
% The given file extension is examined, where a known extension overwrites the
% current setting for \opt{inkscapeformat}. If there's a suffix \file{\_tex},
% the option \opt{inkscapelatex} is set to \val{true} by default.
% \begin{macrocode}
\svg@filename@parse{#2}%
\ifx\filename@ext\relax\else%
\svg@quotes@remove{\filename@ext}%
\expandafter\lowercase\expandafter{%
\expandafter\def\expandafter\filename@ext\expandafter{\filename@ext}%
}%
\def\svg@tempb##1_tex##2\@nil{%
\IfArgIsEmpty{##1}{}{\def\filename@ext{##1}}%
\Ifstr{##2}{_tex}{\@svg@tempswatrue}{\@svg@tempswafalse}%
}%
\@svg@tempswafalse%
\@tfor\svg@tempa:={pdf}{eps}{ps}{png}\do{%
\begingroup%
\expandafter\svg@tempb\filename@ext_tex\@nil%
\svg@extension@parse{\svg@tempa}%
\ifx\filename@ext\relax%
\def\svg@tempb{\endgroup}%
\else%
\edef\svg@tempb{%
\endgroup%
\noexpand\FamilyOptions{SVG}{inkscapeformat=\svg@tempa}%
\if@svg@tempswa%
\noexpand\FamilyOptions{SVG}{inkscapelatex=true}%
\fi%
\def\noexpand\filename@base{\filename@base}%
\def\noexpand\filename@ext{\filename@ext}%
\noexpand\@svg@tempswatrue%
}%
\fi%
\svg@tempb%
% \end{macrocode}
% Break for loop, if valid extension was found.
% \begin{macrocode}
\if@svg@tempswa%
\@break@tfor%
\fi%
}%
% \end{macrocode}
% If no valid extension was found, it is set to the specified format and the
% actual found one is appended to cs{\filename@base}.
% \begin{macrocode}
\if@svg@tempswa\else%
\svg@extension@parse{\svg@ink@format}%
\fi%
\fi%
% \end{macrocode}
% \begin{parameter}{inkscapeformat}
% \begin{parameter}{inkscapelatex}
% \begin{parameter}{width}
% \begin{parameter}{height}
% \begin{parameter}{distort}
% \begin{parameter}{scale}
% \begin{parameter}{pretex}
% \begin{parameter}{apptex}
% \begin{parameter}{draft}
% \begin{parameter}{lastpage}
% \begin{parameter}{angle}
% \begin{parameter}{origin}
% Parameters, which are supported by \cs{includesvg}, can also be used with
% \cs{includeinkscape} even if some of them---more precisely those that control
% the export with \app{Inkscape}---don't have an effect at all. Nevertheless,
% they are set right now in local context (within a group).
% \begin{macrocode}
\svg@local@param@set{#1}%
% \end{macrocode}
% \end{parameter}^^A origin
% \end{parameter}^^A angle
% \end{parameter}^^A lastpage
% \end{parameter}^^A draft
% \end{parameter}^^A apptex
% \end{parameter}^^A pretex
% \end{parameter}^^A scale
% \end{parameter}^^A distort
% \end{parameter}^^A height
% \end{parameter}^^A width
% \end{parameter}^^A inkscapelatex
% \end{parameter}^^A inkscapeformat
% Searching all given paths for the relevant PDF/EPS~file.
% \begin{macrocode}
\svg@get@path[\svg@ink@format]{\filename@area\filename@base}{\svg@out@path}%
\if@svg@file@found%
% \end{macrocode}
% Checking the required files for graphic inclusion.
% \begin{macrocode}
\edef\svg@out@name{\svg@file@name}%
\edef\svg@out@base{\svg@file@path\svg@file@name.\svg@ink@format}%
\if@svg@ink@latex%
\IfFileExists{\svg@out@base_tex}{}{%
\@svg@file@foundfalse%
\svg@file@missing{\svg@out@base_tex}{\svg@out@base}%
}%
\fi%
% \end{macrocode}
% Include the resulting graphic file and maybe extract independent files.
% \begin{macrocode}
\if@svg@file@found%
\svg@input{\svg@out@base}%
\svg@extract{\svg@out@base}%
\fi%
\else%
% \end{macrocode}
% Raise an error, if the requested PDF/EPS~file wasn't found.
% \begin{macrocode}
\svg@file@missing[\svg@ink@format]{\svg@file@base}{\svg@out@path}%
\fi%
\endgroup%
}
% \end{macrocode}
% \end{macro}^^A \includeinkscape
%
%
%
% \subsection{Auxiliary macros}
%
% \begin{macro}{\svg@ink@run}
% \begin{macro}{\if@svg@ink@run}
% The command, which performs the call of \app{Inkscape} via \cs{ShellEscape}.
% \begin{macrocode}
\newif\if@svg@ink@run
\newcommand*\svg@ink@run{%
\ifnum\svg@ink@mode>\z@\relax%
\begingroup%
% \end{macrocode}
% If the mode for \opt{inkscape} was set to \val{forced}, \app{Inkscape} will
% be called in any case. Otherwise, some checks are performed to detect, if a
% run of \app{Inkscape} is actually necessary.
% \begin{macrocode}
\@svg@ink@runtrue%
\ifnum\svg@ink@mode=\tw@\relax\else%
% \end{macrocode}
% This is the case when the SVG~file is newer than the corresponding exported
% file, or if the latter isn't present at all.
% \begin{macrocode}
\svg@iffilenewer{\svg@file@base.\svg@file@ext}{\svg@out@base}{}{%
\@svg@ink@runfalse%
}%
% \end{macrocode}
% The same is true, when the associated \LaTeX~file is missing. But when this
% file already exists, maybe the user did some changes to this file. In this
% case, overwriting this file is maybe not intended.
% \begin{macrocode}
\if@svg@ink@latex%
\IfFileExists{\svg@out@base_tex}{%
\ifnum\pdf@shellescape=\@ne\relax\if@svg@ink@run%
\svg@iffilenewer{\svg@out@base_tex}{\svg@out@base}{%
\@svg@ink@runfalse%
\svg@quotes@remove[\svg@out@base]{\svg@tempa}%
\PackageWarning{svg}{%
Since the encountered filedate of file\MessageBreak%
`\svg@tempa_tex' is newer than \MessageBreak%
`\svg@tempa' it's supposed that\MessageBreak%
you customized this file. To avoid an accidental\MessageBreak%
overwriting of this file, the Inkscape export\MessageBreak%
won't be done. If you want to overwrite the\MessageBreak%
existing file please choose the parameter\MessageBreak%
`inkscape=force'%
}%
}{}%
\fi\fi%
}{\@svg@ink@runtrue}%
\fi%
\fi%
% \end{macrocode}
% If all checks were positive, the export with \app{Inkscape} can be done in
% case flag \file{-{}-shell-escape} is used.
% \begin{macrocode}
\if@svg@ink@run%
\ifnum\pdf@shellescape=\@ne\relax%
% \end{macrocode}
% For exporting PNG~files, the used density ist set to \val{300dpi}, if no
% value was given.
% \begin{macrocode}
\ifx\svg@ink@dpi\relax%
\Ifstr{\svg@ink@format}{png}{%
\FamilyOptions{SVG}{inkscapedpi=300}%
}{}%
\fi%
\PackageInfo{svg}{%
Calling Inkscape%
\ifx\svg@ink@opt\@empty\else%
\space with added options `\svg@ink@opt'%
\fi%
}%
% \end{macrocode}
% Executing \app{Inkscape} on shell. Afterwards, the export results are moved
% into the given output path.
% \begin{macrocode}
\svg@quotes@remove[\svg@file@base]{\svg@tempa}%
\svg@quotes@remove[\svg@out@name]{\svg@tempb}%
% \end{macrocode}
% The last try to detect the version automatically, if this wasn't succesful
% until now. We try to create the desired file by invoking the \app{Inkscape}
% command~line~interface for both versions. If the desired file was created the
% used version is stored in \cs{svg@ink@ver}.
% \begin{macrocode}
\ifnum\svg@ink@ver=\m@ne\relax%
\begingroup%
\@svg@tempswafalse%
\@tfor\svg@ink@ver:={1}{0}\do{%
\ShellEscape{\svg@ink@cmd{\svg@tempa}{\svg@tempb}}%
\IfFileExists{\svg@out@name.\svg@ink@format}{%
\@svg@tempswatrue%
}{}%
\if@svg@tempswa%
\@break@tfor%
\fi%
}%
% \end{macrocode}
% If even this attempt does not lead to a valid version, an error message is
% shown.
% \begin{macrocode}
\if@svg@tempswa%
\xdef\svg@ink@ver{\svg@ink@ver}%
\else%
\PackageError{svg}{Inkscape version not detected}{%
It was tried to invoke `\svg@ink@exe'\MessageBreak%
for file "\svg@tempa.\svg@file@ext"\MessageBreak%
but no result was produced. Check the log file\MessageBreak%
and set `inkscapeversion=<version>' manually.%
}%
\fi%
\endgroup%
% \end{macrocode}
% If we already do have a valid version, we on have to invoke the CLI itself.
% \begin{macrocode}
\else%
\ShellEscape{\svg@ink@cmd{\svg@tempa}{\svg@tempb}}%
\fi%
\IfFileExists{\svg@out@name.\svg@ink@format}{%
\edef\svg@tempb{\svg@tempb.\svg@ink@format}%
\svg@quotes@remove{\svg@out@base}%
\svg@shell@mkdir{\svg@out@path}%
\svg@shell@mv{\svg@tempb}{\svg@out@base}%
\if@svg@ink@latex%
\svg@shell@mv{\svg@tempb_tex}{\svg@out@base_tex}%
\fi%
}{%
\gdef\svg@ink@ver{\m@ne}%
\PackageWarning{svg}{%
The export with Inkscape failed for file\MessageBreak%
`\svg@tempa.\svg@file@ext'\MessageBreak%
Troubleshooting: Please check in the log file how\MessageBreak%
the invocation of Inkscape took place and try to\MessageBreak%
execute it yourself in the terminal%
}%
}%
% \end{macrocode}
% If \file{-{}-shell-escape} wasn't enabled, a warning is issued.
% \begin{macrocode}
\else%
\svg@quotes@remove[\svg@file@base]{\svg@tempa}%
\PackageWarning{svg}{%
You didn't enable `shell escape' (or `write18')\MessageBreak%
so it wasn't possible to launch the Inkscape export\MessageBreak%
for `\svg@tempa.\svg@file@ext'%
}%
\fi%
\fi%
\endgroup%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \if@svg@ink@run
% \end{macro}^^A \svg@ink@run
% \begin{macro}{\svg@input}
% \begin{macro}{\svg@@input}
% \changes{v2.02g}{2020/06/12}{parsing of file extension discarded; meanwhile
% taken over by the kernel}^^A
% \begin{macro}{\svg@box}
% With \cs{svg@@input} the export results of \app{Inkscape} are included. The
% macro \cs{svg@input} is defined in order to realize the option \opt{exclude}
% for package \pkg{svg-extract}. The macro \cs{svg@set@input@path} is called to
% support commands like \cs{input}\marg{tex filename} within SVG~files.
% \begin{macrocode}
\newsavebox\svg@box
\newcommand*\svg@input{\svg@@input}
\newcommand*\svg@@input[2][]{%
\IfArgIsEmpty{#1}{}{\svg@local@param@set{#1}}%
\svg@set@input@path%
\@svg@tempswatrue%
\if@svg@draft%
\@svg@tempswafalse%
\fi%
\if@svg@ink@latex\else%
\@svg@tempswafalse%
\fi%
\edef\svg@tempa{#2}%
% \end{macrocode}
% If the export with \app{Inkscape} was done with \LaTeX~support enabled, the
% corresponding file will be used together with \cs{input}. The necessary
% patches to environment \env{picture} as well as command \cs{includegraphics}
% are made beforehand with \cs{svg@patches}.
% \begin{macrocode}
\if@svg@tempswa%
\svg@patches{\svg@tempa}%
\ifnum\value{svg@param@lastpage}=\z@\relax%
\expandafter\svg@get@lastpage\expandafter{\svg@tempa}%
\fi%
\edef\svg@tempa{%
\ifx\svg@param@pretex\relax\else%
\noexpand\svg@param@pretex%
\fi%
\noexpand\input{\svg@tempa_tex}%
\ifx\svg@param@apptex\relax\else%
\noexpand\svg@param@apptex%
\fi%
}%
% \end{macrocode}
% If \opt{distort=true} is desired, the input is resized with \cs{resizebox*}.
% \begin{macrocode}
\if@svg@param@distort%
\def\svg@tempb{\resizebox*{\svg@param@width}{\svg@param@height}}%
\else%
\let\svg@tempb\@firstofone%
\fi%
\sbox\svg@box{\svg@tempb{\svg@tempa}}%
% \end{macrocode}
% If a rotation angle was given, the input is done within \cs{rotatebox}.
% \begin{macrocode}
\ifdim\dimexpr\svg@param@angle\p@\relax=\z@\relax%
\let\svg@tempb\@firstofone%
\else%
\edef\svg@tempb{%
\noexpand\rotatebox[origin=\svg@param@origin]{\svg@param@angle}%
}%
\fi%
\svg@tempb{\usebox\svg@box}%
\else%
% \end{macrocode}
% If the export with \app{Inkscape} was done without \LaTeX~support, the
% resulting graphic file will be included with \cs{includegraphics}.
% \begin{macrocode}
\svg@wrn@scale%
\edef\svg@tempb{%
draft\if@svg@draft\else=false\fi,%
scale=\svg@param@scale,%
keepaspectratio\if@svg@param@distort=false\fi%
}%
\ifdim\svg@param@height>\z@\relax%
\edef\svg@tempb{\svg@tempb,height=\svg@param@height}%
\fi%
\ifdim\svg@param@width>\z@\relax%
\edef\svg@tempb{\svg@tempb,width=\svg@param@width}%
\fi%
\ifdim\dimexpr\svg@param@angle\p@\relax=\z@\relax\else%
\edef\svg@tempb{%
\svg@tempb,origin=\svg@param@origin,angle=\svg@param@angle%
}%
\fi%
\expandafter\includegraphics\expandafter[\svg@tempb]{\svg@tempa}%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \svg@box
% \end{macro}^^A \svg@@input
% \end{macro}^^A \svg@input
% \begin{macro}{\svg@wrn@scale}
% The option \opt{scale} respectively the parameter \prm{scale} is only
% considered if the size was not specified.
% \begin{macrocode}
\newcommand*\svg@wrn@scale{%
\ifdim\dimexpr\svg@param@scale\p@\relax=\p@\relax\else%
\@svg@tempswafalse%
\ifdim\svg@param@width>\z@\relax%
\@svg@tempswatrue%
\fi%
\ifdim\svg@param@height>\z@\relax%
\@svg@tempswatrue%
\fi%
\if@svg@tempswa%
\PackageWarning{svg}{%
The parameter `scale' is only considered if neither\MessageBreak%
`width' nor `height' are specified%
}%
\fi%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \svg@wrn@scale
% \begin{macro}{\svg@get@lastpage}
% This macro is used to circumvent the multiple pages bug for PDF~files of
% \app{Inkscape}\,0.91, when the the \LaTeX~export was enabled. For this
% purpose, the total page number is read from the PDF~file.
% \begin{macrocode}
\newcommand*\svg@get@lastpage[1]{%
\Ifstr{\svg@ink@format}{pdf}{%
\begingroup%
\@tempcnta=\m@ne\relax%
\ifx\XeTeXpdfpagecount\@undefined%
\ifpdf%
\ifx\pdfximage\@undefined%
\ifx\saveimageresource\@undefined\else%
\saveimageresource{#1}%
\@tempcnta=\lastsavedimageresourcepages\relax%
\fi%
\else%
\pdfximage{#1}%
\@tempcnta=\pdflastximagepages\relax%
\fi%
\fi%
\else%
\@tempcnta=\XeTeXpdfpagecount#1\relax%
\fi%
\ifnum\@tempcnta=\m@ne\relax%
\PackageWarning{svg}{%
It wasn't possible to detect the last page\MessageBreak%
of `#1'%
}%
\else%
\PackageInfo{svg}{Last page of `#1' is \the\@tempcnta}%
\fi%
\edef\svg@tempa{%
\endgroup%
\noexpand\FamilyOptions{SVG}{lastpage=\the\@tempcnta}%
}%
\svg@tempa%
}{}%
}
% \end{macrocode}
% \end{macro}^^A \svg@get@lastpage
% \begin{macro}{\svg@file@missing}
% \changes{v2.02}{2018/09/07}{notify svg file when missing exported files}^^A
% The error message, which is raised, if a file is missing either after the
% export with \app{Inkscape} or in general.
% \begin{macrocode}
\newcommand*\svg@file@missing[3][]{%
\begingroup%
\svg@quotes@remove[{#2}]{\svg@tempa}%
\svg@filename@parse[{#1}]{\svg@tempa}%
\IfArgIsEmpty{#1}{%
\svg@quotes@remove[{#3}]{\svg@tempb}%
\def\svg@tempa{%
Did you run the export with Inkscape? There's no file\MessageBreak%
`\filename@area\filename@base.\filename@ext'\MessageBreak%
although `\svg@tempb' was found.%
}%
}{%
\edef\filename@ext{#1}%
\Ifstr{\filename@area}{./}{\let\filename@area\@empty}{}%
% \end{macrocode}
% Collecting all considered path for the error message.
% \begin{macrocode}
\edef\svg@tempb{#3}%
\Ifstr{\svg@tempb}{./}{\let\svg@tempb\@empty}{}%
\ifx\svg@tempb\@empty%
\svg@set@input@path%
\else%
\svg@set@input@path[\svg@tempb]%
\fi%
\ifx\input@path\@undefined%
\def\svg@tempb{No additional path was given.}%
\else%
\def\svg@tempb{Following folders have additionally been searched:}%
\expandafter\@tfor\expandafter\svg@tempa\expandafter:\expandafter=%
\input@path\do{%
\edef\svg@tempb{\svg@tempb\noexpand\MessageBreak\svg@tempa}%
}%
\fi%
% \end{macrocode}
% The error message itself.
% \begin{macrocode}
\def\svg@tempa{%
There's no file `\filename@base.\filename@ext'\MessageBreak%
\ifx\filename@area\@empty%
neither in the current directory nor any other searched\MessageBreak%
path given by \string\svgpath\space or \string\graphicspath.%
\MessageBreak\svg@tempb%
\else%
in folder `\filename@area'.%
\fi%
}%
}%
\PackageError{svg}{%
File `\filename@base.\filename@ext' is missing%
}{\svg@tempa}%
\endgroup%
}
% \end{macrocode}
% \end{macro}^^A \svg@file@missing
% \begin{macro}{\svg@ink@ver@settings}
% \changes{v2.02f}{2020/05/06}{new}^^A
% \begin{macro}{\svg@ink@ver@detect}
% \changes{v2.02f}{2020/05/06}{new}^^A
% \begin{macro}{\svg@@ink@ver@detect}
% \changes{v2.02f}{2020/05/06}{new}^^A
% \begin{macro}{\if@svg@ink@ver@detect}
% \changes{v2.02f}{2020/05/06}{new}^^A
% As the command~line~interface of \app{Inkscape} has changed between versions
% \val{0.x} and \val{1.x}, option \opt{inkscapeversion}|=|\val{detect} allows
% to detect the used version of \app{Inkscape} in order to define the calling
% macro \cs{svg@ink@cmd}. The obtained version is stored in \cs{svg@ink@ver},
% whereas the following meanings are applied:
% \begin{description}
% \item[\val{-1}] version check has not be done or \app{Inkscape} could not
% be found/executed
% \item[\val{0}] \app{Inkscape} version \val{0.x} was found
% \item[\val{1}] \app{Inkscape} version \val{1.x} or later was found
% \end{description}
%
% All necessary information are stored within \cs{svg@ink@ver@settings} as
% three arguments, whereas the first one is the manually set version, the
% second is the used \opt{inkscapeexe} for automatic detection and the third
% one is the detected version itself.
% \begin{macrocode}
\newcommand*\svg@ink@ver@settings{{\svg@ink@ver}{\svg@ink@exe}{\m@ne}}
\newif\if@svg@ink@ver@detect
% \end{macrocode}
% In order to run the check for \app{Inkscape} version at the beginning of the
% document only if needed, changes of both \opt{inkscapeversion}---at this
% point stored in \cs{svg@ink@ver}--- as well as \opt{inkscapeexe} are detected
% and are triggering the version check. After evaluating the triggers, the
% current values set are stored as two tokens in \cs{svg@ink@ver@settings}. If
% a check has been triggered, the detected version will be evaluated further
% on and is stored in the third token of \cs{svg@ink@ver@settings}.
% \begin{macrocode}
\newcommand*\svg@ink@ver@detect[3]{%
\@svg@ink@ver@detectfalse%
\ifnum\pdf@shellescape=\@ne\relax%
\ifnum\svg@ink@ver=\m@ne\relax%
% \end{macrocode}
% If \opt{inkscapeexe} was not changed\dots
% \begin{macrocode}
\svg@sanitize@dq\svg@tempa{#2}%
\ifx\svg@tempa\svg@ink@exe%
% \end{macrocode}
% \dots then enforce the check after a change of mode to \val{detect}\dots
% \begin{macrocode}
\ifnum#1>\m@ne\relax%
\@svg@ink@ver@detecttrue%
% \end{macrocode}
% \dots or if detection was never invoked, do so.
% \begin{macrocode}
\else%
\ifnum#3=\m@ne\relax%
\@svg@ink@ver@detecttrue%
\fi%
\fi%
% \end{macrocode}
% Enforce the check after a change of \opt{inkscapeexe}.
% \begin{macrocode}
\else%
\@svg@ink@ver@detecttrue%
\fi%
\fi%
\fi%
% \end{macrocode}
% After evaluating the last settings and maybe setting the trigger for version
% detection, the current settings are stored in the main aux file. The detected
% version will be expanded during the write to the aux file.
% \begin{macrocode}
\edef\svg@ink@ver@settings{%
{\svg@ink@ver}{\svg@ink@exe}{\noexpand\svg@ink@ver}%
}%
% \end{macrocode}
% Run detection if necessary and store the result in \cs{svg@ink@ver}\dots
% \begin{macrocode}
\if@svg@ink@ver@detect%
\svg@@ink@ver@detect%
\else%
% \end{macrocode}
% \dots or otherwise set previous detected version in automatic mode.
% \begin{macrocode}
\ifnum\svg@ink@ver=\m@ne\relax%
\def\svg@ink@ver{#3}%
\fi%
\fi%
}
% \end{macrocode}
% If the switch \cs{if@svg@ink@ver@detect} was set by \cs{svg@ink@ver@detect}
% during the evaluation of \cs{svg@ink@settings}, which holds the settings of
% the last run. The call of \app{Inkscape} stored in \cs{svg@ink@exe} is done
% with \cs{@@input\textbar"'\dots'" -V} in order to read from \val{stdout}.
% \begin{macrocode}
\newcommand*\svg@@ink@ver@detect{%
\begingroup%
\@makeother\|%
\endlinechar=\m@ne%
\everyeof{\noexpand}%
\svg@quotes@remove{\svg@ink@exe}%
\edef\svg@tempa{%
\edef\noexpand\svg@tempa{\noexpand\@@input|"'\svg@ink@exe'\space-V" }%
}%
\svg@tempa%
% \end{macrocode}
% The invocation of commands through a pipe is buggy for MiK\TeX so we try to
% deal with this workaround: \url{https://github.com/MiKTeX/miktex/issues/532}
% \ToDo{Markup for link to issue}[v2.03]
% \begin{macrocode}
\ifx\svg@tempa\@empty%
\svg@ifwindowsdetected{%
\def\svg@tempb{\jobname.svg.ink.ver.aux}%
\IfFileExists{\svg@tempb}{}{%
\ShellEscape{call "\svg@ink@exe" -V > \svg@tempb}%
\openin\@inputcheck=\svg@tempb%
\read\@inputcheck to\svg@tempa%
\closein\@inputcheck%
\ShellEscape{del \svg@tempb}%
}%
}{}%
\fi%
% \end{macrocode}
% The found version is stored in \cs{svg@tempa} and parsed afterwards.
% \begin{macrocode}
\def\svg@tempb Inkscape ##1.##2\@nil{%
\gdef\svg@ink@ver{##1}%
}%
\expandafter\svg@tempb\svg@tempa Inkscape \m@ne.\@nil%
\endgroup%
}
% \end{macrocode}
% Comparing the stored settings from last the last run with current settings.
% \begin{macrocode}
\AtBeginDocument{\expandafter\svg@ink@ver@detect\svg@ink@ver@settings}
% \end{macrocode}
% Writing \cs{svg@ink@exe} and \cs{svg@ink@ver} to the main aux-file.
% \begin{macrocode}
\BeforeClosingMainAux{%
\if@filesw%
\immediate\write\@mainaux{%
\string\gdef\string\svg@ink@ver@settings{\svg@ink@ver@settings}%
}%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \if@svg@ink@ver@detect
% \end{macro}^^A \svg@@ink@ver@detect
% \end{macro}^^A \svg@ink@ver@detect
% \end{macro}^^A \svg@ink@ver@settings
%
%
%
% \subsection{Handling path and file names}
%
% \begin{macro}{\svg@set@input@path}
% \changes{v2.01}{2017/11/28}{new}^^A
% \changes{v2.02}{2018/09/07}{usage of \cs{svg@deactivate@dq}}^^A
% \begin{macro}{\svg@append@input@path}
% \changes{v2.01}{2017/11/28}{new}^^A
% \changes{v2.02}{2018/09/07}{avoid duplicates in \cs{input@path}}^^A
% In order to import SVG~files from different folders, \cs{svg@set@input@path}
% evaluates several macros, which are supposed to be used for holding different
% search folders. Any given path will be handled by \cs{svg@normalize@path}.
% The optional argument can be used to append an additional search path.
% \begin{macrocode}
\newcommand*\svg@set@input@path[1][]{%
\begingroup%
\svg@deactivate@dq%
% \end{macrocode}
% If a path was already found and stored within \cs{svg@file@path}, it is
% searched first and wrapped in curly braces. This is necessary for using
% commands like \cs{input}\marg{tex~filename} within SVG~files.
% \begin{macrocode}
\ifx\svg@file@path\@empty\else%
\svg@normalize@path{\svg@file@path}%
\edef\svg@file@path{{\svg@file@path}}%
\fi%
% \end{macrocode}
% Afterwards, several search paths are appended. If \cs{svgpath} was used, it
% is searched next. If nothing was found, \cs{graphicspath} is considered if
% defined followed by a path given in the third argument. If nothing was found
% yet, the standard \cs{input@path} is searched last.
% \begin{macrocode}
\svg@append@input@path{\svg@file@path}{\svg@input@path}%
\svg@append@input@path{\svg@file@path}{\Ginput@path}%
\IfArgIsEmpty{#1}{}{\svg@append@input@path{\svg@file@path}{{#1}}}%
\svg@append@input@path{\svg@file@path}{\input@path}%
% \end{macrocode}
% Finally, \cs{input@path} is set.
% \begin{macrocode}
\edef\svg@tempa{%
\endgroup%
\ifx\svg@file@path\@empty\else%
\def\noexpand\input@path{\svg@file@path}%
\fi%
}%
\svg@tempa%
}
% \end{macrocode}
% Only, if a certain search path is defined, it is added. The paths given in
% the first argument are compared to each path in the second argument and only
% new ones are added.
% \begin{macrocode}
\newcommand*\svg@append@input@path[2]{%
\ifx#2\@undefined\else%
\edef\svg@tempb{#2}%
\expandafter\@tfor\expandafter\svg@tempa\expandafter:\expandafter=%
\svg@tempb\do{%
% \end{macrocode}
% Passing each new path to \cs{svg@normalize@path}. If a path already exists,
% switch \cs{if@svg@tempswa} is set to \val{false}.
% \begin{macrocode}
\ifx\svg@tempa\@empty\else%
\@svg@tempswatrue%
\svg@normalize@path{\svg@tempa}%
\expandafter\@tfor\expandafter\svg@tempb\expandafter:\expandafter=%
#1\do{%
\ifx\svg@tempa\svg@tempb%
\@svg@tempswafalse%
\@break@tfor%
\fi%
}%
\if@svg@tempswa%
\edef#1{#1{\svg@tempa}}%
\fi%
\fi%
}%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \svg@append@input@path
% \end{macro}^^A \svg@set@input@path
% \begin{macro}{\svg@get@path}
% \changes{v2.01}{2017/11/28}{using \cs{svg@set@input@path}}^^A
% \changes{v2.01}{2017/11/28}{using \cs{trim@spaces}}^^A
% \begin{macro}{\if@svg@file@found}
% \begin{macro}{\svg@file@path}
% \begin{macro}{\svg@file@name}
% \begin{macro}{\svg@file@base}
% \begin{macro}{\svg@file@suffix}
% The command \cs{svg@get@path} tries to find a given SVG~file. If the
% searched file wasn't found in the current path, all paths given with
% \cs{svgpath} are evaluated. If there was no appropriate file again, all paths
% given by \cs{graphicspath} are examined. In the last step, a given path
% within the second mandatory argument is browsed. The results for file path
% and name are stored in \cs{svg@file@path} and \cs{svg@file@name} as well as
% the compound of both is saved in \cs{svg@file@base}.
% \begin{macrocode}
\newif\if@svg@file@found
\newcommand*\svg@file@path{}
\newcommand*\svg@file@name{}
\newcommand*\svg@file@base{}
\newcommand*\svg@file@suffix{}
\newcommand*\svg@get@path[3][\svg@file@ext]{%
\begingroup%
\svg@filename@parse[{#1}]{#2}%
\IfArgIsEmpty{#1}{%
\edef\svg@tempa{\filename@area\filename@base.\filename@ext}%
}{%
\edef\svg@tempa{\filename@area\filename@base.#1}%
}%
% \end{macrocode}
% After calling \cs{svg@set@input@path}, all search paths are stored in
% \cs{input@path}, a single path given in the third argument will also be
% considered.
% \begin{macrocode}
\svg@set@input@path[{#3}]%
% \end{macrocode}
% The specified file is searched with \cs{IfFileExists}. If the file search was
% succesful, the macro \cs{svg@filename@parse} is called with the result.
% \begin{macrocode}
\@svg@tempswafalse%
\expandafter\IfFileExists\expandafter{\svg@tempa}{%
\expandafter\svg@quotes@check\expandafter{\svg@tempa}%
\if@svg@quotes@found\else%
\svg@quotes@remove{\@filef@und}%
\fi%
\@svg@tempswatrue%
\edef\@filef@und{\expandafter\trim@spaces\expandafter{\@filef@und}}%
\svg@filename@parse[{#1}]{\@filef@und}%
}{}%
\edef\svg@tempa{%
\endgroup%
\if@svg@tempswa%
\noexpand\@svg@file@foundtrue%
\def\noexpand\svg@file@path{\filename@area}%
\def\noexpand\svg@file@name{\filename@base}%
\def\noexpand\svg@file@base{\filename@area\filename@base}%
\else%
\noexpand\@svg@file@foundfalse%
\def\noexpand\svg@file@path{}%
\def\noexpand\svg@file@name{#2}%
\def\noexpand\svg@file@base{#2}%
\fi%
}%
\svg@tempa%
}
% \end{macrocode}
% \end{macro}^^A \svg@file@suffix
% \end{macro}^^A \svg@file@base
% \end{macro}^^A \svg@file@name
% \end{macro}^^A \svg@file@path
% \end{macro}^^A \if@svg@file@found
% \end{macro}^^A \svg@get@path
%
%
%
% \subsection{Patches}
%
% \begin{macro}{\svg@patches}
% \changes{v2.02b}{2018/11/12}{fix bug for package \pkg{tikzscale}: store
% original definitions of \cs{picture} and \cs{includegraphics} right after
% loading package \pkg{svg}}^^A
% \begin{macro}{\svg@picture@saved}
% \begin{macro}{\svg@includegraphics@saved}
% For including the export results from \app{Inkscape} with \LaTeX~support
% enabled, there are some patches necessary for environment \env{picture} and
% \cs{includegraphics}. These patches are done with \cs{svg@patches}.
% \begin{macrocode}
\newcommand*\svg@picture@saved{}
\let\svg@picture@saved\picture
\newcommand*\svg@includegraphics@saved{}
\let\svg@includegraphics@saved\includegraphics
\newcommand*\svg@patches[1]{%
\let\picture\svg@picture@patched%
\let\includegraphics\svg@includegraphics@patched%
\edef\svg@includegraphics@file{#1}%
}
% \end{macrocode}
% \end{macro}^^A \svg@includegraphics@saved
% \end{macro}^^A \svg@picture@saved
% \end{macro}^^A \svg@patches
% \begin{macro}{\svg@picture@patched}
% \begin{macro}{\svg@pictur@patched}
% In order to provide the possibility specify the desired width of a graphic,
% the appropriate \cs{unitlength} is calculated at the beginning of the
% \env{picture}~environment.
% \begin{macrocode}
\newcommand*\svg@picture@patched{}
\newcommand*\svg@pictur@patched{}
\long\def\svg@picture@patched#1{\svg@pictur@patched@#1}
\def\svg@pictur@patched@(#1,#2){%
\svg@wrn@scale%
% \end{macrocode}
% If a desired height is present, the resulting \cs{unitlength} is calculated
% with the ratio of the coordinates of the \env{picture}~environment given as
% arguments for x- and y-direction by using \cs{Gscale@div}. With this factor,
% \cs{unitlength}---which is connected to the x-coordinate---can be scaled in a
% suitable manner.
% \begin{macrocode}
\ifdim\svg@param@height>\z@\relax%
\Gscale@div\svg@tempa{#1\p@}{#2\p@}%
\setlength\unitlength{\svg@param@height}%
\setlength\unitlength{\svg@tempa\unitlength}%
\ifdim\svg@param@width>\z@\relax%
\ifdim\unitlength>\svg@param@width\relax%
\setlength\unitlength{\svg@param@width}%
\fi%
\fi%
\else%
% \end{macrocode}
% If no height is given, \cs{unitlength} can be set easily.
% \begin{macrocode}
\ifdim\svg@param@width>\z@\relax%
\setlength\unitlength{\svg@param@width}%
\else%
\setlength\unitlength{\svg@param@scale\unitlength}%
\fi%
\fi%
% \end{macrocode}
% After setting \cs{unitlength}, the \env{picture}~environment can be called
% with its original definition.
% \begin{macrocode}
\svg@picture@saved(#1,#2)%
}
% \end{macrocode}
% \end{macro}^^A \svg@pictur@patched
% \end{macro}^^A \svg@picture@patched
% \begin{macro}{\svg@includegraphics@patched}
% \begin{macro}{\svg@includegraphics@file}
% The patch to \cs{includegraphics} is meant to dissolve the \app{Inkscape} bug
% concerning the inclusion of more PDF~pages than actually are existing.
%
% The given optional parameters to \cs{includegraphics} are processed and the
% counter \cnt{svg@param@currpage} is set to the value of a given \prm{page}.
% The value of parameter \prm{width} is ignored.
% \begin{macrocode}
\DefineFamily{SVGpatch}
\DefineFamilyMember{SVGpatch}
\newcounter{svg@param@currpage}
\setcounter{svg@param@currpage}{\m@ne}
\FamilyCounterKey{SVGpatch}{page}{svg@param@currpage}
\DefineFamilyKey{SVGpatch}{width}{\FamilyKeyStateProcessed}
\newcommand*\svg@includegraphics@file{}
\newcommand*\svg@includegraphics@patched[2][]{%
\FamilyOptions{SVGpatch}{#1}%
% \end{macrocode}
% If option \opt{lastpage} was set to \val{false}, each page is included---even
% if it doesn't exist, which may cause errors.
% \begin{macrocode}
\ifnum\value{svg@param@lastpage}<\z@\relax%
\FamilySetCounter{SVGpatch}{page}{svg@param@currpage}{%
\the\value{svg@param@lastpage}%
}%
\fi%
% \end{macrocode}
% Only if counter \cnt{svg@param@lastpage} is smaller than
% \cnt{svg@param@currpage}, pages are included, where \cnt{svg@param@lastpage}
% was either given as a number with parameter \prm{lastpage} or was
% automatically calculated with \cs{svg@get@lastpage}.
% \begin{macrocode}
\ifnum\value{svg@param@currpage}>\value{svg@param@lastpage}\relax\else%
% \end{macrocode}
% A page is included with the original definition of \cs{includegraphics}. All
% optional parameters are passed.
% \begin{macrocode}
\svg@includegraphics@saved[{#1}]{\svg@includegraphics@file}%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \svg@includegraphics@file
% \end{macro}^^A \svg@includegraphics@patched
%
% \iffalse
%</body>
%</package&main>
%<*package&option>
% \fi
%
%
%
% \section{Extracting independent graphic files with \pkg{svg-extract}}
% \subsection{Options}
%
% For package \pkg{svg-extract} the user\hbox{-}interface is extended. The
% following options can either be set with \cs{svgsetup} or be used as local
% optional parameters for \cs{includesvg} and \cs{includeinkscape}.
%
% \begin{macro}{\svg@dummy@key}
% If package \pkg{svg-extract} wasn't loaded, the following options are defined
% for package \pkg{svg} in order to raise a warning message. Primarily this is
% done for compatibility reasons.
% \begin{macrocode}
%<*main>
\DefineFamilyMember[.dummy]{SVG}
\newcommand*\svg@dummy@key[2][]{%
\@ifpackageloaded{svg-extract}{}{%
\IfArgIsEmpty{#1}{%
\DefineFamilyKey[.dummy]{SVG}{#2}{%
\PackageWarning{svg}{%
The option key `#2' can only\MessageBreak%
be used with package `svg-extract', but\MessageBreak%
you didn't load it%
}%
\FamilyKeyStateProcessed%
}%
}{%
\DefineFamilyKey[.dummy]{SVG}{#2}[{#1}]{%
\PackageWarning{svg}{%
The option key `#2' can only\MessageBreak%
be used with package `svg-extract', but\MessageBreak%
you didn't load it%
}%
\FamilyKeyStateProcessed%
}%
}%
% \end{macrocode}
% Before package \pkg{svg-extract} the given key |#2| of family member |.dummy|
% is relaxed.
% \begin{macrocode}
\AfterPackage{svg-extract}{\RelaxFamilyKey[.dummy]{SVG}{#2}}%
}%
}
%</main>
% \end{macrocode}
% \end{macro}^^A \svg@dummy@key
%
%
%
% \subsubsection{Controlling the extract process}
%
% \begin{option}{extract}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\if@svgx@run}
% With option \opt{extract} it can be controlled, if the extraction of
% independent graphic files should be done.
% \begin{macrocode}
%<*main>
\svg@dummy@key[true]{extract}
%</main>
%<*extract>
\newif\if@svgx@run
\DefineFamilyKey{SVG}{extract}[true]{%
\lowercase{\def\svg@tempa{#1}}%
\FamilySetNumerical{SVG}{extract}{svg@tempa}{%
{false}{0},{off}{0},{no}{0},%
{true}{1},{on}{1},{yes}{1},{onlynewer}{1},{newer}{1},%
{overwrite}{1},{force}{1},{forced}{1},%
{pdf}{2},{eps}{3},{ps}{4}%
}{\svg@tempa}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\ifcase\svg@tempa\relax% false
\@svgx@runfalse%
\or% true
\@svgx@runtrue%
\or% pdf
\FamilyOptions{SVG}{extractformat=pdf}%
\or% eps
\FamilyOptions{SVG}{extractformat=eps}%
\or% ps
\FamilyOptions{SVG}{extractformat=ps}%
\fi%
\fi%
}
%</extract>
% \end{macrocode}
% \end{macro}^^A \if@svgx@run
% \end{option}^^A extract
% \begin{option}{on}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{option}{off}
% \changes{v2.00}{2017/02/24}{new}^^A
% Package options which can be used to switch functionality on or off during
% the loading of package \pkg{svg-extract}.
% \begin{macrocode}
%<*extract>
\DeclareOption{on}{\FamilyOptions{SVG}{extract=true}}
\DeclareOption{off}{\FamilyOptions{SVG}{extract=false}}
%</extract>
% \end{macrocode}
% \end{option}^^A off
% \end{option}^^A on
% \begin{option}{extractformat}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@format}
% \begin{option}{pdf}
% \changes{v2.00}{2017/03/02}{deprecated}^^A
% \begin{option}{eps}
% \changes{v2.00}{2017/03/02}{deprecated}^^A
% Option \opt{extractformat} controls the output format (\val{pdf/eps/ps}). It
% is set to \val{pdf} or, if dvi output could be detected, to \val{eps} during
% initialization.
% \begin{macrocode}
%<*main>
\svg@dummy@key{extractformat}
\svg@dummy@key[true]{pdf}
\svg@dummy@key[true]{eps}
%</main>
%<*extract>
\newcommand*\svgx@format{pdf}
\ifxetex\else\ifpdf\else
\renewcommand*\svgx@format{eps}
\fi\fi
\DefineFamilyKey{SVG}{extractformat}{%
\lowercase{\edef\svgx@format{#1}}%
\FamilyKeyStateProcessed%
}
\DefineFamilyKey{SVG}{pdf}[true]{%
\FamilySetBool{SVG}{pdf}{@svg@tempswa}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\if@svg@tempswa%
\svgx@ifinlist{pdf}{\svgx@format}{}{%
\edef\svgx@format{\svgx@format,pdf}%
}%
\svg@deprecated@key{pdf}{extractformat={\svgx@format}}%
\else%
\FamilyKeyStateUnknownValue%
\fi%
\fi%
}
\DefineFamilyKey{SVG}{eps}[true]{%
\FamilySetBool{SVG}{eps}{@svg@tempswa}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\if@svg@tempswa%
\svgx@ifinlist{eps}{\svgx@format}{}{%
\edef\svgx@format{\svgx@format,eps}%
}%
\svg@deprecated@key{eps}{extractformat={\svgx@format}}%
\else%
\FamilyKeyStateUnknownValue%
\fi%
\fi%
}
%</extract>
% \end{macrocode}
% \end{option}^^A eps
% \end{option}^^A pdf
% \end{macro}^^A \svgx@format
% \end{option}^^A extractformat
% \begin{option}{extractpreamble}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{option}{preamble}
% \changes{v2.00}{2017/02/24}{deprecated}^^A
% \begin{macro}{\svgx@preamble}
% \begin{option}{extractpreambleend}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{option}{end}
% \changes{v2.00}{2017/02/24}{deprecated}^^A
% \begin{macro}{\svgx@endpreamble}
% For the extraction process, a preamble is necessary for a separate auxiliary
% \LaTeX~file. By default, the preamble of the main document is used, which end
% is detected at \cs{begin}|{document}|.
% \begin{macrocode}
%<*main>
\svg@dummy@key{extractpreamble}
\svg@dummy@key{preamble}
\svg@dummy@key{extractpreambleend}
\svg@dummy@key{end}
%</main>
%<*extract>
\newcommand*\svgx@preamble{\jobname.\svgx@latex@ext}%
\DefineFamilyKey{SVG}{extractpreamble}{%
\renewcommand*\svgx@preamble{#1}%
\FamilyKeyStateProcessed%
}
\DefineFamilyKey{SVG}{preamble}{%
\svg@deprecated@key[svg-extract]{preamble=#1}{extractpreamble=#1}%
}
\newcommand*\svgx@endpreamble{}
\expandafter\def\expandafter\svgx@endpreamble\expandafter{%
\csname begin\endcsname{document}%
}
\DefineFamilyKey{SVG}{extractpreambleend}{%
\renewcommand*\svgx@endpreamble{#1}%
\FamilyKeyStateProcessed%
}
\DefineFamilyKey{SVG}{end}{%
\svg@deprecated@key[svg-extract]{end=#1}{extractpreambleend=#1}%
}
%</extract>
% \end{macrocode}
% \end{macro}^^A \svgx@endpreamble
% \end{option}^^A end
% \end{option}^^A extractpreambleend
% \end{macro}^^A \svgx@preamble
% \end{option}^^A preamble
% \end{option}^^A extractpreamble
% \begin{option}{extractruns}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{counter}{svgx@runs}
% With this option, the number of \LaTeX~runs for the separate auxiliary file
% can be set.
% \begin{macrocode}
%<*main>
\svg@dummy@key{extractruns}
%</main>
%<*extract>
\newcounter{svgx@runs}
\DefineFamilyKey{SVG}{extractruns}{%
\FamilySetCounter{SVG}{extractruns}{svgx@runs}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\ifnum\value{svgx@runs}<\@ne\relax%
\PackageWarning{svg-extract}{%
The count for runs has to be at least one%
}%
\FamilySetCounter{SVG}{extractruns}{svgx@runs}{\@ne}%
\fi%
\fi%
}
%</extract>
% \end{macrocode}
% \end{counter}^^A svgx@runs
% \end{option}^^A extractruns
% \begin{option}{latexexe}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{option}{pdflatex}
% \changes{v2.00}{2017/02/24}{deprecated}^^A
% \begin{macro}{\svgx@latex@exe}
% \begin{option}{latexext}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@latex@ext}
% \begin{option}{latexopt}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@latex@opt}
% The command and facultative options for the \LaTeX~call of the separate
% auxiliary file. The default is set according to the currently used engine.
% \begin{macrocode}
%<*main>
\svg@dummy@key{latexexe}
\svg@dummy@key{pdflatex}
\svg@dummy@key{latexext}
\svg@dummy@key{latexopt}
%</main>
%<*extract>
\ifxetex
\newcommand*\svgx@latex@exe{xelatex}
\else\ifluatex
\ifpdf
\newcommand*\svgx@latex@exe{lualatex}
\else
\newcommand*\svgx@latex@exe{lualatex --output-format=dvi}
\fi
\else\ifpdf
\newcommand*\svgx@latex@exe{pdflatex}
\else
\newcommand*\svgx@latex@exe{latex}
\fi\fi\fi
\DefineFamilyKey{SVG}{latexexe}{%
\renewcommand*\svgx@latex@exe{#1}%
\FamilyKeyStateProcessed%
}
\DefineFamilyKey{SVG}{pdflatex}{%
\svg@deprecated@key[svg-extract]{pdflatex=#1}{latexexe=#1}%
}
\newcommand*\svgx@latex@ext{tex}
\DefineFamilyKey{SVG}{latexext}{%
\renewcommand*\svgx@latex@ext{#1}%
\FamilyKeyStateProcessed%
}
\newcommand*\svgx@latex@opt{}
\DefineFamilyKey{SVG}{latexopt}{%
\renewcommand*\svgx@latex@opt{#1}%
\FamilyKeyStateProcessed%
}
%</extract>
% \end{macrocode}
% \end{macro}^^A \svgx@latex@opt
% \end{option}^^A latexopt
% \end{macro}^^A \svgx@latex@ext
% \end{option}^^A latexext
% \end{macro}^^A \svgx@latex@exe
% \end{option}^^A latexexe
% \end{option}^^A pdflatexexe
% \begin{option}{dvipsopt}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@dvips@exe}
% \begin{macro}{\svgx@dvips@opt}
% \begin{option}{pstoepsopt}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@pstoeps@exe}
% \begin{macro}{\svgx@pstoeps@opt}
% \begin{option}{pstopdfopt}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@pstopdf@exe}
% \begin{macro}{\svgx@pstopdf@opt}
% \begin{option}{pdftoepsopt}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@pdftoeps@exe}
% \begin{macro}{\svgx@pdftoeps@opt}
% \begin{option}{pdftopsopt}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@pdftops@exe}
% \begin{macro}{\svgx@pdftops@opt}
% \begin{option}{pdftops}
% \changes{v2.00}{2017/02/24}{deprecated}^^A
% Options and macros for calling convert commands, which are supplied by most
% \LaTeX~distributions. These are used to generate all files, which are
% supported by option \opt{extractformat}, as they don't need an additional
% application.
% \begin{macrocode}
%<*main>
\svg@dummy@key{dvipsopt}
\svg@dummy@key{pstoepsopt}
\svg@dummy@key{pstopdfopt}
\svg@dummy@key{pdftoepsopt}
\svg@dummy@key{pdftopsopt}
\svg@dummy@key{pdftops}
%</main>
%<*extract>
\newcommand*\svgx@dvips@exe{dvips}
\newcommand*\svgx@dvips@opt{}
\DefineFamilyKey{SVG}{dvipsopt}{%
\renewcommand*\svgx@dvips@opt{#1}%
\FamilyKeyStateProcessed%
}
\newcommand*\svgx@pstoeps@exe{ps2eps}
\newcommand*\svgx@pstoeps@opt{-B -C}
\DefineFamilyKey{SVG}{pstoepsopt}{%
\renewcommand*\svgx@pstoeps@opt{#1}%
\FamilyKeyStateProcessed%
}
\newcommand*\svgx@pstopdf@exe{ps2pdf}
\newcommand*\svgx@pstopdf@opt{}
\DefineFamilyKey{SVG}{pstopdfopt}{%
\renewcommand*\svgx@pstopdf@opt{#1}%
\FamilyKeyStateProcessed%
}
\newcommand*\svgx@pdftoeps@exe{pdftops -eps}
\newcommand*\svgx@pdftoeps@opt{}
\DefineFamilyKey{SVG}{pdftoepsopt}{%
\renewcommand*\svgx@pdftoeps@opt{#1}%
\FamilyKeyStateProcessed%
}
\newcommand*\svgx@pdftops@exe{pdftops}
\newcommand*\svgx@pdftops@opt{}
\DefineFamilyKey{SVG}{pdftopsopt}{%
\renewcommand*\svgx@pdftops@opt{#1}%
\FamilyKeyStateProcessed%
}
\DefineFamilyKey{SVG}{pdftops}{%
\PackageWarning{svg-extract}{%
The option key `pdftops' is deprecated. \MessageBreak%
You should use either `pdftoepsopt' or\MessageBreak%
`pdftopsopt' instead. See the manual for\MessageBreak%
more. Nothing was done%
}%
\FamilyKeyStateProcessed%
}
%</extract>
% \end{macrocode}
% \end{option}^^A pdftops
% \end{macro}^^A \svgx@pdftops@opt
% \end{macro}^^A \svgx@pdftops@exe
% \end{option}^^A pdftopsopt
% \end{macro}^^A \svgx@pdftoeps@opt
% \end{macro}^^A \svgx@pdftoeps@exe
% \end{option}^^A pdftoepsopt
% \end{macro}^^A \svgx@pstopdf@opt
% \end{macro}^^A \svgx@pstopdf@exe
% \end{option}^^A pstopdfopt
% \end{macro}^^A \svgx@pstoeps@opt
% \end{macro}^^A \svgx@pstoeps@exe
% \end{option}^^A pstoepsopt
% \end{macro}^^A \svgx@dvips@opt
% \end{macro}^^A \svgx@dvips@exe
% \end{option}^^A dvipsopt
%
%
%
% \subsubsection{Invoking external application for graphic conversion}
%
% Besides the use of a conversion tool supplied by the \LaTeX~distribution,
% the applications \app{ImageMagick} and \app{Ghostscript} can be used for
% converting graphics.
%
% \begin{option}{convert}
% \changes{v2.00}{2017/02/24}{changed/extended}^^A
% \begin{macro}{\if@svgx@cnv@run}
% \begin{macro}{\svgx@cnv@cmd}
% The option \opt{convert} can be used to define, which of both applications
% should be use. \app{ImageMagick} is set by default.
% \begin{macrocode}
%<*main>
\svg@dummy@key[true]{convert}
%</main>
%<*extract>
\newif\if@svgx@cnv@run
\newcommand*\svgx@cnv@cmd{}
\DefineFamilyKey{SVG}{convert}[true]{%
\FamilySetNumerical{SVG}{convert}{svg@tempa}{%
{false}{0},{off}{0},{no}{0},%
{true}{1},{on}{1},{yes}{1},{onlynewer}{1},{newer}{1},%
{overwrite}{1},{force}{1},{forced}{1},%
{magick}{2},{imagemagick}{2},{convert}{2},%
{gs}{3},{ghostscript}{3},%
{gs64}{4},{ghostscript64}{4},%
{gs32}{5},{ghostscript32}{5}%
}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\ifcase\svg@tempa\relax% false
\@svgx@cnv@runfalse%
\or% true
\@svgx@cnv@runtrue%
\or% magick
\@svgx@cnv@runtrue%
\renewcommand*\svgx@cnv@cmd{\svgx@magick@cmd}%
\or% gs
\@svgx@cnv@runtrue%
\renewcommand*\svgx@cnv@cmd{\svgx@gs@cmd}%
\or% gs64
\@svgx@cnv@runtrue%
\renewcommand*\svgx@cnv@cmd{\svgx@gs@cmd}%
\svg@ifwindowsdetected{%
\renewcommand*\svgx@gs@exe{gswin64c}%
}{}%
\or% gs32
\@svgx@cnv@runtrue%
\renewcommand*\svgx@cnv@cmd{\svgx@gs@cmd}%
\svg@ifwindowsdetected{%
\renewcommand*\svgx@gs@exe{gswin32c}%
}{}%
\fi%
% \end{macrocode}
% In version~v1.0 the option \opt{convert} was used to set both the executable
% and options for the conversion application, meant for the usage of
% \app{ImageMagick}. This is taken into account here.
% \begin{macrocode}
\else% legacy option
% \end{macrocode}
% Same doing like with legacy part of option \opt{inkscape}.
% \begin{macrocode}
\def\svg@tempa##1-##2\@nil{%
\IfArgIsEmpty{##2}{\def\svg@tempb{}}{%
\def\svg@tempa##1####1\@nil{\def\svg@tempb{####1}}%
\svg@tempa#1\@nil%
}%
\def\svg@tempa{##1}%
}%
\svg@tempa#1-\@nil%
\PackageWarning{svg-extract}{%
Setting the executable%
\ifx\svg@tempb\@empty\else%
\space and associated options%
\fi%
\MessageBreak%
for ImageMagick should be done with options\MessageBreak%
`magickexe=\svg@tempa'%
\ifx\svg@tempb\@empty\else%
\MessageBreak and `magicksetting' and/or `magickoperator'%
\fi.\MessageBreak%
Nevertheless, this was done by now%
\ifx\svg@tempb\@empty\else%
, whereby \MessageBreak `magicksetting=\svg@tempb' was used%
\fi%
}%
\FamilyOptions{SVG}{convert=magick}%
\edef\svg@tempa{%
\noexpand\FamilyOptions{SVG}{magickexe=\svg@tempa}%
\ifx\svg@tempb\@empty\else%
\noexpand\FamilyOptions{SVG}{magicksetting=\svg@tempb}%
\fi%
}%
\svg@tempa%
\fi%
}
%</extract>
% \end{macrocode}
% \end{macro}^^A \svgx@cnv@cmd
% \end{macro}^^A \if@svgx@cnv@run
% \end{option}^^A convert
% \begin{option}{convertformat}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@cnv@format}
% \begin{option}{png}
% \changes{v2.00}{2017/03/02}{deprecated}^^A
% Option \opt{convertformat} controls the output format for converted files. It
% is set to \val{png} by default.
% \begin{macrocode}
%<*main>
\svg@dummy@key{convertformat}
\svg@dummy@key[true]{png}
%</main>
%<*extract>
\newcommand*\svgx@cnv@format{png}
\DefineFamilyKey{SVG}{convertformat}{%
\lowercase{\edef\svgx@cnv@format{#1}}%
\ifx\svgx@cnv@format\@empty\else%
\@svgx@cnv@runtrue%
\fi%
\FamilyKeyStateProcessed%
}
\DefineFamilyKey{SVG}{png}[true]{%
\FamilySetBool{SVG}{png}{@svg@tempswa}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\if@svg@tempswa%
\svgx@ifinlist{png}{\svgx@cnv@format}{}{%
\edef\svgx@cnv@format{\svgx@cnv@format,png}%
}%
\svg@deprecated@key{png}{convertformat={\svgx@cnv@format}}%
\else%
\FamilyKeyStateUnknownValue%
\fi%
\fi%
}
%</extract>
% \end{macrocode}
% \end{option}^^A png
% \end{macro}^^A \svgx@cnv@format
% \end{option}^^A convertformat
% \begin{option}{convertdpi}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{option}{convertdensity}
% \begin{macro}{\svgx@cnv@dpi}
% \begin{macro}{\svgx@cnv@get@dpi}
% The option \opt{convertdpi} is meant to define the used density during the
% conversion process. It can be set either for all designated output formats or
% targeted for a specific format. It's also possible to use something like
% \val{500x300}. Given values are resolved by \cs{svgx@cnv@get@dpi}. It's used
% like \opt{convertdpi}|=|\val{300} or \opt{convertdpi}|=|\val{\{png=600\}} If
% the option is used for a specific or for all output formats is recocnized by
% \cs{svgx@ifkeyandval}.
% \begin{macrocode}
%<*main>
\svg@dummy@key{convertdpi}
\svg@dummy@key{convertdensity}
%</main>
%<*extract>
\newcommand*\svgx@cnv@dpi{}
\let\svgx@cnv@dpi\relax
\DefineFamilyKey{SVG}{convertdpi}{%
\FamilyKeyStateUnknownValue%
\svgx@ifkeyandval{#1}{%
\svgx@cnv@get@dpi{##2}%
\ifx\svg@tempa\relax\else%
\expandafter\edef\csname svgx@cnv@dpi@##1\endcsname{\svg@tempa}%
\FamilyKeyStateProcessed%
\fi%
}{%
\svgx@cnv@get@dpi{##1}%
\ifx\svg@tempa\relax\else%
\edef\svgx@cnv@dpi{\svg@tempa}%
\FamilyKeyStateProcessed%
\fi%
}%
}
\DefineFamilyKey{SVG}{convertdensity}{\FamilyOptions{SVG}{convertdpi=#1}}
% \end{macrocode}
% This macro is used to resolve a given value to set the density for the
% conversion. The delimited macros \cs{svg@tempa} and \cs{svg@tempb} are
% defined to first crop any given suffix \val{dpi} and second to split two
% numbers at |x|, if present. Pay attention how both macros are invoked. In the
% end, a passed value in any of the forms \val{300}, \val{300dpi}, \val{300x400}
% or \val{300x400dpi} and even \val{300dpix400dpi} is possible. The result is
% stored in \cs{svg@tempa}.
% \begin{macrocode}
\newcommand*\svgx@cnv@get@dpi[1]{%
\begingroup%
\def\svg@tempa##1dpi##2x##3dpi##4\@nil{%
\edef\svg@tempa{##1}%
% \end{macrocode}
% Switch \cs{if@svg@tempswa} as \cs{iftrue} means, a valid value was found.
% \begin{macrocode}
\@svg@tempswafalse%
% \end{macrocode}
% If only the first argument is a number and third is empty, a single number
% was given and there's nothing more to do. If the argument is something like
% \val{300dpix400dpi}, the third argument is the second number.
% \begin{macrocode}
\Ifnumber{##1}{%
\IfArgIsEmpty{##3}{\@svg@tempswatrue}{%
\Ifnumber{##3}{\edef\svg@tempa{##1x##3}}{}%
}%
}{}%
\if@svg@tempswa\else%
\expandafter\svg@tempb\svg@tempa xx\@nil%
\fi%
}%
% \end{macrocode}
% Macro \cs{svg@tempb} splits at |x| and checks, if something valid like
% \val{300x400} was given. If true, the value is stored in \cs{svg@tempa}.
% \begin{macrocode}
\def\svg@tempb##1x##2x##3\@nil{%
\Ifstr{##3}{x}{%
\@svg@tempswatrue%
\IfArgIsEmpty{##1}{\@svg@tempswafalse}{%
\Ifnumber{##1}{}{\@svg@tempswafalse}%
}%
\IfArgIsEmpty{##2}{\@svg@tempswafalse}{%
\Ifnumber{##2}{}{\@svg@tempswafalse}%
}%
\if@svg@tempswa%
\edef\svg@tempa{##1x##2}%
\fi%
}{}%
}%
\IfArgIsEmpty{#1}{%
\let\svg@tempa\@empty%
}{%
\lowercase{\svg@tempa#1dpi#1xdpi\@nil}%
\if@svg@tempswa\else%
\let\svg@tempa\relax%
\fi%
}%
\edef\svg@tempb{%
\endgroup%
\ifx\svg@tempa\relax%
\let\noexpand\svg@tempa\noexpand\relax%
\else%
\def\noexpand\svg@tempa{\svg@tempa}%
\fi%
}%
\svg@tempb%
}
%</extract>
% \end{macrocode}
% \end{macro}^^A \svgx@cnv@get@dpi
% \end{macro}^^A \svgx@cnv@dpi
% \end{option}^^A convertdensity
% \end{option}^^A convertdpi
%
% \iffalse
%<*extract>
% \fi
%
% \begin{macro}{\svgx@setformatkey}
% \begin{macro}{\svgx@useformatkey}
% With \cs{svgx@setformatkey} the---maybe output format depend---keys for the
% conversion tools are set. First argument contains the value given to a key,
% second the command sequence name of the macro, to whom the value shall be
% allocated.
% \begin{macrocode}
\newcommand*\svgx@setformatkey[2]{%
% \end{macrocode}
% A key of the form \val{\meta{key}=\{\meta{format}=\meta{value}\}} is given.
% The desired output format can be accessed with |##1|, the value with |##2|
% within the arguments of \cs{svgx@ifkeyandval}.
% \begin{macrocode}
\svgx@ifkeyandval{#1}{%
\svg@ifvalueisrelax{##2}{%
\expandafter\let\csname #2@##1\endcsname\relax%
}{%
\@namedef{#2@##1}{##2}%
}%
% \end{macrocode}
% A key of the form \val{\meta{key}=\{\meta{format}=\meta{value}\}} is given.
% The value can be used with |##1|.
% \begin{macrocode}
}{%
\svg@ifvalueisrelax{##1}{%
\expandafter\let\csname #2\endcsname\relax%
}{%
\@namedef{#2}{##1}%
}%
}%
}
% \end{macrocode}
% The command \cs{svgx@useformatkey} checks, if a format specific key was
% definded with \cs{svgx@setformatkey}, whereas the format is given in the
% second argument. If this is not the case, the setting for all output formats
% is used. After that, a specific key appended with a |+| can be used to do
% some additional stuff.
% \begin{macrocode}
\newcommand*\svgx@useformatkey[3]{%
\scr@ifundefinedorrelax{#1@#2}{%
\scr@ifundefinedorrelax{#1}{}{%
\expandafter\ifx\csname #1\endcsname\@empty\else%
#3\@nameuse{#1}\space%
\fi%
}%
\scr@ifundefinedorrelax{#1@#2+}{}{%
\expandafter\ifx\csname #1@#2+\endcsname\@empty\else%
#3\@nameuse{#1@#2+}\space%
\fi%
}%
}{%
% \end{macrocode}
% If a format specific key was definded, it is used.
% \begin{macrocode}
\expandafter\ifx\csname #1@#2\endcsname\@empty\else%
#3\@nameuse{#1@#2}\space%
\fi%
}%
}
% \end{macrocode}
% \end{macro}^^A \svgx@useformatkey
% \end{macro}^^A \svgx@setformatkey
%
% \iffalse
%</extract>
% \fi
%
% \begin{option}{magickexe}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@magick@exe}
% \begin{option}{magicksetting}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@magick@set}
% \begin{option}{magickoperator}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@magick@opr}
% \begin{macro}{\svgx@magick@cmd}
% Setting the command including maybe the path to \app{ImageMagick}. The keys
% \opt{magicksetting} and \opt{magickoperator} should be used to add optional
% arguments before (\emph{Settings}) or after (\emph{Operators}) the input
% file. They can either be set for all or a specific output format as like
% option \opt{convertdpi}. For this \cs{svgx@setformatkey} is used.
% \begin{macrocode}
%<*main>
\svg@dummy@key{magickexe}
\svg@dummy@key{magicksetting}
\svg@dummy@key{magickoperator}
%</main>
%<*extract>
\svg@ifwindowsdetected{%
\newcommand*\svgx@magick@exe{magick}%
}{%
\newcommand*\svgx@magick@exe{convert}%
}
\DefineFamilyKey{SVG}{magickexe}{%
\renewcommand*\svgx@magick@exe{#1}%
\FamilyKeyStateProcessed%
}
\newcommand*\svgx@magick@set{}
\DefineFamilyKey{SVG}{magicksetting}{%
\svgx@setformatkey{#1}{svgx@magick@set}%
\FamilyKeyStateProcessed%
}
\newcommand*\svgx@magick@opr{}
\DefineFamilyKey{SVG}{magickoperator}{%
\svgx@setformatkey{#1}{svgx@magick@opr}%
\FamilyKeyStateProcessed%
}
\newcommand*\svgx@magick@cmd[3]{%
\svgx@magick@exe\space%
\svgx@useformatkey{svgx@cnv@dpi}{#3}{-density }%
\svgx@useformatkey{svgx@magick@set}{#3}{}%
"#1.#2"\space%
\svgx@useformatkey{svgx@magick@opr}{#3}{}%
"#1.#3"%
}
%</extract>
% \end{macrocode}
% \end{macro}^^A \svgx@magick@cmd
% \end{macro}^^A \svgx@magick@opr
% \end{option}^^A magickoperator
% \end{macro}^^A \svgx@magick@set
% \end{option}^^A magicksetting
% \end{macro}^^A \svgx@magick@exe
% \end{option}^^A magickexe
% \begin{option}{gsexe}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@gs@exe}
% \begin{option}{gsopt}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@gs@opt}
% \begin{option}{gsdevice}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svgx@gs@device}
% \begin{macro}{\svgx@gs@cmd}
% Options to set the command including maybe the path to \app{Ghostscript}. As
% \app{Ghostscript} needs a specific device defined for different output
% formats, the option \opt{gsdevice} can be used. It can either be set for all
% or a specific output format just like \opt{gsopt} in the same manner like
% option \opt{convertdpi}.
% \begin{macrocode}
%<*main>
\svg@dummy@key{gsexe}
\svg@dummy@key{gsopt}
\svg@dummy@key{gsdevice}
%</main>
%<*extract>
\svg@ifwindowsdetected{%
\newcommand*\svgx@gs@exe{gswin64c}%
}{%
\newcommand*\svgx@gs@exe{gs}%
}
\DefineFamilyKey{SVG}{gsexe}{%
\renewcommand*\svgx@gs@exe{#1}%
\FamilyKeyStateProcessed%
}
\newcommand*\svgx@gs@opt{}
\DefineFamilyKey{SVG}{gsopt}{%
\svgx@setformatkey{#1}{svgx@gs@opt}%
\FamilyKeyStateProcessed%
}
\newcommand*\svgx@gs@device{}
\DefineFamilyKey{SVG}{gsdevice}{%
\svgx@setformatkey{#1}{svgx@gs@device}%
\FamilyKeyStateProcessed%
}
\newcommand*\svgx@gs@cmd[3]{%
\svgx@gs@exe\space-dSAFER -dBATCH -dNOPAUSE\space%
\svgx@useformatkey{svgx@gs@device}{#3}{-sDEVICE=}%
\svgx@useformatkey{svgx@cnv@dpi}{#3}{-r}%
\svgx@useformatkey{svgx@gs@opt}{#3}{}%
-sOutputFile="#1.#3"\space"#1.#2"%
}
%</extract>
% \end{macrocode}
% \end{macro}^^A \svgx@gs@cmd
% \end{macro}^^A \svgx@gs@device
% \end{option}^^A gsdevice
% \end{macro}^^A \svgx@gs@opt
% \end{option}^^A gsopt
% \end{macro}^^A \svgx@gs@exe
% \end{option}^^A gsexe
%
%
%
% \subsubsection{Setting output folder}
%
% \begin{option}{extractpath}
% \changes{v2.00}{2017/02/24}{new}^^A
% \changes{v2.02}{2018/09/07}{usage of \cs{svg@sanitize@dq}}^^A
% \begin{option}{path}
% \changes{v2.00}{2017/02/24}{deprecated}^^A
% \begin{macro}{\svgx@out@path}
% The option \opt{extractpath} controls, in which folder the results both of
% the extraction as well as the conversion of \app{ImageMagick} or
% \app{Ghostscript} will be located.
% \begin{macrocode}
%<*main>
\svg@dummy@key{extractpath}
\svg@dummy@key{path}
%</main>
%<*extract>
\newcommand*\svgx@out@path{}
\DefineFamilyKey{SVG}{extractpath}{%
\svg@sanitize@dq\svg@tempb{#1}%
\FamilySetNumerical{SVG}{extractpath}{svg@tempa}{%
{svgpath}{0},{svgdir}{0},%
{svgsubpath}{1},{svgsubdir}{1},%
{basepath}{2},{basedir}{2},{jobpath}{2},{jobdir}{2},%
{basesubpath}{3},{basesubdir}{3},{jobsubpath}{3},{jobsubdir}{3}%
}{\svg@tempb}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\ifcase\svg@tempa\relax% svgpath
\renewcommand*\svgx@out@path{\svg@file@path}%
\or% svgsubpath
\renewcommand*\svgx@out@path{\svg@file@path svg-extract/}%
\or% basepath
\renewcommand*\svgx@out@path{./}%
\or% basesubpath
\renewcommand*\svgx@out@path{./svg-extract/}%
\fi%
\else%
\edef\svgx@out@path{\svg@tempb}%
\svg@normalize@path{\svgx@out@path}%
\FamilyKeyStateProcessed%
\fi%
}
\DefineFamilyKey{SVG}{path}{%
\svg@deprecated@key[svg-extract]{path=#1}{extractpath=#1}%
}
%</extract>
% \end{macrocode}
% \end{macro}^^A \svgx@out@path
% \end{option}^^A path
% \end{option}^^A extractpath
% \begin{option}{extractname}
% \changes{v2.00}{2017/02/24}{new}^^A
% \changes{v2.02}{2018/09/07}{usage of \cs{svg@quotes@remove}}^^A
% \begin{option}{name}
% \changes{v2.00}{2017/02/24}{deprecated}^^A
% \changes{v2.00}{2017/02/24}{support of \pkg{subfig} removed}^^A
% \begin{macro}{\svgx@out@name}
% \begin{macro}{\if@svgx@out@sec}
% \begin{counter}{svgx@out@count}
% \begin{macro}{\svgx@out@sec}
% With option \opt{extractname} the name of the extracted and maybe converted
% file itself can be changed.
% \begin{macrocode}
%<*main>
\svg@dummy@key{extractname}
\svg@dummy@key{name}
%</main>
%<*extract>
\newcommand*\svgx@out@name{}
\newif\if@svgx@out@sec
\newcounter{svgx@out@count}
\newcommand*\svgx@out@sec{unknown}
\DefineFamilyKey{SVG}{extractname}{%
\svg@quotes@remove[{#1}]{\svg@tempb}%
\FamilySetNumerical{SVG}{extractname}{svg@tempa}{%
{filename}{0},{name}{0},%
{filenamenumbered}{1},{namenumbered}{1},%
{numberedfilename}{1},{numberedname}{1},%
{numbered}{2},{section}{2},{numberedsection}{2},{sectionnumbered}{2}%
}{\svg@tempb}%
\@svgx@out@secfalse%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\ifcase\svg@tempa\relax% filename
\renewcommand*\svgx@out@name{\svg@out@name-extract}%
\or% filenamenumbered
\renewcommand*\svgx@out@name{\the\value{svgx@out@count}-\svg@out@name}%
\or% numbered
\renewcommand*\svgx@out@name{\the\value{svgx@out@count}-\svgx@out@sec}%
\@svgx@out@sectrue%
\fi%
\else%
\if@svg@quotes@found%
\edef\svgx@out@name{"\svg@tempb"}%
\else%
\edef\svgx@out@name{\svg@tempb}%
\fi%
\FamilyKeyStateProcessed%
\fi%
}
\DefineFamilyKey{SVG}{name}{%
\svg@deprecated@key[svg-extract]{name=#1}{extractname=#1}%
}
%</extract>
% \end{macrocode}
% \end{macro}^^A \svgx@out@sec
% \end{counter}^^A svgx@out@count
% \end{macro}^^A \if@svgx@out@sec
% \end{macro}^^A \svgx@out@name
% \end{option}^^A name
% \end{option}^^A extractname
%
%
%
% \subsubsection{Options for the extraction of graphics}
%
% \begin{option}{extractwidth}
% \changes{v2.00}{2017/02/20}{new}^^A
% \begin{macro}{\svgx@param@width}
% \begin{option}{extractheight}
% \changes{v2.00}{2017/02/20}{new}^^A
% \begin{macro}{\svgx@param@width}
% \begin{option}{extractdistort}
% \changes{v2.02}{2018/09/07}{new}^^A
% \begin{option}{extractkeepaspectratio}
% \begin{macro}{\svgx@param@distort}
% \begin{option}{extractscale}
% \changes{v2.00}{2017/02/20}{new}^^A
% \begin{macro}{\svgx@param@scale}
% For graphic extraction, the given settings regarding the size for inclusion
% can be overwritten with these options. Using \val{\cs{relax}} as value leads
% to reseting an option as unset, regardless of what was previously given. The
% value \val{inherit} means, that the actual option for including is used for
% extraction as well. This is the default setting.
% \begin{macrocode}
%<*main>
\svg@dummy@key{extractwidth}
\svg@dummy@key{extractheight}
\svg@dummy@key{extractdistort}
\svg@dummy@key{extractkeepaspectratio}
\svg@dummy@key{extractscale}
%</main>
%<*extract>
\newcommand*\svgx@param@width{\svg@param@width}
\DefineFamilyKey{SVG}{extractwidth}{%
\FamilyKeyStateUnknownValue%
\svg@ifvalueisrelax{#1}{%
\renewcommand*\svgx@param@width{\z@}%
\FamilyKeyStateProcessed%
}{%
\Ifstr{#1}{inherit}{%
\renewcommand*\svgx@param@width{\svg@param@width}%
\FamilyKeyStateProcessed%
}{%
\FamilySetLengthMacro{SVG}{extractwidth}{\svgx@param@width}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\ifdim\svgx@param@width<\z@\relax%
\FamilyKeyStateUnknownValue%
\fi%
\fi%
}%
}%
}
\newcommand*\svgx@param@height{\svg@param@height}
\DefineFamilyKey{SVG}{extractheight}{%
\FamilyKeyStateUnknownValue%
\svg@ifvalueisrelax{#1}{%
\renewcommand*\svgx@param@height{\z@}%
\FamilyKeyStateProcessed%
}{%
\Ifstr{#1}{inherit}{%
\renewcommand*\svgx@param@height{\svg@param@height}%
\FamilyKeyStateProcessed%
}{%
\FamilySetLengthMacro{SVG}{extractheight}{\svgx@param@height}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\ifdim\svgx@param@height<\z@\relax%
\FamilyKeyStateUnknownValue%
\fi%
\fi%
}%
}%
}
\newif\if@svgx@param@distort
\DefineFamilyKey{SVG}{extractdistort}[true]{%
\FamilyKeyStateUnknownValue%
\svg@ifvalueisrelax{#1}{%
\@svgx@param@distortfalse%
\FamilyKeyStateProcessed%
}{%
\Ifstr{#1}{inherit}{%
\renewcommand*\if@svgx@param@distort{\if@svg@param@distort}%
\FamilyKeyStateProcessed%
}{%
\FamilySetBool{SVG}{extractdistort}{@svgx@param@distort}{#1}%
}%
}%
}
\DefineFamilyKey{SVG}{extractkeepaspectratio}[true]{%
\FamilySetBool{SVG}{extractkeepaspectratio}{@svg@tempswa}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\if@svg@tempswa%
\FamilyOptions{SVG}{extractdistort=false}%
\else%
\FamilyOptions{SVG}{extractdistort=true}%
\fi%
\else%
\FamilyOptions{SVG}{extractdistort=#1}%
\fi%
}
\newcommand*\svgx@param@scale{\svg@param@scale}
\DefineFamilyKey{SVG}{extractscale}{%
\FamilyKeyStateUnknownValue%
\svg@ifvalueisrelax{#1}{%
\renewcommand*\svgx@param@scale{1}%
\FamilyKeyStateProcessed%
}{%
\Ifstr{#1}{inherit}{%
\renewcommand*\svgx@param@scale{\svg@param@scale}%
\FamilyKeyStateProcessed%
}{%
\Ifisdimension{#1\p@}{%
\ifdim\dimexpr#1\p@\relax>\z@\relax%
\renewcommand*\svgx@param@scale{#1}%
\FamilyKeyStateProcessed%
\fi%
}{}%
}%
}%
}
%</extract>
% \end{macrocode}
% \end{macro}^^A \svgx@param@scale
% \end{option}^^A extractscale
% \end{macro}^^A \svgx@param@distort
% \end{option}^^A extractkeepaspectratio
% \end{option}^^A extractdistort
% \end{macro}^^A \svgx@param@height
% \end{option}^^A extractheight
% \end{macro}^^A \svgx@param@width
% \end{option}^^A extractwidth
% \begin{option}{extractpretex}
% \changes{v2.00}{2017/02/20}{new}^^A
% \begin{macro}{\svgx@param@pretex}
% \begin{option}{extractapptex}
% \changes{v2.00}{2017/02/20}{new}^^A
% \begin{macro}{\svgx@param@apptex}
% \begin{option}{extractpostex}
% The similar hooks for executing code right before or after the graphic
% extraction.
% \begin{macrocode}
%<*main>
\svg@dummy@key{extractpretex}
\svg@dummy@key{extractapptex}
\svg@dummy@key{extractpostex}
%</main>
%<*extract>
\newcommand*\svgx@param@pretex{\svg@param@pretex}
\DefineFamilyKey{SVG}{extractpretex}{%
\svg@ifvalueisrelax{#1}{%
\let\svgx@param@pretex\relax%
}{%
\Ifstr{#1}{inherit}{%
\renewcommand*\svgx@param@pretex{\svg@param@pretex}%
}{%
\renewcommand*\svgx@param@pretex{#1}%
}%
}%
\FamilyKeyStateProcessed%
}
\newcommand*\svgx@param@apptex{\svg@param@apptex}
\DefineFamilyKey{SVG}{extractapptex}{%
\svg@ifvalueisrelax{#1}{%
\let\svgx@param@apptex\relax%
}{%
\Ifstr{#1}{inherit}{%
\renewcommand*\svgx@param@apptex{\svg@param@apptex}%
}{%
\renewcommand*\svgx@param@apptex{#1}%
}%
}%
\FamilyKeyStateProcessed%
}
\DefineFamilyKey{SVG}{extractpostex}{%
\svg@deprecated@key[svg-extract]{extractpostex=#1}{extractapptex=#1}%
}
%</extract>
% \end{macrocode}
% \end{option}^^A extractpostex
% \end{macro}^^A \svgx@param@apptex
% \end{option}^^A extractapptex
% \end{macro}^^A \svgx@param@pretex
% \end{option}^^A extractpretex
%
%
%
% \subsubsection{Miscellaneous options}
%
% \begin{option}{clean}
% \changes{v2.00}{2017/02/24}{changes, file list possible}^^A
% \begin{option}{clear}
% \begin{macro}{\svgx@clean}
% With option \opt{clean} files generated during the extraction process can be
% deleted. Setting \val{true} will remove all files, \val{false} won't clear
% any file. Additionally, a specific file list of suffixes can be given.
% \begin{macrocode}
%<*main>
\svg@dummy@key[true]{clean}
\svg@dummy@key[true]{clear}
%</main>
%<*extract>
\newcommand*\svgx@clean{}
\DefineFamilyKey{SVG}{clean}[true]{%
\FamilySetBool{SVG}{clean}{@svg@tempswa}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\if@svg@tempswa%
\renewcommand*\svgx@clean{log,aux,dvi,out,ps,eps,pdf,\svgx@latex@ext}%
\else%
\renewcommand*\svgx@clean{}%
\fi%
\else%
\renewcommand*\svgx@clean{#1}%
\FamilyKeyStateProcessed%
\fi%
}
\DefineFamilyKey{SVG}{clear}[true]{\FamilyOptions{SVG}{clean=#1}}
%</extract>
% \end{macrocode}
% \end{macro}^^A \svgx@clean
% \end{option}^^A clear
% \end{option}^^A clean
% \begin{option}{exclude}
% If it is desired not to include but only extract graphics with package
% \pkg{svg-extract}, option \opt{exclude} can be used.
% \begin{macrocode}
%<*main>
\svg@dummy@key[true]{exclude}
%</main>
%<*extract>
\DefineFamilyKey{SVG}{exclude}[true]{%
\FamilySetBool{SVG}{exclude}{@svg@tempswa}{#1}%
\ifx\FamilyKeyState\FamilyKeyStateProcessed%
\if@svg@tempswa%
\renewcommand*\svg@input[2][]{%
\if@svgx@run\else%
\PackageWarning{svg-extract}{%
The image `##2' was\MessageBreak%
neither extracted nor included%
}%
\fi%
}%
\else%
\renewcommand*\svg@input{\svg@@input}%
\fi%
\fi%
}
%</extract>
% \end{macrocode}
% \end{option}^^A exclude
%
% \iffalse
%</package&option>
%<*package&body>
% \fi
%
%
%
% \subsection{User commands}
%
% \begin{macro}{\includesvg}
% \begin{parameter}{extract}
% \begin{parameter}{extractpreamble}
% \begin{parameter}{extractformat}
% \begin{parameter}{extractwidth}
% \begin{parameter}{extractheight}
% \begin{parameter}{extractdistort}
% \changes{v2.02}{2018/09/07}{new}^^A
% \begin{parameter}{extractscale}
% \begin{parameter}{extractangle}
% \changes{v2.02}{2018/09/07}{new}^^A
% \begin{parameter}{extractpretex}
% \begin{parameter}{extractapptex}
% \begin{parameter}{extractruns}
% \begin{parameter}{latexexe}
% \begin{parameter}{latexopt}
% \begin{parameter}{latexext}
% \begin{parameter}{dvipsopt}
% \begin{parameter}{pstoepsopt}
% \begin{parameter}{pstopdfopt}
% \begin{parameter}{pdftoepsopt}
% \begin{parameter}{pdftopsopt}
% \begin{parameter}{convert}
% \begin{parameter}{convertformat}
% \begin{parameter}{convertdpi}
% \begin{parameter}{magicksetting}
% \begin{parameter}{magickoperator}
% \begin{parameter}{gsopt}
% \begin{parameter}{gsdevice}
% \begin{parameter}{clean}
% \begin{parameter}{exclude}
% \begin{macro}{\includeinkscape}
% \begin{parameter}{extract}
% \begin{parameter}{extractpreamble}
% \begin{parameter}{extractformat}
% \begin{parameter}{extractwidth}
% \begin{parameter}{extractheight}
% \begin{parameter}{extractdistort}
% \changes{v2.02}{2018/09/07}{new}^^A
% \begin{parameter}{extractscale}
% \begin{parameter}{extractangle}
% \changes{v2.02}{2018/09/07}{new}^^A
% \begin{parameter}{extractpretex}
% \begin{parameter}{extractapptex}
% \begin{parameter}{extractruns}
% \begin{parameter}{latexexe}
% \begin{parameter}{latexopt}
% \begin{parameter}{latexext}
% \begin{parameter}{dvipsopt}
% \begin{parameter}{pstoepsopt}
% \begin{parameter}{pstopdfopt}
% \begin{parameter}{pdftoepsopt}
% \begin{parameter}{pdftopsopt}
% \begin{parameter}{convert}
% \begin{parameter}{convertformat}
% \begin{parameter}{convertdpi}
% \begin{parameter}{magicksetting}
% \begin{parameter}{magickoperator}
% \begin{parameter}{gsopt}
% \begin{parameter}{gsdevice}
% \begin{parameter}{clean}
% \begin{parameter}{exclude}
% The parameters \prm{angle} and \prm{origin} are definied as pendants to the
% keys provided by \cs{includegraphics}.
% \begin{macrocode}
%<*extract>
\newcommand*\svgx@param@angle{0}
\svg@local@param@def{%
\DefineFamilyKey[.param]{SVG}{extractangle}{%
\FamilyKeyStateUnknownValue%
\svg@ifvalueisrelax{#1}{%
\renewcommand*\svgx@param@angle{0}%
\FamilyKeyStateProcessed%
}{%
\Ifstr{#1}{inherit}{%
\renewcommand*\svgx@param@angle{\svg@param@angle}%
\FamilyKeyStateProcessed%
}{%
\Ifisdimension{#1\p@}{%
\renewcommand*\svgx@param@angle{#1}%
\FamilyKeyStateProcessed%
}{}%
}%
}%
}%
}
%</extract>
% \end{macrocode}
% \end{parameter}^^A exclude
% \end{parameter}^^A clean
% \end{parameter}^^A gsdevice
% \end{parameter}^^A gsopt
% \end{parameter}^^A magickoperator
% \end{parameter}^^A magicksetting
% \end{parameter}^^A convertdpi
% \end{parameter}^^A convertformat
% \end{parameter}^^A convert
% \end{parameter}^^A pdftopsopt
% \end{parameter}^^A pdftoepsopt
% \end{parameter}^^A pstopdfopt
% \end{parameter}^^A pstoepsopt
% \end{parameter}^^A dvipsopt
% \end{parameter}^^A latexext
% \end{parameter}^^A latexopt
% \end{parameter}^^A latexexe
% \end{parameter}^^A extractruns
% \end{parameter}^^A extractapptex
% \end{parameter}^^A extractpretex
% \end{parameter}^^A extractangle
% \end{parameter}^^A extractscale
% \end{parameter}^^A extractdistort
% \end{parameter}^^A extractheight
% \end{parameter}^^A extractwidth
% \end{parameter}^^A extractformat
% \end{parameter}^^A extractpreamble
% \end{parameter}^^A extract
% \end{macro}^^A \includeinkscape
% \end{parameter}^^A exclude
% \end{parameter}^^A clean
% \end{parameter}^^A gsdevice
% \end{parameter}^^A gsopt
% \end{parameter}^^A magickoperator
% \end{parameter}^^A magicksetting
% \end{parameter}^^A convertdpi
% \end{parameter}^^A convertformat
% \end{parameter}^^A convert
% \end{parameter}^^A pdftopsopt
% \end{parameter}^^A pdftoepsopt
% \end{parameter}^^A pstopdfopt
% \end{parameter}^^A pstoepsopt
% \end{parameter}^^A dvipsopt
% \end{parameter}^^A latexext
% \end{parameter}^^A latexopt
% \end{parameter}^^A latexexe
% \end{parameter}^^A extractruns
% \end{parameter}^^A extractapptex
% \end{parameter}^^A extractpretex
% \end{parameter}^^A extractangle
% \end{parameter}^^A extractscale
% \end{parameter}^^A extractdistort
% \end{parameter}^^A extractheight
% \end{parameter}^^A extractwidth
% \end{parameter}^^A extractformat
% \end{parameter}^^A extractpreamble
% \end{parameter}^^A extract
% \end{macro}^^A \includesvg
% \begin{macro}{\svghidepreamblestart}
% \changes{v2.00}{2017/02/24}{new}^^A
% \begin{macro}{\svghidepreambleend}
% \changes{v2.00}{2017/02/24}{new}^^A
% Some dummys for package \pkg{svg}.
% \begin{macrocode}
%<*main>
\newcommand*\svghidepreamblestart{%
\PackageWarning{svg}{%
The macro `\string\svghidepreamblestart' is only meant\MessageBreak%
to be used together with package `svg-extract'. \MessageBreak%
Nevertheless, nothing will happen%
}%
}
\newcommand*\svghidepreambleend{%
\PackageWarning{svg}{%
The macro `\string\svghidepreambleend' is only meant\MessageBreak%
to be used together with package `svg-extract'. \MessageBreak%
Nevertheless, nothing will happen%
}%
}
%</main>
% \end{macrocode}
% These two macros can be used to hide some parts of the preamble during
% reading the preamble of the main document.
% \begin{macrocode}
%<*extract>
\let\svghidepreamblestart\relax
\let\svghidepreambleend\relax
%</extract>
% \end{macrocode}
% \end{macro}^^A \svghidepreambleend
% \end{macro}^^A \svghidepreamblestart
%
%
%
% \subsection{Auxiliary macros}
%
% \begin{macro}{\svg@extract}
% The macro \cs{svg@extract} does the actual job of both extracting and
% converting independent graphic files. Since it is necessary to run it with
% \file{-{}-shell-escape} enabled, the command raises a warning if it is not
% activated. Afterwards, the package is finished.
% \begin{macrocode}
%<*main>
\newcommand*\svg@extract[1]{}
%</main>
%<*extract>
\ifnum\pdf@shellescape=\@ne\relax\else%
\renewcommand*\svg@extract[1]{%
\if@svgx@run%
\begingroup%
\edef\svg@tempa{#1}%
\svg@quotes@remove{\svg@tempa}%
\PackageWarning{svg-extract}{%
You didn't enable `shell escape' (or `write18')\MessageBreak%
so it wasn't possible to run the extraction for\MessageBreak%
file `\svg@tempa'\MessageBreak%
}%
\endgroup%
\fi%
}%
\expandafter\endinput%
\fi
%</extract>
% \end{macrocode}
% \end{macro}^^A \svg@extract
%
% \iffalse
%</package&body>
%<*package&body&extract>
% \fi
%
% \begin{macro}{\svgx@stream@in}
% \begin{macro}{\svgx@read@line}
% \begin{macro}{\svgx@stream@out}
% \begin{macro}{\if@svgx@preamble@write}
% Both an input stream and an output stream are necessary for this as well as a
% token register, which is used to store all commands which should be executed
% on shell.
% \begin{macrocode}
\newread\svgx@stream@in
\newcommand*\svgx@read@line{}
\newwrite\svgx@stream@out
\newif\if@svgx@preamble@write
% \end{macrocode}
% \end{macro}^^A \if@svgx@preamble@write
% \end{macro}^^A \svgx@stream@out
% \end{macro}^^A \svgx@read@line
% \end{macro}^^A \svgx@stream@in
% \begin{macro}{\svg@extract}
% If flag \file{-{}-shell-escape} is enabled, the command is defined with its
% intended functionality. It runs all necessary processes to extract and
% convert grahic files.
% \begin{macrocode}
\renewcommand*\svg@extract[1]{%
% \end{macrocode}
% If option \opt{extract} is enabled\dots
% \begin{macrocode}
\if@svgx@run%
% \end{macrocode}
% \dots the macro \cs{svgx@get@out@sec} is used to get the current level
% numbering within the document and the counter for extracted graphics is
% stepped. After that, a separate auxiliary \LaTeX~file is created for
% extracting independent graphic files. The macro \cs{svgx@get@out@sec} is used
% to get the current level numbering within the document. The specified
% preamble is read for this task, if it exists. It is first searched in the
% same folder as the SVG~file and if it wasn't found, in any other valid folder
% for SVG~files.
% \begin{macrocode}
\if@svgx@out@sec%
\svgx@get@out@sec%
\fi%
\stepcounter{svgx@out@count}%
\begingroup%
\def\svg@tempa##1.##2\@nil{%
\IfArgIsEmpty{##2}{\edef\svgx@preamble{##1.\svgx@latex@ext}}{}%
}%
\expandafter\svg@tempa\svgx@preamble.\@nil%
\IfFileExists{\svg@file@path\svgx@preamble}{%
\@svg@file@foundtrue%
}{%
\svg@get@path[]{\svgx@preamble}{\svg@out@path}%
\def\svg@tempa####1.####2\@nil{%
\edef\svgx@preamble{\svg@file@name.####2}%
}%
\expandafter\svg@tempa\svgx@preamble\@nil%
}%
\edef\svg@tempa{%
\endgroup%
\if@svg@file@found%
\ifx\svg@file@path\@empty%
\def\noexpand\svgx@preamble{./\svgx@preamble}%
\else%
\def\noexpand\svgx@preamble{\svg@file@path\svgx@preamble}%
\fi%
\fi%
}%
\svg@tempa%
\begingroup%
\endlinechar=\m@ne%
\IfFileExists{\svgx@preamble}{%
\PackageInfo{svg-extract}{%
The preamble file `\svgx@preamble'\MessageBreak%
is used for the generation of the auxiliary file\MessageBreak%
`\svgx@out@name.\svgx@latex@ext'%
}%
% \end{macrocode}
% The catcodes for |#| need to be changed to prevent doublification when
% reading the line.
% \begin{macrocode}
\catcode`\#=12\relax%
\immediate\openout\svgx@stream@out=\svgx@out@name.\svgx@latex@ext%
\immediate\openin\svgx@stream@in=\svgx@preamble%
\@svg@tempswatrue%
\@svgx@preamble@writetrue%
\def\svgx@read@line{}%
% \end{macrocode}
% The given preamble file is read line by line and written to the separate
% auxiliary \LaTeX~file \file{\cs{svgx@out@name}.\cs{svgx@latex@ext}} via the
% output stream.
% \begin{macrocode}
\@whilesw\if@svg@tempswa\fi{%
\immediate\read\svgx@stream@in to\svgx@read@line%
\ifx\svgx@read@line\@empty%
\ifeof\svgx@stream@in\@svg@tempswafalse\fi%
\else%
% \end{macrocode}
% With \cs{svghidepreamblestart} and \cs{svghidepreambleend} it is possible for
% the user to omit certain parts of the preamble. Therefor the two macros
% \cs{svgx@read@preamble@till} and \cs{svgx@read@preamble@from} are toggling
% the switch \cs{if@svgx@preamble@write}
% \begin{macrocode}
\svgx@read@preamble@till{\svghidepreamblestart}{}%
\svgx@read@preamble@from{\svghidepreambleend}{}%
% \end{macrocode}
% If the desired end of the preamble (\cs{svgx@endpreamble}) was found, the
% readout is terminated by switching \cs{if@svg@tempswa} to \val{false}.
% \begin{macrocode}
\svgx@read@preamble@till{\svgx@endpreamble}{\@svg@tempswafalse}%
\if@svgx@preamble@write%
% \end{macrocode}
% During the readout process, it is searched with \cs{svgx@documentclass} for
% the appearance of \cs{documentclass} and \cs{if@svgx@classfound} is set to
% \val{true} if it was found.
% \begin{macrocode}
\if@svgx@classfound\else%
\expandafter\svgx@documentclass%
\svgx@read@line\documentclass\documentclass\@nil%
\fi%
% \end{macrocode}
% Writing out the---maybe manipulated---read in line.
% \begin{macrocode}
\ifx\svgx@read@line\@empty\else%
\immediate\write\svgx@stream@out{%
\unexpanded\expandafter{\svgx@read@line}%
}%
\fi%
\fi%
\fi%
}%
\immediate\closein\svgx@stream@in%
\immediate\closeout\svgx@stream@out%
\catcode`\#=6\relax%
% \end{macrocode}
% Once the separate auxiliary \LaTeX~file is written, it is read in again and
% its content is stored in \cs{svg@tempa}, since it is necessary to prepend
% some stuff to the preamble, for example a maybe not existent document class.
% \begin{macrocode}
\immediate\openin\svgx@stream@in=\svgx@out@name.\svgx@latex@ext%
\def\svg@tempa{}%
\loop\unless\ifeof\svgx@stream@in%
\readline\svgx@stream@in to\svgx@read@line%
\ifx\svgx@read@line\@empty\else%
\edef\svg@tempa{%
\unexpanded\expandafter{\svg@tempa}%
\unexpanded\expandafter{\svgx@read@line}^^J%
}%
\fi%
\repeat%
\immediate\closein\svgx@stream@in%
}{%
% \end{macrocode}
% If a file was given that doesn't exist, a warning is issued.
% \begin{macrocode}
\svg@quotes@remove{\svgx@preamble}%
\ifx\svgx@preamble\@empty\else%
\PackageWarning{svg-extract}{%
The preamble file `\svgx@preamble'\MessageBreak%
does not exist%
}%
\fi%
\def\svg@tempa{}%
}%
% \end{macrocode}
% After the preamble was read in and stored in \cs{svg@tempa}, the separate
% auxiliary \LaTeX~file is written again. Some information are written right at
% the beginning of the file.
% \begin{macrocode}
\immediate\openout\svgx@stream@out=\svgx@out@name.\svgx@latex@ext%
\immediate\write\svgx@stream@out{%
\@percentchar\@percentchar\space This file was generated by package
`svg-extract'^^J%
\@percentchar\@percentchar\space from source `\jobname'^^J%
\@percentchar\@percentchar\space It's intended to be compiled with
`\svgx@latex@exe\ifx\svgx@latex@opt\@empty\else\space\svgx@latex@opt\fi'
}%
% \end{macrocode}
% With the intention of passing the correct paper dimensions, the calculating
% of the paper size is executed with \cs{AtBeginDocument} even before the
% document class, so that this is definitely the first thing to happen at the
% beginning of the document. Additionally, it is ensured that the \cs{special}
% command is definitely used with the correct paper size, when creating a
% DVI~file.
% \begin{macrocode}
\immediate\write\svgx@stream@out{%
\string\AtBeginDocument{\@percentchar^^J%
\space\space\string\svgxsetpapersize\@percentchar^^J%
\ifxetex\else\ifpdf\else%
\space\space\string\AtBeginDvi{\string\special{%
papersize=\string\the\string\paperwidth,%
\string\the\string\paperheight%
}}\@percentchar^^J%
\fi\fi%
}^^J%
\string\PassOptionsToPackage{hidelinks}{hyperref}%
}%
% \end{macrocode}
% If no document class was found during reading the preamble file, then class
% \cs{article} is used.
% \begin{macrocode}
\if@svgx@classfound\else%
\immediate\write\svgx@stream@out{\string\documentclass{article}}%
\fi%
% \end{macrocode}
% And now the stored preamble.
% \begin{macrocode}
\ifx\svg@tempa\@empty\else%
\immediate\write\svgx@stream@out{\unexpanded\expandafter{\svg@tempa}}%
\fi%
% \end{macrocode}
% After the given preamble was written, package \pkg{svg-extract} will be
% loaded in case it was forgotten.
% \begin{macrocode}
\immediate\write\svgx@stream@out{\string\usepackage{svg-extract}}%
% \end{macrocode}
% Now all parameters relevant for the extraction are evaluated and appended.
% \begin{macrocode}
\def\svg@tempa##1{%
\immediate\write\svgx@stream@out{\string\svgsetup{##1}}%
}%
\if@svg@ink@latex\else%
\svg@tempa{inkscapelatex=false}%
\fi%
\ifdim\svgx@param@width>\z@\relax%
\svg@tempa{width=\svgx@param@width}%
\fi%
\ifdim\svgx@param@height>\z@\relax%
\svg@tempa{height=\svgx@param@height}%
\fi%
\if@svgx@param@distort%
\svg@tempa{distort=true}%
\fi%
\ifdim\dimexpr\svgx@param@scale\p@\relax=\p@\relax\else%
\svg@tempa{scale=\svgx@param@scale}%
\fi%
\def\svg@tempb{\svg@param@pretex}%
\ifx\svgx@param@pretex\svg@tempb\relax%
\let\svgx@param@pretex\svg@param@pretex%
\fi%
\ifx\svgx@param@pretex\relax\else%
\svg@tempa{pretex=\unexpanded\expandafter{\svgx@param@pretex}}%
\fi%
\def\svg@tempb{\svg@param@apptex}%
\ifx\svgx@param@apptex\svg@tempb\relax%
\let\svgx@param@apptex\svg@param@apptex%
\fi%
\ifx\svgx@param@apptex\relax\else%
\svg@tempa{apptex=\unexpanded\expandafter{\svgx@param@apptex}}%
\fi%
% \end{macrocode}
% Parameter \prm{lastpage} is only considered for including PDF~files with
% \LaTeX~support.
% \begin{macrocode}
\let\svg@tempa\@empty%
\if@svg@ink@latex%
\Ifstr{\svg@ink@format}{pdf}{%
\ifnum\value{svg@param@lastpage}>\z@\relax%
\edef\svg@tempa{lastpage=\the\value{svg@param@lastpage}}%
\else%
\ifnum\value{svg@param@lastpage}=\z@\relax%
\def\svg@tempa{lastpage=true}%
\else%
\def\svg@tempa{lastpage=false}%
\fi%
\fi%
}{}%
\fi%
% \end{macrocode}
% The rotation angle, if given.
% \begin{macrocode}
\ifdim\dimexpr\svgx@param@angle\p@\relax=\z@\relax\else%
\edef\svg@tempa{%
angle=\svgx@param@angle\ifx\svg@tempa\@empty\else,\svg@tempa\fi%
}%
\fi%
% \end{macrocode}
% As we are now at the end of the preamble and just before the beginning of the
% document, the paper dimension are set again to make sure, that these settings
% are active at the end of the preamble. Additionally, it is executed again at
% the very end of \cs{AtBeginDocument} to ensure, that no other package used
% this hook for manipulating the paper size.
% \begin{macrocode}
\ifx\svg@tempa\@empty%
\def\svg@tempa{\string\svgxsetbox{#1}}%
\else%
\edef\svg@tempa{\noexpand\string\noexpand\svgxsetbox[\svg@tempa]{#1}}%
\fi%
\immediate\write\svgx@stream@out{\svg@tempa}%
% \end{macrocode}
% Package \pkg{xr} is used to evaluate possible labels within the included
% \app{Inkscape}~\LaTeX~file.
% \begin{macrocode}
\if@svg@ink@latex%
\IfFileExists{xr.sty}{%
\immediate\write\svgx@stream@out{%
\string\usepackage{xr}^^J%
\string\externaldocument{\jobname}^^J%
}%
}{}%
\fi%
\immediate\write\svgx@stream@out{%
\string\begin{document}^^J%
\string\pagestyle{empty}^^J%
\string\svgxoutputbox\@percentchar^^J%
\string\end{document}%
}%
\immediate\closeout\svgx@stream@out%
\endgroup%
% \end{macrocode}
% After creating the separate auxiliary \LaTeX~file, the actual extraction and
% conversion can be done.
% \begin{macrocode}
\Ifstr{\svgx@format\svgx@cnv@format}{}{%
\PackageWarning{svg-extract}{%
Both keys `extractformat' and `convertformat' are\MessageBreak%
empty, so nothing to do so far%
}%
}{%
% \end{macrocode}
% As the extraction maybe needs to include the main~auxiliary~file with
% \cs{externaldocument} provided by package \pkg{xr} it is necessary to do all
% related stuff after the main~auxiliary~file was written. This is done with
% \cs{AfterReadingMainAux} provided by package \pkg{scrlfile}.
% \begin{macrocode}
\svg@quotes@remove{\svgx@out@path}%
\svg@quotes@remove{\svgx@out@name}%
% \end{macrocode}
% All generated files will be moved to the desired output folder, which is
% given by option \opt{extractpath}. Therefor, this folder is created.
% \begin{macrocode}
\edef\svg@tempb{%
\noexpand\svg@shell@mkdir{\svgx@out@path}%
}%
\expandafter\AfterReadingMainAux\expandafter{\svg@tempb}%
% \end{macrocode}
% First of all the separate auxiliary \LaTeX~file is compiled with the detected
% \LaTeX~engine (\cs{svgx@latex@exe}) as often as defined by counter option
% \opt{extractruns}.
% \begin{macrocode}
\edef\svg@tempb{%
\noexpand\PackageInfo{svg-extract}{%
Running LaTeX (\svgx@latex@exe) for graphic extraction%
\ifx\svgx@latex@opt\@empty\else%
\MessageBreak with added options `\svgx@latex@opt'%
\fi%
}%
}%
\expandafter\AfterReadingMainAux\expandafter{\svg@tempb}%
\edef\svg@tempb{%
\noexpand\ShellEscape{%
\svgx@latex@exe\space\svgx@latex@opt\space%
"\svgx@out@name.\svgx@latex@ext"%
}%
}%
\loop\ifnum\value{svgx@runs}>\z@\relax%
\expandafter\AfterReadingMainAux\expandafter{\svg@tempb}%
\advance\c@svgx@runs\m@ne%
\repeat%
% \end{macrocode}
% All files requested with option \opt{extractformat} are created with internal
% conversion tools supplied by most \LaTeXe~distributions if necessary.
% \begin{macrocode}
\def\svg@tempa##1##2##3{%
\edef\svg@tempb{%
\noexpand\ShellEscape{%
\@nameuse{svgx@##1@exe}\space\@nameuse{svgx@##1@opt}\space%
"\svgx@out@name.##2"%
}%
}%
\AfterReadingMainAux{\PackageInfo{svg-extract}{Running ##1}}%
\expandafter\AfterReadingMainAux\expandafter{\svg@tempb}%
}%
\@svg@tempswafalse%
\ifxetex\else\ifpdf\else%
\@svg@tempswatrue%
\fi\fi%
\if@svg@tempswa%
\svg@tempa{dvips}{dvi}{ps}%
\svgx@ifinlist{eps}{\svgx@format}{\svg@tempa{pstoeps}{ps}{eps}}{}%
\svgx@ifinlist{pdf}{\svgx@format}{\svg@tempa{pstopdf}{ps}{pdf}}{}%
\else%
\svgx@ifinlist{eps}{\svgx@format}{\svg@tempa{pdftoeps}{pdf}{eps}}{}%
\svgx@ifinlist{ps}{\svgx@format}{\svg@tempa{pdftops}{pdf}{ps}}{}%
\fi%
% \end{macrocode}
% Now the desired conversion tool is invoked if requested.
% \begin{macrocode}
\if@svgx@cnv@run%
% \end{macrocode}
% If no density was given at all, the density for PNG~files is set to
% \val{300dpi} by default.
% \begin{macrocode}
\ifx\svgx@cnv@dpi\relax%
\ifx\svgx@cnv@dpi@png\@undefined%
\def\svgx@cnv@dpi@png{300}%
\fi%
\fi%
% \end{macrocode}
% The first given file type with option \opt{extractformat} is used as source
% for the conversion process.
% \begin{macrocode}
\expandafter\svgx@cnv@get@informat\expandafter{\svgx@format}%
% \end{macrocode}
% The conversion is done for each desired file type given in a list by option
% \opt{convertformat}.
% \begin{macrocode}
\@for\svg@tempa:=\svgx@cnv@format\do{%
\ifx\svg@tempa\@empty\else%
\expandafter\svgx@ifinlist\expandafter{\svg@tempa}{\svgx@format}{%
\PackageWarning{svg-extract}{%
File type `\svg@tempa' was specified for option\MessageBreak%
`extractformat' (\svgx@format) as well as for \MessageBreak%
option `convertformat' (\svgx@cnv@format) so the\MessageBreak%
conversion won't be done%
}%
}{%
\edef\svg@tempb{%
\noexpand\PackageInfo{svg-extract}{%
Converting `\svgx@out@name.\svgx@cnv@informat'\MessageBreak%
to `\svgx@out@name.\svg@tempa'%
}%
}%
\expandafter\AfterReadingMainAux\expandafter{\svg@tempb}%
\edef\svg@tempb{%
\noexpand\ShellEscape{%
\svgx@cnv@cmd{\svgx@out@name}{\svgx@cnv@informat}{\svg@tempa}%
}%
}%
\expandafter\AfterReadingMainAux\expandafter{\svg@tempb}%
}%
\fi%
}%
\fi%
% \end{macrocode}
% As both extraction and conversion are done, all files are moved to the
% desired output folder (\opt{extractpath}).
% \begin{macrocode}
\edef\svg@tempa{\svgx@format\if@svgx@cnv@run,\svgx@cnv@format\fi}%
\@for\svg@tempb:=\svg@tempa\do{%
\ifx\svg@tempb\@empty\else%
\edef\svg@tempb{%
\noexpand\svgx@move{\svgx@out@name}{\svg@tempb}{\svgx@out@path}%
}%
\expandafter\AfterReadingMainAux\expandafter{\svg@tempb}%
\fi%
}%
% \end{macrocode}
% At the very end, all unwanted auxiliary files are deleted.
% \begin{macrocode}
\@for\svg@tempa:=\svgx@clean\do{%
\expandafter\svgx@ifinlist\expandafter{\svg@tempa}{\svg@tempb}{}{%
\edef\svg@tempb{%
\noexpand\IfFileExists{"\svgx@out@name".\svg@tempa}{%
\noexpand\svg@shell@rm{\svgx@out@name.\svg@tempa}%
}{}%
}%
\expandafter\AtEndDocument\expandafter{%
\expandafter\AfterReadingMainAux\expandafter{\svg@tempb}%
}%
}%
}%
}%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \svg@extract
% \begin{macro}{\svgx@get@out@sec}
% The macro \cs{svgx@get@out@sec} reads all sectioning counters in order to
% get the numbering of the current sectioning level. The value is stored in
% \cs{svgx@out@sec}.
% \begin{macrocode}
\newcommand*\svgx@get@out@sec{%
\begingroup%
\def\svg@tempa{}%
\@for\svg@tempb:={%
part,chapter,section,subsection,subsubsection,paragraph,subparagraph%
}\do{%
\ifx\svg@tempb\@empty\else%
\scr@ifundefinedorrelax{the\svg@tempb}{}{%
\ifnum\value{\svg@tempb}>\z@\relax%
\edef\svg@tempa{\svg@tempb}%
\fi%
}%
\fi%
}%
\edef\svg@tempb{%
\endgroup%
\ifx\svg@tempa\@empty\else%
\def\noexpand\svgx@out@sec{\csname the\svg@tempa\endcsname}%
\fi%
}%
\svg@tempb%
}
% \end{macrocode}
% \end{macro}^^A \svgx@get@out@sec
% \begin{macro}{\svgx@documentclass}
% \begin{macro}{\if@svgx@classfound}
% This delimited macro is used to find the occurrence of \cs{documentclass}
% within a read in line. The delinmiter \cs{documentclass} is used twice in
% order to ignore the possible occurrence of white space or anything else right
% before \cs{documentclass}.
% \begin{macrocode}
\newif\if@svgx@classfound
\newcommand*\svgx@documentclass{}
\def\svgx@documentclass#1\documentclass#2\documentclass#3\@nil{%
\IfArgIsEmpty{#2}{}{\@svgx@classfoundtrue}%
}
% \end{macrocode}
% \end{macro}^^A \if@svgx@classfound
% \end{macro}^^A \svgx@documentclass
% \begin{macro}{\svgx@read@preamble@till}
% \begin{macro}{\svgx@read@preamble@from}
% \begin{macro}{\svgx@read@preamble@skip}
% These macros are used to skip some parts of a read in preamble file.
% \begin{macrocode}
\newcommand*\svgx@read@preamble@till[2]{%
\svgx@read@preamble@skip#1\@nil{till}{#2}%
}
\newcommand*\svgx@read@preamble@from[2]{%
\svgx@read@preamble@skip#1\@nil{from}{#2}%
}
% \end{macrocode}
% In principle, the functionality is the same as for \cs{svgx@documentclass}.
% \begin{macrocode}
\newcommand*\svgx@read@preamble@skip{}
\def\svgx@read@preamble@skip#1\@nil#2#3{%
% \end{macrocode}
% A given token is used to create the macro \cs{svg@tempa} delimited by the
% token itself which is used twice to get any stuff right before or after the
% occurrence.
% \begin{macrocode}
\def\svg@tempa##1{%
\def\svg@tempa####1##1####2##1####3\@nil{%
\IfArgIsEmpty{####3}{}{%
% \end{macrocode}
% Write everything which was found right before the macro which starts hiding
% area to the output stream and stop writing with \cs{if@svgx@preamble@write}.
% \begin{macrocode}
\Ifstr{#2}{till}{%
\IfArgIsEmpty{####1}{}{%
\immediate\write\svgx@stream@out{####1}%
}%
\@svgx@preamble@writefalse%
}{%
% \end{macrocode}
% Write everything which was found right after the macro which ends the hiding
% area and start writing again with \cs{if@svgx@preamble@write}.
% \begin{macrocode}
\Ifstr{#2}{from}{%
\IfArgIsEmpty{####2}{%
\def\svgx@read@line{}%
}{%
\def\svgx@read@line{####2}%
}%
\@svgx@preamble@writetrue%
}{}%
}%
% \end{macrocode}
% Additonal stuff which should be done.
% \begin{macrocode}
#3%
}%
}%
}%
% \end{macrocode}
% Creating the macro \cs{svg@tempa} delimited by the first argument.
% \begin{macrocode}
\edef\svg@tempb{\expandafter\detokenize\expandafter{#1}}%
\expandafter\svg@tempa\expandafter{\svg@tempb}%
% \end{macrocode}
% Calling the created macro.
% \begin{macrocode}
\edef\svg@tempb{%
\expandafter\detokenize\expandafter{\svgx@read@line}\svg@tempb\svg@tempb%
}%
\expandafter\svg@tempa\svg@tempb\@nil%
}
% \end{macrocode}
% \end{macro}^^A \svgx@read@preamble@skip
% \end{macro}^^A \svgx@read@preamble@from
% \end{macro}^^A \svgx@read@preamble@till
% \begin{macro}{\svgx@cnv@informat}
% \begin{macro}{\svgx@cnv@get@informat}
% The first list entry from argument (\cs{svgx@format}) is extracted by
% \cs{svgx@cnv@get@informat}.
% \begin{macrocode}
\newcommand*\svgx@cnv@informat{}
\newcommand*\svgx@cnv@get@informat[1]{%
\begingroup%
\def\svg@tempa##1,##2\@nil{%
\def\svg@tempa{##1}%
}%
\svg@tempa#1,\@nil%
\edef\svg@tempa{%
\endgroup%
\def\noexpand\svgx@cnv@informat{\svg@tempa}%
}%
\svg@tempa%
% \end{macrocode}
% If the first argument (\cs{svgx@format}) was empty, \cs{svgx@cnv@informat} is
% set to the a file type, which is generated anyway.
% \begin{macrocode}
\ifx\svgx@cnv@informat\@empty%
\renewcommand*\svgx@cnv@informat{pdf}%
\ifxetex\else\ifpdf\else%
\renewcommand*\svgx@cnv@informat{ps}%
\fi\fi%
\fi%
}
% \end{macrocode}
% \end{macro}^^A \svgx@cnv@get@informat
% \end{macro}^^A \svgx@cnv@informat
% \begin{macro}{\svgx@move}
% If the file doesn't exist
% \begin{macrocode}
\newcommand*\svgx@move[3]{%
\begingroup%
\IfFileExists{"#1".#2}{%
\svg@shell@mv{#1.#2}{#3#1.#2}%
}{%
\edef\svg@tempa{#2}%
\@svg@tempswafalse%
\expandafter\svgx@ifinlist\expandafter{\svg@tempa}{\svgx@cnv@format}{%
\@svg@tempswatrue%
\def\svg@tempb{conversion}%
}{%
\expandafter\svgx@ifinlist\expandafter{\svg@tempa}{pdf,ps,eps}{%
\@svg@tempswatrue%
\def\svg@tempb{extraction}%
}{}%
}%
\if@svg@tempswa%
\edef\svg@tempb{%
The graphic file \svg@tempb\space failed\MessageBreak%
for `#1.#2'\MessageBreak%
Troubleshooting: Please check the log file how\MessageBreak%
the invocation of the extraction took place and\MessageBreak%
try to execute it yourself in the terminal%
}%
\else%
\def\svg@tempb{%
The extraction to format `#2' failed\MessageBreak%
for `#1.#2'\MessageBreak%
Only file types `pdf,ps,eps' are supported for\MessageBreak%
key `exportformat'%
}%
\fi%
\PackageWarning{svg-extract}{\svg@tempb}%
}%
\endgroup%
}
% \end{macrocode}
% \end{macro}^^A \svgx@move
%
% \iffalse
%</package&body&extract>
%<*package&standalone&extract>
% \fi
%
%
%
%
% \subsection{Commands for the separate auxiliary \LaTeX-file}
%
% For the extraction of independent graphics, an auxiliary \LaTeX~file is
% needed. Within this file, the following commands are used to include the
% desired graphic.
%
% \begin{macro}{\svgxsetbox}
% \changes{v2.02}{2018/09/07}{late execution of \cs{svgxsetpapersize}}^^A
% \begin{macro}{\svgx@setbox}
% \changes{v2.02}{2018/09/07}{new}^^A
% \begin{macro}{\if@svgx@standalone}
% \changes{v2.02}{2018/09/07}{new}^^A
% Within the preamble of the auxiliary \LaTeX~file, the desired grahic is used
% to setup a box, which is used both to define the papersize as well as for the
% output itself. The macro \cs{svgx@setbox} is executed twice, the first time
% in the preamble and the second time at the very end of \cs{AtBeginDocument}
% if package \pkg{etoolbox} was loaded.
%
% The switch \cs{if@svgx@standalone} is defined for enabling classes to
% implement a different behavoiur for \pkg{svg-extract} in standalone mode.
% for example, \TUDScript-classes are using this switch.
% \begin{macrocode}
\newif\if@svgx@standalone
\newcommand*\svgxsetbox[2][]{%
\@svgx@standalonetrue%
\svgx@setbox{#1}{#2}%
\scr@ifundefinedorrelax{AtEndPreamble}{%
\let\svg@tempa\@firstofone%
}{%
\def\svg@tempa{\AtEndPreamble}%
}%
\svg@tempa{\AtBeginDocument{\svgx@setbox{#1}{#2}}}%
}
\newcommand*\svgx@setbox[2]{%
\sbox\svg@box{\svg@@input[{#1},draft=false]{#2}}%
\svgxsetpapersize%
}
% \end{macrocode}
% \end{macro}^^A \if@svgx@standalone
% \end{macro}^^A \svgx@setbox
% \end{macro}^^A \svgxsetbox
% \begin{macro}{\svgxsetpapersize}
% \changes{v2.00a}{2017/02/28}{Bug fix for checking stock- and mediasizes}^^A
% This macro sets all well known length macros for defining the paper size as
% well as the type area to the size of \cs{svg@box}.
% \begin{macrocode}
\newcommand*\svgxsetpapersize{%
\setlength\paperwidth{\the\wd\svg@box}%
% \end{macrocode}
% Due to the fact, that the lengths for stock- and mediasizes are maybe set to
% \cs{relax}, these macros are checked with \cs{scr@ifundefinedorrelax}.
% \begin{macrocode}
\scr@ifundefinedorrelax{stockwidth}{}{%
\setlength\stockwidth{\paperwidth}%
}%
\scr@ifundefinedorrelax{mediawidth}{}{%
\setlength\mediawidth{\paperwidth}%
}%
\setlength\textwidth{\paperwidth}%
\setlength\paperheight{\the\dimexpr\ht\svg@box+\dp\svg@box\relax}%
\scr@ifundefinedorrelax{stockheight}{}{%
\setlength\stockheight{\paperheight}%
}%
\scr@ifundefinedorrelax{mediaheight}{}{%
\setlength\mediaheight{\paperheight}%
}%
\setlength\textheight{\paperheight}%
% \end{macrocode}
% Any other length regarding the layout is set to have no influence at all.
% Hence the document has the same size as the graphic.
% \begin{macrocode}
\hoffset=-1in%
\oddsidemargin=\z@%
\evensidemargin=\z@%
\voffset=-1in%
\topmargin=\z@%
\headheight=\z@%
\headsep=\z@%
\topskip=\z@%
\footskip=\z@%
\marginparsep=\z@%
\marginparwidth=\z@%
\marginparpush=\z@%
}
\@onlypreamble\svgxsetpapersize
% \end{macrocode}
% \end{macro}^^A \svgxsetpapersize
% \begin{macro}{\svgxoutputbox}
% \begin{macro}{\if@svgx@beamer}
% With \cs{svgxoutputbox} the created box is displayed.
% \begin{macrocode}
\newif\if@svgx@beamer
\@ifclassloaded{beamer}{\@svgx@beamertrue}{}%
\newcommand*\svgxoutputbox{%
\begingroup%
\setlength\parindent{\z@}%
\setlength\parskip{\z@}%
\setlength\parfillskip{\z@}%
\if@svgx@beamer%
\setbeamertemplate{navigation symbols}{}%
\begin{frame}[plain]%
\usebox\svg@box%
\end{frame}%
\else%
\usebox\svg@box%
\fi%
\endgraf%
\endgroup%
}
% \end{macrocode}
% \end{macro}^^A \if@svgx@beamer
% \end{macro}^^A \svgxoutputbox
%
% \iffalse
%</package&standalone&extract>
%<*package&option>
% \fi
%
%
%
% \section{Processing Options}
%
% Setting the default options and processing the given ones during when loading
% the packages.
% \begin{macrocode}
%<*main>
\FamilyExecuteOptions{SVG}{%
inkscape=true,inkscapeversion=auto,inkscapepath=basesubdir,%
inkscapelatex=true,inkscapearea=drawing,distort=false,%
usexcolor=true,usetransparent=true%
}
%</main>
%<*extract>
\FamilyExecuteOptions{SVG}{%
extract=true,extractpath=basesubdir,%
extractruns=2,extractname=namenumbered,extractdistort=false,%
convert=magick,convert=false,%
gsdevice={png=png16m},gsdevice={jpeg=jpeg},gsdevice={jpg=jpeg},%
gsdevice={tif=tiff48nc},gsdevice={tiff=tiff48nc},%
gsdevice={eps=eps2write},gsdevice={ps=ps2write}%
}
%</extract>
\FamilyProcessOptions{SVG}
% \end{macrocode}
%
% \iffalse
%</package&option>
% \fi
%
% \Finale
%
\endinput
%
% \iffalse
%<*package&old>
% \fi
%
%
%
% \section{Old Implementation}
%
% The package, which requires the packages \pkg{xkeyval} for the options,
% \pkg{subfig} for automatic labeling within the subfigure command, the
% \pkg{import} package for correct handling of paths, \pkg{graphicx} for the
% PDF~file inclusion commands, \pkg{transparent} for transparency, and
% \pkg{xcolor} for color, is initialized.
% \begin{macrocode}
\ProvidesPackage{svg}[2012/09/05 v1.0 SVG inclusion and extraction]%
\@ifpackageloaded{xkeyval}{}{\RequirePackage{xkeyval}}%
\@ifpackageloaded{subfig}{}{\RequirePackage{subfig}}%
\@ifpackageloaded{import}{}{\RequirePackage{import}}%
\@ifpackageloaded{graphicx}{}{\RequirePackage{graphicx}}%
\@ifpackageloaded{transparent}{}{\RequirePackage{transparent}}%
\@ifpackageloaded{xcolor}{}{\RequirePackage{xcolor}}%
% \end{macrocode}
%
%
%
% \subsection{Input definition}
%
% All commands used for input (i.e. for the SVG~file and preamble) are
% defined within the \cs{SVG@in} prefix, and set by the key definition of the
% line following their definition. The \opt{exclude} boolean, used to stop the
% inclusion of the SVG~file within the document is also defined.
% \begin{macrocode}
\def\SVG@in@preamble{\jobname.tex}%
\define@key[SVG]{svg.sty}{preamble}{\def\SVG@in@preamble{#1}}%
\def\SVG@in@path{./}%
\define@key[SVG]{svg.sty}{svgpath}{\def\SVG@in@path{#1}}%
\def\SVG@in@end{\begin{document}}%
\define@key[SVG]{svg.sty}{end}{\def\SVG@in@end{#1}}%
\define@boolkey[SVG]{svg.sty}[SVG@in@]{exclude}[true]{}%
% \end{macrocode}
%
%
%
% \subsection{Length definition}
%
% All commands used for output are defined within the \cs{SVG@out} prefix,
% beginning with the dimensions of the extracted image. If no dimensions are
% supplied both \cs{ifSVG@out@usewidth} and \cs{ifSVG@out@useheight} are
% \val{false}, and so the natural dimensions of the SVG~file are used.
% If both \cs{ifSVG@out@usewidth} and \cs{ifSVG@out@useheight} are
% \val{true}, the width is used.
% \begin{macrocode}
\newlength\SVG@out@width%
\newif\ifSVG@out@usewidth%
\define@key[SVG]{svg.sty}{width}{%
\setlength{\SVG@out@width}{#1}\SVG@out@usewidthtrue%
}%
\newlength\SVG@out@height%
\newif\ifSVG@out@useheight%
\define@key[SVG]{svg.sty}{height}{%
\setlength{\SVG@out@height}{#1}\SVG@out@useheighttrue%
}%
% \end{macrocode}
%
%
%
% \subsection{Extract booleans}
%
% The booleans for the extraction formats are defined. Additionally,
% the global export variable is defined, which is set to \val{true}
% whenever any extraction is requested.
% \begin{macrocode}
\define@boolkey[SVG]{svg.sty}[SVG@out@]{pdf}[true]{}%
\define@boolkey[SVG]{svg.sty}[SVG@out@]{eps}[true]{}%
\define@boolkey[SVG]{svg.sty}[SVG@out@]{png}[true]{}%
\newif\ifSVG@out@extract
% \end{macrocode}
%
%
%
% \subsection{Output definitions}
%
% The extraction path, extraction root name, clean boolean,
% pre-\LaTeX~commands, and post-\LaTeX~commands are defined.
% \begin{macrocode}
\def\SVG@out@path{./}%
\define@key[SVG]{svg.sty}{path}{\def\SVG@out@path{#1}}%
\def\SVG@out@name{Fig.\arabic{svgfigure}\alph{subfigure}}%
\define@key[SVG]{svg.sty}{name}{\def\SVG@out@name{#1}}%
\define@boolkey[SVG]{svg.sty}[SVG@out@]{clean}[true]{}%
\def\SVG@out@pretex{}%
\define@key[SVG]{svg.sty}{pretex}{\def\SVG@out@pretex{#1}}%
\def\SVG@out@postex{}%
\define@key[SVG]{svg.sty}{postex}{\def\SVG@out@postex{#1}}%
% \end{macrocode}
%
%
%
% \subsection{Command definitions}
%
% The command options are defined within the prefix \cs{SVG@cmd} and
% are set by the key definition following each command definition.
% \begin{macrocode}
\def\SVG@cmd@inkscape{inkscape -z -C}%
\define@key[SVG]{svg.sty}{inkscape}{\def\SVG@cmd@inkscape{#1}}%
\def\SVG@cmd@pdflatex{pdflatex}%
\define@key[SVG]{svg.sty}{pdflatex}{\def\SVG@cmd@pdflatex{#1}}%
\def\SVG@cmd@pdftops{pdftops -eps}%
\define@key[SVG]{svg.sty}{pdftops}{\def\SVG@cmd@pdftops{#1}}%
\def\SVG@cmd@convert{convert -density 300}%
\define@key[SVG]{svg.sty}{convert}{\def\SVG@cmd@convert{#1}}%
% \end{macrocode}
%
%
%
% \subsection{Process options}
%
% All the options for the package are processed, and a counter is defined,
% which is used to correctly handle the \cnt{subfigure} counting.
% \begin{macrocode}
\ProcessOptionsX[SVG]%
\newcounter{svgfigure}[figure]%
% \end{macrocode}
%
%
%
% \subsection{User interface}
%
% Define the macro to globally set keys.
% \begin{macrocode}
\def\setsvg#1{\setkeys[SVG]{svg.sty}{#1}}%
% \end{macrocode}
%
% Define the macro used to include a SVG~file. Set the keys and
% determine if extraction should occur.
% \begin{macrocode}
\newread\SVG@in@file%
\newwrite\SVG@out@file%
\def\includesvg{\@ifnextchar[\@includesvg{\@includesvg[]}}%
\def\@includesvg[#1]#2{%
\setkeys[SVG]{svg.sty}{#1}%
\SVG@out@extractfalse%
\ifSVG@out@pdf \SVG@out@extracttrue \fi%
\ifSVG@out@eps \SVG@out@extracttrue \fi%
\ifSVG@out@png \SVG@out@extracttrue \fi%
% \end{macrocode}
% Run \app{Inkscape} to separate the SVG~file into text and image. Only
% run \app{Inkscape} if the SVG~file is newer than the generated text
% and image.
% \begin{macrocode}
\ifnum\pdfstrcmp{%
\pdffilemoddate{\SVG@in@path#2.svg}%
}{%
\pdffilemoddate{\SVG@in@path#2.pdf}%
}>0\relax%
\immediate\write18{%
\SVG@cmd@inkscape\space%
-f \SVG@in@path#2.svg\space%
-A \SVG@in@path#2.pdf\space%
--export-latex%
}%
\fi%
% \end{macrocode}
% Determine the image width and height using \cs{includegraphics}.
% \begin{macrocode}
\ifSVG@out@usewidth%
\settoheight\SVG@out@height{%
\includegraphics[width=\SVG@out@width]{\SVG@in@path#2}%
}%
\else%
\ifSVG@out@useheight%
\settowidth\SVG@out@width{%
\includegraphics[height=\SVG@out@height]{\SVG@in@path#2}%
}%
\else%
\settoheight\SVG@out@height{%
\includegraphics{\SVG@in@path#2}%
}%
\settowidth\SVG@out@width{\includegraphics{\SVG@in@path#2}}%
\fi%
\fi%
% \end{macrocode}
% Open the output file for extraction.
% \begin{macrocode}
% Open the output file.
\ifSVG@out@extract%
\setcounter{svgfigure}{\value{figure}}%
\stepcounter{svgfigure}%
\def\SVG@out@filename{\SVG@out@name}%
\immediate\openout\SVG@out@file=\SVG@out@path\SVG@out@filename.tex%
\fi%
% \end{macrocode}
% Open and write the preamble. Notice that the catcodes for |#| need
% to be changed to prevent double expansion when reading the line.
% \begin{macrocode}
\ifSVG@out@extract%
\def\SVG@in@line{}%
\immediate\openin\SVG@in@file=\SVG@in@preamble%
\fi%
\newif\ifSVG@in@read%
\ifSVG@out@extract \SVG@in@readtrue \fi%
\@whilesw\ifSVG@in@read\fi{%
\catcode`\#=12\relax\endlinechar=-1%
\immediate\read\SVG@in@file to \SVG@in@line%
\ifx\SVG@in@end\SVG@in@line%
\SVG@in@readfalse%
\else%
\immediate\write\SVG@out@file{\unexpanded\expandafter{\SVG@in@line}}%
\fi%
\ifeof\SVG@in@file\SVG@in@readfalse\fi%
\endlinechar=13\catcode`\#=6\relax%
}%
\ifSVG@out@extract \immediate\closein\SVG@in@file \fi%
% \end{macrocode}
% Now write everything needed after the preamble. This includes
% requiring the \pkg{import} package and defining all the dimensions need
% to match the document size with the image size.
% \begin{macrocode}
\ifSVG@out@extract%
\def\SVG@out@defpack{%
\makeatletter%
\@ifpackageloaded{import}{}{\RequirePackage{import}}%
\@ifpackageloaded{graphicx}{}{\RequirePackage{graphicx}}%
\@ifpackageloaded{transparent}{}{\RequirePackage{transparent}}%
\@ifpackageloaded{xcolor}{}{\RequirePackage{xcolor}}%
\makeatother%
}%
\def\SVG@out@defwidth{\def\svgwidth{0.99\textwidth}}%
\def\SVG@out@definput{\import{\SVG@in@path}{#2.pdf_tex}}%
\immediate\write\SVG@out@file{\unexpanded\expandafter{\SVG@out@defpack}}%
\immediate\write\SVG@out@file{%
\noexpand\setlength{\pdfpagewidth}{\the\SVG@out@width}%
}%
\immediate\write\SVG@out@file{%
\noexpand\setlength{\pdfpageheight}{\the\SVG@out@height}%
}%
\immediate\write\SVG@out@file{%
\noexpand\setlength{\paperheight}{\pdfpageheight}%
}%
\immediate\write\SVG@out@file{%
\noexpand\setlength{\paperwidth}{\pdfpagewidth}%
}%
\immediate\write\SVG@out@file{%
\noexpand\setlength{\textheight}{\paperheight}%
}%
\immediate\write\SVG@out@file{%
\noexpand\setlength{\textwidth}{\paperwidth}%
}%
\immediate\write\SVG@out@file{%
\noexpand\setlength{\textheight}{\paperheight}%
}%
\immediate\write\SVG@out@file{\noexpand\setlength{\oddsidemargin}{-1in}}%
\immediate\write\SVG@out@file{\noexpand\setlength{\evensidemargin}{-1in}}%
\immediate\write\SVG@out@file{\noexpand\setlength{\topmargin}{-1in}}%
\immediate\write\SVG@out@file{\noexpand\setlength{\headheight}{0in}}%
\immediate\write\SVG@out@file{\noexpand\setlength{\headsep}{0in}}%
\immediate\write\SVG@out@file{\noexpand\setlength{\topskip}{0in}}%
\immediate\write\SVG@out@file{\noexpand\setlength{\footskip}{0in}}%
\immediate\write\SVG@out@file{\noexpand\setlength{\parindent}{0in}}%
\immediate\write\SVG@out@file{\noexpand\setlength{\parsep}{0in}}%
\immediate\write\SVG@out@file{\noexpand\setlength{\parskip}{0in}}%
\immediate\write\SVG@out@file{%
\noexpand\begin{document}%
\noexpand\pagestyle{empty}%
\noexpand\begin{center}%
\unexpanded\expandafter{\SVG@out@defwidth}%
\unexpanded\expandafter{\SVG@out@pretex}%
\expandafter\noexpand\SVG@out@definput%
\unexpanded\expandafter{\SVG@out@postex}%
\noexpand\end{center}%
\noexpand\end{document}%
}%
\immediate\closeout\SVG@out@file%
\fi%
% \end{macrocode}
% Run \LaTeX{} on the extracted file and create the PDF~file.
% \begin{macrocode}
\ifSVG@out@extract%
\immediate\write18{%
\SVG@cmd@pdflatex\space\SVG@out@path\SVG@out@filename.tex%
}%
\fi%
% \end{macrocode}
% Convert the PDF~file to EPS~file if requested.
% \begin{macrocode}
\ifSVG@out@eps%
\immediate\write18{\SVG@cmd@pdftops\space\SVG@out@filename.pdf}%
\immediate\write18{%
mv \SVG@out@filename.eps\space\SVG@out@path\SVG@out@filename.eps%
}%
\fi%
% \end{macrocode}
% Convert the PDF~file to PNG~file if requested.
% \begin{macrocode}
\ifSVG@out@png%
\immediate\write18{%
\SVG@cmd@convert\space%
\SVG@out@filename.pdf\space\SVG@out@filename.png%
}%
\immediate\write18{%
mv \SVG@out@filename.png\space\SVG@out@path\SVG@out@filename.png%
}%
\fi%
% \end{macrocode}
% Clean up if requested.
% \begin{macrocode}
\ifSVG@out@extract%
\ifSVG@out@pdf%
\immediate\write18{%
mv \SVG@out@filename.pdf\space\SVG@out@path\SVG@out@filename.pdf%
}%
\else%
\ifSVG@out@clean \immediate\write18{rm \SVG@out@filename.pdf} \fi%
\fi%
\ifSVG@out@clean%
\immediate\write18{%
rm
\SVG@out@path\SVG@out@filename.tex\space%
\SVG@out@filename.aux\space%
\SVG@out@filename.log\space%
\SVG@out@filename.out%
}%
\fi%
\fi%
% \end{macrocode}
% Finally, include the SVG~file in the current document and end the package.
% \begin{macrocode}
\ifSVG@in@exclude\else%
{%
\def\svgwidth{\the\SVG@out@width}%
\SVG@out@pretex%
\import{\SVG@in@path}{#2.pdf_tex}%
\SVG@out@postex%
}%
\fi%
}%
% \end{macrocode}
%
% \iffalse
%</package&old>
% \fi
%
% \Finale
%
\endinput
|