summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/hvextern/hvextern.tex
blob: 22c26b7669cf4aea0e6b06ca92f4dcc5549ceb70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
%% $Id: hvextern.tex 570 2022-06-06 05:40:08Z herbert $
\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{}
\documentclass[ngerman,a4paper,twoside]{article}
\usepackage{babel}
\usepackage{libertinus}
\setmonofont[Scale=MatchLowercase,FakeStretch=0.88]{AnonymousPro}
\usepackage{iftex}

\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{hvlogos}
\usepackage{hvextern}
\usepackage{hvindex}
\usepackage{hvdoctools}
\usepackage{listings}
\lstset{basicstyle=\ttfamily\small,language=[LaTeX]TeX,breaklines}
\usepackage{xcolor,xspace}
\usepackage{hyperref}

\def\Python{\textsf{Python}\xspace}
\def\Perl{\textsf{Perl}\xspace}
\def\Lua{\textsf{Lua}\xspace}
\def\Java{\textsf{Java}\xspace}


\begin{document}
\title{Writing, running and including the output of external documents 
from within a main\newline \LaTeX\ document~--v. \hvexternFileversion}
\author{Herbert Voß \url{herbert@dante.de}}
\maketitle
\tableofcontents

%\newpage

\setkeys{hv}{moveToExampleDir,ExampleDir=Exa,showFilename,verbose}
\section{Syntax}

\begin{verbatim}
\usepackage{hvextern}
\end{verbatim}

\addtocontents{toc}{\protect\enlargethispage{2ex}}


\begin{sloppypar}
This package allows to write external \MP, \TeX, \ConTeXt, \LaTeX, \LuaTeX, \LuaLaTeX, \XeTeX, \XeLaTeX, 
\Index{Lua}, \Index{Perl}, \Index{Java} and/or \Index{Python}
source code, which will then be run via \texttt{shell escape} to create a PDF oder text output to include
it into the main \LaTeX\ document. 
\end{sloppypar}


There is only one environment and one command:

\begin{verbatim}
\begin{externalDocument}[<options>]{<external filename without extension>}
...
source code
...
\end{externalDocument}

\runExtCmd[<options>]
    {<command with arguments>}
    {<external filename without extension>}
\end{verbatim}

The main document \emph{must} be run with the \Loption{-shell-escape} option, otherwise it won't work, e.g.:

\begin{verbatim}
lualatex --shell-escape <file>
\end{verbatim}




The purpose for this package is to show the output of documents which have to be compiled with
a different preamble or a different engine or a complete different system, but integrating the output
automatically in the main document..

\bigskip
\noindent
\fbox{\begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}
\emph{All} examples in this document are created on-the-fly while running this \LaTeX\ document
with \texttt{lualatex} with the  \texttt{-\kern1pt-shell-escape} option.
\end{minipage}}



\section{First examples}
\subsection{Without showing the code}

This document was run with \LuaLaTeX. Suppose you want to insert the output of a document
which needs for several reasons a \XeLaTeX\ run. Instead of created and running a document 
outside of the main document and then to insert the output
we can do this from within this \LuaLaTeX\ document itself. The external document is compiled
with \XeLaTeX\ and the output is insert as pdf image: 
\begin{externalDocument}[%
  compiler=xelatex, inline, force, runs=2, grfOptions={height=8pt},%
  crop, cropmargin=0, cleanup, docType=latex]{voss}
\documentclass{ctexart}
\pagestyle{empty}
\begin{document} 
美好的一天.
\end{document}
\end{externalDocument}

Another example which needs a \pdfLaTeX\ run.  The \Index{source} code itself is also not
shown by the environment \Lenv{externalDocument}.


\begin{minipage}{.59\linewidth}
\begin{lstlisting}
\begin{externalDocument}[
  compiler=pdflatex,force,cleanup]{voss}
\documentclass{standalone}
%StartVisiblePreamble
\usepackage{fontenc}
\usepackage{libertinus}
\usepackage[linguistics]{forest}
\forestapplylibrarydefaults{linguistics, edges}
%StopVisiblePreamble
\begin{document}
\begin{forest}
[VP
  [DP]
  [V’
   [V]
  [DP]
  ]
]
\end{forest}
\end{document}
\end{externalDocument}
\end{lstlisting}
\end{minipage}
\begin{minipage}{.39\linewidth}
\begin{externalDocument}[
  compiler=pdflatex,force=false,cleanup={log,aux},showFilename=false]{voss}
\documentclass{standalone}
%StartVisiblePreamble
\usepackage{fontenc}
\usepackage{libertinus}
\usepackage[linguistics]{forest}
\forestapplylibrarydefaults{linguistics, edges}
%StopVisiblePreamble
\begin{document}
\begin{forest}
[VP
  [DP]
  [V’
   [V]
  [DP]
  ]
]
\end{forest}
\end{document}
\end{externalDocument}
\end{minipage}

\subsection{Showing code and output of a Python example}
The \ttIndex{png} image  is created on the fly with the following arguments of \Lenv{externalDocument}:

\begin{Verbatim}
\begin{externalDocument}[
  compiler=python3,
  code,
  ext=py,
  docType=py,
  usefancyvrb,
  grfOptions={width=\linewidth}]{python}
... Python code ...
\end{externalDocument}
\end{Verbatim}

The code which is declared as header and main can be marked by:

\begin{Verbatim}
\hv@extern@exampleType{py}
  {\NumChar StartVisibleMain}
  {\NumChar StopVisibleMain}
  {\NumChar StartVisiblePreamble}
  {\NumChar StopVisiblePreamble}
\end{Verbatim}

\Lcs{NumChar} is the default Python comment character \#\index{\#} and needs to be saved with a different
catagory, which is done internally by the package. The complete definition of the code is:


\begin{Verbatim}
\begin{externalDocument}[
  compiler=python3,
  code,
  ext=py,
  force=false,
  docType=py,
  usefancyvrb,
  grfOptions={width=\linewidth}]{python}
import os
#StartVisiblePreamble
from PIL import Image
import subprocess
# drawing area (xa < xb and ya < yb)
xa = -0.1716
xb = -0.1433
ya = 1.022
yb = 1.044
maxIt = 1024  # iterations
imgx = 1000   # image size
imgy = 750
image = Image.new("RGB", (imgx, imgy))
#StopVisiblePreamble

#StartVisibleMain
for y in range(imgy):
    cy = y * (yb - ya) / (imgy - 1)  + ya
    for x in range(imgx):
        cx = x * (xb - xa) / (imgx - 1) + xa
        c = complex(cx, cy)
        z = 0
        for i in range(maxIt):
            if abs(z) > 2.0: break 
            z = z * z + c 
        r = i % 4 * 6
        g = i % 8 * 32
        b = i % 16 * 16
        image.putpixel((x, y), b * 65536 + g * 256 + r)
#StopVisibleMain
# now get the filename created by the latex document
imageName = os.path.basename(os.path.splitext(__file__)[0])+".png" # get filename
image.save(imageName, "PNG")
\end{externalDocument}
\end{Verbatim}

And with using this code we get the image as png inserted. The given filename of the external
document is 
internally extended by a consecutive number which isn't known to the \Index{Python} code. However,
it is no problem in any programming language to get the name of a running file. The  forlast
line in the above code shows how it can be done with Python.


\begin{externalDocument}[
  compiler=python3,
  progpath=/usr/local/bin/,
  force=false,
  runs=1,
  code,
  ext=py,
  docType=py,
  usefancyvrb,
  grfOptions={width=\linewidth}]{python}
