summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/support/ltximg/ltximg-doc.dtx
blob: b703faf7ec569acdfce281e67215c37dca8dd9c7 (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
% arara: xelatex
% arara: xelatex
% arara: clean: { extensions: [ aux, log, out, ilg, ind, idx, toc, hd ] }
% \iffalse meta-comment
%<*internal>
\iffalse
%</internal>
%<*readme>
## LTXimg &ndash; LaTeX environments to image format

## Description

**ltximg** is a perl *script* that automates the process of extracting and converting
environments provided by **tikz**, **pstricks** and other packages from input file
to image formats in individual files using `ghostscript` and `poppler-utils`. Generates a file
with only extracted environments and other with environments converted to `\includegraphics`.

## Syntax
```bash
$ ltximg [<compiler>] [<options>] [--] <input file>.<tex|ltx>
```
## Usage
```bash
$ ltximg --latex  [<options>] <file.tex>
$ ltximg --arara  [<options>] <file.tex>
$ ltximg [<options>] <file.tex>
$ ltximg <file.tex>
```
If used without `[<compiler>]` and `[<options>]` the extracted environments are converted to `pdf` image format
and saved in the `/images` directory using `pdflatex` and `preview` package. Relative or absolute `paths` for files
and directories is not supported. If the last `[<options>]` take a *list separated by commas*, you need `--` at the end.

## Default environments extract
```bash
    pspicture    tikzpicture    pgfpicture    psgraph    postscript    PSTexample
```
## Options

```bash
                                                                    [default]
-h, --help            Display command line help and exit            [off]
-l, --license         Display GPL license and exit                  [off]
-v, --version         Display current version (1.7) and exit        [off]
-t, --tif             Create .tif files using ghostscript           [gs]
-b, --bmp             Create .bmp files using ghostscript           [gs]
-j, --jpg             Create .jpg files using ghostscript           [gs]
-p, --png             Create .png files using ghostscript           [gs]
-e, --eps             Create .eps files using poppler-utils         [pdftops]
-s, --svg             Create .svg files using poppler-utils         [pdftocairo]
-P, --ppm             Create .ppm files using poppler-utils         [pdftoppm]
-g, --gray            Gray scale for images using ghostscript       [off]
-f, --force           Capture "\psset" and "\tikzset" to extract    [off]
-n, --noprew          Create images files whitout "preview" package [off]
-d <integer>, --dpi <integer>
                      Dots per inch resolution for images           [150]
-m <integer>, --margin <integer>
                      Set margins for pdfcrop                       [0]
--imgdir <dirname>    Set name of directory to save images          [images]
--zip                 Compress files generated in .zip format       [off]
--tar                 Compress files generated in .tar.gz format    [off]
-o <filename>, --output <filename>
                      Create output file                            [off]
--verbose             Verbose printing                              [off]
--srcenv              Create files whit only code environment       [off]
--subenv              Create files whit preamble and code           [off]
--latex               Using latex>dvips>ps2pdf for compiler input
                      and pdflatex for compiler output              [off]
--dvips               Using latex>dvips>ps2pdf for compiler input
                      and latex>dvips>ps2pdf for compiler output    [off]
--arara               Use arara for compiler input and output       [off]
--xetex               Using xelatex for compiler input and output   [off]
--dvipdf              Using dvipdfmx for compiler input and output  [off]
--luatex              Using lualatex for compiler input and output  [off]
--prefix <string>     Set prefix append to each image file          [off]
--norun               Run script, but no create images files        [off]
--nopdf               Don't create a ".pdf" image files             [off]
--nocrop              Don't run pdfcrop                             [off]
--verbcmd <cmdname>   Set "\cmdname" verbatim command               [myverb]
--clean (doc|pst|tkz|all|off)
                      Removes specific text in output file          [doc]
--extrenv <env1,...>  Add new environments to extract               [empty]
--skipenv <env1,...>  Skip environments to extract                  [empty]
--verbenv <env1,...>  Add verbatim environments                     [empty]
--writenv <env1,...>  Add verbatim write environments               [empty]
--deltenv <env1,...>  Delete environments in output file            [empty]
```
## Example
```bash
$ ltximg --latex -e -p --srcenv --imgdir=mypics -o test-out test-in.ltx
```
```bash
$ ltximg --latex -ep --srcenv --imgdir mypics -o test-out  test-in.ltx
```
   Create a `/mypics` directory whit all extracted environments converted to
   image formats (`.pdf`, `.eps`, `.png`), individual files whit source code (`.tex`)
   for all extracted environments, a file `test-out.ltx` whit all environments converted to `\includegraphics`
   and file `test-in-fig-all.tex` with only the extracted environments using
   `latex>dvips>ps2pdf` and `preview` package for `<input file>` and `pdflatex`
   for `<output file>`.

## Documentation
   For full documentation use:
```bash
$ texdoc ltximg
```
   For recreation all documentation use:
```bash
$ arara ltximg-doc.dtx
```

## Licence
This program is free software; you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.

## Author

Written by Pablo González L <pablgonz@yahoo.com>, last update 2019-08-24.

## Copyright

Copyright 2013 - 2019 by Pablo González L
%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*internal>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\nopreamble\nopostamble
\generate{
  \file{README.md}{\from{\jobname.dtx}{readme}}
}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
%<*documentation>
\documentclass{ltxdoc}
\usepackage[top=0.5in, bottom=0.5in, left=2in, right=1in,footskip=0.2in,%
            headsep=10pt]{geometry} % page dimension
\usepackage{unicode-math} %
\setmathfont[Scale = 0.95]{Latin Modern Math}
\setmainfont[
   Numbers           = OldStyle,
   Ligatures         = TeX,
   Scale             = 0.95,
   UprightFont       = *-Regular,
   ItalicFont        = *-Italic,
   BoldFont          = *-Bold,
   BoldItalicFont    = *-BoldItalic,
   SmallCapsFeatures = {Letters=SmallCaps},
   Extension =.otf]{LibertinusSerif}
\setsansfont[
   Numbers           = OldStyle,
   Ligatures         = TeX,
   Scale             = 0.95,
   UprightFont       = *-Regular,
   ItalicFont        = *-Italic,
   BoldFont          = *-Bold,
   SmallCapsFeatures = {Letters=SmallCaps},
   Extension = .otf]{LibertinusSans}
\setmonofont[
   Scale             = 0.80,
   Extension         = .otf,
   UprightFont       = *-Regular ,
   ItalicFont        = *-RegularIt,
   BoldFont          = *-Medium ,
   BoldItalicFont    = *-MediumIt
            ]{SourceCodePro} % source code font
\newfontfamily\lmmitalic{lmmono10-italic.otf}[
   Scale             = 0.95,%
   Extension         = .otf,%
   ItalicFont        = lmmono10-italic,%
   SmallCapsFont     = lmmonocaps10-oblique,%
   SlantedFont       = lmmonoslant10-regular,
   ]
\newfontfamily\fetamono{ffmw10.otf}[
   Scale             = 0.95,%
   RawFeature        ={+latn,+rand,+kern,+size},%
   ]
\newfontfamily\libertinusinitials{LibertinusSerifInitials-Regular.otf}
\usepackage{microtype,hologo} % LaTeX logo
\usepackage{enumitem,lastpage,microtype,titletoc} % custom
\usepackage[svgnames]{xcolor} %
\usepackage[sf,bf,compact,medium,pagestyles]{titlesec}
\usepackage{adjustbox,multicol,hyperref,xparse,listings,accsupp}
\usepackage{hyperxmp,imakeidx}%
\PageIndex
\EnableCrossrefs
\newcommand{\HP}[1]{\emph{\hyperpage{#1}}\normalsize}
\def\SortIndex#1#2{\index{#1\actualchar#2|HP}}
\indexsetup{level=\section,firstpagestyle=myheader}
%\makeindex[name=mydoc,options=-s gind.ist,columnsep=15pt,title={Index of Documentation}]
\makeindex[options=-s gind.ist,columnsep=15pt,title={Index of Documentation}]
% don't copy numbers in code example
\newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}

% parindent
\setlength{\parindent}{0pt}

% Colors for options
\definecolor{optcolor}{rgb}{0.281,0.275,0.485}

% Identification
\def\myscript{ltximg}
\def\fileversion{1.7}
\def\filedate{2019-08-24}

% Logo whit libertuns and fetamono font
\newsavebox{\logobox}
\savebox{\logobox}{%
    \normalsize%
    {\libertinusinitials%
     \textcolor{red}{L}\hspace{-3.0pt}%
     \raisebox{-0.2em}{\small \textcolor{green}{T}}%
     \hspace{-2.9pt}\textcolor{blue}{X}}%
     \hspace{-1pt}\fetamono{\textcolor{gray}{img}}%
}%
\makeatletter
\newcommand{\LTXimg}{%
  \settoheight{\@tempdima}{L}%
  \resizebox{!}{\@tempdima}{\usebox{\logobox}}%
}
\makeatother

% email https://tex.stackexchange.com/a/663
\catcode`\_=11\relax%
\newcommand\email[1]{\_email #1\q_nil}%
\def\_email#1@#2\q_nil{%
  \href{mailto:#1@#2}{{\emailfont #1\emailampersat #2}}%
}%
\newcommand\emailfont{\sffamily}%
\newcommand\emailampersat{{\color{NavyBlue}\footnotesize@}}%
\catcode`\_=8\relax% %

% Config hyperref
\hypersetup{
  linkcolor          = blue!50,
  citecolor          = red!50,%
  urlcolor           = magenta,%
  colorlinks         = true,%
  pdftitle           = {.:: ltximg \fileversion{} (\filedate) --- LaTeX environments to image formats ::.},%
  pdfauthor          = {Pablo Gonz\'{a}lez Luengo},%
  pdfsubject         = {Documentation for version \fileversion},%
  pdfcopyright       = {\textcopyright 2019 by Pablo González Luengo},
  pdfcontacturl      = {https://github.com/pablgonz/ltximg},
  pdfkeywords        = {extract, conversion, images, tikz, pstricks},
  pdfstartview       = {FitH},%
  bookmarksopenlevel = 2,%
}

% Configuration titleps
\settitlemarks{section}
\renewpagestyle{plain}[\color{gray}\small\sffamily]{
\setfoot{}{}{\thepage/\pageref{LastPage}}}

\newpagestyle{myheader}[\color{gray}\small\sffamily]{
\renewcommand\makeheadrule{\color{gray}\rule[0.45\baselineskip]{\linewidth}{0.4pt}}
\setfoot{\scalebox{0.85}{\LTXimg}\space\textcopyright\space 2019 by Pablo González L}
        {}
        {\thepage/\pageref{LastPage}}
\sethead{\raisebox{0.75\baselineskip}{Documentation for version \fileversion\space[\filedate]}}
        {}
        {\raisebox{0.75\baselineskip}{\scshape\small\S.\thesection\space\sectiontitle}}
}
\setlength{\headheight}{21pt}%

% Table of contents
\titlecontents{section}[0mm]{}%
    {\bfseries\contentspush{\makebox[4mm][l]{\thecontentslabel\hfill}}}%
    {\hspace*{-4mm}}% numberless
    {\hspace{0.25em}\titlerule*[6pt]{.}\contentspage}%

\titlecontents{subsection}[4mm]{}%
    {\contentspush{\makebox[6mm][l]{\thecontentslabel\hfill}}}
    {\hspace*{-10mm}}% numberless
    {\hspace{0.25em}\titlerule*[6pt]{.}\contentspage}%

\titlecontents{subsubsection}[10mm]{}%
    {\contentspush{\makebox[8mm][l]{\thecontentslabel\hfill}}}
    {\hspace*{-18mm}}% numberless
    {\hspace{0.25em}\titlerule*[6pt]{.}\contentspage}%

\makeatletter
\renewcommand\tableofcontents{%
\begingroup%
\section*{\contentsname\quad{\color{gray}\leaders\hrule height 5pt depth -4.4pt\hfill}%
  \@mkboth{%
    \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
\vspace*{-14pt}
\setlength{\columnsep}{10pt}%
 \begin{multicols}{2}%
    \@starttoc{toc}%
\end{multicols}%
\vspace*{-3pt}{\color{gray}\hrule height 0.6pt}%
\vspace*{5pt}
\endgroup
}
\makeatother

% Custom \meta[...]{...}, \marg[...]{...} and \oarg[...]{...} for color
\ExplSyntaxOn
%^^A user level commands
\RenewDocumentCommand{\meta}{O{}m}
  {
   \ltximg_meta_generic:Nnn \ltximg_meta:n { #1 } { #2 }
  }
\RenewDocumentCommand{\marg}{O{}m}
  {
   \ltximg_meta_generic:Nnn \ltximg_marg:n { #1 } { #2 }
  }
\RenewDocumentCommand{\oarg}{O{}m}
  {
   \ltximg_meta_generic:Nnn \ltximg_oarg:n { #1 } { #2 }
  }
%^^A variables and keys
\tl_new:N \l_ltximg_meta_font_tl

\keys_define:nn { ltximg/meta }
  {
   type .choice:,
   type / tt .code:n = \tl_set:Nn \l_ltximg_meta_font_tl { \ttfamily },
   type / rm .code:n = \tl_set:Nn \l_ltximg_meta_font_tl { \rmfamily },
   type .initial:n = tt,
   cf .tl_set:N = \l_ltximg_meta_color_tl,
   cf .initial:n = black,
   ac .tl_set:N = \l_ltximg_meta_anglecolor_tl,
   ac .initial:n = black,
   sbc .tl_set:N = \l_ltximg_meta_brackcolor_tl,
   sbc .initial:n = black,
   cbc .tl_set:N = \l_ltximg_meta_bracecolor_tl,
   cbc .initial:n = black,
  }
%^^A internal commands
\cs_new_protected:Npn \ltximg_meta_generic:Nnn #1 #2 #3
  {
   \group_begin:
    \keys_set:nn { ltximg/meta } { #2 }
    \color{ \l_ltximg_meta_color_tl }
    \l_ltximg_meta_font_tl
    #1 { #3 } % #1 is \ltximg_meta:n, \ltximg_marg:n or \ltximg_oarg:n
   \group_end:
  }
\cs_new_protected:Npn \ltximg_meta:n #1
  {
   \ltximg_meta_angle:n { \textlangle }
   \ltximg_meta_meta:n { #1 }
   \ltximg_meta_angle:n { \textrangle }
  }
\cs_new_protected:Npn \ltximg_marg:n #1
  {
   \ltximg_meta_brace:n { \textbraceleft }
   \ltximg_meta:n { #1 }
   \ltximg_meta_brace:n { \textbraceright }
  }
\cs_new_protected:Npn \ltximg_oarg:n #1
  {
   \ltximg_meta_brack:n { [ }
   \ltximg_meta:n { #1 }
   \ltximg_meta_brack:n { ] }
  }
\cs_new_protected:Npn \ltximg_meta_meta:n #1
  {
   \textnormal{\textit{#1}}
  }
\cs_new_protected:Npn \ltximg_meta_angle:n #1
  {
   \group_begin:
    \fontfamily{cmr}\selectfont
    \textcolor{\l_ltximg_meta_anglecolor_tl}{#1}
   \group_end:
  }
\cs_new_protected:Npn \ltximg_meta_brace:n #1
  {
   \group_begin:
    \color{\l_ltximg_meta_bracecolor_tl}
    #1
   \group_end:
  }
\cs_new_protected:Npn \ltximg_meta_brack:n #1
  {
   \textcolor{\l_ltximg_meta_brackcolor_tl}{#1}
  }

% \ltximg for body document
\DeclareDocumentCommand{\ltximg}{}
  {
   \normalsize\texttt{\bfseries\textcolor{NavyBlue}{ltximg}}
  }

% \prgname{sm} : #1 index compiler, #2 index programs:
\DeclareDocumentCommand{\prgname}{sm}
  {%
    \IfBooleanTF{#1}
     {
       \textcolor{ForestGreen}{\ttfamily\bfseries{#2}}
       \SortIndex{compiler}{Compiler>\small\texttt{#2}}
     }
     {
       \textcolor{ForestGreen}{\ttfamily\bfseries{#2}}
       \SortIndex{programs}{Programs>\small\texttt{#2}}
     }
  }%

% \prgopt{sm} : #1 compiler opt, #2 program opt:
\DeclareDocumentCommand{\prgopt}{sm}
  {%
    \IfBooleanTF{#1}
      {
        \textcolor{gray}{\ttfamily\bfseries{-{}#2}}
        \SortIndex{compiler  ~ options}{Compiler  ~ options>\small\texttt{-{}#2}}%
      }
      {
        \mbox{\texttt{-{}#2}}%
        \SortIndex{#2}{\small\texttt{-{}#2} (program ~ option)}%
      }
  }

% \scriptname*{m}
\DeclareDocumentCommand{\scriptname}{m}
  {
    \textcolor{ForestGreen}{\ttfamily\bfseries{#1}}
    \SortIndex{scripts}{Scripts>\small\texttt{#1}}%
  }

% \scriptopt{m}
\DeclareDocumentCommand{\scriptopt}{m}
  {
    \mbox{\texttt{#1}}
    \SortIndex{script ~ option}{Script ~ options>\small\texttt{#1}}%
  }

% \pkgname{m}
\DeclareDocumentCommand{\pkgname}{ m }
  {
    \textsf{\textcolor{SlateBlue}{#1}}
    \SortIndex{packages}{Packages>\small\texttt{#1}}
    \SortIndex{#1}{\texttt{#1} ~ (package)}
  }%

% \pkgopt{m}
\DeclareDocumentCommand{\pkgopt}{ m }
  {
    \textsf{\textcolor{Orange}{#1}}
    \SortIndex{package ~  options}{Package ~  options>\small\texttt{#1}}
    \SortIndex{#1}{\texttt{#1} (package  ~ option)}
  }

% \env{sm}, #1 not used now
\DeclareDocumentCommand{\env}{m}
  {
    \textcolor{optcolor}{\texttt{#1}}%
    \SortIndex{environment}{Environments>\small\texttt{#1}}%
  }

% \ics{sm}, #1 not used now
\DeclareDocumentCommand{\ics}{sm}
  {
    \textcolor{optcolor}{\ttfamily{\textbackslash#2}}%
    \SortIndex{#2}{\texttt{\small\textbackslash#2}}
  }

% file extention
\DeclareDocumentCommand{\fext}{m}
  {
    \mbox{\textcolor{optcolor}{\ttfamily\bfseries{.#1}}}%
    \SortIndex{files  ~ extention}{File  ~ extentions >\small\texttt{.#1}}%
  }

% image format/extention
\DeclareDocumentCommand{\iext}{m}
  {%
    \textcolor{optcolor}{\ttfamily\bfseries{#1}}%
    \SortIndex{Image format}{Image formats>\small\texttt{#1}}%
  }

% \sysydir{m}
\DeclareDocumentCommand{\sysdir}{m}
  {
    \mbox{\textcolor{NavyBlue}{\ttfamily{/#1}}}%
  }

% \sysfile{m} ...only for color in some examples
\DeclareDocumentCommand{\sysfile}{m}
  {
    \mbox{\textcolor{gray}{\ttfamily{#1}}}
  }

% \OSsystem{m} ...only for color in some examples
\DeclareDocumentCommand{\OSsystem}{m}
  {
    \mbox{\textcolor{NavyBlue}{\ttfamily\bfseries{#1}}}%
    \SortIndex{Operating ~ system}{Operating ~ system>\small\texttt{#1}}
  }

% \cmdopt[short]{long}
\DeclareDocumentCommand{\cmdopt}{om}
  {
    \IfNoValueTF{#1}
      {
        \textcolor{optcolor}{\ttfamily\bfseries{-\/-#2}}
      }
      {
        \textcolor{optcolor}{\ttfamily\bfseries{-{}#1}},
        \textcolor{optcolor}{\ttfamily\bfseries{-\/-#2}}
      }
    \SortIndex{options}{\textsf{\myscript}\ options ~ in ~ command ~ line>\small\texttt{-\/-#2}}%
  }

\ExplSyntaxOff
% \DescribeIF{m}, #1 image format
\newsavebox{\marginIF}
\NewDocumentCommand{\DescribeIF}{ m }
  {%
    \begin{lrbox}{\marginIF}%
      \begin{minipage}[t]{\marginparwidth}%
        \raggedleft
        \iext{#1}
      \end{minipage}%
    \end{lrbox}%
      \leavevmode%
      \marginpar{\usebox{\marginIF}}%
      \ignorespaces%
  }%

% \myenv{environ}
\DeclareDocumentCommand\myenv{m}
  {
    \moveright 0.0pt \hbox{%
    \begin{minipage}[t]{\marginparwidth}%
        \raggedleft\ttfamily%\small%
        {\textcolor{gray}{\textbackslash begin\{}}{\bfseries\textcolor{optcolor}{#1}}\textcolor{gray}{\}}\par%
        \meta[ac=gray,cf=gray]{env content}\par%
        {\textcolor{gray}{\textbackslash end\{}}{\bfseries\textcolor{optcolor}{#1}}\textcolor{gray}{\}}%
    \end{minipage}%
                    } % close hbox
    \SortIndex{Environment}{Environments suport by default>\small\texttt{#1}}%
  }

% \mytag{dtxtag}
\DeclareDocumentCommand\mytag{m}{%
\moveright 0.0pt \hbox{%
    \begin{minipage}[t]{\marginparwidth}%
        \raggedleft\ttfamily%\small%
        \textcolor{gray}{\%<*}{\bfseries\textcolor{optcolor}{#1}}\textcolor{gray}{>}\par%
        \meta[ac=gray,cf=gray]{content}\par%
        \textcolor{gray}{\%</}{\bfseries\textcolor{optcolor}{#1}}\textcolor{gray}{>}%
    \end{minipage}%
                    } % close hbox
    \SortIndex{docstrip}{Docstrip tag>\small\texttt{#1}}%
}%

% \DescribeTE{sm}, #1 tag, #2 env
\newsavebox{\marginenvtag}
\NewDocumentCommand\DescribeTE{sm}{%
\begin{lrbox}{\marginenvtag}%
   \begin{minipage}[t]{\marginparwidth}%
    \raggedleft
    \IfBooleanTF{#1}{\mytag{#2}}{\myenv{#2}}
    \end{minipage}%
\end{lrbox}%
    \leavevmode%
    \marginpar{\usebox{\marginenvtag}}%
    \ignorespaces%
}%

% DescribeOptFile*{options}{example}[!]
\newsavebox{\optinfile}
\NewDocumentCommand\DescribeOptFile{s m m O{\hphantom{!}}}{
\begin{lrbox}{\optinfile}%
   \begin{minipage}[t]{\marginparwidth}%
        \raggedleft\ttfamily\bfseries%
        \textcolor{optcolor}{\%{#4}\myscript\hspace*{1.5pt}}%
    \end{minipage}%
\end{lrbox}%
\leavevmode%
\marginpar{\usebox{\optinfile}}%
\lapbox[0pt]{-0.85\marginparsep}{\textcolor{red}{\texttt{:}}}%
\textcolor{optcolor}{\bfseries\texttt{{#2}}}%
\textcolor{red}{\hspace*{2.5pt}\texttt{:}}
\hspace*{-1pt}\marg[cbc=optcolor,ac=gray,cf=gray]{#3}
\vspace*{2pt}\par%
\IfNoValueTF{#1}
{}%%
{%
\SortIndex{options}{\textsf{\myscript}\ options in input file>\small\texttt{#2}}%
}%
}

% \DescribeCmd[...]{...}{...}{...}, need changue to \DescribeOptCmd
\newsavebox{\optcmdline}
\NewDocumentCommand\DescribeCmd{ommm}{
\begin{lrbox}{\optcmdline}%
   \begin{minipage}[t]{\marginparwidth}%
    \ttfamily\bfseries\raggedleft%
    \IfNoValueTF{#1}
    {\textcolor{optcolor}{-\/-#2}}
    {\textcolor{optcolor}{-{#1}}\textcolor{gray}{,} \textcolor{optcolor}{-\/-#2}}%
    \end{minipage}%
\SortIndex{options}{\textsf{\myscript}\ options in command line>\small\texttt{-\/-#2}}%
\end{lrbox}%
    \leavevmode%
    \marginpar{\usebox{\optcmdline}}%
    \ignorespaces
    \meta[ac=gray,cf=gray]{\textnormal{\sffamily{#3}}}
    \hfill\textcolor{gray}{\textsf{(default: {#4})}}%
    \vspace*{2pt}\par%
}

% Create a language for documentation
\lstdefinelanguage{ltximg-doc}{
    texcsstyle=*,%
    escapechar=`,%
    showstringspaces=false,%
    extendedchars=true, %
    stringstyle = {\color{red}},%
% comments
    morecomment=[l]{\%},%
    commentstyle=\lmmitalic\color{lightgray},%
% Important words 1
    keywordstyle=[1]{\color{NavyBlue}},%
    keywords=[1]{AtBeginDocument,begin,end,documentclass,BEGIN,END},%
% Other words 2
    keywordstyle=[2]{\color{blue!75}},%
    keywords=[2]{usepackage,graphicspath,RequirePackage,renewcommand,%
    PreviewBbAdjust,usetikzlibrary,tikzexternalize,psset,tikzset,PrependGraphicsExtensions,%
    DefineShortVerb,lstMakeShortInline,MakeSpecialShortVerb,UndefineShortVerb},%
% Other words 3
    keywordstyle=[3]{\color{optcolor!85}},%
    keywords=[3]{document,graphicx,preview,active,tightpage,article,grfext,description,filecontents,%
    external,tikz,clean,pst,tkz,eps,pdf,xetex,latex,luatex,dvips,png,srcenv,noprew,imgdir,prefix,output},%
% Reserved words 4(inputfile options)
    keywordstyle=[4]{\color{optcolor}},%
    keywords=[4]{ltximg,noltximg,remove,options,pspicture,endpspicture,%
    PSTexample,pgfpicture, endpgfpicture, tikzpicture, endtikzpicture, %
    psgraph, endpsgraph,nopreview,postscript, arara,extrenv,deltenv,skipenv},%
% Reserved in orange
    keywordstyle=[5]{\color{OrangeRed}},%
    keywords=[5]{images,includegraphics,env,file-out,pics,doc},%
% Reserved in orange
    keywordstyle=[6]{\color{red}},%
    keywords=[6]{verb,myverb},%
}[keywords,tex,comments,strings]% end languaje

% \begin{examplecode}[optlst]...\end{examplecode}
\lstnewenvironment{examplecode}[1][]{%
\lstset{
    language=ltximg-doc,%
    stringstyle = {\color{red}},%
    basicstyle=\ttfamily\small,%
    numbersep=1em,%
    numberstyle=\tiny\color{gray}\noaccsupp,%
    rulecolor=\color{gray!50},%
    framesep=\fboxsep,%
    framerule=\fboxrule,%
    xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,%
    xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,%
% literateee
    literate=*{\{}{{\bfseries\textcolor{gray}{\{}}}{1}
              {\}}{{\bfseries\textcolor{gray}{\}}}}{1}
              {[}{{\bfseries\textcolor{optcolor}{[}}}{1}
              {]}{{\bfseries\textcolor{optcolor}{]}}}{1}
              {*}{{\bfseries\textcolor{red}{*}}}{1}
              {:}{{\textcolor{red}{:}}}{1}
              {,}{{\textcolor{gray}{,}}}{1}
              {=}{{\textcolor{gray}{=}}}{1}
              {/}{{\textcolor{gray}{/}}}{1}
              {\%\ ltximg}{{\textcolor{gray}{\%}\space\bfseries\textcolor{optcolor}{ltximg}}}{8}
              {\%\ arara}{{\textcolor{gray}{\%}\space\bfseries\textcolor{optcolor}{arara}}}{7}
              {\{arara}{{\textcolor{gray}{\{arara}}}{6}
              {\%<*remove>}{{\bfseries\textcolor{gray}{\%<*remove>}}}{10}
              {\%</remove>}{{\bfseries\textcolor{gray}{\%</remove>}}}{10}
              {\%<*ltximg>}{{\bfseries\textcolor{gray}{\%<*ltximg>}}}{10}
              {\%</ltximg>}{{\bfseries\textcolor{gray}{\%</ltximg>}}}{10}
              {\%<*noltximg>}{{\bfseries\textcolor{gray}{\%<*noltximg>}}}{12}
              {\%</noltximg>}{{\bfseries\textcolor{gray}{\%</noltximg>}}}{12},%
          #1,%
    }% close lstset
}%
{}% close examplecode

% \begin{examplecmd}...\end{examplecmd}
\lstnewenvironment{examplecmd}{%
\lstset{
    language=ltximg-doc,%
    basicstyle=\ttfamily\small,%
    frame=single,%
    rulecolor=\color{gray!50},%
    framesep=\fboxsep,%
    framerule=\fboxrule,%
    xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,%
    xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,%
% Reserved words (cmd line options)
    classoffset=7,%
    keywordstyle=\bfseries\color{optcolor},%
    morekeywords={ltximg},%
% % Reserved words (cmd line options)
    classoffset=8,%
    keywordstyle={\bfseries\color{ForestGreen}},%
    morekeywords={gs,pdftoppm,pdftocairo,pdftops},%
% Only for command line options
    classoffset=5,%
    keywordstyle=\color{blue},%
    keywords={user,machine},%
    literate=*{[}{{\textcolor{darkgray}{[}}}{1}
              {]}{{\textcolor{darkgray}{]}}}{1}
              {@}{{\textcolor{blue}{@}}}{1}
              {\$}{{\textcolor{blue}{\$}}}{1}
              {:}{{\textcolor{blue}{:}}}{1}
              {§}{{\textcolor{red}{\$}}}{1}
              {~}{{\textcolor{blue}{\bfseries\textasciitilde}}}{1}%
    }% close lstset
}%
{}% close examplecmd

% \lstinline[style=inline]|...|
\lstdefinestyle{inline}
  {
   language=ltximg-doc,%
   basicstyle=\ttfamily\color{gray},%
   escapechar=`,%
   upquote=true,%
   literate=*{\%}{{\bfseries\textcolor{gray}{\%}}}{1}
  }

% set default style
\lstset{style=inline}


\begin{document}

\title{%
    {\fetamono latex environments }\\[3pt]%
    \scalebox{3.4}{\LTXimg}\\[2pt]%
    {\fetamono\addfontfeature{LetterSpace=12.0} to image format}\\%
    \Large
    v\fileversion{} --- \filedate\thanks{%
    This file describes a documentation for version \fileversion, last revised \filedate.}\\[25pt]%
    \author{%
    \large%
    \raisebox{-1pt}{\textcopyright}{}2013--2019 by Pablo González L%
    \thanks{E-mail: \texttt{\guillemotleft}\email{pablgonz@yahoo.com}\texttt{\guillemotright}}
    }%
\small
\textsc{ctan}: \url{http://www.ctan.org/pkg/ltximg}\\
\textsc{git}: \url{https://github.com/pablgonz/ltximg}
\vspace*{-2cm}
}%
\date{}
\maketitle

\begin{abstract}
\ltximg{} is a \prgname{perl} \emph{script} that automates the process of
extracting and converting environments provided by \pkgname{tikz}, %
\pkgname{pstricks} and other packages from \meta{input file} to image
formats in individual files using \prgname{ghostscript} and %
\prgname{poppler-utils}. Generates a file with only extracted environments
and another with environments converted to \ics{includegraphics}.
\end{abstract}

\tableofcontents
\setlength{\parskip}{3pt}

\section{Motivation}

The original idea was to extend the functionality of the \scriptname{pst2pdf}
script (only for \env{pspicture} and \env{postscript}) to work with %
\env{tikzpicture} and other environments.

The \pkgname{tikz} package allows to externalize the environments, but, the
idea was to be able to extend this to any type of environment covering three
central points:

\begin{enumerate}[font=\small , noitemsep,leftmargin=*]

\item Generate separate files for environments and converted into images.

\item Generate a file with only the extracted environments.

\item Generate a file replacing the environments by \ics{includegraphics}.
\end{enumerate}

From the side of \TeX{} there are some packages that cover several of these
points such as the \pkgname{preview}, \pkgname{xcomment}, \pkgname{external}
and \pkgname{cachepic} packages among others, but none covered all points.

In the network there are some solutions in \texttt{bash} that were able to
extract and convert environments, but in general they presented problems
when the document contained \emph{verbatim style} code or were only
available for \OSsystem{Linux}.

Analysed the situation the best thing was to create a new \emph{script} that
was able to cover the three points and was multi platform, the union of all
these ideas is born \ltximg. Finding the correct \emph{regular expressions}
and writing \emph{documentation} would be the great mission (which does not
end yet).

\thispagestyle{plain}
\newpage
\pagestyle{myheader}
\section{Required Software}\label{sec:software}

For the complete operation of \ltximg{} you need to have a modern %
\hologo{TeX} distribution such as \hologo{TeX}Live or \hologo{MiKTeX}, have
a version equal to or greater than \liningnums{5.28} of \prgname{perl}, a
version equal to or greater than \liningnums{9.24} of \prgname{ghostscript}
and have a version equal to or greater than \liningnums{0.52} of %
\prgname{poppler-utils}.

The distribution of \hologo{TeX}Live 2019 for \OSsystem{Windows} includes %
\ltximg{} and all requirements, \hologo{MiKTeX} users must install the
appropriate software for full operation.

The script has been tested on \OSsystem{Windows} (version 10) and %
\OSsystem{Linux} (fedora 30) in x64 architecture using \prgname{ghostscript} %
\liningnums{v9.26}, \prgname{poppler-utils} \liningnums{v0.52} to %
\liningnums{v0.73} and \prgname{perl} from \liningnums{v5.28} to %
\liningnums{v5.30}.

\section{How it works}

\label{sec:howtowork}

It is important to have a general idea of how the \emph{extraction and
conversion} process works and the requirements that must be fulfilled so
that everything works correctly, for this we must be clear about some
concepts related to how to work with the \meta{verbatim content}, the %
\meta{input file}, the \meta{output file} and the \meta{steps process}.

\subsection{The input file}

\label{sec:inputfile}

The \meta{input file} must comply with certain characteristics in order to
be processed, the content at the beginning and at the end of the \meta{input
file} is treated in a special way, before \lstinline|\documentclass| can only be
commented lines and after \lstinline|\end{document}| can go any type of content,
internally will split the \meta{input file} at this points.

If the \meta{input file} contains files using \ics{input} or \ics{include}
these will not be processed, from the side of the \emph{script} they only
represent lines within the file, if you want them to be processed it is
better to use the \scriptname{latexpand} first and then process the file.

Like \ics{input} or \ics{include}, blank lines, vertical spaces and tab
characters are treated literally, for the \emph{script} the \meta{input file}
is just a set of characters, as if it was a simple text file. It is
advisable to format the source code \meta{input file} using utilities such
as \prgname{chktex} and \scriptname{latexindent}, especially if you want to
extract the source code of the environments.

An example of the \meta{input file}:

\begin{examplecode}[numbers=left,frame=single]
% some commented lines at begin document
\documentclass{article}
\usepackage{tikz}
\begin{document}
Some text
\begin{tikzpicture}
Some code
\end{tikzpicture}
Always use \verb|\begin{tikzpicture}|
and \verb|\end{tikzpicture}| to open
and close environment
\begin{tikzpicture}
Some code
\end{tikzpicture}
Some text
\end{document}
% some lines after end document
\end{examplecode}

\subsection{Verbatim contents}\label{sec:verbatim}

One of the greatest capabilities of \ltximg{} script is to skip the complications
that \emph{verbatim style} content produces with the extraction of environments.
In order to skip the complications, the verbatim content is classified into
three types:

\begin{itemize}[nosep]
    \item Verbatim in line
    \item Verbatim standard
    \item Verbatim write
\end{itemize}

Each of these classifications works differently within the creation and
extraction process using different regular expressions for it.

\newpage

\subsubsection{Verbatim in line}

\label{sec:verbatim:inline}

The small pieces of code written in the same line using a verbatim command
are considered \meta{verbatim in line}, such as \lstinline+\verb|<code>|+.
Most verbatim commands provide by packages \pkgname{minted}, %
\pkgname{fancyvrb} and \pkgname{listings} have been tested and are fully
supported. They are automatically detected the verbatim command generates by
\ics{newmint} and \ics{newmintinline} and the following command list:

\begin{multicols}{3}
\begin{itemize}[font=\sffamily\small,partopsep=5pt,parsep=5pt,nosep,leftmargin=*]
\small
\item \ics{mint}
\item \ics{spverb}
\item \ics{qverb}
\item \ics{fverb}
\item \ics{verb}
\item \ics{Verb}
\item \ics{lstinline}
\item \ics{pyginline}
\item \ics{pygment}
\item \ics{Scontents}
\item \ics{tcboxverb}
\item \ics{mintinline}
\end{itemize}
\end{multicols}

Some packages define abbreviated versions for verbatim commands as %
\ics{DefineShortVerb}, \ics{lstMakeShortInline} and %
\ics{MakeSpecialShortVerb}, will be detected automatically if are declared
explicitly in \meta{input file}.

The following consideration should be kept in mind for some packages that
use abbreviations for verbatim commands, such as \pkgname{shortvrb} or %
\pkgname{doc} for example in which there is no explicit command in the
document by means of which the abbreviated form can be detected, for
automatic detection need to find \ics{DefineShortVerb} explicitly to process
it correctly. The solution is quite simple, just add in \meta{input file}:

\begin{examplecode}
\UndefineShortVerb{\|}
\DefineShortVerb{\|}
\end{examplecode}

depending on the package you are using. If your verbatim command is not
supported by default or can not detect, use the options described in \ref%
{sec:optline} and \ref{sec:optfile}.

\subsubsection{Verbatim standard}

\label{sec:verbatim:std}

These are the classic environments for writing code are considered %
\meta{verbatim standard}, such as \env{verbatim} and \env{lstlisting}
environments. The following list is considered as \meta{verbatim standard}
environments:

\begin{multicols}{4}
\begin{itemize}[font=\sffamily\small, noitemsep,leftmargin=*]
\ttfamily\small
\item Example
\item CenterExample
\item SideBySideExample
\item PCenterExample
\item PSideBySideExample
\item verbatim
\item Verbatim
\item BVerbatim
\item LVerbatim
\item SaveVerbatim
\item PSTcode
\item LTXexample
\item tcblisting
\item spverbatim
\item minted
\item listing
\item lstlisting
\item alltt
\item comment
\item chklisting
\item verbatimtab
\item listingcont
\item boxedverbatim
\item demo
\item sourcecode
\item xcomment
\item pygmented
\item pyglist
\item program
\item programl
\item programL
\item programs
\item programf
\item programsc
\item programt
\end{itemize}
\end{multicols}

They are automatically detected \meta{verbatim standard} environments generates by commands:

\begin{multicols}{2}
\begin{itemize}[font=\sffamily\small, noitemsep,leftmargin=*]
\small
\item \ics{DefineVerbatimEnvironment}
\item \ics{NewListingEnvironment}
\item \ics{DeclareTCBListing}
\item \ics{ProvideTCBListing}
\item \ics{lstnewenvironment}
\item \ics{newtabverbatim}
\item \ics{specialcomment}
\item \ics{includecomment}
\item \ics{newtcblisting}
\item \ics{NewTCBListing}
\item \ics{newverbatim}
\item \ics{NewProgram}
\item \ics{newminted}
\end{itemize}
\end{multicols}

If any of the \meta{verbatim standard} environments is not supported by
default or can not detected, you can use the options described in \ref%
{sec:optline} and \ref{sec:optfile}.

\subsubsection{Verbatim write}

\label{sec:verbatim:write}

Some environments have the ability to write external files directly, these
environments are considered \meta{verbatim write}, such as \env{filecontents}
or \env{VerbatimOut} environments. The following list is considered as %
\meta{verbatim write} environments:

\begin{multicols}{3}
\begin{itemize}[font=\sffamily\small, noitemsep,leftmargin=*]
\ttfamily\small
\item scontents
\item filecontents
\item tcboutputlisting
\item tcbexternal
\item tcbwritetmp
\item extcolorbox
\item extikzpicture
\item VerbatimOut
\item verbatimwrite
\item filecontentsdef
\item filecontentshere
\item filecontentsdefmacro
\end{itemize}
\end{multicols}

They are automatically detected \meta{verbatim write} environments generates
by commands:

\begin{multicols}{2}
\begin{itemize}[font=\sffamily\small, noitemsep,leftmargin=*]
\small
\item \ics{renewtcbexternalizetcolorbox}
\item \ics{renewtcbexternalizeenvironment}
\item \ics{newtcbexternalizeenvironment}
\item \ics{newtcbexternalizetcolorbox}
\end{itemize}
\end{multicols}

If any of the \meta{verbatim write} environments is not supported by default
or can not detected, you can use the options described in \ref{sec:optline}
and \ref{sec:optfile}.

\subsection{Steps process}

\label{sec:steps:process}

For creation of the image formats, extraction of code and creation of an
output file, \ltximg{} need a various steps. Let's assume that the %
\meta{input file} is \sysfile{test.tex}, \meta{output file} is %
\sysfile{test-out}, the working directory are \sysdir{workdir}, the
directory for images are \sysdir{workdir/images} and the user's temporary
directory is \sysdir{tmp} and we want to generate images in \iext{pdf}
format together with the source codes of the environments.

\begin{description}[font=\sffamily\small,leftmargin=0em,style=nextline]
\item[Comment and ignore]
The first step is read and validated \oarg[type=rm,cf=gray,sbc=optcolor,ac=gray]{options} from the command
line and \sysfile{test.tex}, verifying that \sysfile{test.tex}, \sysfile{test-out} and the
directory \sysdir{images} are in \sysdir{workdir}, create the directory \sysdir{workdir/images} if it does
not exist and a temporary directory \sysdir{tmp/hG45uVklv9}. The entire file \sysfile{test.tex} is loaded
in memory and proceeds (in general terms) as follows:

\begin{quotation}
Search the words \lstinline|\begin{| and \lstinline|\end{| in verbatim standard, verbatim write, verbatim in line and
commented lines, if it finds them, converts to \lstinline|\BEGIN{| and \lstinline|\END{|, then places all code to
extract inside the \lstinline|\begin{preview}| \ldots \lstinline|\end{preview}|.
\end{quotation}

At this point all the code you want to extract is inside \lstinline|\begin{preview}| \ldots \lstinline|\end{preview}|
and the files \sysfile{test-fig-1.tex}, \sysfile{test-fig-2.tex}, \ldots{} are generated and saved in \sysdir{images}.

\item[Create random file]
In the second step, with the file already loaded in memory, creating a temporary file with a
random number (1981 for example) and proceed in two ways according to the \oarg[type=rm,cf=gray,sbc=optcolor,ac=gray]{options}
passed to the script:

\begin{enumerate}
\item If script is call \emph{whitout} \cmdopt[n]{noprew} options, adds the
following lines to the beginning of the \sysfile{test.tex} (in memory):

\begin{examplecode}
\AtBeginDocument{%
\RequirePackage[active,tightpage]{preview}
\renewcommand\PreviewBbAdjust{-60pt -60pt 60pt 60pt}}%
% rest of input file
\end{examplecode}
And save in a temporary file \sysfile{test-fig-1981.tex} in \sysdir{workdir}.

\item If script is call \emph{whit} \cmdopt[n]{noprew} options, all code to extract
its put inside the \env{preview} environment. The \lstinline|\begin{preview}|\ldots \lstinline|\end{preview}|
lines are only used as delimiters for extracting the content \emph{without} using the package \pkgname{preview}.

Creating a temporary file \sysfile{test-fig-1981.tex} in \sysdir{workdir}
whit the same preamble of \sysfile{test.tex} but the body only contains code that you want to extract.
\end{enumerate}

\item[Generate image formats]
In the third step the script run:
\begin{examplecmd}
[user@machine ~:]§`\small\meta[type=tt,cf=ForestGreen,ac=ForestGreen]{compiler}` -recorder -shell-escape `\small\sysfile{test-fig-1981.tex}`
\end{examplecmd}
generating the file \sysfile{test-fig-1981.pdf} whit all code extracted, move \sysfile{test-fig-1981.pdf}
to \sysdir{tmp/hG45uVklv9}, separate in individual files \sysfile{test-fig-1.pdf}, \sysfile{test-fig-2.pdf}, \ldots{}
and copy to \sysdir{workdir/images/}. The file \sysfile{test-fig-1981.tex} is moved to the \sysdir{workdir/images/}
and rename to \sysfile{test-fig-all.tex}.

Note the options passed to \meta[type=tt,cf=ForestGreen,ac=ForestGreen]{compiler} does not include \prgopt*{output-directory}
(it is not supported) and always use \prgopt*{recorder} \prgopt*{shell-escape} you must keep this in mind if you use \prgname{arara}.

\item[Create output file]
In the fourth step the script creates the output file \sysfile{test-out.tex} converting all extracted code to
\ics{includegraphics} and adding the following lines at end of preamble:

\begin{examplecode}[numbers=left]
\usepackage{graphicx}
\graphicspath{{images/}}
\usepackage{grfext}
\PrependGraphicsExtensions*{.pdf}
\end{examplecode}

If the packages \pkgname{graphicx} and \pkgname{grfext} are already loaded and the command \ics{graphicspath}
is found in the input file were detected automatically and only the changes will be added then proceed to run:
\begin{examplecmd}
[user@machine ~:]§`\small\meta[type=tt,cf=ForestGreen,ac=ForestGreen]{compiler}` -recorder -shell-escape `\small\sysfile{test-out.tex}`
\end{examplecmd}
generating the file \sysfile{test-out.pdf}.
\end{description}
Now the script read the files \sysfile{test-fig-1981.fls} and \sysfile{test-out.fls}, extract the information from the
temporary files generated in the process and then delete them together with the directory \sysdir{tmp/hG45uVklv9}.
An example for input and output file:

\begin{minipage}[c]{0.5\textwidth}
\begin{examplecode}[numbers=left]
\documentclass{article}
\usepackage{tikz}
\begin{document}
Some text
\begin{tikzpicture}
Some code
\end{tikzpicture}
Always use \verb|\begin{tikzpicture}|
and \verb|\end{tikzpicture}| to open
and close environment
\begin{tikzpicture}
some code
\end{tikzpicture}
Some text
\end{document}
\end{examplecode}
\begin{flushleft}
\sysfile{test.tex}
\end{flushleft}
\end{minipage}
\begin{minipage}[c]{0.5\textwidth}
\begin{examplecode}[numbers=left]
\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}
\graphicspath{{images/}}
\usepackage{grfext}
\PrependGraphicsExtensions*{.pdf}
\begin{document}
Some text
\includegraphics[scale=1]{test-fig-1}
Always use \verb|\begin{tikzpicture}|
and \verb|\end{tikzpicture}| to open
and close environment
\includegraphics[scale=1]{test-fig-2}
Some text
\end{document}
\end{examplecode}
\begin{flushleft}
\sysfile{test-out.tex}
\end{flushleft}
\end{minipage}

\section{Extract content}
\label{sec:extract}
The script provides two ways to extract content from \meta{input file}, using \meta[type=rm,cf=optcolor,ac=gray]{environments}
and \meta[type=rm,cf=optcolor,ac=gray]{docstrip tags}. Some environment (including a starred \texttt{\small\bfseries\textcolor{red}{*}} version)
are supported by default and if the environments are nested, the outermost will be extracted.

\subsection{Default environments}
\label{sec:extract:env}
\DescribeTE{preview}
Environment provide by \pkgname{preview} package. If \env{preview} environments
found in the input file will be extracted and converted these. Internally
converts all environments to extract in \env{preview} environments.
Is better comment this package in preamble unless the option \cmdopt[n]{noprew}{} is
used.

\vspace{\baselineskip}

\DescribeTE{pspicture}
Environment provide by \pkgname{pstricks} package. The plain
syntax \lstinline|\pspicture ... \endpspicture| its converted to
\lstinline|\begin{pspicture} ... \end{pspicture}|.
\vspace{\baselineskip}

\DescribeTE{psgraph}
Environment provide by \pkgname{pst-plot} package. The plain syntax \lstinline|\psgraph ... \endpsgraph|
its converted to \lstinline|\begin{psgraph} ... \end{psgraph}|.

\vspace{\baselineskip}

\DescribeTE{postscript}
Environment provide by \pkgname{pst-pdf} and \pkgname{auto-pst-pdf} packages.
Since the \pkgname{pst-pdf} and \pkgname{auto-pst-pdf} packages internally use
the \pkgname{preview} package, is better comment this in preamble.

\vspace{\baselineskip}

\DescribeTE{tikzpicture}
Environment provide by \pkgname{tikz} package. The plain syntax \lstinline|\tikzpicture ... \tikzpicture|
its converted to \lstinline|\begin{tikzpicture} ... \end{tikzpicture}|
but no a short \lstinline|\tikz...;|.
\vspace{\baselineskip}

\DescribeTE{pgfpicture}
Environment provide by \pkgname{pgf} package. Since the script uses a
\emph{recursive regular expression} to extract environments, no presents problems
if present \lstinline|pgfinterruptpicture|.
\vspace{\baselineskip}

\DescribeTE{PSTexample}
Environment provide by \pkgname{pst-exa} packages. The script automatically detects the
\lstinline|\begin{PSTexample}|  \lstinline|...\end{PSTexample}|
environments and processes them as separately compiled files. The user should have loaded the
package with the [\pkgopt{swpl}] or [\pkgopt{tcb}] option and run the script
using \cmdopt{latex}{} or \cmdopt{xetex}.

If you need to extract more environments you can use one of the options described in \ref{sec:optline} or \ref{sec:optfile}.

\subsection{Extract whit docstrip tags}

\label{sec:extract:tag}
\DescribeTE*{ltximg}
All content included between \lstinline|%<*ltximg> ... %</ltximg>| is extracted.
The tags can not be nested and should be at the beginning of the line and in separate lines.

\begin{examplecode}[frame=single]
% no space before open tag %<*
%<*ltximg>
code to extract
%</ltximg>
% no space before close tag %</
\end{examplecode}

\subsection{Prevent extraction and remove}\label{sec:noextract}
Sometimes you do not want to extract all the environments from \meta{input file} or you want to
remove environments or arbitrary content, for example auxiliary files to generate a graphic.
The script provides a convenient way to solve this situation.

\DescribeTE{nopreview}
Environment provide by \pkgname{preview} package. Internally the script
converts all no extract environments to \lstinline|\begin{nopreview} ... \end{nopreview}|.
Is better comment this package in preamble unless the option \cmdopt[n]{noprew}{} is used.
\vspace{\baselineskip}

\DescribeTE*{noltximg}
All content betwen \lstinline|%<*noltximg> ... %</noltximg>| are ignored and no
extract. The start and closing of the tag must be at the beginning of the line.

\begin{examplecode}[frame=single]
% no space before open tag %<*
%<*noltximg>
no extract this
%</noltximg>
% no space before close tag %</
\end{examplecode}

\DescribeTE*{remove}
All content betwen \lstinline|%<*remove> ... %</remove>| are deleted in the \meta{output file}. The start and closing
of the tag must be at the beginning of the line.

\begin{examplecode}[frame=single]
% no space before open tag %<*
%<*remove>
lines removed in output file
%</remove>
% no space before close tag %</
\end{examplecode}

If you want to remove specific environments automatically you can use one of
the options described in \ref{sec:optline} or \ref{sec:optfile}.

\section{Image Formats}\label{sec:image:format}
The \meta{image formats} generated by the \ltximg{} using \prgname{ghostscript}
and \textcolor{ForestGreen}{\ttfamily\bfseries poppler-utils}
are the following command lines:

\DescribeIF{pdf}
The image format generated using \prgname{ghostscript}. The line executed by the system is:

\begin{examplecmd}
[user@machine ~:]§ gs -q -dNOSAFER -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress
\end{examplecmd}

\DescribeIF{eps}
The image format generated using \prgname{pdftoeps}. The line executed by the system is:

\begin{examplecmd}
[user@machine ~:]§ pdftops -q -eps
\end{examplecmd}

\DescribeIF{png}
The image format generated using \prgname{ghostscript}. The line executed by the system is:

\begin{examplecmd}
[user@machine ~:]§ gs -q -dNOSAFER -sDEVICE=pngalpha -r 150
\end{examplecmd}

\newpage

\DescribeIF{jpg}
The image format generated using \prgname{ghostscript}. The line executed by the system is:
\begin{examplecmd}
[user@machine ~:]§ gs -q -dNOSAFER -sDEVICE=jpeg -r 150 -dJPEGQ=100 \
                      -dGraphicsAlphaBits=4 -dTextAlphaBits=4
\end{examplecmd}

\DescribeIF{ppm}
The image format generated using \prgname{pdftoppm}. The line executed by the system is:

\begin{examplecmd}
[user@machine ~:]§ pdftoppm -q -r 150
\end{examplecmd}

\DescribeIF{tif}
The image format generated using \prgname{ghostscript}. The line executed by the system is:

\begin{examplecmd}
[user@machine ~:]§ gs -q -dNOSAFER -sDEVICE=tiff32nc -r 150
\end{examplecmd}

\DescribeIF{svg}
The image format generated using \prgname{pdftocairo}. The line executed by the system is:

\begin{examplecmd}
[user@machine ~:]§ pdftocairo -q -r 150
\end{examplecmd}

\DescribeIF{bmp}
The image format generated using \prgname{ghostscript}. The line executed by the system is:

\begin{examplecmd}
[user@machine ~:]§ gs -q -dNOSAFER -sDEVICE=bmp32b -r 150
\end{examplecmd}

\section{How to use}
\subsection{Syntax}
The syntax for \ltximg{} is simple:

\begin{examplecmd}
[user@machine ~:]§ ltximg `\small\meta[type=tt,cf=ForestGreen,ac=ForestGreen]{compiler} \oarg[type=tt,cf=gray,sbc=optcolor,ac=gray]{options} \textcolor{gray}{\texttt{[-\/-]}} \meta[type=tt,cf=OrangeRed,ac=OrangeRed]{file.ext}`
\end{examplecmd}

The extension \meta[type=tt,cf=OrangeRed,ac=OrangeRed]{ext} for \meta{input file} are \fext{tex} or \fext{ltx},
relative or absolute paths for files and directories is not supported. If used without \meta[type=tt,cf=ForestGreen,ac=ForestGreen]{compiler}
and \oarg[type=tt,cf=gray,sbc=optcolor,ac=gray]{options} the extracted environments are converted to \iext{pdf}
image format and saved in the \sysdir{images} directory using \prgname*{pdflatex} and \pkgname{preview} package.

\subsection{Options in command line}
\label{sec:optline}

\ltximg{} provides a \emph{command line interface} with short and long option names.
They may be given before the name of the file. Also, the order of specifying the
options is significant. Certain options accept a list separate by commas, this require a separated by
white space or equals sign \textcolor{red}{\texttt{=}} between option and list and if it's the last option
need \textcolor{red}{\texttt{-\/-}} at the end. Multiple short options can be bundling.

\DescribeCmd[h]{help}{bolean}{off}
Display a command line help text and exit.

\DescribeCmd[l]{license}{bolean}{off}
Display a license text and exit.

\DescribeCmd[v]{version}{bolean}{off}
Display the current version (\fileversion) and exit.

\DescribeCmd[d]{dpi}{int}{150}
Dots per inch for images files.

\DescribeCmd[t]{tif}{bolean}{off}
Create a .\iext{tif} images files using \prgname{ghostscript}.

\DescribeCmd[b]{bmp}{bolean}{off}
Create a .\iext{bmp} images files using \prgname{ghostscript}.

\DescribeCmd[j]{jpg}{bolean}{off}
Create a .\iext{jpg} images files using \prgname{ghostscript}.

\DescribeCmd[p]{png}{bolean}{off}
Create a .\iext{png} transparent image files using \prgname{ghostscript}.

\DescribeCmd[e]{eps}{bolean}{off}
Create a .\iext{eps} image files using \prgname{pdftops}.

\DescribeCmd[s]{svg}{bolean}{off}
Create a .\iext{svg} image files using \prgname{pdftocairo}.

\DescribeCmd[P]{ppm}{bolean}{off}
Create a .\iext{ppm} image files using \prgname{pdftoppm}.

\DescribeCmd[g]{gray}{bolean}{off}
Create a gray scale for all images using \prgname{ghostscript}. The line behind this options is:

\begin{examplecmd}
[user@machine ~:]§ gs -q -dNOSAFER -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress        \
                      -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray
\end{examplecmd}

\DescribeCmd[f]{force}{bolean}{off}
Try to capture \lstinline|\psset{...}| and \lstinline|\tikzset{...}| to extract.
When using the \cmdopt{force} option the script will try to capture \lstinline|\psset{...}| or
\lstinline|\tikzset{...}| and leave it inside the \env{preview} environment, any line that is between \lstinline|\psset{...}| and
\lstinline|\begin{pspicture}| or between \lstinline|\tikzset{...}| and \lstinline|\begin{tikzpicture}| will be captured.

\DescribeCmd[n]{noprew}{bolean}{off}
Create images files without \pkgname{preview} package. The \lstinline|\begin{preview}|\ldots \lstinline|\end{preview}|
lines are only used as delimiters for extracting the content \emph{without} using the package \pkgname{preview}.
Sometimes it is better to use it together with \cmdopt{force}.

\DescribeCmd[m]{margin}{numeric}{0}
Set margins in bp for \scriptname{pdfcrop}.

\DescribeCmd[o]{output}{output file name}{empty}
Create \meta{output file name} whit all extracted environments/contents converted to \ics{includegraphics}.
The \meta{output file name} must not contain extension.

\DescribeCmd{imgdir}{string}{images}
The name of directory for save images and source code.

\DescribeCmd{zip}{bolean}{off}
Compress only the files generated by the script during the process in \sysdir{images} in \fext{zip} format.
Does not include \meta{output file}.

\DescribeCmd{tar}{bolean}{off}
Compress only the files generated by the script during the process in \sysdir{images} in \fext{tar.gz} format.
Does not include \meta{output file}.

\DescribeCmd{verbose}{bolean}{off}
Show verbose information in screen and change \prgopt*{interaction} for compiler.

\DescribeCmd{srcenv}{bolean}{off}
Create separate files whit \emph{only code} for all extracted environments, is mutually exclusive whit \cmdopt{subenv}.

\DescribeCmd{subenv}{bolean}{off}
Create sub files whit \emph{preamble} and code for all extracted environments, is mutually exclusive whit \cmdopt{srcenv}.

\DescribeCmd{arara}{bolean}{off}
Use \prgname*{arara} for compiler files, need to pass \prgopt*{recorder} option to \meta{input file}:\par

\lstinline|% arara : <compiler> : { options: [-recorder] }|

\DescribeCmd{xetex}{bolean}{off}
Using \prgname*{xelatex} compiler \meta{input file} and \meta{output file}.

\DescribeCmd{latex}{bolean}{off}
Using \prgname*{latex}\texttt{\bfseries\guillemotright}\prgname*{dvips}\texttt{\bfseries\guillemotright}\scriptname{ps2pdf}
compiler in \meta{input file} and \prgname*{pdflatex} for \meta{output file}.

\DescribeCmd{dvips}{bolean}{off}
Using \prgname*{latex}\texttt{\bfseries\guillemotright}\prgname*{dvips}\texttt{\bfseries\guillemotright}\scriptname{ps2pdf}
for compiler \meta{input file} and \meta{output file}.

\newpage

\DescribeCmd{dvipdf}{bolean}{off}
Using \prgname*{latex}\texttt{\bfseries\guillemotright}\prgname*{dvipdfmx} for compiler \meta{input file} and \meta{output file}.

\DescribeCmd{luatex}{bolean}{off}
Using \prgname*{lualatex} for compiler \meta{input file} and \meta{output file}.

\DescribeCmd{prefix}{string}{fig}
Add prefix append to each files created.

\DescribeCmd{norun}{bolean}{off}
Run script, but no create images. This option is designed to debug the file and
when you only need to extract the code

\DescribeCmd{nopdf}{bolean}{off}
Don't create a .\iext{pdf} image files.

\DescribeCmd{nocrop}{bolean}{off}
Don't run \scriptname{pdfcrop} in image files.

\DescribeCmd{clean}{doc\textbar pst\textbar tkz\textbar all\textbar off}{doc}
Removes specific content in \meta{output file}. Valid values for this option are:

\begin{description}[font=\ttfamily, nosep, noitemsep, leftmargin=*]
\item[doc] All content after \lstinline+\end{document}+ is removed.
\item[pst] All \lstinline|\psset{...}| and \pkgname{pstricks} package  is removed.
\item[tkz] All \lstinline|\tikzset{...}| is removed.
\item[all] Activates doc, pst and tkz.
\item[off] Deactivate all.
\end{description}

\DescribeCmd{verbcmd}{command name}{myverb}
Set custom verbatim command \lstinline+\myverb|<code>|+.

\DescribeCmd{extrenv}{list separate by comma}{empty}
List of environments to extract, need \texttt{-\/-} at end.\par

\DescribeCmd{skipenv}{list separate by comma}{empty}

List of environments that should not be extracted and that the script supports
by default, need \texttt{-\/-} at end.\par

\DescribeCmd{verbenv}{list separate by comma}{empty}

List of \meta{verbatim standard} environment support, need \texttt{-\/-} at end.\par

\DescribeCmd{writenv}{list separate by comma}{empty}

List of \meta{verbatim write} environment support, need \texttt{-\/-} at end.\par

\DescribeCmd{deltenv}{list separate by comma}{empty}
List of environment deleted in \meta{output file}, need \texttt{-\/-} at end.

\subsection{Options in input file}\label{sec:optfile}

Many of the ideas in this section are inspired by the \prgname{arara} program (I adore it).
A very useful way to pass options to the script is to place them in commented
lines at the beginning of the file, very much in the style of \prgname{arara}.

\DescribeOptFile*{\meta[ac=gray,cf=gray]{argument}}{option one, option two, option three, \ldots}
\DescribeOptFile*{\meta[ac=gray,cf=gray]{argument}}{option one, option two, option three, \ldots}[!]

The vast majority of the options can be passed into the \meta{input file}. These
should be put at the beginning of the file in commented lines and everything must
be on the same line, the exclamation mark deactivates the option. Valid values for
\meta[ac=gray,cf=gray]{argument} are the following:

\DescribeOptFile{options}{option one = value, option two = value, option three = value, \ldots}
This line is to indicate to the script which options need to process.

\DescribeOptFile{extrenv}{environment one, environment two, environment three, \ldots}
This line is to indicate to the script which environments, not supported by
default, are extracted.

\DescribeOptFile{skipenv}{environment one, environment two, environment three, \ldots}
This line is to indicate to the script which environments, of the ones
supported by default, should not be extracted.

\DescribeOptFile{verbenv}{environment one, environment two, environment three, \ldots}
This line is to indicate to the script which environments, its considerate a \meta{verbatim standard}.

\DescribeOptFile{writenv}{environment one, environment two, environment three, \ldots}
This line is to indicate to the script which environments its consider \meta{verbatim write}.

\DescribeOptFile{deltenv}{environment one, environment two, environment three, \ldots}
This line is to indicate to the script which environments are deleted.

If you are going to create an \meta{output file} and you do not want these lines to remain, it is better to
place them inside the \lstinline|%<*remove> ... %</remove>|. Like this:

\begin{examplecode}[numbers=left]
%<*remove>
% ltximg : options : {png,srcenv,xetex}
% ltximg : extrenv : {description}
%</remove>
\end{examplecode}


\section{Examples}
\label{sec:examples}

\subsection{From command line}
\begin{examplecmd}
[user@machine ~:]§ ltximg --latex -s -o test-out  test-in.ltx
\end{examplecmd}
Create a \sysdir{images} directory whit all extracted environments converted to image
formats (\iext{pdf}, \iext{svg}) in individual files, an \meta{output file} \sysfile{test-out.ltx} whit all supported  environments
converted to \ics{includegraphics} and a single file \sysfile{test-in-fig-all.ltx} with only the extracted environments
using \prgname*{latex}\texttt{\bfseries\guillemotright}\prgname*{dvips}\texttt{\bfseries\guillemotright}\scriptname{ps2pdf}
and \pkgname{preview} package for \meta{input file} and \prgname*{pdflatex} for \meta{output file}.

\subsection{From input file}
Adding the following lines to the beginning of the file \sysfile{file-in.tex}:

\begin{examplecode}[numbers=left]
%<*remove>
% ltximg : options : {output = file-out, noprew, imgdir = pics, prefix = env, clean = doc}
% ltximg : skipenv : {tikzpicture}
% ltximg : deltenv : {filecontents}
%</remove>
\end{examplecode}
and run:
\begin{examplecmd}
[user@machine~:]§ ltximg file-in.tex
\end{examplecmd}
Create a \sysdir{pics} directory whit all extracted environments, except \env{tikzpicture}, converted to image
formats (\iext{pdf}) in individual files, an \meta{output file} \sysfile{file-out.tex} whit all extracted  environments
converted to \ics{includegraphics} and environment \env{filecontents} removed, a single file \sysfile{test-in-env-all.ltx}
with only the extracted environments using \prgname*{pdflatex} and \pkgname{preview} package for \meta{input file} and \meta{output file}.

\newpage

\section{Change history}\label{sec:change:history}

Some of the notable changes in the history of the \ltximg{} along with the
versions, both development (devp) and public (ctan).

\setlist[itemize, 1]{label=\textendash, wide=0.5em,  nosep, noitemsep, leftmargin=10pt}

% length for change history
\newlength\descrwidth
\settowidth{\descrwidth}{\textsf{v1.4.5, (ctan), 2013-01-23}}
\begin{description}[font=\small\sffamily, wide=0pt, style=multiline, leftmargin=\descrwidth,  nosep, noitemsep]
\item [v\fileversion{} (ctan), \filedate]
    \begin{itemize}
        \item Add \texttt{scontents} environment support
        \item Add \texttt{filecontentsdefmacro} environment support
        \item Fix regex in source code
        \item Update documentation
    \end{itemize}
\item [v1.6 (ctan), 2019-07-13]
    \begin{itemize}
        \item Add \texttt{zip} and \texttt{tar} options
        \item Add new \texttt{Verb} from \texttt{fvextra}
        \item Fix and update source code and documentation
    \end{itemize}
\item [v1.5 (ctan), 2018-04-12]
    \begin{itemize}
        \item Use \texttt{GitHub} to control version
        \item Rewrite and optimize most part of source code and options
        \item Change \texttt{pdf2svg} for \texttt{pdftocairo}
        \item Complete support for \texttt{pst-exa} package
        \item Escape characters in regex according to \texttt{perl} v5.4x.x
    \end{itemize}
\item [v1.4 (devp), 2016-11-29]
    \begin{itemize}
        \item Remove and rewrite code for regex and system call
        \item Add \texttt{arara} compiler, clean and comment code
        \item Add \texttt{dvips} and \texttt{dvipdfm(x)} for creation images
        \item Add \texttt{bmp}, \texttt{tiff} image format
    \end{itemize}
\item [v1.3 (devp), 2016-08-14]
    \begin{itemize}
        \item Rewrite some part of code (norun, nocrop, clean)
        \item Suport \texttt{minted} and \texttt{tcolorbox} package
        \item Escape some characters in regex according to \texttt{perl} v5.2x.x
        \item All options read from command line and input file
        \item Use \texttt{/tmp} dir for work process
    \end{itemize}
\item [v1.2 (ctan), 2015-04-22]
    \begin{itemize}
        \item Remove unused modules
        \item Add more image format
        \item Fix regex
    \end{itemize}
\item [v1.1 (ctan), 2015-04-21]
    \begin{itemize}
        \item Change \texttt{mogrify} to \texttt{gs} for image formats
        \item Create output file
        \item Rewrite source code and fix regex
        \item Change format date to iso format
    \end{itemize}
\item [v1.0 (ctan), 2013-12-01]
    \begin{itemize}
        \item First public release
    \end{itemize}
\end{description}

\newpage

\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
\cleardoublepage
\phantomsection
%\printindex[mydoc]
%\PrintIndex
\printindex
\end{document}
%</documentation>