summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/psfragx/psfragx.dtx
blob: 3a01ae353b8b32225304801fa5c6012bbc4976a3 (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
% \iffalse
%<*gobble>
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%
% Run LaTeX on this file and read the generated file readmePFX.txt.
%
%
%
% Copyright 2003, Pascal Kockaert
% This file is distributed under the LPPL license.
% (see http://www.latex-project.org/lppl.txt for details)
%
%
% You can check the integrity of this file by looking at the
% character table below.
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%</gobble>
%<*license>
% This package IS NOT psfrag.sty. It is an eXtension to psfrag.sty.
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in
%    http://www.latex-project.org/lppl.txt
% and version 1.2 or later is part of all distributions of LaTeX
% version 1999/12/01 or later.
%</license>
%<*readme>
\begin{filecontents*}{readmePFX.txt}
Readme file associated to the psfragx package.

This file describes how to install the package.

All you need is the file psfragx.dtx. If the file psfragx.ins does
not exist, run LaTeX on the file psfragx.dtx. This should
generated the file psfragx.ins.

Run LaTeX on the file psfragx.ins. This generates all the files of
the package. The documentation will be generated if you run LaTeX
on psfragx.drv.

In order to create the index, you should run makeindex like this.
> makeindex -s gind psfragx.idx
> makeindex -s gglo -o psfragx.gls psfragx.glo

Do not forget to re-run LaTeX on psfragx.drv two times.

You can now read the file psfragx.dvi or transform it into
psfragx.ps or psfragx.pdf.

If you want to modify the default behaviour of psfragx, do not
edit the code, but create a file psfragx.cfg to this end. This
file will be input after the package psfragx is loaded.

Finally, if your TeX implementation uses a database to find files,
you should rebuild this database. fpTeX and teTeX systems use
> mktexlsr

Happy TeXing.

Pascal Kockaert

\end{filecontents*}
%</readme>
%<*gobble>
% Next lines create file psfragx.ins.
% Run it through LaTeX in order to install the package.
\begin{filecontents*}{psfragx.ins}
%</gobble>
%<*ins>
% This file will generate fast loadable files and documentation
% driver files from the doc files in this package when run through
% LaTeX or TeX.
%
% Copyright (C) 2003,2004 Pascal Kockaert
% Pascal.Kockaert ad ulb.ac.be
% Note that ''ad´´ is often replaced by the ligature: ''@´´.
% ----------------------------------------------------------
%
% This package may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in
%    http://www.latex-project.org/lppl.txt
% and version 1.2 or later is part of all distributions of LaTeX
% version 1999/12/01 or later.
%
% --------------- start of docstrip commands ------------------
%
\input docstrip

\keepsilent\askonceonly

\usedir{tex/latex/psfragx}

\preamble

This is a generated file.


Copyright (C) 2003, 2004 Pascal Kockaert
Pascal.Kockaert ad ulb.ac.be
Note that ''ad´´ is often replaced by the ''@´´ sign.
----------------------------------------------------------

This package may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either version 1.2
of this license or (at your option) any later version.
The latest version of this license is in
   http://www.latex-project.org/lppl.txt
and version 1.2 or later is part of all distributions of LaTeX
version 1999/12/01 or later.

\endpreamble

\generate{\file{psfragx.drv}{\from{psfragx.dtx}{driver}}}
\generate{\file{psfragx.sty}{\from{psfragx.dtx}{package,version}}}
\generate{\file{psfragx.ins}{\from{psfragx.dtx}{ins}}}
\generate{\file{psfragx.cfg}{\from{psfragx.dtx}{cfg,version}}}
\generate{\nopreamble\nopostamble%
          \file{psfragx.m}  {\from{psfragx.dtx}{matlab}}}
\generate{\nopreamble\nopostamble%
          \file{pfxprint.m}  {\from{psfragx.dtx}{pfxprint}}}
%\generate{\file{Example.eps}{\from{psfragx.dtx}{example}}}

\Msg{***********************************************************}
\Msg{* To complete the installation of psfragx, you should}
\Msg{* move psfragx.sty to a directory seen by TeX.}
\Msg{*}
\Msg{* The file psfragx.cfg should be adapted to your needs}
\Msg{* and put into a personal directory (HOME rather than LOCAL)}
\Msg{* You can adapt the format of the documentation file by}
\Msg{* editing the file psfragx.drv, before compiling it.}
\Msg{*}
\Msg{***************************************************************}
\Msg{* This message is transcripted at the end of  psfragx.log}
\Msg{***************************************************************}

\endbatchfile
%</ins>
%<*gobble>
\end{filecontents*}
%</gobble>
%<*gobble>
              \ProvidesFile{psfragx.dtx}
%</gobble>
%<package>\NeedsTeXFormat{LaTeX2e}[2001/06/01]
%<package>\ProvidesPackage{psfragx}
%<driver>\ProvidesFile{psfragx.drv}
%<cfg>\ProvidesFile{psfragx.cfg}
%<*version>
% %\fi
%             \ProvidesFile{psfragx.dtx}
                           [2004/12/10 v1.0 psfragx (Pascal Kockaert)]
% % \iffalse
%</version>
%<*gobble>
\csname endinput\endcsname\csname @@end\endcsname\csname end\endcsname
%</gobble>
%<*driver>
\documentclass[a4paper,11pt]{ltxdoc}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[francais,english]{babel}
%% Uncomment the following line if you don't want to include a
%% source-code listing.
%%\OnlyDescription
\CodelineIndex
%%
%%% Babel french option
\NoAutoSpaceBeforeFDP
%%%
\begin{document}
       \DocInput{psfragx.dtx}
\end{document}
%</driver>
% %\fi
%
% \GetFileInfo{psfragx.dtx}
%
% \title{PSfragX: one graphic in one file%
%         \thanks{This file has version~\fileversion.
%                 It was processed on ~\filedate.}}
% \author{Pascal Kockaert}
% \date{\filedate}
%
% \CheckSum{646}
% \RecordChanges
% \MakeShortVerb{\"}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \newcommand{\EPS}{\textsc{eps}}
% \newcommand{\PFX}{\textsc{pfx}}
% \newcommand{\OVP}{\textsc{ovp}}
% \maketitle
% \begin{abstract}
% "\usepackage["\textit{options}"]{pfragx}" inputs the packages "psfrag" and
% "graphicx", and adds essentially one \LaTeX{} command, which is
% "\includegraphicx" (with an 'x´ at the end).
%
% This command differs from "\includegraphics" in the fact that it
% inputs "\psfrag" replacements contained into the included {\EPS} file
% itself.
%
% If the {\EPS} files contains those replacements at the right place,
% "\usepackage[sub]{psfragx}"
% will substitute "\includegraphicx" to "\includegraphics"
% automatically.
% At the same time, it is possible to include overpic commands into the
% {\EPS} file, and they will be automatically processed.
%
% The {\EPS} file can be written by a matlab script, so that the user
% needs only to call the script in order to print the matlab figure.
% No additional work will be necessary.
% \end{abstract}
%
% \tableofcontents
%
% \section{Warning}
% Some options of this package allow to overwrite some files ending
% in .pfx and in .ovp. Be sure to understand how these options work
% before using them.
%
% The text below assumes that you are used to
% "\includegraphics" from the "graphicx" package, and
% also to "\psfrag" from the "psfrag" package. Reading
% the documentation of "overpic" could also help to
% understand what follows.
%
% \section{Motivation}
%
% Using graphics drawn by mathematical softwares is very convenient
% but does not offer all the flexibility of \TeX{} and \LaTeX{} when
% it comes to write labels.
%
% Some solutions exist, like the matlab "laprint.m" function
% (http://www.uni-kassel.de/fb16/rat/matlab/laprint/) to print from
% matlab(TM)
% into {\EPS} files suited to be easily handled by "psfrag". All the
% labels (including numbers on the axis) are converted into strings
% like `x01´ that should be replaced by their values, like `3.141'.
%
% Though the result is pleasant, it is \textsc{mandatory} to keep track
% of the substitutions. This is why the "laprint.m" function takes care
% to write a \TeX{} file that contains all the "\psfrag" commands
% necessary to obtain the original labels. This \TeX{} file can be
% edited to modify the "\psfrag" commands. This scheme works well, but
% has some limitations. You must obviously take care to move the ".tex"
% and the ".eps" file together. But in addition, you must input the
% graphic using an "\input" command. If you intend to modify its size
% or change some "\psfrag" replacements, you need to open and modify
% the original ".tex" file. If you want to use packages like
% "overpic", you must modify the ".tex" file output by "laprint" or
% copy all the "psfrag" replacements that it contains to your main
% \TeX{} file. In case you would choose to copy the psfrag replacements
% into your main \TeX{} file, you will end up with a lot of lines like
% \begin{verbatim}
% \psfrag{x01}[B][B][1][0]{3.141}
% \psfrag{x02}[B][B][1][0]{6.283}
% \psfrag{x03}[B][B][1][0]{9.425}
% \psfrag{x04}[B][B][1][0]{12.566}
% \end{verbatim}
% into your \LaTeX{} document.
%
% In fact, you \textsc{do not need} to see all these lines, and should
% never see them, except, for example, if you want to replace them with
% \begin{verbatim}
% \psfrag{x01}[B][B][1][0]{$\pi$}
% \psfrag{x02}[B][B][1][0]{$\2\,\pi$}
% \end{verbatim}
% and so on.
%
% What is said here about "\psfrag" commands can be transposed to the
% "overpic" environment that allows to put "picture" objects over a
% graphic.
%
% The authors of "psfrag" have designed a mechanism that allows to
% embed "\psfrag" commands into the {\EPS} file itself\footnote
%        {This was kindly reminded to me by Michael C. Grant, one of the
%        authors of "psfrag", that I would like to thank here.%
%        }.
% Though this mechanism can be convenient, it presents some drawbacks
% that are described into the documentation of "psfrag".
%
% The package "psfragX" aims to circumvent these drawbacks, as well as
% to introduce more flexibility into the automatic inclusion mechanism.
% For example, "psfragX" allows to define different "\psfrag"
% replacements for different languages. If "babel" is used,
% replacements will be selected according to the current language of
% the document. It also allows to make use of "color" commands that are
% ignored if the "color" package is not loaded.
%
% \section{How PSfragX works}
%
% \subsection{PSfrag, \textsc{pfx}, overpic and \textsc{ovp}}
%
% The package "psfragx" allows to embed "\psfrag" commands into the
% {\EPS} file, as well as "picture" objects in "overpic" environments.
% In order to simplify the description, we will refer only to
% "\psfrag" inclusions here below.
% The "overpic" inclusion mechanism works in the same way and will
% not be described. The differences between "psfrag" and "overpic"
% inclusions will appear in the syntax of some commands. We use the
% three letters "pfx" to prefix things that relate to "psfrag" and
% "ovp" to prefix things that relate to "overpic".
%
% The psfragx mechanism can be divided into two parts that are
% described separately.
%
% \subsection{Merging and separating the \TeX{} and {\EPS} documents}
%
% We use the result of "laprint.m" as an example, but all the {\EPS} file
% could be processed in the same way. "laprint" outputs
% "Fig1.tex" \&\ "Fig1.eps" files that can be converted into a single
% file that we call Figure1.eps, which is a copy of Fig1.eps, with
% additional comments that contain all the interesting lines of
% Fig1.tex. At this stage, you can throw the original files Fig1.tex
% and Fig1.eps. \textsc{Be careful to make a backup!!!}
%
% The added comments are not read by the PostScript interpreter and
% should not affect the resulting {\EPS} file. As far as I know, the
% comments used conform to the Adobe(TM) Document Structuring
% Convention (ADSC). These comments can be added by hand or using
% the matlab script "psfragx.m" that should be accompanying this file.
% Their structure also conforms to the DocStrip convention (see
% "docstrip.dtx"): the part to be copied starts with a comment "%<*pfx>"
% and ends with "%</pfx>". All the lines between these marks will be
% taken into account by "psfragx".
%
% \begin{verbatim}
% %<*pfx>
% %\psfrag{x01}[B][B][1][0]{3.141}
% %\psfrag{x02}[B][B][1][0]{6.283}
% %\psfrag{x03}[B][B][1][0]{9.425}
% %\psfrag{x04}[B][B][1][0]{12.566}
% %</pfx>
% \end{verbatim}
% PSfragx looks for these lines into the {\EPS} file and outputs them
% into a file with the same name, but a ".pfx" extension. In other
% words, "Figure1.pfx" is created with the comments of "Figure1.eps".
% This file is normally created only once, though there is an option
% to overwrite it. This means that you could edit it by hand without
% loosing your work next time you run LaTeX.
%
% In the same manner, it is possible to include picture commands using
% \begin{verbatim}
% %<*ovp>
% %\put(50,50){Middle of the graphic}
% %</ovp>
% \end{verbatim}
% These lines will go into the file "Figure1.ovp".
%
% The process of seeking for "pfx" and "ovp" environments stops
% as soon as a line starting with "%\endinput" is found. Including
% such a line will speed the things up.
%
% \subsection{Input the right file at the right moment}
%
% Once the "Figure1.pfx" file exists, the command "\includegraphicx"
% includes it and uses the conventional "\includegraphics" from
% "graphicx" with the same arguments. The result is that all the
% "\psfrag" replacements are processed before the
% "Figure1.eps" file is included.
%
% The "\psfrag" commands do not appear into the \TeX{} file.
% The {\PFX} file could be deleted, and all the replacements would still
% be performed, because the {\PFX} file would be re-generated on the fly.
%
% Now that all the labels on the axes are perfectly drawn, we could
% still want to replace the value "3.141" by the tag "$\pi$". This
% is why the "\includegraphicx" command has a second facultative
% argument. Inside this argument, you should issue all the "\psfrag"
% commands that you want to perform after the inclusion of the {\PFX}
% file.
%
% \begin{verbatim}
% \includegraphicx[width=\linewidth]
%                 (\psfrag{x01}[B][B]{$\pi$}%
%                  \psfrag{x02}[B][B]{$2\,\pi$})
%                 {Figure1.eps}
% \end{verbatim}
%
% The second optional argument is defined with "()" to avoid an
% interaction between the brackets of the "\psfrag" command and
% those of the "\includegraphicx" command.
%
% All that is said about {\PFX} files and "psfrag" replacements can be
% transposed to {\OVP} files and "overpic" "picture" commands.
%
% If we want to add "overpic" commands before or after the inclusion
% of the {\OVP} file, we can use the two other optional arguments of
% "\includegraphicx":
% \begin{verbatim}
% \includegraphicx[width=\linewidth]
%                 <\put(50,50){Foreground object}>
%                 [\put(0,0){Background object}]
%                 {Figure1.eps}
% \end{verbatim}
%
%
%
% \section{Usage}
%
% \subsection{Package options}
%
% The package is input by
% "\usepackage["\textit{options}"]{psfragx}"
%
%
% The \textit{options} are
% \begin{description}
% \item[sub, nosub] substitute or do not substitute
%                   "\includegraphicx" to "\includegraphics";
% \item[allcom,selcom] copy all or
% only selected MetaComments from the {\EPS} file to the {\PFX} file
% (if you do not understand what this means, you can safely ignore it);
% \item[ovp, noovp] makes use of overpic to (automatically) put picture
% objects over the graphics.
% \end{description}
%
% \subsection{Two new commands}
%
% \DescribeMacro{\includegraphicx}
% \DescribeEnv{overpix}
% \begin{itemize}
% \item \textsc{The} command of the package is:
%        \begin{tabular}{rl}
%        "\includegraphicx"   &"["\textit{keys}"]"\\
%                             &"("\textit{psfrags}")"\\
%                             &"<"\textit{foreground overpic}">"\\
%                             &"["\textit{background overpic}"]"\\
%                             &"{"\textit{file.eps}"}"\\
%        \end{tabular}
% \item \textsc{The} environment of the package is:
%        \begin{tabular}{rl}
%        "\begin{overpix}"   &"["\textit{keys}"]"\\
%                             &"<"\textit{foreground overpic}">"\\
%                             &"["\textit{background overpic}"]"\\
%                             &"{"\textit{file.eps}"}"\\
%        "\end{overpix}"&\\
%        \end{tabular}
% \end{itemize}
%
% The meaning of the keys is explained in table~\ref{Tab:mean:keys}.
% \begin{table}{h!}
% \centering
% \caption{Meaning of the keys for \texttt{\string\includegraphics}
%          and \texttt{overpix}}
% \label{Tab:mean:keys}
% \footnotesize
% \begin{tabular}{ccl}
% \hline
%  key          &acceptable values          &action\\
% \hline
% \textit{graphicx keys}
%               & \textit{usual values}
%                                           &\textit{usual meanings}\\
%  pfx          &"true"/"false"             &allows/disallows the
%                                            inclusion of the
%                                            {\PFX} file\\
%  overwritepfx &"true"/"false"             &allows/disallows to
%                                            overwrite an existing
%                                            {\PFX} file\\
%  pfxadd       &\textit{psfrags}           &"\psfrag" commands to be
%                                            processed after the
%                                            inclusion of the
%                                            {\PFX} file\\
%  ovp          &"true"/"false"             &allows/disallows the
%                                            inclusion of the
%                                            {\OVP} file\\
%  overwriteovp &"true"/"false"             &allows/disallows to
%                                            overwrite an existing
%                                            {\OVP} file\\
%  ovpbgd       &\textit{picture commands}  &"picture" commands to be
%                                            processed before the
%                                            inclusion of the
%                                            {\OVP} file\\
%  ovpfgd       &\textit{picture commands}  &"picture" commands to be
%                                            processed after the
%                                            inclusion of the
%                                            {\OVP} file\\
% \hline
% \end{tabular}
% \end{table}
%
% The item denoted by \textit{psfrags} should consist only in
% "\psfrag{A}[b][c][d][e]{F}" commands, where A,b,c,d,e,F can be
% anything. In addition, the "\psfrag" commands can be selectively
% included according to the current language of the document
% (at the point of inclusion). Two commands are provided.
% The commands "\iflanguage" is explained in the "babel"
% documentation. If "babel" is not loaded, "\iflanguage" is redefined
% to match the definition of "babel", that is:\\
% "\iflanguage{"\textit{languagename}"}"%
%            "{"\textit{true case}"}"%
%            "{"\textit{false case}"}".
% The configuration file "psfragxcfg" given below, as an example,
% redefines the main commands of the "color" package so that no
% error occurs if the \textit{psfrags} contains color commands and
% the package "color" is not loaded.
%
% The item denoted by \textit{picture commands} should consist only in
% commands that are allowed in the usual "picture" environment of
% \LaTeX{}. You can also make use of "\iflanguage" and color commands,
% provided that the configuration file given below is used.
%
% \textsc{You cannot put blank lines}, that is lines that would 
% consist only in one ``\%'' sign. If you insert such lines, the 
% ``\%'' sign will be removed and some space will be added in front of
% the included figure.
% 
%
% \subsection{Other new commands}
%
%  Though they are not needed in a normal use of "psfragx",
%  the following commands are available:
%  "\allmetacomments",
%  "\selectedmetacomments",
%  "\copypfxfromto{<EPS file>}{<PFX file>}",
%  "\setpfxinput{<File>}",
%  "\setpfxoutput{<File>}",
%  "\copypfxlines",
%  "\pfxinput",
%  "\ovpinput".
%  Their usage can be deduced from the commented source code.
%
% The other commands are internal and start with "\pfx@" or "\ovp@".
%
% \section{Configuration file}
%
% The file "psfragx.cfg" will be input by psfrags, if it exists.
% This file can contain new commands of general use, or commands that
% must appear just before or just after the inclusion of the {\PFX}/{\OVP}
% file occurs. To this aim, four commands can be defined. Their names
% are "\Beforepfxinput", "\Afterpfxinput",
% "\Beforeovpinput", and "\Afterovpinput". They can be used as
% in the example below.
%    \begin{macrocode}
%<*cfg>
% Example of configuration file for psfragx.sty
% The macros \Beforepfxinput, \Afterpfxinput
% \Beforeovpinput, and \Afterovpinput are executed
% into a group. They should not define global commands to
% avoid side effects.
%
%
% The command \providecolorcommands defines commands that
% take the same arguments as the mains commands of the
% color package, in case this package is not loaded.
%
\newcommand{\providecolorcommands}
           {\def\pfx@gobble@two##1##2{\typeout{Some psfragx
                                       replacement would appear
                                       in color ##1{##2}
                                       if the color package was
                                       loaded!!!}}%
            \def\pfx@gobble@three@fbox##1##2##3{\typeout{Some psfragx
                                                replacement would
                                                appear
                                                in color ##1{##2}
                                                and others
                                                in color ##1{##3}
                                                if the color package
                                                was loaded!!!}%
                                                \fbox}%
            \def\pfx@fm@to@mm##1##2##{\csname ##1\endcsname{##2}}%
            \expandafter\ifx\csname textcolor\endcsname\relax
              \def\textcolor{\pfx@fm@to@mm{pfx@gobble@two}}\fi
            \expandafter\ifx\csname color\endcsname\relax
              \def\color{\pfx@fm@to@mm{pfx@gobble@two}}\fi
            \expandafter\ifx\csname colorbox\endcsname\relax
              \def\colorbox{\pfx@fm@to@mm{pfx@gobble@two}}\fi
            \expandafter\ifx\csname fcolorbox\endcsname\relax
              \def\fcolorbox{\pfx@fm@to@mm{pfx@gobble@three@fbox}}\fi
            }
% The name of the next four commands are specific to psfragx
\def\Beforepfxinput{\providecolorcommands}
\def\Afterpfxinput{}
\def\Beforeovpinput{\providecolorcommands}
\def\Afterovpinput{}
%</cfg>
%    \end{macrocode}
% \section{Example of tagged {\EPS} file}
%
% We provide here below an example of {\EPS} that uses
% the language and color features... According to the
% “Adobe Document Structuring Convention” (ADSC), comments
% starting with two percent signs have a special meaning.
% You should therefore avoid to put \textsc{exactly} two
% percents signs at the beginning of a line. If you respect this
% rule and avoid very long lines, you should never broke your
% {\EPS} file.
%
%    \begin{macrocode}
%<*example>
 %%!PS-Adobe-2.0 EPSF-1.2
 %%Creator: Adobe Illustrator(TM) 1.2d4
 %%Title: tiger.eps
 %%CreationDate: 4/12/90 3:20 AM
 %%BoundingBox: 17 171 567 739
 %<*pfx>
 %\psfrag{T}[B][B]{\fcolorbox{white}{black}{\color{white}Title}}
 %\psfrag{t}[t][t]{time (s)}
 %\psfrag{I}[b][b]{I (W)}
 %\iflanguage{french}
 %           {\psfrag{T}[B][B]{Title}%
 %            \psfrag{t}[t][t]{temps (s)}}
 %           {}
 %\psfrag{T}[B][B]{Title}
 %</pfx>
 %<*ovp>
 %\put(0,80){(a)}
 %</ovp>
 %\endinput
 %%EndComments
 %%
 %% [The code of the {\EPS} file should come HERE]
 %%
 %% End
%</example>
%    \end{macrocode}
%
% Full examples should be provided with this package. They are
% not included into "psfrags.dtx".
%
% \section{Associated matlab scripts}
%
% The script "psfragx.m" is written for matlab and can be used in
% conjunction with "laprint.m" (see URL above) in order to benefit from
% the advantages of "laprint.m" and mix the resulting .tex and .eps
% files into a file that contains all the information.
%
% The scripts "pfxprint.m" can be used with the same syntax as 
% "laprint.m" (see documentation of "laprint"). This script invoques 
% "laprint" with the settings contained in the file "laprpfx.mat", and 
% immediately after, it merges the generated \EPS{} and \TeX{} files. 
% Therefore, you should ensure that the files "laprint.m", "laprpfx.mat", and 
% "psfragx.m" are in a directory searched by matlab before using the 
% "pfxprint" command.
%
% At the time of writing, the current version of "laprint" is "3.16". 
% This version works well with "pfxprint.m" and "psfragx.sty".
% 
%
% \section{Credits}
%
% All the code to extract the comments from the {\EPS} file is inspired
% from "docstrip". The set of commands was reduced to its
% minimum, and a "\pfx@" prefix was added to all the commands, in
% order to avoid any interaction with other packages.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \StopEventually{\PrintChanges\PrintIndex}
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \section{Mise en œuvre}
%
% \changes{v0.1}{2003/08/30}{First dtx version}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% Almost all the internal commands start with "\pfx@", "\ovp@",
% "\ifpfx@", or "\ifovp@".
% Two exceptions are "\@..@overpix" and "\@..@igx",
% where "@..@" can be "@", "@@", "@@@" or "@@@@".
%
% \subsection{Required packages and options}
%
% We offer the option to substitute the new "\includegraphicx" command
% to the usual "\includegraphics", and optionally, the overpix
% environment to the usual overpic one. This could broke things but
% allows to use "psfragx" with existing documents almost transparently.
% \begin{macro}{\pfx@subfalse}
% \begin{macro}{\pfx@subtrue}
%    \begin{macrocode}
\DeclareOption{sub}{\pfx@subtrue}
\DeclareOption{nosub}{\pfx@subfalse}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% The next option was of some help to debug this package.
% With "allcom", all the lines of the {\EPS} file starting with "%%" are
% copied to the {\PFX} and {\OVP} files. Otherwise, these lines are not
% copied if they are out of a tagged environment.
%    \begin{macrocode}
\DeclareOption{allcom}{\allmetacomments}
\DeclareOption{selcom}{\selectedmetacomments}
%    \end{macrocode}
% The next option specifies that the overpic environment will be used.
% Therefore, the overpic package should be loaded.
%
% \begin{macro}{\pfx@ovptrue}
% \begin{macro}{\pfx@ovpfalse}
%    \begin{macrocode}
\DeclareOption{ovp}{\pfx@ovptrue}
\DeclareOption{noovp}{\pfx@ovpfalse}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% We define the new commands needed to process the options.
% \begin{macro}{\allmetacomments}
% \begin{macro}{\selectedmetacomments}
%    \begin{macrocode}
       \newif\ifpfx@sub\pfx@subfalse
       \newif\ifpfx@ovp\pfx@ovptrue
       \newif\ifpfx@metacomments
       \pfx@metacommentsfalse
       \def\allmetacomments{\pfx@metacommentstrue}
       \def\selectedmetacomments{\pfx@metacommentsfalse}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% Finally, default options are defined.
%    \begin{macrocode}
\ExecuteOptions{sub,ovp,selcom}
\ProcessOptions*
%    \end{macrocode}
%
% Now, we load the other packages.
%    \begin{macrocode}
\RequirePackage{graphicx}
\RequirePackage{psfrag}
%    \end{macrocode}
%
% The overpic package is not loaded if this was required by the user.
% Otherwise, we load this package. To ensure proper placement of the
% objects put into the picture environment, we must always use the
% same option when loading "overpic". We choose this option to be "percent".
%
%    \begin{macrocode}
\ifpfx@ovp \RequirePackage[percent]{overpic} \fi
%    \end{macrocode}
%
% \subsection{Reading the {\EPS} file and writing {\PFX} or {\OVP} files}
% The code that follows is highly inspired from that of docstrip.tex.
%
% \subsubsection{Copying selected lines from the {\EPS} file}
% Below, we write the code to copy specific lines contained in the
% {\EPS} file into an auxiliary file. Comments (single "%" sign)
% in front of these lines are automatically removed.
%
% First, we define a few macros of general use.
%
% \begin{macro}{\pfx@gobble}
% \begin{macro}{\pfx@percent}
% \begin{macro}{\pfx@doublepercent}
%    \begin{macrocode}
\def\pfx@gobble#1{}
{\catcode`\%=12
 \gdef\pfx@percent{%}
 \gdef\pfx@doublepercent{%%}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% Here we define the extension of the auxiliary file, and the name of
% the tag associated to this file. The "metaprefix" replaces double
% percent signs found into the original {\EPS} file.
% \begin{macro}{\pfx@ext}
% \begin{macro}{\pfx@tag}
% \begin{macro}{\pfx@metaprefix}
%    \begin{macrocode}
\let\pfx@metaprefix\pfx@doublepercent
\def\pfx@tag{pfx}
\def\pfx@ext{pfx}
\def\pfx@tmp{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% We also need to define the string after which we will stop to scan
% the {\EPS} file. This string must appear at the beginning of a line.
% If this string is not present into the {\EPS} file, the file will be
% scanned up to the end. This string is defined to be "%\endinput".
% \begin{macro}{\pfx@endinput}
%    \begin{macrocode}
\edef\pfx@endinput
     {\pfx@percent\expandafter\pfx@gobble\string\\endinput}
%    \end{macrocode}
% \end{macro}
%
% And now, we copy the needed code from "docstrip", with some
% modifications to throw the leading percent sign when we copy
% the lines that appear between two tags "<*pfx>...</pfx>".
%
% We define a command to change catcodes,
%    \begin{macrocode}
\def\pfx@makeother#1{\catcode`#1=12\relax}
%    \end{macrocode}
% another to copy a given token,
%    \begin{macrocode}
\def\pfx@iden#1{#1}
%    \end{macrocode}
% and a few boolean variables.
%    \begin{macrocode}
\newif\ifpfx@continue
\newif\ifpfx@outputtofile
%    \end{macrocode}
%
% The names of the input and output files are contained into the
% internal variables "\pfx@infile" and "\pfx@outfile". These named
% can be accessed from the document through the two commands
% "\setpfxinput" and "\setpfxoutput".
% \begin{macro}{\setpfxinput}
% \begin{macro}{\setpfxoutput}
%    \begin{macrocode}
\def\setpfxinput#1{\gdef\pfx@infile{#1}}
\def\setpfxoutput#1{\gdef\pfx@outfile{#1}}
\gdef\pfx@infile{} \gdef\pfx@outfile{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% Two streams are reserved by "psfragx". I do not know if I should
% use them locally rather than globally.
%    \begin{macrocode}
\newread\pfx@in
\newwrite\pfx@out
%    \end{macrocode}
%
% The macro "\copypfsfromto" \textsc{does not check}
% that the input file exists.
% \begin{macro}{\copypfxfromto}
%    \begin{macrocode}
\def\copypfxfromto#1#2{%
\setpfxinput{#1}%
\setpfxoutput{#2}%
\copypfxlines%
}
%    \end{macrocode}
% \end{macro}
% The macro "\copypfxlines" does the real job.
% See "docstrip" to understand how it works.
% \begin{macro}{\copypfxlines}
%    \begin{macrocode}
\def\pfx@ignorespaces{\ignorespaces}%
\def\copypfxlines{% input and output files are global names
\immediate\openin\pfx@in\pfx@infile\relax \ifeof\pfx@in
       \errmessage{psfragx tried to read from a file that
                   does not exist. This seems to be a bug!}%
\else
       \immediate\openout\pfx@out=\pfx@outfile\relax
       \immediate\write\pfx@out{\pfx@ignorespaces}
       \ifeof\pfx@out
             \begingroup
             \pfx@makeother\ \pfx@makeother\\\pfx@makeother\$%
             \pfx@makeother\#\pfx@makeother\^\pfx@makeother\^^K%
             \pfx@makeother\_\pfx@makeother\^^A\pfx@makeother\%%
             \pfx@makeother\~\pfx@makeother\{\pfx@makeother\}%
             \pfx@makeother\&\endlinechar-1\relax
             \loop
                     \read\pfx@in to \pfx@inline
                     \ifx\pfx@inline\pfx@endinput
                            \pfx@continuefalse
                            \typeout{psfragx: \pfx@percent
                                     \expandafter\pfx@gobble
                                     \string\\endinput was
                                     found in \pfx@infile.}%
                     \else
                            \ifeof\pfx@in
                                   \pfx@continuefalse
                            \typeout{psfragx: End of file
                                     \pfx@infile was reached.}%
                            \else
                                   \pfx@continuetrue
                                   \expandafter\pfx@processline
                                   \pfx@inline\pfx@endline
                            \fi%
                     \fi%
             \ifpfx@continue
             \repeat
             \endgroup
       \else
              \errmessage{psfragx: output file already exists!}%
       \fi %\pfx@out
       \immediate\closeout\pfx@out
\fi %\pfx@in
\immediate\closein\pfx@in
}
%    \end{macrocode}
% At this stage, all "<pfx>" and "<*pfx>...</pfx>" lines from
% "\pfx@infile" should be in "\pfx@outfile".
% \end{macro}
%
% Each time a new line is found by the previous macro, the line is
% processed using "\pfx@processline". This macro scans the beginning
% of the line and defers the treatment to the right macro.
% In the "docstrip" code, normal lines are copied without change.
% In our code, the leading percent of copied lines is removed.
%
% \begin{macro}{\pfx@processline}
%    \begin{macrocode}
\def\pfx@normalline#1\pfx@endline{%
       \def\pfx@inline{#1}%
       \ifpfx@outputtofile%
              \immediate\write\pfx@out{\pfx@inline}%
       \fi%
}
%
\def\pfx@removecomment#1\pfx@endline{%
       \def\pfx@inline{#1}%
       \ifpfx@outputtofile%
              \immediate\write\pfx@out{\pfx@inline}%
       \fi%
}
%
\bgroup\catcode`\%=12 \pfx@iden{\egroup
\def\pfx@putmetacomment%}#1\pfx@endline{%
       \edef\pfx@inline{\pfx@metaprefix#1}%
       \ifpfx@metacomments
              \immediate\write\pfx@out{\pfx@inline}%
       \else
              \ifpfx@outputtofile
                     \immediate\write\pfx@out{\pfx@inline}%
              \fi
      \fi
}
%
\begingroup
\catcode`\%=12 \catcode`\*=14 \gdef\pfx@processline#1{*
       \ifx%#1*
              \expandafter\pfx@processlinex
       \else
              \expandafter\pfx@normalline
       \fi
#1}
\endgroup
%
\begingroup
\catcode`\%=12 \catcode`\*=14
\gdef\pfx@processlinex%#1{*
       \ifcase\ifx%#10\else
              \ifx<#11\else2\fi\fi\relax
       \expandafter\pfx@putmetacomment\or
       \expandafter\pfx@checkoption\or
       \expandafter\pfx@removecomment\fi
#1}
\endgroup
%
\def\pfx@checkoption<#1{%
       \ifcase\ifx*#10\else
              \ifx/#11\else2\fi\fi\relax
       \expandafter\pfx@staroption\or
       \expandafter\pfx@slashoption\or
       \expandafter\pfx@tagoption\fi
#1}
%
\def\pfx@staroption*#1>#2\pfx@endline{%
       \def\pfx@tmp{#1}%
       \ifx\pfx@tmp\pfx@tag
              \pfx@outputtofiletrue
       \fi
}
%
\def\pfx@slashoption/#1>#2\pfx@endline{%
       \def\pfx@tmp{#1}%
       \ifx\pfx@tmp\pfx@tag\relax
              \pfx@outputtofilefalse
       \fi
}
%
\def\pfx@tagoption#1>#2\pfx@endline{%
       \def\pfx@tmp{#1}%
       \ifx\pfx@tmp\pfx@tag\relax
              \def\pfx@inline{#2}%
              \immediate\write\pfx@out{\pfx@inline}%
       \fi
}
%    \end{macrocode}
% \end{macro}
% This ends the code to read {\EPS} file and write {\PFX} file. It is
% clear that only "\pfx@tag" and "\pfx@ext" should be changed from
% "pfx"to "ovp" in order to process "overpic" inclusions rather than
% "psfrag" replacements.
%
% \subsection{Code that inputs the {\PFX} and {\OVP} files}
%
% This code will add commands to input the {\PFX} and {\OVP} files if
% they exist. If they do not, they will be created on the fly and read
% just after. An option allows to ignore existing files and generate
% {\PFX} and {\OVP} files from the {\EPS} file each time the {\EPS}
% file is included.
%
% At first, we define commands related to {\PFX} files.
% Later on, we will adapt them to {\OVP} files.
%
% \subsubsection{Saving and providing commands of other packages}
%
% We save the commands that could be redefined later
%    \begin{macrocode}
\let\pfx@includegraphics=\includegraphics
\let\pfx@overpic=\overpic
\let\pfx@endoverpic=\endoverpic
%    \end{macrocode}
%
% Even if "overpic" is not loaded, the "overpic" environment should
% exist. In this case, the {\OVP} files will not be processed, and
% no "picture" element should be put over the graphics.
% Nonetheless, "\includegraphicx"
% is defined to always use the "overpic" environment.
%
% Therefore, we provide a definition of the "overpic" environment
% that is partially copied from overpic.sty. We have removed all the
% code that makes computations about the size and the position of the
% grid.
% \begin{macro}{\pfx@overpic}
% \begin{macro}{\pfx@endoverpic}
%    \begin{macrocode}
\@ifundefined{pfx@overpic}{%
                       \newcommand*{\pfx@overpic}[2][]
                       {\sbox{\z@}{\includegraphics[#1]{#2}}%
                       \settodepth{\@tempcnta}{\usebox{\z@}}%
                       \settoheight{\@tempcntb}{\usebox{\z@}}%
                       \advance\@tempcntb\@tempcnta%
                       \settowidth{\@tempcnta}{\usebox{\z@}}%
                       \begin{picture}(\@tempcnta,\@tempcntb)%
                       \put(0,0){\makebox(0,0)[bl]{\usebox{\z@}}}}%
                      }{}
\@ifundefined{pfx@endoverpic}{\def\pfx@endoverpic{\end{input}}}{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \DescribeMacro{\iflanguage}
% We also have to provide "\iflanguage" command, in case "babel"
% is not loaded. We could have simplified the code, because
% "\pfx@iflanguage" should always expand to "\@secondoftwo"
% if babel is not loaded. Because this code was also copied from
% the babel package with some changes, we use it even if "babel"
% is loaded. This could cause problems if the internal command
% "l@"\textit{language} of "babel" was redefined. Though we redefine
% a "babel" command, this should cause no major problem, because
% the command "\iflanguage" will be provided only at time of the
% file inclusion. This means that "\psfrag" replacements should
% contain no reference to "\iflanguage" as these commands will
% be evaluated  after the file is read. The command "\iflanguage"
% should be evaluated at time of inclusion, in order to decide
% which "psfrag" or "picture" commands are to be taken into account.
%
% \DescribeMacro{\onlylanguage}
% \DescribeMacro{\endonlylanguage}
% In order to simplify the writing of multilingual {\EPS} files, we
% also provide the command "\onlylanguage" "{"\textit{language}"}..."
% "\endonlylanguage", which argument is read only if the current
% language of the document is \textit{language}.
%
% In order to simplify the writing of multilingual {\EPS} files, we
% also provide the command "\onlylanguage" "{"\textit{language}"}..."
% "\endonlylanguage", which argument is read only if the current
% language of the document is \textit{language}.
% \begin{macro}{\pfx@iflanguage}
% \begin{macro}{\iflanguage}
% \begin{macro}{\onlylanguage}
% \begin{macro}{\endonlylanguage}
% \begin{macro}{\pfx@save@iflanguage}
% \begin{macro}{\pfx@restore@iflanguage}
% \begin{macro}{\pfx@firstoftwo}
% \begin{macro}{\pfx@secondoftwo}
%    \begin{macrocode}
\long\def\pfx@firstoftwo#1#2{#1\ignorespaces}%
\long\def\pfx@secondoftwo#1#2{#2\ignorespaces}%
\def\pfx@iflanguage#1{%
    \ifnum\csname l@#1\endcsname=\language
      \expandafter\pfx@firstoftwo
    \else
      \expandafter\pfx@secondoftwo
    \fi}
\long\def\onlylanguage#1#2\endonlylanguage{\pfx@iflanguage{#1}{#2}{}\ignorespaces}
\def\pfx@save@iflanguage{\let\save@pfx@iflanguage=\iflanguage%
                         \let\iflanguage=\pfx@iflanguage}
\def\pfx@restore@iflanguage{\let\iflanguage=\save@pfx@iflanguage}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% The two commands "\pfx@save@iflanguage" and
% "\pfx@restore@iflanguage" will be called just before
% and after the inclusion of the {\PFX} file.
%
% \subsubsection{New commands to read and write files}
%
% We start with some declarations (new commands and new if)
% The names of the "ifGin" series are chosen to be easily processed
% through the "keyval" package mechanism. "Gin" is the prefix used
% by the "graphicx" package.
% \begin{macro}{\ifpfx@generate}
% \begin{macro}{\ifovp@generate}
% \begin{macro}{\pfx@add}
% \begin{macro}{\ovp@add@bgd}
% \begin{macro}{\ovp@add@fgd}
% \begin{macro}{\ifGin@pfx}
% \begin{macro}{\ifGin@overwritepfx}
% \begin{macro}{\ifGin@ovp}
% \begin{macro}{\ifGin@overwriteovp}
%    \begin{macrocode}
\newif\ifpfx@generate
\newif\ifovp@generate
\newcommand*\pfx@add{}
\newcommand*\ovp@add@bgd{}
\newcommand*\ovp@add@fgd{}
\newif\ifGin@pfx
\newif\ifGin@overwritepfx
\newif\ifGin@ovp
\newif\ifGin@overwriteovp
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% As the names indicate, these macros are attached to {\PFX} or
% {\OVP} inclusions. They allow to save information to know if a
% {\PFX}/{\OVP} file is to be generated, if the {\PFX}/{\OVP}
% automatic inclusion mechanism is to be used and if existing
% {\PFX}/{\OVP} files should be overwritten. Finally, three commands
% will contain the "\psfrag" commands ("\pfx@add") to be issued
% after the inclusion of the {\PFX} file, as well as "picture"
% commands to be issued before ("\ovp@add@bgd") and after
% ("\ovp@add@fgd") the {\OVP} file inclusion.
%
% The new keys will be available through the optional arguments of
% "\includegraphicx".
% This is why they are defined as belonging to the same group as the
% "graphicx" keys: "Gin".
%
% The role that we have described for the previous commands is
% assigned here below. As is common, the boolean keys are set
% to be true if they are invoked without argument.
%    \begin{macrocode}
\define@key{Gin}{pfx}[true]%
           {\lowercase{\Gin@boolkey{#1}}{pfx}}
\define@key{Gin}{overwritepfx}[true]%
           {\lowercase{\Gin@boolkey{#1}}{overwritepfx}}
\define@key{Gin}{pfxadd}[]%
           {\def\pfx@add{#1}}
\define@key{Gin}{ovp}[true]%
           {\lowercase{\Gin@boolkey{#1}}{ovp}}
\define@key{Gin}{overwriteovp}[true]%
           {\lowercase{\Gin@boolkey{#1}}{overwriteovp}}
\define@key{Gin}{ovpbgd}[]%
           {\def\ovp@add@bgd{#1}}
\define@key{Gin}{ovpfgd}[]%
           {\def\ovp@add@fgd{#1}}
%    \end{macrocode}
% We will define a handy syntax for the "\includegraphicx" command.
% This command will mainly convert some of its optional arguments
% to keys "pfxadd={"\textit{argument}"}",
%         "ovpbgd={"\textit{argument}"}",
%     and "ovpfgd={"\textit{argument}"}".
%
% It is now time to define the commands that will test for the
% existence of the input and output files and decide if an output
% file is to be generated. This command makes use of values
% defined previously for {\PFX} files. This is why we prefix the
% command with "\pfx".
% To understand the code below, it is important to know that the
% command "\filename@parse{}" defines three commands that are
% "\filename@area", "\filename@base" and "\filename@ext".
% \begin{macro}{\pfxinput}
%    \begin{macrocode}
\newcommand*{\pfxinput}[1]{%
  \filename@parse{#1}%
  \IfFileExists{\filename@base.\pfx@ext}
               {\pfx@generatefalse}
               {\pfx@generatetrue}%
  \ifGin@overwritepfx\pfx@generatetrue\fi
  \IfFileExists{#1}{}{\pfx@generatefalse}%
  \ifpfx@generate%
       \copypfxfromto{\filename@area\filename@base.\filename@ext}
                     {\filename@base.\pfx@ext}%
  \fi%
  \pfx@save@iflanguage
  \csname Before\pfx@tag input\endcsname
  \InputIfFileExists{\filename@base.\pfx@ext}
                    {\typeout{psfragx: reading commands from
                                       \filename@base.\pfx@ext}}
                    {\typeout{psfragx: I was not able to read psfrag
                              definitions from
                              \filename@base.\pfx@ext}}%
  \csname After\pfx@tag input\endcsname
  \pfx@restore@iflanguage
}
%    \end{macrocode}
% \end{macro}
% As was announced, we determine if the output file exists.
% In case this file exists we decide not to generate the output file.
% If the user required that the output file be overwritten, we
% ask to generate the output file in any case.
% Then we test if the input file exists. If not, we cannot generate
% the ouptut file.
%
% Now that the existence of the input file has been checked, we can
% call the low level command "\copypfxfromto". This completes the
% first step.
%
% The second step is to input the {\PFX} file if it exists. The file
% is input inside a "\pfx@save@iflanguage" "\pfx@restore@iflanguage"
% pair. In addition, the commands "\Beforepfxinput" and
% "\Afterpfxinput" are issued if they exist. Otherwise, they expand
% to "\relax". These commands should be defined into the "psfragx.cfg"
% file in order to customise the behaviour of "psfragx".
%
% Now, we define variations of "\pfx@" commands in order to work with
% the "overpic" environment rather than with "psfrag" replacements.
%
% We redefine the tag and the extension, copy the overwrite
% permission and call "\pfxinput".
% \begin{macro}{\ovpinput}
%    \begin{macrocode}
\newcommand*{\ovpinput}[1]{%
\begingroup
       \def\pfx@ext{ovp}%
       \def\pfx@tag{ovp}%
       \ifGin@overwriteovp\Gin@overwritepfxtrue
                     \else\Gin@overwritepfxfalse\fi
       \pfxinput{#1}%
\endgroup}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The main command of this package}
%
%  Here comes the definition of the main command of this package,
% as seen by the user : "\includegraphicx".
%  This new command will make use of the new environment called
% "overpix", in order to include the graphics.
%
% \subsubsection{Internal commands}
%
% First, we define two internal commands that perform the
% required task. Then we define external commands with optional
% arguments.
% \begin{macro}{\pfx@includegraphicx}
% The macro "\pfx@includegraphics" is just a shortcut to acces
% the "overpix" environment. We do not call
% "\begin{pfx@overpix}..." "\end{pfx@overpix}", in order to save time.
%    \begin{macrocode}
\def\pfx@includegraphicx#1#2{%
       \mbox{\pfx@overpix{#1}{#2}\endpfx@overpix}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ovp@box@tmp}
% In what follows, we need a temporary box. This is called "\ovp@box@tmp".
%    \begin{macrocode}
\newbox{\ovp@box@tmp}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\pfx@overpix}
% \begin{macro}{\endpfx@overpix}
% The environment "overpix" has the same syntax as the "overpic" one.
% You can notice that the original version of "\includegraphics" is
% used. This is important if we decide, later, to let
% "\includegraphics" be equivalent to "\includegraphicx".
% The "\psfrag" commands and the "picture" commands are processed
% inside this environment. To avoid side effects of command
% redefinitions inside the included files, we enclose the contents of
% "overpix" inside a "\begingroup" "\endgroup" pair.
%
% The graphic is included via the original or the lightened version
% of the "overpic" environment.
%
% All we do is to evaluate the keys of the first argument, then
% input the {\PFX} file, and process the contents of "\pfx@add".
% Thereafter, we call the original or lightened version of the
% "overpic" environment. We read the keys again and add the
% background layer of the picture environment, then the layer
% contained into the {\OVP} file.
%
% When the "\pfx@overpix" command is issued, we end up into a
% "picture" environment that constitutes yet another layer.
% Finally, the "picture" environment should be closed by an
% "\endpfx@overpix" command. Before doing so, the foreground
% layer of the picture environment is drawn.
%
% It is mandatory to take care that not spurious space is added
% at the end of the lines. A percent sign should appear each time
% the line is ending with something else than a command name.
%
%    \begin{macrocode}
\def\pfx@overpix#1#2{%
       \begingroup%
       \begin{lrbox}{\ovp@box@tmp}%
       \let\includegraphics=\pfx@includegraphics%
       \Gin@pfxtrue%
       \Gin@overwritepfxfalse%
       \def\pfx@add{}%
       \setkeys{Gin}{#1}%
       \ifGin@pfx%
          \pfxinput{#2}%
       \fi%
       \pfx@add
       \pfx@overpic[#1]{#2}
              \Gin@ovptrue
              \Gin@overwriteovpfalse
              \def\ovp@add@bgd{}%
              \def\ovp@add@fgd{}%
              \setkeys{Gin}{#1}%
              \ovp@add@bgd
              \ifGin@ovp
                     \ovpinput{#2}%
              \fi
       }% \pfx@overpix
%
\def\endpfx@overpix{%
              \ovp@add@fgd%
       \pfx@endoverpic
       \end{lrbox}%
       \usebox{\ovp@box@tmp}%
       \endgroup%
       }%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \subsubsection{External commands}
%
% The definitions here below ensure that the optional arguments
% are optional.
% \begin{macro}{\overpix}
% \begin{macro}{\endoverpix}
% The syntax of "overpix" is as follows.\\
% \begin{tabular}{rl}
% "\overpix"  &"["\textit{keys}"]"\\
%             &"<"\textit{foreground layer}">"\\
%             &"["\textit{background layer}"]"\\
%             &"{"\textit{file.eps}"}"
% \end{tabular}
%    \begin{macrocode}
\def\overpix{\@ifnextchar[{\@overpix}%
                          {\@overpix[]}}%
\def\@overpix[#1]{\@ifnextchar<{\@@overpix[#1]}%
                               {\@@overpix[#1]<>}}%
\def\@@overpix[#1]<#2>%
              {\@ifnextchar[{\@@@overpix[#1]<#2>}%
                            {\@@@overpix[#1]<#2>[]}}%
\def\@@@overpix[#1]<#2>[#3]#4%
               {\pfx@overpix{#1,ovpfgd={#2},ovpbgd={#3}}{#4}}
\def\endoverpix{\endpfx@overpix}
%    \end{macrocode}
% This set of commands converts the optional arguments into keys.
% \end{macro}
% \end{macro}
% \begin{macro}{\includegraphicx}
% The syntax of "\includegraphicx" is as follows.\\
% \begin{tabular}{rl}
% "\includegraphicx" &"["\textit{keys}"]"\\
%                    &"("\textit{psfrag replacements}")"\\
%                    &"<"\textit{foreground layer}">"\\
%                    &"["\textit{background layer}"]"\\
%                    &"{"\textit{file.eps}"}"
% \end{tabular}
%    \begin{macrocode}
\def\includegraphicx{\@ifnextchar[{\@igx}%
                                  {\@igx[]}}%
\def\@igx[#1]{\@ifnextchar({\@@igx[#1]}%
                           {\@@igx[#1]()}}%
\def\@@igx[#1](#2){\@ifnextchar<{\@@@igx[#1](#2)}%
                                {\@@@igx[#1](#2)<>}}%
\def\@@@igx[#1](#2)<#3>{\@ifnextchar[{\@@@@igx[#1](#2)<#3>}%
                                     {\@@@@igx[#1](#2)<#3>[]}}%
\def\@@@@igx[#1](#2)<#3>[#4]#5%
    {\pfx@includegraphicx{#1,pfxadd={#2},ovpfgd={#3},ovpbgd={#4}}{#5}}
%    \end{macrocode}
% This set of commands converts the optional arguments into keys.
% \end{macro}
%
% \subsection{Overloading includegraphics and overpic}
%
% If the user requires so, we let "\includegraphics" and the "overpic"
% environment act as their counterparts ending in "x".
% Though this substitution was tested, it could broke things and
% should be used with care.
%
%
% \begin{macro}{\includegraphics}
% \begin{macro}{\overpic}
% \begin{macro}{\endoverpic}
%    \begin{macrocode}
\ifpfx@sub
       \let\includegraphics=\includegraphicx
       \ifpfx@ovp
              \let\overpic=\overpix
              \let\endoverpic=\endoverpix
       \fi
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Configuration file}
%
% Finally, we input the configuration file if it exists.
%    \begin{macrocode}
\InputIfFileExists{psfragx.cfg}{}{}
%    \end{macrocode}
% This ends the code of "psfragx.sty".
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \section{Code of the matlab script}
%
% Note that the lines containing the "rm" and "mv" commands should be
% replaced by their equivalents on the operating system 
% on wich matlab is running. For example, under \textsc{dos} and its 
% successors the replacements are "del" and "ren".
% 
%
%    \begin{macrocode}
%<*matlab>
% psfragx.m                      %%% [-*- Matlab -*-]
%
% function psfragx(NomTeX,NomEPS)
% nargin=1 -> NomTeX=NomEPS
%
% Copy lines of NomTeX.tex 
% starting with 
% \psfrag 
% and 
% %<pfx> 
% to the file NomEPS.eps, as a comment following the 
% %%BoundigBox 
% line.

function psfragx(TeXname,EPSname,Outname)
TMPname='psfragx_tmp';
if nargin<2, EPSname=TeXname; end
if nargin<3, Outname=EPSname; end
if Outname==EPSname, 
   eval(['!rm ',TMPname,'.eps'])    
   eval(['!mv ',EPSname,'.eps ',TMPname,'.eps'])
   EPSname=TMPname;
end
TeXName=([TeXname,'.tex']);
EPSName=([EPSname,'.eps']);
OutName=([Outname,'.eps']);

BeginInput ='%%BoundingBox:';
BeginPSFRAG='%<pfx>\pfxbegin[1.0]{laprint}%';
EndPSFRAG  ='%<pfx>\pfxend';
StartPFX   ='%<*pfx> Inserted where \begin{psfrags}% occured';
StopPFX    ='%</pfx> Inserted where \end{psfrags}% occured';
EndInput  ='%\endinput';
EndOfFile ='%%EOF';
ResizeBox ='%<pfx>\def\naturalwidth';
StopOn    ={'\psfrag{','<pfx>','\begin{psfrags}','\end{psfrags}','\resizebox'};

TeXFile=fopen(TeXName,'r');
if (TeXFile==-1)
        error(['I was not able to open ',TeXName,'!']);
end
EPSFile=fopen(EPSName,'r');
if (EPSFile==-1)
        error(['I was not able to open ',EPSName,'!']);
end
OutFile=fopen(OutName,'w');
if (OutFile==-1)
        error(['I was not able to open ',OutName,'!']);
end

[sEPS,llEPS,iEPS]=CopyUntil(EPSFile,OutFile,{BeginInput});
       if sEPS~=1, error(['No line contains ',BeginInput]); 
       else
                 fprintf(OutFile,'%s\n',llEPS);       
       end

%%%
%%% Write preamble
%%% 
fprintf(OutFile,'%%<*pfx> Begin Preamble\n');
fprintf(OutFile,'%%\\providecommand*{\\pfxbegin}[2][]{}%%\n');
fprintf(OutFile,'%%\\providecommand{\\pfxend}{}%%\n');
fprintf(OutFile,'%%</pfx> End Preamble\n');
%%%
%%% Copy interesting lines
%%%
while 1
       [sTeX,llTeX,iTeX]=ReadUntil(TeXFile,StopOn);
              if sTeX~=1, break; end
       switch iTeX
          case 1,    %   \psfrag
                 fprintf(OutFile,'%%%s\n',llTeX);
          case 2,    %   %<pfx>
                 fprintf(OutFile,'%s\n',llTeX);
          case 3,    %   \begin{psfrags}
                 fprintf(OutFile,'%s\n',BeginPSFRAG);
                 fprintf(OutFile,'%s\n',StartPFX);          
          case 4,    %   \end{psfrags}
                 fprintf(OutFile,'%s\n',StopPFX);                    
                 fprintf(OutFile,'%s\n',EndPSFRAG);
          case 5,    %   \resizebox   
                 tmpbeg=findstr(llTeX,'{');
                 tmpend=findstr(llTeX,'}');       
                 if (length(tmpbeg)>0)&(length(tmpend)>0)
                     if (tmpbeg(1)<tmpend(1))
                        fprintf(OutFile,'%s%s%%\n',ResizeBox,llTeX(tmpbeg(1):tmpend(1)));
                     end
                 end
       otherwise
              error('Otherwise should never happen !')
       end
end
%%%
%%% Write postamble
%%%
fprintf(OutFile,'%s\n',EndInput);
%%%
%%% Copy to the end of file
%%%
[sEPS,llEPS,iEPS]=CopyUntil(EPSFile,OutFile,{''});
%%%
%%% Close files
%%%
fclose(OutFile);
fclose(TeXFile);
fclose(EPSFile);
return

function [OK,lastline,elt]=CopyUntil(fidIn,fidOut,linebeg);
sl=length(linebeg);
if sl==0, OK=-2; return, end
llb=zeros(sl);
for ii=1:sl
       llb(ii)=length(linebeg{ii});
end
lastline='';
OK=0;
elt=0;
while 1
       Line=fgetl(fidIn);
       if ~isstr(Line), 
              OK=-1;
              return, 
       end  %EndOfFile
       for ii=1:sl
%%%              fprintf('Seeking for line starting with %s.\n',linebeg{ii});
              if llb==0,    %%% Copying to the end of file
              else
                     if length(Line)>=llb(ii)
%%%                            fprintf('This line counts more than %i chars.\n',llb(ii));
                            if Line(1:llb(ii))==linebeg{ii},
                                   OK=1;
                                   elt=ii;
                                   lastline=Line;
                                   break
                            end
                     end
              end
       end    %%% No matching string
       if OK==1, break, end
       if ~isempty(fidOut)
              fprintf(fidOut,'%s\n',Line);
       end
end
return

function [OK,lastline,elt]=ReadUntil(fidIn,linebeg);
         [OK,lastline,elt]=CopyUntil(fidIn,[],linebeg);
return
%</matlab>
%<*pfxprint>
%%% pfxprint [ -*- Matlab -*- ] Time-stamp: <2004-08-12 18:20:57 Pascal Kockaert>
%%%
% function pfxprint(fig,name,'optA','valA','optB','valB',...)
%
% TO USE THIS FUNCTION, THE FILE laprpfx.mat SHOULD BE IN THE MATLAB PATH
% 
% This function is to be used like laprint.m
% The EPS and TeX files resulting from the call to laprint with the given arguments
% are automatically merged into one EPS file that contains the 
% psfrags replacements as comments.
% These comments can be automatically used in LaTeX, with the help of the psfragx package.
%
% This file is subject to the LPPL licence (see other files in the source archive or www.ctan.org)
% Copyright 2004, Pascal Kockaert
%

function pfxprint(fig,name,varargin)
 deftxtint=get(0,'DefaultTextInterpreter');
 set(0,'DefaultTextInterpreter','none');

  laprint(fig,name,'options','laprpfx',varargin{:});
  psfragx(name);

 set(0,'DefaultTextInterpreter',deftxtint)

% Default options are
% LAPRINTOPT =
%              figno: 2
%           filename: 'laprint'
%              width: 12
%             factor: 0.8
%         scalefonts: 1
%      keepfontprops: 0
%         asonscreen: 0
%     keepticklabels: 0
%     mathticklabels: 0
%               head: 0
%            comment: 'Test de laprint'
%            caption: ''
%       extrapicture: 0
%             nzeros: 3
%            verbose: 'off'
%            figcopy: 1
%           printcmd: 'print('-f<figurenumber>','-depsc2','<filename.eps>')'
%            package: 'graphicx'
%              color: 0
%         createview: 0
%       viewfilename: 'unnamed_'
%        processview: 0
%               cmd1: 'latex -halt-on-error -interaction nonstopmode <viewfile>.tex'
%               cmd2: 'dvips -D600 -E* -o<viewfile>.eps <viewfile>.dvi'
%               cmd3: 'epstool --bbox --copy --output <filename>_final.eps <viewfile>.eps'
%               cmd4: 'rm <viewfile>.eps <viewfile>.dvi <viewfile>.aux <viewfile>.log <viewfile>.pfg'
%               cmd5: 'ghostview <filename>_final.eps&'
%               cmd6: ''
%               cmd7: ''
%               cmd8: ''
%</pfxprint>
%    \end{macrocode}
%\typeout{^^J***************************************************}
%\typeout{In order to generate index files, run^^J}
%\typeout{makeindex -s gglo -o psfragx.gls psfragx.glo}
%\typeout{makeindex -s gind psfragx.idx^^J}
%\typeout{***************************************************^^J}
%\Finale
\endinput