import os
#StartVisiblePreamble
from PIL import Image
import subprocess
# drawing area (xa < xb and ya < yb)
xa = -0.1716
xb = -0.1433
ya = 1.022
yb = 1.044
maxIt = 1024  # iterations
imgx = 1000   # image size
imgy = 750
image = Image.new("RGB", (imgx, imgy))
#StopVisiblePreamble

#StartVisibleMain
for y in range(imgy):
    cy = y * (yb - ya) / (imgy - 1)  + ya
    for x in range(imgx):
        cx = x * (xb - xa) / (imgx - 1) + xa
        c = complex(cx, cy)
        z = 0
        for i in range(maxIt):
            if abs(z) > 2.0: break 
            z = z * z + c 
        r = i % 4 * 6
        g = i % 8 * 32
        b = i % 16 * 16
        image.putpixel((x, y), b * 65536 + g * 256 + r)
#StopVisibleMain
# now get the filename created by the latex document
imageName = os.path.basename(os.path.splitext(__file__)[0]) # get filename
image.save(imageName+".png", "PNG")
\end{externalDocument}


The external filename, extended by a consequtive number, kan be printed in the
margin by setting the keyword \Lkeyword{showFilename}. In general it is printed 
in the outer margin or in twocolumn mode in the outer column. If the example is
set in twocolumn mode but inside a starred floating environment over both
column, then use the keyword \Lkeyword{outerFN}. Then \Lpack{hvextern} doesn't
test for twocolumn mode.

A vertical shift of the filename is possible by setting a length to the keyword \Lkeyword{shiftFN},
e.g. \texttt{shiftFN=5ex}. 


\clearpage%%%%%%%%%%%%

\begin{externalDocument}[grfOptions={width=0.95\linewidth},
  compiler=xelatex,code,mpwidth=0.6\linewidth,
  crop,cleanup,force=false,usefancyvrb=false,ext=tex,showFilename=false]{voss}
\documentclass{article}
%StartVisiblePreamble
\usepackage{tikz}
\usepackage[hks,pantone,xcolor]{xespotcolor}
%StopVisiblePreamble
\pagestyle{empty}
\begin{document}
\SetPageColorSpace{HKS}
\definecolor{HYellow}{spotcolor}{HKS05N,0.5}
\definecolor{HRed}{spotcolor}{HKS14N,0.5}
\definecolor{HBlue}{spotcolor}{HKS38N,0.5}
\begin{tikzpicture}[scale=0.7,fill opacity=0.7]
 \fill[HYellow]( 90:1.2) circle (2);
 \fill[HRed]   (210:1.2) circle (2);
 \fill[HBlue]  (330:1.2) circle (2);
 \node at ( 90:2)  {Typography};
 \node at ( 210:2) {Design};
 \node at ( 330:2) {Coding};
 \node {\LaTeX};
\end{tikzpicture}
\end{document}
\end{externalDocument}



\section{Setting marker in the source}
The marker for the code ranges which should be listed depend to the used programming language:

\begin{verbatim}
[...]
%StartVisiblePreamble
[... listed preamble code ]
%StopVisiblePreamble
[...]
\begin{document}
[...]
\end{document}
\end{verbatim}

everything between \ttIndex{\%StartVisiblePreamble} and \ttIndex{\%StopVisiblePreamble} will be listed as
preamble and in case of a \LaTeX\ source everything between
 \Lcs{begin\{document\}} and \Lcs{end\{document\}} as body. The marker must be defined with an own
macro, e.g.:
 
\begin{verbatim}
\hv@extern@exampleType{py}
  {\NumChar StartVisibleMain}
  {\NumChar StopVisibleMain}
  {\NumChar StartVisiblePreamble}
  {\NumChar StopVisiblePreamble}
\end{verbatim}
 
\Lcs{NumChar} is the comment character \#, which needs a special handling. This version of \Lpack{hvextern}
supports the following programming languages (option \Lkeyword{compiler}):
\Lkeyval{mpost}, \Lkeyval{tex}, \Lkeyval{latex}, \Lkeyval{luatex}, 
\Lkeyval{python3}, \Lkeyval{perl}, \Lkeyval{lua}, \Lkeyval{xetex}, 
\Lkeyval{pdflatex}, \Lkeyval{lualatex}, \Lkeyval{xelatex}, and \Lkeyval{context}. The default
is \Lkeyval{pdflatex}. The option \Lkeyword{docType} selects the config file, which must be one of 
\Lkeyval{context}, \Lkeyval{lua}, \Lkeyval{pl}, \Lkeyval{tex}, \Lkeyval{latex}, 
\Lkeyval{mp}, and \Lkeyval{py}. For Lua it is

\begin{verbatim}
\hv@extern@exampleType{lua}
  {--StartVisibleMain}
  {--StopVisibleMain}
  {--StartVisiblePreamble}
  {--StopVisiblePreamble}
\end{verbatim}


It defines the marker strings for the listed code sequences.  
In some cases you have to use multiple times the same value
for different optional arguments, e.g.

\begin{verbatim}
ext=lua, compiler=lua, docType=lua, ... 
\end{verbatim}


\section{Optional arguments}
The default setting is always shown in brackets. 
\subsection{Programs and runs}

The \Lkeyword{progpath} should only in some
rare cases needed. In general all used compilers will be found by the system. A given \Lkeyword{progpath}
must be end with a slash, e.g. \Lkeyval{./bin/} 

\begin{verbatim}
\define@key{hv}{progpath}[]{\def\hv@extern@progpath{#1}}
\define@key{hv}{compiler}[pdflatex]{\def\hv@extern@compiler{#1}}
\define@key{hv}{runsequence}[]{\def\hv@extern@runsequence{#1}}
\define@key{hv}{runs}[1]{\setcounter{hv@extern@runs}{#1}}
\end{verbatim}

Instead of the optional arguments
 \Lkeyword{compiler}, \Lkeyword{biber}, and \Lkeyword{xindex} one can define an individual
 command sequence by using the optional argument
 \Lkeyword{runsequence}. It must be comma separated list:
 
\begin{verbatim}
runsequence={lualatex,biber,xindex -l de -c AU,lualatex,lualatex}
\end{verbatim}

\begin{externalDocument}[
  grfOptions={width=0.30\linewidth},
  pages={1,3,5},
  pagesep=2pt,
  frame,
  runsequence={lualatex,biber,xindex -l de -c AU,lualatex,lualatex},
  ,
  verbose,
  force=false,
  cleanup={log,aux,toc,bbl,blg},
  code,docType=latex,
  lstOptions={columns=fixed}]{voss}
\documentclass[paper=a5,parskip=half-,DIV=12,fontsize=12pt]{scrbook}
%StartVisiblePreamble
\usepackage[ngerman]{babel}
\usepackage{libertinus,hvindex}
\usepackage{makeidx}\makeindex
\usepackage{biblatex}\addbibresource{biblatex-examples.bib}
%StopVisiblePreamble
\usepackage{blindtext}
\begin{document}
Sort with xindex \verb|-l DE --config AU|
\blindtext
\Index{Österreich} \Index{Öresund} 
\Index{Ostern} \Index{Ober} \Index{Oberin} 
\Index{Österreich} \Index{Öresund} 
\Index{Ödem} \Index{Oligarch} \Index{Oder} 
\Index{Goldmann}
\printindex
\nocite{*}\printbibliography
\blindtext
\blinddocument

\end{document}
\end{externalDocument}


The following \Java-program creates the Mandelbrot set as png image. The valid setting for 
the environment \Lenv{externalDocument} is:

\begin{verbatim}
  compiler=java,ext=java,docType=java,
\end{verbatim}

\begin{externalDocument}[
  verbose,
  compiler=java,ext=java,code,
  force=false,docType=java,includegraphic,
  usefancyvrb,grfOptions={width=0.9\linewidth}]{java}
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import javax.imageio.ImageIO;

public class Main {

//StartVisiblePreamble
  public static int iterZahl(final double cx, final double cy, int maxIt, 
                final double radius) {
  // bestimmt Anzahl der Iterationen
    int zaehler = 0;
    double zx = 0.0, zy = 0.0, tmp;
    do {
      tmp = zx*zx - zy*zy + cx;
      zy = 2*zx*zy + cy; zx = tmp;
      zaehler++;
    } while (zx*zx + zy*zy <= radius && zaehler < maxIt);
    return zaehler;
  }
//StopVisiblePreamble
  public static void main(String[] argv) throws Exception {  
    String f_name = new File ((Main.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath()).getName();
    String basename = f_name.replaceAll("\\.[^.]*$", "");
    int imageBreite = 540, imageHoehe = 405;
    BufferedImage bufferedImage = new BufferedImage(imageBreite, imageHoehe, BufferedImage.TYPE_INT_RGB);
    Graphics g = bufferedImage.createGraphics();
//StartVisibleMain
    double xa = -2.5, xe = 0.7, ya = -1.2, ye = 1.2; // Ratio 20:15 
    double dx = (xe-xa)/(imageBreite-1), dy = (ye-ya)/(imageHoehe-1);
    double cx, cy; int R, G, B;
    double radius = 10.0;  int maxIt = 1024;
    cx = xa;
    for (int sp = 0; sp < imageBreite; sp++) {
      cy = ye; // von oben nach unten
      for (int ze = 0; ze < imageHoehe; ze++) {
        int zIter = iterZahl(cx, cy, maxIt, radius);
        if (zIter == maxIt) {
          g.setColor(Color.WHITE);
          g.drawLine(sp, ze, sp, ze);
        } else { 
          R = zIter % 4 * 6 ; G = zIter % 8 * 32; B = zIter % 16 * 16;
          g.setColor(new Color(R,G,B));
          g.drawLine(sp, ze, sp, ze);
        }
        cy = cy - dy;
      } // for ze
      cx = cx + dx;
    } // for sp
//StopVisibleMain
    g.dispose();
    RenderedImage rendImage = bufferedImage;

    File file = new File(basename+".png");
    ImageIO.write(rendImage, "png", file);
  }
}
\end{externalDocument}


%$




\subsection{Grafik options}
\begin{verbatim}
\define@key{hv}{grfOptions}[]{\def\hv@extern@grfOptions{#1}}
\end{verbatim}

The option is passed to \Lcs{includegraphics}, e.g. \verb|angle=90,width=\linewidth| for
the follwing example.

\begin{externalDocument}[grfOptions={angle=90,width=\linewidth},
  compiler=xelatex,code,mpwidth=0.6\linewidth,
  crop,cleanup,force]{voss}
\documentclass{article}
%StartVisiblePreamble
\usepackage{tikz}
\usepackage[hks,pantone,xcolor]{xespotcolor}
%StopVisiblePreamble
\pagestyle{empty}
\begin{document}
\SetPageColorSpace{HKS}
\definecolor{HYellow}{spotcolor}{HKS05N,0.5}
\definecolor{HRed}{spotcolor}{HKS14N,0.5}
\definecolor{HBlue}{spotcolor}{HKS38N,0.5}
\begin{tikzpicture}[scale=0.7,fill opacity=0.7]
 \fill[HYellow]   ( 90:1.2) circle (2);
 \fill[HRed] (210:1.2) circle (2);
 \fill[HBlue]  (330:1.2) circle (2);
 \node at ( 90:2) {Typography};
 \node at ( 210:2) {Design};
 \node at ( 330:2) {Coding};
 \node {\LaTeX};
\end{tikzpicture}
\end{document}
\end{externalDocument}



\newpage%%%%%%%%%%%


\subsection{Listings options}

\begin{verbatim}
\define@key{hv}{lstOptions}[]{\def\hv@extern@lstOptions{#1}}
\end{verbatim}

The option is passed either to \Lcs{lstinputlisting}, or, if \Lkeyword{usefancyvrb} is active, 
to \Lcs{VerbatimInput}. The following example uses 

\begin{verbatim}
  lstOptions={basicstyle=\sffamily\itshape\scriptsize},
\end{verbatim}



\begin{externalDocument}[
  grfOptions={width=\linewidth},
  lstOptions={basicstyle=\sffamily\itshape\scriptsize},
  compiler=lualatex,
  code,
  mpwidth=0.6\linewidth,
  crop,
  cleanup,
  force=false,
  docType=latex]{voss}
\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{}
\documentclass{article}
%StartVisiblePreamble
\usepackage{pst-calendar} 
%StopVisiblePreamble
\pagestyle{empty}
\begin{document}
\psscalebox{0.3}{%
  \psCalDodecaeder[Year=2022,style=april]%
}
\end{document}
\end{externalDocument}



\subsection{Background color}

There are different colors for the preamble and body listing: the backgrund and frame color.
\begin{verbatim}
\define@key{hv}{BGpreamble}[black12]{\def\hv@extern@BGpreamble{#1}}
\define@key{hv}{BGbody}[black8]{\def\hv@extern@BGbody{#1}}
\define@key{hv}{BOpreamble}[black12]{\def\hv@extern@BOpreamble{#1}}
\define@key{hv}{BObody}[black8]{\def\hv@extern@BObody{#1}}
\end{verbatim}

The options are passed to \Lpack{tcolorbox} and preset to \Lcolor{black"!12} and \Lcolor{black"!8}.
The color of the frame is set to the same values, hence not seen. The following example uses

\begin{verbatim}
  BGpreamble=red!10, BOpreamble=red, 
  BGbody=blue!8, BObody=blue,
\end{verbatim}

%\clearpage

\begin{externalDocument}[
  grfOptions={width=\linewidth},
  lstOptions={fontsize=\small,fontfamily=tt},
  compiler=lualatex,
  BGpreamble=red!10, BOpreamble=red, 
  BGbody=blue!8, BObody=blue,
  code,
  mpwidth=0.6\linewidth,
  crop,
  cleanup,
  force=false,
  usefancyvrb,
  docType=latex]{voss}
\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{}
\documentclass{article}
%StartVisiblePreamble
\usepackage{pst-calendar} 
%StopVisiblePreamble
\pagestyle{empty}
\begin{document}
\psscalebox{0.3}{%
  \psCalDodecaeder[Year=2022,style=may]%
}
\end{document}
\end{externalDocument}

\subsection{Type of the source code}

The current version of \Lpack{hvextern} supports code written as
\MP, \plainTeX, \LaTeX, \ConTeXt, and Python. Every type has its own keywords for the 
linerange which should be printed for the preamble and
the body. For example the \texttt{latex} config is:

\begin{verbatim}
\hv@extern@exampleType{latex}%                   for _all_LaTeX engines   
  {\string\begin\string{document\string}}%       
  {\string\end\string{document\string}}%         
  {\perCent StartVisiblePreamble}%               
  {\perCent StopVisiblePreamble}%                

% only for the sequence latex->dvips->ps2pdf
\def\hv@extern@runLATEX#1#2#3#4{% path compiler file extension  
  \ifhv@extern@verbose \typeout{>>>> running #1#2 #3#4}\fi
  \ShellEscape{#1#2\space #3#4}%
  \ifhv@extern@verbose \typeout{>>>> running #1dvips #3}\fi
  \ShellEscape{#1dvips\space #3.dvi}%
  \ifhv@extern@verbose \typeout{>>>> running ps2pdf #3.ps}\fi
  \ShellEscape{#1ps2pdf\space -dAutoRotatePages=/None\space -dALLOWPSTRANSPARENCY\space  #3.ps}%
}
\end{verbatim}

If a source needs more than running the defined compiler, it must be defined by a macro
\begin{verbatim}
\def\hv@extern@run<NAME>#1#2#3#4{% path compiler file extension
...}
\end{verbatim}

The type of the source code can be different to the compiler, e.g. source \Lkeyval{latex},
but compiler \Lkeyval{lualatex}.

\subsection{Output more than one page}
The pages which should be printed can be defined by


\begin{verbatim}
\define@key{hv}{pages}[1]{\def\hv@extern@pages{#1}}
\define@key{hv}{pagesep}[1em]{\hv@extern@pagesep=#1}
\define@boolkey{hv}[hv@extern@]{frame}[true]{}
\end{verbatim}

With \Lkeyword{frame} the pages can be framed (internally by \Lcs{fbox}).
It is leaved to the user to choose the correct image width for the pages.
The separation between the pages is defined by the length \Lkeyword{pagesep}.
The following example uses:

\begin{verbatim}
  pages={1,2,3},
  pagesep=2pt,
  grfOptions={width=0.3\linewidth},
  compiler=lualatex, runs=2,  % for the TOC
  frame,
\end{verbatim}

\begin{externalDocument}[
  pages={1,2,3},
  pagesep=2pt,
  shiftFN=5ex,
  grfOptions={width=0.3\linewidth},
%  lstOptions={fontsize=\small,fontfamily=tt},
  compiler=lualatex, runs=2,
  BGpreamble=red!10, BOpreamble=red, 
  BGbody=blue!8, BObody=blue,
  code,
%  mpwidth=0.6\linewidth,
%  crop,
  cleanup,
  force=false,
  frame,
%  usefancyvrb,
%  float,
%  caption={An example for Coxeter images},
%  label=img:cox,
  docType=latex]{voss}
\documentclass{article}
%StartVisiblePreamble
\usepackage[american]{babel}
\usepackage{libertinus} 
\usepackage{blindtext} 
%StopVisiblePreamble
\pagestyle{empty}
\begin{document}
\title{A multipage example}
\author{Erasmus von Rotterdam}
\maketitle
\tableofcontents
\blinddocument
\end{document}
\end{externalDocument}




\subsection{Output as floating object with caption and label}

By default the images are not inserted as a float. This can be changed by
the keyword \Lkeyword{float}, a caption and a label are optional. The float type is always
\Lenv{figure}.

\begin{verbatim}
\define@boolkey{hv}[hv@extern@]{float}[true]{}
\define@key{hv}{floatsetting}[]{\def\hv@extern@floatsetting{#1}}
\define@key{hv}{caption}[]{\def\hv@extern@caption{#1}}
\define@key{hv}{label}[]{\def\hv@extern@label{#1}}
\end{verbatim}

The image Figure~\ref{img:cox} shows an example for a floating object, which uses the floatsetting \verb|!htb|,
which is the default. Using a caption and a label are optional.

\begin{externalDocument}[
  grfOptions={width=\linewidth},
  lstOptions={fontsize=\small,fontfamily=tt},
%  lstOptions={basicstyle=\small\ttfamily},
  compiler=lualatex,
  BGpreamble=red!10, BOpreamble=red, 
  BGbody=blue!8, BObody=blue,
  code,
%  mpwidth=0.6\linewidth,
  crop,
  cleanup,
  force=false,
  usefancyvrb,
  float,
  floatsetting=!ht,
  caption={An example for Coxeter images},
  label=img:cox,
  docType=latex]{voss}
\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{}
\documentclass{article}
%StartVisiblePreamble
\usepackage{pst-coxeterp} 
%StopVisiblePreamble
\pagestyle{empty}
\begin{document}
\begin{pspicture}(-1,-1)(1,1)\Simplex[dimension=2]\end{pspicture}
\begin{pspicture}(-1,-1)(1,1)\Simplex[dimension=3]\end{pspicture}
\begin{pspicture}(-1,-1)(1,1)\Simplex[dimension=5]\end{pspicture}
\begin{pspicture}(-1,-1)(1,1)\Simplex[dimension=7]\end{pspicture}
\end{document}
\end{externalDocument}



%\clearpage%%%%%%%%%%%%%%%%%


\subsection{Cropping the PDF}
Instead of using the \Index{documentclass} \Lclass{standalone}, which already crops the created PDF,
one can use the optional argument \Lkeyword{crop}.

\begin{verbatim}
\define@boolkey{hv}[hv@extern@]{crop}[true]{}
\define@key{hv}{cropmargin}[2]{\def\hv@extern@cropmargin{#1 }}% length in pt
\end{verbatim}


It is also possible to crop a document with more than one page. In this case the
beginning and end of the pages should be on the same height. Otherwise the pages
will have different heights after \Index{cropping} (see next image). 
The follwoing example was created with

\begin{verbatim}
  pages={1,2,3},
  pagesep=2pt,
  grfOptions={width=0.3\linewidth},
  compiler=lualatex, runs=2,  % for the TOC
  frame,
  crop, cropmargin=5,%    5pt margin
\end{verbatim}

\begin{externalDocument}[
  pages={1,2,3},
  pagesep=2pt,
  grfOptions={width=0.3\linewidth},
%  lstOptions={fontsize=\small,fontfamily=tt},
  compiler=lualatex, runs=2,
  BGpreamble=red!10, BOpreamble=red, 
  BGbody=blue!8, BObody=blue,
  code,
%  mpwidth=0.6\linewidth,
  crop, cropmargin=5,
  cleanup,
  force=false,
  frame,
%  usefancyvrb,
%  float,
%  caption={An example for Coxeter images},
%  label=img:cox,
  docType=latex]{voss}
\documentclass{article}
%StartVisiblePreamble
\usepackage[american]{babel}
\usepackage{libertinus} 
\usepackage{blindtext} 
\pagestyle{headings}
%StopVisiblePreamble
\begin{document}
\title{A multipage example}
\author{Erasmus von Rotterdam}
\maketitle
\tableofcontents
\Blinddocument
\end{document}
\end{externalDocument}


\subsection{Code and output side by side}
By default the code and the output is on top of each other. With setting the
width of a minipage with \Lkeyword{mpwidth} greater than 0\,pt  the output will be side by side.

\begin{verbatim}
\define@key{hv}{mpwidth}[0pt]{\setlength\hv@extern@mpwidth{#1}}
\define@key{hv}{mpvalign}[0pt]{\def\hv@extern@mpvalign{#1}}
\end{verbatim}

\Lkeyword{mpwidth} is  the width of the code. The rest of the line, minus 1em for the space between
the minipages, will be the possible
width for the output and will be calculated automatically. The two \Index{minipages} are
aligned by defaults to its top. This can be changed by setting \Lkeyword{mpvalign} to \Lkeyval{c} 
or \Lkeyval{b}.



\subsection{Horizontal alignment of the output}

%\begin{verbatim}
%\define@key{hv}{align}[\centering]{\def\hv@extern@align{#1}}
%\end{verbatim}

%\textbf{the default}
%
\begin{verbatim}
  align=\centering,  % default
\end{verbatim}
%
\begin{externalDocument}[
  compiler=lualatex, runs=2,
  BGpreamble=red!10, BOpreamble=red, 
  BGbody=blue!8, BObody=blue,
  code,
  showFilename=false,
  crop,
  cleanup,
  force=false,
  docType=latex]{voss}
\documentclass{article}
\pagestyle{empty}
\begin{document}
\rule{0.5\linewidth}{5mm}
\end{document}
\end{externalDocument}

%\textbf{Left aligned}

\begin{verbatim}
  align=\raggedright,
\end{verbatim}

\begin{externalDocument}[
  align=\raggedright,
  compiler=lualatex, runs=2,
  BGpreamble=red!10, BOpreamble=red, 
  BGbody=blue!8, BObody=blue,
  showFilename=false,
  code,
  crop,
  cleanup,
  force=false,
  docType=latex]{voss}
\documentclass{article}
\pagestyle{empty}
\begin{document}
\rule{0.5\linewidth}{5mm}
\end{document}
\end{externalDocument}

%\textbf{Right aligned}

\begin{verbatim}
  align=\raggedleft,
\end{verbatim}


\begin{externalDocument}[
  align=\raggedleft,
  compiler=lualatex, runs=2,
  BGpreamble=red!10, BOpreamble=red, 
  BGbody=blue!8, BObody=blue,
  code,
  showFilename=false,
  crop,
  cleanup,
  force=false,
  docType=latex]{voss}
\documentclass{article}
\pagestyle{empty}
\begin{document}
\rule{0.5\linewidth}{5mm}
\end{document}
\end{externalDocument}


%Now the same for side by side output.

%\textbf{the default -- side by side}
\begin{verbatim}
  align=\centering,  mpwidth=0.5\linewidth,   % default for side by side
\end{verbatim}

\begin{externalDocument}[
  compiler=lualatex, runs=2,
  BGpreamble=red!10, BOpreamble=red, 
  BGbody=blue!8, BObody=blue,
  code,
  crop,
  showFilename=false,
  cleanup,
  force=false,
  mpwidth=0.5\linewidth,
  docType=latex]{voss}
\documentclass{article}
\pagestyle{empty}
\begin{document}
\rule{0.25\linewidth}{5mm}
\end{document}
\end{externalDocument}

%\textbf{Left aligned -- side by side}

\begin{verbatim}
  align=\raggedright,   mpwidth=0.5\linewidth,
\end{verbatim}

\begin{externalDocument}[
  align=\raggedright,
  compiler=lualatex, runs=2,
  BGpreamble=red!10, BOpreamble=red, 
  BGbody=blue!8, BObody=blue,
  code,
  showFilename=false,
  crop,
  cleanup,
  force=false,
  mpwidth=0.5\linewidth,
  docType=latex]{voss}
\documentclass{article}
\pagestyle{empty}
\begin{document}
\rule{0.25\linewidth}{5mm}
\end{document}
\end{externalDocument}

%\textbf{Right aligned -- side by side}

\begin{verbatim}
  align=\raggedleft,  mpwidth=0.5\linewidth,
\end{verbatim}


\begin{externalDocument}[
  align=\raggedleft,
  compiler=lualatex, runs=2,
  BGpreamble=red!10, BOpreamble=red, 
  BGbody=blue!8, BObody=blue,
  code,
  showFilename=false,
  crop,
  cleanup,
  force=false,
  mpwidth=0.5\linewidth,
  docType=latex]{voss}
\documentclass{article}
\pagestyle{empty}
\begin{document}
\rule{0.25\linewidth}{5mm}
\end{document}
\end{externalDocument}




\subsection{Inline images}
By default code and image are own paragraphs. With the optional argument \Lkeyword{inline} the created
image can be part of the \Index{current line}. This may make sense, if you need characters which are
not part of your current font.

\begin{verbatim}
\define@boolkey{hv}[hv@extern@]{inline}[true]{%
    \hv@extern@codefalse
    \hv@extern@showFilenamefalse}
\end{verbatim}

With the setting \LKeyset{inline=true} the optional keyword \Lkeyword{code}  and \Lkeyword{showFilename}
is automatically set to false. The
next  Chinese characters 
\begin{externalDocument}[
  compiler=xelatex, inline, runs=2, grfOptions={height=8pt},
  crop, cropmargin=0, 
  cleanup, force=false, docType=latex]{voss}%
\documentclass{ctexart}
\pagestyle{empty}
\begin{document}
美好的一天
\end{document}
\end{externalDocument}
are inserted as \Index{inline image} without showing the code. The complete code looks like:



\begin{Verbatim}
With \Lkeyset{inline} the optional argument \Lkeyword{code} is 
automatically set to false. The next  Chinese characters 
\begin{externalDocument}[
  compiler=xelatex, inline, runs=2, grfOptions={height=8pt},
  crop, cropmargin=0, cleanup, force=false, docType=latex]{voss}
\documentclass{ctexart}
\pagestyle{empty}
\begin{document}
美好的一天
\end{document}
\end{externalDocument}
are inserted as inline image without showing the code. The complete 
code looks like:
\end{Verbatim}


\subsection{Input text instead of an image}
By default the created pdf which can be, of course, only text, will be inserted by \Lcs{includegraphics}.
If you have only text as output and don't want to create a pdf you can insert this kind of
output as verbatim text by setting \Lkeyset{includegraphic=false}. 

\begin{verbatim}
\define@boolkey{hv}[hv@extern@]{includegraphic}[true]{}
\end{verbatim}


The textfile must have the same main filename with the extension
\Lext{txt}. As already mentioned, in every programming language you can get the current
used filename from within the code itself. The following \Perl example which calculates the
\Index{Kaprekar} constants uses 

\begin{verbatim}
my $filename = $0;             # the current filename
$filename =~ s/\.pl//;         # without extension .pl
$filename = "${filename}.txt"; # for the output
\end{verbatim}

Only for some completeness: a Kaprekar constant is a number $A$ with $\max(A)-\min(A)=A$. 
$\max$ and $\min$ are the
sorted digits of the number $A$: $495=954-459$.


\begin{externalDocument}[
  compiler=perl, force=false, docType=pl, ext=pl, includegraphic=false,
  code, mpwidth=0.6\linewidth]{voss}
#!/usr/bin/perl
#
# Herbert Voss 2005-05-31
#
#StartVisiblePreamble
my $zahl = 1;
my $anfang = 1;
my $ende = 9;
#StopVisiblePreamble
my $filename = $0;             # the current filename
$filename =~ s/\.pl//;         # without extension .pl
$filename = "${filename}.txt"; # for the output
my $found = 0;
open(my $fh, '>', $filename);

#StartVisibleMain
print $fh "Finding Kaprekarconstants ...\n";
while ($zahl < 8) {
  print $fh "${zahl}-stellig: ";
  foreach ($anfang...$ende) { # for every row $_
    @Zeichen = split(//,$_);
    $Min = join("",sort(@Zeichen));
    $Max = reverse($Min);
    $Dif=$Max-$Min;
    if($_ eq $Dif) {
      $found = 1;
      print $fh $_,",  ";
    }
  }
  if (!$found) { print $fh "---\n"; }
  else         { print $fh "\n";    }
  $found = false;
  $zahl = $zahl+1;
  $anfang = $anfang*10;
  $ende = $ende*10;
}
#StopVisibleMain
close $fh;
\end{externalDocument}


%$
Another example with running \Lua to calculate and print the \Index{Pascal's triangle}. The internal filename
is available with

\begin{verbatim}
local filename = arg[0]
local shortFN = str:match("(.+)%..+")   -- delete extension
outFile = io.open(shortFN..".txt","w+") -- open external file
\end{verbatim}


\begin{externalDocument}[
  compiler=lua, force=false, docType=lua, ext=lua, includegraphic=false, 
  code, usefancyvrb=false,textOptions={basicstyle=\ttfamily\footnotesize},
  shiftFN=6ex]{voss}
#!/usr/bin/env lua
local filename = arg[0]
local shortFN = filename:match("(.+)%..+")
outFile = io.open(shortFN..".txt","w+")

--StartVisiblePreamble
function nextrow(t)
  local ret = {}
  t[0], t[#t+1] = 0, 0
  for i = 1, #t do ret[i] = t[i-1] + t[i] end
  return ret
end

function triangle(n)
  t = {1}
  for i = 1, n do
    m = (n - i)
    for j = 1,m do outFile:write("    ") end
    for k = 1,i do outFile:write(string.format("%8s",t[k])) end
    outFile:write("\n")
    t = nextrow(t)
  end
end
--StopVisiblePreamble

--StartVisibleMain
triangle(10)
--StopVisibleMain
outFile:close()
\end{externalDocument}






\subsection{Running additional external programs}

For a \LaTeX\ additional programs for \Index{bibliography}, \Index{index}, a.s.o. maybe needed.

\begin{verbatim}
\define@boolkey{hv}[hv@extern@]{biber}[true]{}
\define@boolkey{hv}[hv@extern@]{xindex}[true]{}
\define@key{hv}{xindexOptions}[]{\def\hv@extern@xindexOptions{#1}}
\define@key{hv}{runsequence}[]{\def\hv@extern@runsequence{#1}}
\end{verbatim}

The \Lkeyword{biber} run needs no additional options, but for \Lkeyword{xindex} it maybe useful.
The following examples uses

\begin{verbatim}
\begin{externalDocument}[
  compiler=lualatex, runs=2, pages=2,crop,
  xindex, xindexOptions={-l DE --config AU},
  mpwidth=0.6\linewidth, usefancyvrb=false,
  docType=latex,
  ...
]{voss}
\end{verbatim}




\begin{externalDocument}[
  grfOptions={scale=0.75},
  compiler=lualatex, runs=2,
  BGpreamble=red!10, BOpreamble=red, 
  BGbody=blue!8, BObody=blue,
  code,
  pages=2,
  crop,
  cleanup,
  force=false,
  xindex,
  xindexOptions={-l DE --config AU},
  mpwidth=0.6\linewidth,
  usefancyvrb=false,
  docType=latex]{voss}
\documentclass[paper=a6,DIV=18,parskip=half-]{screxa}
\pagestyle{empty}
\usepackage{libertinus}
\setmonofont{DejaVu Sans Mono}[Scale=MatchLowercase,FakeStretch=0.9]
\usepackage[ngerman]{babel}
\usepackage{multicol}
\makeatletter
\def\theindex{%    only for demonstration
  \newpage
  \section*{\indexname}
  \begin{multicols}{2}
  \parskip\z@ \@plus .3\p@\relax \parindent\z@
  \let\item\@idxitem}
\def\endtheindex{\end{multicols}}
\makeatother
%StartVisiblePreamble
\usepackage{makeidx}\makeindex
\usepackage{hvindex}
%StopVisiblePreamble
\begin{document}
Sort with xindex \verb|-l DE --config AU|
\Index{Österreich} \Index{Öresund} 
\Index{Ostern} \Index{Ober} \Index{Oberin} 
\Index{Österreich} \Index{Öresund} 
\Index{Ödem} \Index{Oligarch} \Index{Oder} 
\Index{Ostern} \Index{Ober} \Index{Oberin} 
\Index{Obstler} \Index{Öl} \Index{ölen} 
\Index{Oder|seealso{Fluss}} \Index{Göbel}
\Index{oder} \index{Fluss!Oder}
\Index{Goethe} \Index{Göthe} \Index{Götz}
\Index{Goldmann}
\printindex
\end{document}
\end{externalDocument}


Instad of using the options \Lkeyword{compiler}, \Lkeyword{biber}, and \Lkeyword{xindex} 
one can also use only the optional argument \Lkeyword{runsequence} to define an individuell
sequence of commands, e.g.:
\begin{verbatim}
runsequence={lualatex,biber,{xindex -l de -c AU},lualatex,lualatex}
\end{verbatim}

\begin{externalDocument}[
  grfOptions={width=0.30\linewidth},
  pages={1,2,3,4,5,6},
  pagesep=2pt,
  frame,
  runsequence={lualatex,biber,xindex -l de -c AU,lualatex,lualatex},
  verbose,
  force=false,
  cleanup={log,aux,toc,bbl,blg},
  code,docType=latex,
  lstOptions={columns=fixed}]{voss}
\documentclass[paper=a5,parskip=half-,DIV=12,fontsize=12pt]{scrbook}
%StartVisiblePreamble
\usepackage[ngerman]{babel}
\usepackage{libertinus,hvindex}
\usepackage{makeidx}\makeindex
\usepackage{biblatex}\addbibresource{biblatex-examples.bib}
%StopVisiblePreamble
\usepackage{blindtext}
\begin{document}
\blindtext
\Index{Österreich} \Index{Öresund} 
\Index{Ostern} \Index{Ober} \Index{Oberin} 
\Index{Österreich} \Index{Öresund} 
\Index{Ödem} \Index{Oligarch} \Index{Oder} 
\Index{Goldmann}
\printindex
\nocite{*}\printbibliography
\blindtext
\blinddocument

\end{document}
\end{externalDocument}






\subsection{Using \texttt{listings}}
The default is using \Lcs{lstinputlisting} for the printed code sequences.

\begin{externalDocument}[
  grfOptions={width=0.45\linewidth},
  pages={1,3},
  frame,compiler=pdflatex,
%  crop,
  force=false,runs=2,code,docType=latex,
  frame,
  lstOptions={columns=fixed}]{voss}
%StartVisiblePreamble
\documentclass[chapterprefix=on,parskip=half-,DIV=12,fontsize=12pt]{scrbook}
\DeclareNewSectionCommand[
  style=section,
  level=4,
  beforeskip=-3.25ex plus -1ex minus -.2ex,
  afterskip=1.5ex plus .2ex,
  font=\normalsize,
  indent=0pt,
  counterwithin=subsubsection
]{subsubsubsection}
\RedeclareSectionCommand[
  level=5,
  toclevel=5,
  tocindent=13em,
  tocnumwidth=5.9em,
  counterwithin=subsubsubsection
]{paragraph}
\RedeclareSectionCommand[
  level=6,
  toclevel=6,
  tocindent=15em,
  tocnumwidth=6.8em
]{subparagraph}
\setcounter{secnumdepth}{\subsubsubsectionnumdepth}
\setcounter{tocdepth}{\subsubsubsectiontocdepth}
%StopVisiblePreamble
\usepackage[ngerman]{babel}
\usepackage{libertinus}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\chapter{Einführung}
\section{Ein Abschnitt}
\subsection{Ein Unterabschnitt}
\subsubsection{Ein Unter-Unterabschnitt}
\subsubsubsection{Ein Unter-Unter-Unterabschnitt}
\paragraph{Der normale Paragraph}
\blindtext
\subparagraph{Der normale Unterparagraph}
\blindtext
\blinddocument
\end{document}
\end{externalDocument}



It also possible to use \Lcs{VerbatimInput} from package \Lpack{fancyvrb}. In general
it makes no difference using the optional argument \Lkeyword{usefancyvrb} or not.


\begin{externalDocument}[
  grfOptions={width=0.23\linewidth},
  pages={1,2,3,4},pagesep=1pt,
  frame,compiler=pdflatex,
  showFilename,
%  crop,
  force=false,runs=2,code,docType=latex,
  frame,framesep=0pt,usefancyvrb]{voss}
%StartVisiblePreamble
\documentclass[chapterprefix=on,parskip=half-,DIV=12,fontsize=12pt]{scrbook}
\DeclareNewSectionCommand[
  style=section,
  level=4,
  beforeskip=-3.25ex plus -1ex minus -.2ex,
  afterskip=1.5ex plus .2ex,
  font=\normalsize,
  indent=0pt,
  counterwithin=subsubsection
]{subsubsubsection}
\RedeclareSectionCommand[
  level=5,
  toclevel=5,
  tocindent=13em,
  tocnumwidth=5.9em,
  counterwithin=subsubsubsection
]{paragraph}
\RedeclareSectionCommand[
  level=6,
  toclevel=6,
  tocindent=15em,
  tocnumwidth=6.8em
]{subparagraph}
\setcounter{secnumdepth}{\subsubsubsectionnumdepth}
\setcounter{tocdepth}{\subsubsubsectiontocdepth}
%StopVisiblePreamble
\usepackage[ngerman]{babel}
\usepackage{libertinus}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\chapter{Einführung}
\section{Ein Abschnitt}
\subsection{Ein Unterabschnitt}
\subsubsection{Ein Unter-Unterabschnitt}
\subsubsubsection{Ein Unter-Unter-Unterabschnitt}
\paragraph{Der normale Paragraph}
\blindtext
\subparagraph{Der normale Unterparagraph}
\blindtext
\blinddocument
\end{document}
\end{externalDocument}


%\clearpage


\subsection{Vertical space}

\begin{verbatim}
\define@key{hv}{aboveskip}[\medskipamount]{%
        \setlength\hv@extern@aboveskip{#1}}
\define@key{hv}{belowpreambleskip}[\smallskipamount]{%
        \setlength\hv@extern@belowpreambleskip{#1}}
\define@key{hv}{belowbodyskip}[\smallskipamount]{%
        \setlength\hv@extern@belowbodyskip{#1}}
\define@key{hv}{belowskip}[\medskipamount]{%
        \setlength\hv@extern@belowskip{#1}}
\end{verbatim}

\begin{description}
\item[\Lkeyword{aboveskip}] Vertical space \emph{before} the environment \Lenv{externalDocument} or
    the command \Lcs{runExtCmd} (default \Lcs{medskipamount})
\item[\Lkeyword{belowpreambleskip}] Vertical  space between preamble and body (default \Lcs{smallskipamount})
\item[\Lkeyword{belowbodyskip}] Vertical space between  body and output (default \Lcs{smallskipamount})
\item[\Lkeyword{belowskip}] Vertical space \emph{after}  the environment \Lenv{externalDocument} or
    the command \Lcs{runExtCmd} (default \Lcs{medskipamount})
\end{description}


\subsection{No output}
By default there is an image or text as output of the external run. In a case, where
you are only interested in the code, which should be formatted in the same style as
other examples, you can set \Lkeyword{showoutput} to false.


\begin{externalDocument}[
  showoutput=false,
  frame,compiler=pdflatex,
  crop,
  force,runs=2,code,docType=latex,
  frame,usefancyvrb]{voss}
%StartVisiblePreamble
\documentclass[chapterprefix=on,parskip=half-,DIV=12,fontsize=12pt]{scrbook}
\DeclareNewSectionCommand[
  style=section,
  level=4,
  beforeskip=-3.25ex plus -1ex minus -.2ex,
  afterskip=1.5ex plus .2ex,
  font=\normalsize,
  indent=0pt,
  counterwithin=subsubsection
]{subsubsubsection}
%StopVisiblePreamble
\RedeclareSectionCommand[
  level=5,
  toclevel=5,
  tocindent=13em,
  tocnumwidth=5.9em,
  counterwithin=subsubsubsection
]{paragraph}
\RedeclareSectionCommand[
  level=6,
  toclevel=6,
  tocindent=15em,
  tocnumwidth=6.8em
]{subparagraph}
\setcounter{secnumdepth}{\subsubsubsectionnumdepth}
\setcounter{tocdepth}{\subsubsubsectiontocdepth}
\usepackage[ngerman]{babel}
\usepackage{libertinus}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\chapter{Einführung}
\section{Ein Abschnitt}
\subsection{Ein Unterabschnitt}
\subsubsection{Ein Unter-Unterabschnitt}
\subsubsubsection{Ein Unter-Unter-Unterabschnitt}
\blindtext
\end{document}
\end{externalDocument}


\clearpage%%%%%%%%%%%%%%

\section{Defining new marker}
Suppose you do not want for a \LaTeX\ document the complete body part between \Lcs{begin}
and \Lcs{end} printed. In this case you can define own markers, e.g.:

\begin{Verbatim}[fontsize=\small,label={New marker definition},fontfamily=tt]
\defMarkerType{ltx}
  {\perCent StartVisibleBody}
  {\perCent StopVisibleBody}     
  {\perCent StartVisiblePreamble}               
  {\perCent StopVisiblePreamble}
\end{Verbatim}

Whith this definition and the setting \Lkeyset{docType=ltx} the last example looks like:


\defMarkerType{ltx}
  {\perCent StartVisibleBody}
  {\perCent StopVisibleBody}     
  {\perCent StartVisiblePreamble}               
  {\perCent StopVisiblePreamble}


\begin{externalDocument}[
  grfOptions={width=\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax},
%  pages={1},
  crop,
%  mpwidth=0.6\linewidth,
  frame,
  compiler=pdflatex,
  showFilename,
  force=false,
  runs=2,code,docType=ltx,
  usefancyvrb]{voss}
\documentclass[chapterprefix=on,parskip=half-,DIV=12,fontsize=12pt]{scrreprt}
%StartVisiblePreamble
\DeclareNewSectionCommand[
  style=section,
  level=4,
  beforeskip=-3.25ex plus -1ex minus -.2ex,
  afterskip=1.5ex plus .2ex,
  font=\normalsize,
  indent=0pt,
  counterwithin=subsubsection
]{subsubsubsection}
%StopVisiblePreamble
\RedeclareSectionCommand[
  level=5,
  toclevel=5,
  tocindent=13em,
  tocnumwidth=5.9em,
  counterwithin=subsubsubsection
]{paragraph}
\RedeclareSectionCommand[
  level=6,
  toclevel=6,
  tocindent=15em,
  tocnumwidth=6.8em
]{subparagraph}
\setcounter{secnumdepth}{\subsubsubsectionnumdepth}
\setcounter{tocdepth}{\subsubsubsectiontocdepth}
\usepackage[ngerman]{babel}
\usepackage{libertinus}
\usepackage{blindtext}
\makeatletter\let\ps@plain\ps@empty\makeatother
\begin{document}
\tableofcontents
\chapter{Einführung}
\section{Ein Abschnitt}
\subsection{Ein Unterabschnitt}
\subsubsection{Ein Unter-Unterabschnitt}
%StartVisibleBody
\subsubsubsection{Ein Unter-Unter-Unterabschnitt}
%StopVisibleBody
\blindtext
\end{document}
\end{externalDocument}




\section{Supported engines}
\subsection{\MP\ example}

Needs the run sequence setting to get a \texttt{pdf} from the created \texttt{dvi} output.
It is already internally defined. 

\begin{externalDocument}[
%  grfOptions={width=0.45\linewidth},
%  pages={1,3},
  frame,
  verbose=false,
  compiler=mpost,
  showFilename,
%  crop,
  force=false,
  cleanup,
  code,
  docType=mp,
  ext=mp,]{voss}
%StartVisiblePreamble
defaultfont:="ptmr8r";
warningcheck:=0;
%StopVisiblePreamble
beginfig(1)
draw fullcircle shifted (0.5,0.6) xscaled 8cm yscaled 3.5cm 
  withpen pencircle scaled 5bp withcolor red;
special( " /Times-Roman findfont 150 scalefont setfont " &
  " 0 10 moveto (MPost) false charpath clip stroke gsave 150 70 translate " &
  " 2 4 600 {dup 0 moveto 0 exch 0 exch 0 360 arc stroke} for grestore ");
endfig;
end;
\end{externalDocument}




\subsection{plain\TeX\ example}

Needs the run sequence setting to get a \texttt{pdf} from the created \texttt{dvi} output.
It is already internally defined. 


\begin{externalDocument}[
  grfOptions={width=0.5\linewidth},
%  pages={1,3},
  frame,
  verbose=false,
  compiler=tex,
  showFilename,
%  crop,
  force=false,
  code,
  docType=tex,
  ext=tex,]{voss}
\magnification=\magstep1
\baselineskip=12pt
\hsize=6.3truein
\vsize=8.7truein
\font\footsc=cmcsc10 at 8truept
\font\footbf=cmbx10 at 8truept
\font\footrm=cmr10 at 10truept
%StartVisiblePreamble
\footline={\footsc the electronic journal of combinatorics
   {\footbf 16} (2009), \#R00\hfil\footrm\folio}
%StopVisiblePreamble
%StartBody
\font\bigrm=cmr12 at 14pt
\centerline{\bigrm An elementary proof of the reconstruction conjecture}

\bigskip\bigskip
\centerline{D. Remifa\footnote*{Thanks to the editors of this journal!}}
\smallskip
\centerline{Department of Inconsequential Studies}
\centerline{Solatido College, North Kentucky, USA}
\centerline{\tt remifa@dis.solatido.edu}
\bigskip
\centerline{\footrm 
Submitted: Jan 1, 2009; Accepted: Jan 2, 2009; Published: Jan 3, 2009}
\centerline{\footrm Mathematics Subject Classifications: 05C88, 05C89}
\bigskip\bigskip
\centerline{\bf Abstract}
\smallskip
{\narrower\noindent
The reconstruction conjecture states that the multiset of unlabeled
vertex-deleted subgraphs of a graph determines the graph, provided it
has at least 3 vertices.  A version of the problem was first stated
by Stanis\l aw Ulam.  In this paper, we show that the conjecture can
be proved by elementary methods.  It is only necessary to integrate
the Lenkle potential of the Broglington manifold over the quantum
supervacillatory measure in order to reduce the set of possible
counterexamples to a small number (less than a trillion).  A simple
computer program that implements Pipletti's classification theorem
for torsion-free Aramaic groups with simplectic socles can then
finish the remaining cases.}

\bigskip
\beginsection 1. Introduction.

This is the start of the introduction.
\bye
\end{externalDocument}



\subsection{\LuaLaTeX\ example}
With Lua\LaTeX\ and and using PostScript code the intermediate GhostScript run is
not needed. The \texttt{pdf} is directly created.

\begin{externalDocument}[
  grfOptions={width=0.5\linewidth},
%  pages={1,3},
%  frame,
  verbose=false,
  compiler=lualatex,
  showFilename,
  crop,
  force=false,
  code,
  docType=latex,
  ext=tex,]{voss}
\documentclass{report}
\pagestyle{empty}
%StartVisiblePreamble
\usepackage{fontenc}\usepackage{libertinus}
\usepackage{pst-all}
%StopVisiblePreamble
\begin{document}
\psset{unit=0.8cm}
\begin{pspicture}(-9,-15)(9,2)
\psaxes(0,0)(-9,-15)(9,2)
\psplot[algebraic,plotstyle=curve,curvature=1 1 0, 
  linewidth=2pt,linecolor=red]{-8}{8}{
  1 - 3876218985722260225*x^2/10892114744073986176 
    + 14975974793271450625*x^4/174273835905183778816 
    - 317095420958296875*x^6/26811359370028273664 
    + 194412970920703125*x^8/214490874960226189312 
    - 2090988251953125*x^10/53622718740056547328 
    + 99480224609375*x^12/107245437480113094656 
    - 7879638671875*x^14/697095343620735115264 
    + 152587890625*x^16/2788381374482940461056}
\end{pspicture}
\end{document}
\end{externalDocument}


\subsection{\ConTeXt\ example}


\begin{externalDocument}[
  grfOptions={width=0.31\linewidth},
  pages={1,2,3,4,5,6},
  pagesep=2pt,
  frame,
  framesep=0pt,
  verbose=false,
  compiler=context,
  showFilename,
  runs=2,
  force=false, 
  code,
  docType=context,
  ext=tex,]{voss}
%StartVisiblePreamble
\definehead
  [myhead]
  [section]
\setuphead
  [myhead]
  [numberstyle=bold,
   textstyle=bold,
   before=\hairline\blank,
   after=\nowhitespace\hairline]
%StopVisiblePreamble
\starttext
\startstandardmakeup
\midaligned{From Hasselt to America}
\midaligned{by}
\midaligned{J. Jonker and C. van Marle}
\stopstandardmakeup
\placecombinedlist[content]
\chapter{Introduction}
\input knuth \input knuth 
\chapter[rensselaer]{The Rensselaer family}
\input knuth
\section{The first born}
\input knuth 
\section{The early years}
... in those days Hasselt was ...
\input knuth
\section{Living and workin in America}
\input knuth
\chapter[lansing]{The Lansing family}
... the Lansing family was also ...
\input knuth
\chapter[cuyler]{The Cuyler family}
... much later Tydeman Cuyler ...
\input knuth
\myhead[headlines]{And the end}
foo
\stoptext
\end{externalDocument}


\addtocontents{toc}{\protect\newpage}


\section{Running external commands}
Integrating the current directory of this document we can use the macro \Lcs{runExtCmd} with
the optional argument \Lkeyword{redirect}

\begin{verbatim}
\runExtCmd[redirect]{ls -la}{voss}
\end{verbatim}

to get the directory listed:

\medskip
\runExtCmd[redirect,verbose]{ls -la}{voss}


\section{Other options}

\begin{description}
%\item[\Lkeyword{showFilename}] Prints the filename in the outer margin (right for oneside) or in twocolumn mode for
%    the first column in the left and the second column in the right margin.
%\item[\Lkeyword{outerFN}] Only valid for the twocolumn mode with onecolumn floats (environment \texttt{figure*}),
%    to get the filename on the right or left of the whole page.
%\item[\Lkeyword{shiftFN}] A length to move the printed filename up or down.
\item[\Lkeyset{force=false}] can speed up the comiling time for the document. If a created image/output
already exists, there is no need to create it with the next run again and again.
\item[\Lkeyword{cleanup}] the auxiliary files of a \LaTeX-run are deleted, preset to \texttt{aux}, \texttt{log}.
   It must be a comma seperated list of the extensions of the main file, s.g. \texttt{cleanup=\{aux,log\}}.
\item[\Lkeyword{copyToExampleDir}] name of a directory for the examples, must first be created by the user himself
\item[\Lkeyword{ExamplesDir}] move all examples into a directory
\item[\Lkeyset{tclbox=false}] Can be used if there are some negative interactions between package \Lpack{listings}
   and package \Lpack{tcolorbox}.
\item[\Lkeyword{framesep}] Value for \Lcs{fbox} if keyword \texttt{frame} is used.
\item[\Lkeyword{mpsep}] Distance between code and output (default 1\,em).
\item[\Lkeyword{pagesep}] Distance between pages for multipage output (default 1\,em).
\item[\Lkeyword{verbose}] Print control messages into the terminal and logfile.
\item[\Lkeyword{eps}] create an eps from the pdf (historical).
\end{description}


\printindex


\end{document}