summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/support/latex-make/texdepends.dtx
blob: f1e66e116d8cf7702c6bd27886df7f964e87d8eb (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
%    \iffalse meta-comment
%%
%% File: texdepends.dtx Copyright (C) 2004--2011 V. Danjean
%%    Vincent.Danjean@ens-lyon.org
%% Modified by Matthieu Gallet
%%    Matthieu.Gallet@ens-lyon.org
%%
%% 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 2
%% 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.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; if not, write to the Free Software
%% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
%%
%
%<*dtx>
          \ProvidesFile{texdepends.dtx}
%</dtx>
%<package>\NeedsTeXFormat{LaTeX2e}%
%<package>\ProvidesPackage{texdepends}%
%    \fi
%         \ProvidesFile{texdepends.dtx}
[2018/05/29 v2.2.4 no change in this version]
% \iffalse
%<*driver>
\documentclass{ltxdoc}
\usepackage[latin1]{inputenc}
\usepackage[french,english]{babel}
\usepackage{pdfswitch}
\NoAutoSpaceBeforeFDP
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\setcounter{IndexColumns}{2}    % make a twocolumn index
\setlength{\columnseprule}{0pt} % no rules between columns ...
\setlength{\columnsep}{2em}     % ... but more spacing instead.
\setcounter{unbalance}{4}
\setlength{\IndexMin}{100pt}
%%%%\OnlyDescription  % uncomment this line to suppress printing the source code
\makeatletter
% don't show underfull hboxes in index/glossary:
\g@addto@macro{\IndexParms}{\hbadness=10000}
\g@addto@macro{\GlossaryParms}{\hbadness=10000}
\makeatother
\begin{document}
  \DocInput{texdepends.dtx}
  \PrintIndex
  \PrintChanges
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{texdepends.dtx}
%
% \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ }
% \DoNotIndex{\def,\long,\edef,\xdef,\gdef,\let,\global}
% \DoNotIndex{\if,\ifnum,\ifdim,\ifcat,\ifmmode,\ifvmode,\ifhmode,%
%             \iftrue,\iffalse,\ifvoid,\ifx,\ifeof,\ifcase,\else,\or,\fi,\loop,\do}
% \DoNotIndex{\box,\copy,\setbox,\unvbox,\unhbox,\hbox,%
%             \vbox,\vtop,\vcenter}
% \DoNotIndex{\@empty,\immediate,\write}
% \DoNotIndex{\egroup,\bgroup,\expandafter,\begingroup,\endgroup}
% \DoNotIndex{\divide,\advance,\multiply,\count,\dimen}
% \DoNotIndex{\relax,\space,\string}
% \DoNotIndex{\csname,\endcsname,\@spaces,\openin,\openout,%
%             \closein,\closeout}
% \DoNotIndex{\catcode,\endinput}
% \DoNotIndex{\jobname,\message,\read,\the,\noexpand}
% \DoNotIndex{\hsize,\vsize,\hskip,\vskip,\kern,\hfil,\hfill,\hss}
% \DoNotIndex{\m@ne,\z@,\@m,\z@skip,\@ne,\tw@,\p@}
% \DoNotIndex{\DeclareRobustCommand,\DeclareOption,\newcommand,\newcommand*}
% \DoNotIndex{\newcount,\newif,\newlinechar,\newread,\newtoks,\newwrite}
% \DoNotIndex{\dp,\wd,\ht,\vss,\unskip,\ifthenelse}
%
% \DoNotIndex{\@filef@und,\@nameddef,\@tempa}
% \DoNotIndex{\define@key,\equal,\ExecuteOptions}
% \DoNotIndex{\filename@area,\filename@base,\filename@ext,\filename@parse}
% \DoNotIndex{\Gin@exclamation,\Gin@getbase,\Gin@scalex,\Gin@scaley}
% \DoNotIndex{\Gread@eps,\Gread@pdf,\Gscale@box}
% \DoNotIndex{\IfFileExists,\ifpdf,\input,\InputIfFileExists}
% \DoNotIndex{\MessageBreak,\PackageWarning,\PackageWarningNoLine}
% \DoNotIndex{\ProcessOptions,\RequirePackage,\typeout}
% \DoNotIndex{}
% \DoNotIndex{}
%
% \title{The \textsf{texdepends} package\thanks{This file
%        has version number \fileversion, last
%        revised \filedate.}}
% \author{Vincent \textsc{Danjean}}
% \date{\filedate}
% \maketitle
% \begin{abstract}
%   This package allows \LaTeX\space to automatically generate
%   dependencies while compiling documents.
% \end{abstract}
% \CheckSum{785}
%
% \changes{v1.0.1}{2005/03/22}{Version 1.0.1 at last}
% \changes{v1.0.2}{2005/10/22}{Add support for package index.sty}
% \changes{v1.1.0}{2005/11/05}{Manage index/glossary}
% \changes{v1.1.0}{2005/11/05}{Rewrite of the package}
% \changes{v1.2.0}{2008/01/28}{Better management of subfig files}
% \changes{v1.3.0}{2011/09/25}{Management of svg files}
%
% \makeatletter
% \def\SpecialOptionIndex#1{\@bsphack
%     \index{#1\actualchar{\protect\ttfamily#1}
%            (option)\encapchar usage}%
%     \index{options:\levelchar{\protect\ttfamily#1}\encapchar
%            usage}\@esphack}
% \def\SpecialFileIndex#1{\@bsphack
%     \index{#1\actualchar{\protect\ttfamily#1}
%            (file)\encapchar usage}%
%     \index{files:\levelchar{\protect\ttfamily#1}\encapchar
%            usage}\@esphack}
% \def\SpecialMainOptionIndex#1{\@bsphack\special@index{#1\actualchar
%                                       {\string\ttfamily\space#1}
%                                          (option)\encapchar main}%
%     \special@index{options:\levelchar{%
%                    \string\ttfamily\space#1}\encapchar
%            main}\@esphack}
% \def\option{\begingroup
%    \catcode`\\12
%    \MakePrivateLetters \mym@cro@ \iffalse}
% \long\def\mym@cro@#1#2{\endgroup \topsep\MacroTopsep \trivlist
%    \edef\saved@macroname{\string#2}%
%   \def\makelabel##1{\llap{##1}}%
%   \if@inlabel
%     \let\@tempa\@empty \count@\macro@cnt
%     \loop \ifnum\count@>\z@
%       \edef\@tempa{\@tempa\hbox{\strut}}\advance\count@\m@ne \repeat
%     \edef\makelabel##1{\llap{\vtop to\baselineskip
%                                {\@tempa\hbox{##1}\vss}}}%
%     \advance \macro@cnt \@ne
%   \else  \macro@cnt\@ne  \fi
%   \edef\@tempa{\noexpand\item[%
%      #1%
%        \noexpand\PrintMacroName
%      \else
%        \noexpand\PrintEnvName
%      \fi
%      {\string#2}]}%
%   \@tempa
%   \global\advance\c@CodelineNo\@ne
%    #1%
%       \SpecialMainIndex{#2}\nobreak
%       \DoNotIndex{#2}%
%    \else
%       \SpecialMainOptionIndex{#2}\nobreak
%    \fi
%   \global\advance\c@CodelineNo\m@ne
%   \ignorespaces}
% \let\endoption \endtrivlist
% \def\DescribeOption{\leavevmode\@bsphack\begingroup\MakePrivateLetters
%   \Describe@Option}
% \def\Describe@Option#1{\endgroup
%               \marginpar{\raggedleft\PrintDescribeEnv{#1}}%
%               \SpecialOptionIndex{#1}\@esphack\ignorespaces}
% \def\DescribeFile{\leavevmode\@bsphack\begingroup\MakePrivateLetters
%   \Describe@Option}
% \def\Describe@File#1{\endgroup
%               \marginpar{\raggedleft\PrintDescribeEnv{#1}}%
%               \SpecialFileIndex{#1}\@esphack\ignorespaces}
% \makeatother
% \MakeShortVerb{\|}
%
% \tableofcontents
% \section{Introduction}
% This package automatically generates dependancies on \LaTeX\ files and
% packages, figures, bibliography files, glossary and index files. The
% generated file is then used by a Makefile to handle dependancies.
% \StopEventually{
% }
% \section{Implementation of texdepends}
% \subsection{Options}
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
% |texdepends| is easier to write with the |ifthen| package.
%    \begin{macrocode}
\RequirePackage{ifthen}
%    \end{macrocode}
% \begin{option}{debug}
% The debug option (enable debug messages, useful for debuging)
%    \begin{macrocode}
\newboolean{TD@debug}
\newcommand{\TD@option@debug}[1][true]{%
  %\PackageWarningNoLine{texdepends}{Setting debug to #1}
  \setboolean{TD@debug}{#1}%
}%
%    \end{macrocode}
% \end{option}
% \begin{option}{extension}
% The extension option. We can use it to let |texdepends|
% know whether we compile a dvi or a pdf file.
%    \begin{macrocode}
\def\TD@option@extension[#1]{%
  %\PackageWarningNoLine{texdepends}{Using extention #1}
  \def\TD@extention{#1}%
}%
%    \end{macrocode}
% \end{option}
% Managing options with specific code. Using the |keyval|
% package could be a solution, but this would add one more dependency.
%    \begin{macrocode}
\def\TD@option@split#1=#2=#3\relax{%
  \def\TD@option@name{#1}%
  \ifx\TD@option@name\@empty\else
    \expandafter\let\expandafter\TD@option@cmd
      \csname TD@option@\TD@option@name\endcsname
    %\PackageWarningNoLine{texdepends}{1: '#1', 2: '#2', 3: '#3'}
    \ifx\TD@option@cmd\relax
      \@unknownoptionerror%
    \else
      \ifx\@empty#3\@empty
         \TD@option@cmd\relax%
      \else
        \def\TD@option@value{#2}%
        \TD@option@cmd[\TD@option@value]%
      \fi
    \fi
  \fi
}%
%    \end{macrocode}
% All option are managed by the same code.
%    \begin{macrocode}
\DeclareOption*{%
  %\PackageWarningNoLine{texdepends}{Option \CurrentOption}%
  \expandafter\TD@option@split\CurrentOption==\relax%
}%
%    \end{macrocode}
% So lets process options
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
% If the |extension| option is not used, we try to find ourselves
% the good extension based on TeX engine or mode.
%    \begin{macrocode}
\ifthenelse{\isundefined{\TD@extention}}{%
  \PackageWarningNoLine{texdepends}{No extension given: detecting it}%
  \RequirePackage{ifxetex,ifpdf}%
  \ifxetex%
    \PackageWarningNoLine{textdepends}{Detected XeTeX: using .pdf}%
    \def\TD@extention{.pdf}%
  \else\ifpdf%
    \PackageWarningNoLine{texdepends}{Detected PDF mode: using .pdf}%
    \def\TD@extention{.pdf}%
  \else%
    \PackageWarningNoLine{texdepends}{Detected DVI mode. Using .dvi}%
    \def\TD@extention{.dvi}%
  \fi\fi%
}{}%
%    \end{macrocode}
%
% \subsection{Tools}
%    Some macros to help development
% \subsubsection{Debug/info wrapper}
% \begin{macro}{\TD@warning}
% To write a warning
%    \begin{macrocode}
\newcommand{\TD@warning}[1]{%
  \PackageWarningNoLine{texdepends}{#1}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@warningLine}
% To write a warning with line info
%    \begin{macrocode}
\newcommand{\TD@warningLine}[1]{%
  \PackageWarning{texdepends}{#1}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@info}
% To write an info (as a warning if the |debug| option is set
%    \begin{macrocode}
\newcommand{\TD@info}[1]{%
  \ifthenelse{\boolean{TD@debug}}{%
    \PackageWarningNoLine{texdepends}{#1}%
  }{%
    \PackageInfo{texdepends}{#1}%
  }%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@debug}
% To write a message if the |debug| option is set
%    \begin{macrocode}
\newcommand{\TD@debug}[1]{%
  \ifthenelse{\boolean{TD@debug}}{%
    \PackageWarningNoLine{texdepends}{#1}%
  }{%
  }%
}%
%    \end{macrocode}
% \end{macro}
% \subsubsection{Writing dependencies} 
% We open the file where we will write dependencies and other infos.
%    \begin{macrocode}
\newwrite\TD@write
\TD@info{Writing info in '\jobname\TD@extention.mk'}
\immediate\openout\TD@write\jobname\TD@extention.mk%
%    \end{macrocode}
% And we define a few macro to write in this file
% 
% \begin{macro}{\TD@print}
%   We write something in the file
%    \begin{macrocode}
\def\TD@print#1{%
  \immediate\write\TD@write{#1}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printClass}
% We need a class
%    \begin{macrocode}
\def\TD@printClass#1{%
  \TD@print{TD_\jobname\TD@extention _INPUTS\space += #1.cls}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printPackage}
% We need a package
%    \begin{macrocode}
\def\TD@printPackage#1{%
  \TD@print{TD_\jobname\TD@extention _INPUTS\space += #1.sty}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printInput}
% We need a (\LaTeX) file
%    \begin{macrocode}
\def\TD@printInput#1{%
  \TD@print{TD_\jobname\TD@extention _INPUTS\space += #1}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printFig}
% We need an |XFig| file
%    \begin{macrocode}
\def\TD@printFig#1{%
  \TD@print{TD_\jobname\TD@extention _FIGURES\space += #1}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printSubfig}
% Web need a subfig file (see figlatex.dtx)
%    \begin{macrocode}
\def\TD@printSubfig#1{%
  \TD@print{TD_\jobname\TD@extention _SUBFIGS\space += #1}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printRequiredFile}
% A file is missing. |texdepend| will try to skip it this time,
%   but it will be needed at the next compilation
%    \begin{macrocode}
\def\TD@printRequiredFile#1{%
  \TD@print{TD_\jobname\TD@extention _REQUIRED\space += #1}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\RequireFile}
% LaTeX users can directly declare a dependencie
%    \begin{macrocode}
\let\RequireFile\TD@printRequiredFile
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printOut}
% We write in a file
%    \begin{macrocode}
\def\TD@printOut#1{%
  \TD@print{TD_\jobname\TD@extention _OUTPUTS\space += #1}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printGraphicspath}
% We modify the graphicspath
%    \begin{macrocode}
\def\TD@printGraphicspath#1{%
  \TD@print{TD_\jobname\TD@extention _GRAPHICSPATH\space := #1}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printBibfile}
% We use a bibfile (|*.bib|)
%    \begin{macrocode}
\def\TD@printBibfile#1{%
  \TD@print{TD_\jobname\TD@extention _BIBFILES\space += #1.bib}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printBibstyle}
% We use a bibstyle file (|*.bst|)
%    \begin{macrocode}
\def\TD@printBibstyle#1{%
  \TD@print{TD_\jobname\TD@extention _BIBSTYLES\space += #1.bst}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printBblfile}
% We use a bibliography file (|*.bbl|)
%    \begin{macrocode}
\def\TD@printBblfile#1{%
  \TD@print{TD_\jobname\TD@extention _BBLFILES\space += #1.bbl}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printRebuildRule}
% We need a specific rule in the |Makefile| to check if a
% rebuild is needed
%    \begin{macrocode}
\def\TD@printRebuildRule#1{%
  \TD@print{TD_\jobname\TD@extention _REBUILD_RULES\space += #1}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printIndex}
% We use a new index
%    \begin{macrocode}
\def\TD@printIndex#1{%
  \TD@print{TD_\jobname\TD@extention _INDEXES\space += INDEX}%
  \TD@print{TD_\jobname\TD@extention _INDEXES_INDEX\space += #1}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printIndexSource}
% The index file filled by \LaTeX
%    \begin{macrocode}
\def\TD@printIndexSource#1#2{%
  \TD@print{TD_\jobname\TD@extention _INDEX_#1_SRC\space = #2}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printIndexTarget}
% And the index file read by \LaTeX{} after |makeindex|
% processing
%    \begin{macrocode}
\def\TD@printIndexTarget#1#2{%
  \TD@print{TD_\jobname\TD@extention _INDEX_#1_TARGET\space = #2}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printIndexStyle}
% The index style to be used with |makeindex| (never
% called for now)
%    \begin{macrocode}
\def\TD@printIndexStyle#1#2{%
  \TD@print{TD_\jobname\TD@extention _INDEX_#1_STYLE\space = #2}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printGlossary}
% And the same things for glossary. Its name
%    \begin{macrocode}
\def\TD@printGlossary#1{%
  \TD@print{TD_\jobname\TD@extention _INDEXES += GLOSS}%
  \TD@print{TD_\jobname\TD@extention _INDEXES_GLOSS\space += #1}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printGlossarySource}
% The glossary file filled by \LaTeX
%    \begin{macrocode}
\def\TD@printGlossarySource#1#2{%
  \TD@print{TD_\jobname\TD@extention _GLOSS_#1_SRC\space = #2}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printGlossaryTarget}
% And the glossary file read by \LaTeX{} after |makeindex|
% processing
%    \begin{macrocode}
\def\TD@printGlossaryTarget#1#2{%
  \TD@print{TD_\jobname\TD@extention _GLOSS_#1_TARGET\space = #2}%
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@printGlossaryStyle}
% The glossary style to be used with |makeindex| (never
% called for now)
%    \begin{macrocode}
\def\TD@printGlossaryStyle#1#2{%
  \TD@print{TD_\jobname\TD@extention _GLOSS_#1_STYLE\space = #2}%
}%
%    \end{macrocode}
% \end{macro}
% 
% \subsubsection{Diverting a macro}
% \begin{macro}{\TD@switch}
% |\TD@switch| replace the macro |\#1| by the macro |\TD@#1|. The
% original macro is stored in the |\TD@orig@#1| macro. Nothing is done
% if |\#1| is already |\TD@#1| (that is if |\TD@switch| is called
% severall times with the same argument)
%    \begin{macrocode}
\def\TD@switch#1{%
  \expandafter\let\expandafter\TD@local@old\csname#1\endcsname%
  \expandafter\let\expandafter\TD@local@new\csname TD@#1\endcsname%
  \ifx\TD@local@old\TD@local@new
    \PackageWarning{texdepends}{#1 already redefined. Skipping it.}%
  \else
    \ifx\TD@local@old\relax
      \TD@warning{Diverting empty macro '#1' \MessageBreak%
        Probably a bug in texdepends.sty}%
    \else
      \TD@info{Diverting macro '#1'}%
    \fi
    \expandafter\let\csname TD@orig@#1\endcsname\TD@local@old%
    \expandafter\let\csname#1\endcsname\TD@local@new%
  \fi
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TD@docswitch}
% Sometimes, we want the diversion to be delayed until the start of
% the document.
%    \begin{macrocode}
\def\TD@docswitchlist{}%
\def\TD@docswitch#1{%
  \TD@info{Registering macro '#1' for diversion}%  
  \ifx\TD@docswitchlist\@empty%
    \xdef\TD@docswitchlist{#1}%
  \else%
    \xdef\TD@docswitchlist{\TD@docswitchlist,#1}%
  \fi%
}%
\AtBeginDocument{%
  \TD@info{Diverting registered macros...}%  
  \@for\TD@cmd:=\TD@docswitchlist\do{%
    \TD@switch{\TD@cmd}%
  }%
  \TD@info{Divertions done}%  
}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\TD@PackagePreDivert}
% \begin{macro}{\TD@PackagePostDivert}
%   And then, two macros to insert command just before or after
%   loading a package. The first argument is the name of the package
%   we want to add an hook before or after, and then there is the
%   definition of the hook that will be called. Four parameters (|#1|,
%   \ldots, |#4|) are available (the same as the |@onefilewithoptions|
%   \LaTeX{} macro, ie package name, options, and the two remaining ;-)).
%    \begin{macrocode}
\def\TD@PackagePreDivert#1{%
  \expandafter\def\csname TD@PackageStart@#1\endcsname ##1##2##3##4%
}%
\def\TD@PackagePostDivert#1{%
  \expandafter\def\csname TD@PackageEnd@#1\endcsname ##1##2##3##4%
}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsubsection{Initialisation}
% We need to be loaded \emph{before} \string\documentclass
%    \begin{macrocode}
\ifx\documentclass\@twoclasseserror
  \PackageError{texdepends}{texdepends needs to be loaded BEFORE
	\string\documentclass \MessageBreak 
	Use \string\RequirePackage\space instead of \string\usepackage
	\MessageBreak as the later is not allowed before
	\string\documentclass}
\fi
%    \end{macrocode}
% And we write the first dependency (upon ourself)
%    \begin{macrocode}
\TD@printPackage{texdepends}
%    \end{macrocode}
% We write default graphicspath (is this really needed ?)
%    \begin{macrocode}
\TD@printGraphicspath{{.}}
%    \end{macrocode}
%
% \subsubsection{Warning upon missing figures}
% \begin{macro}{\TD@depends}
% \begin{macro}{\TD@dependsWarning}
% \begin{macro}{\TD@missingDepends}
% If some figures are missing, |\TD@missingDepends| will be called so
% that a warning will be displayed at the end of the
% compilation. Figures should be generated before the next run.
%    \begin{macrocode}
\def\TD@depends{}%
\def\TD@dependsWarning{%
  \PackageWarningNoLine{texdepends}{Figure(s) missing. Check
    dependencies again}%
}%
\def\TD@missingDepends{%
  \global\let\TD@depends\TD@dependsWarning%
}%
\AtEndDocument{%
  \TD@depends%
}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \subsection{Diversion of \LaTeX{} macros}
% 
% \subsubsection{Class and package loading}
% \begin{macro}{\TD@@fileswith@pti@ns}
% \begin{macro}{\TD@@@fileswith@pti@ns}
% Diverting |\@fileswith@pti@ns| and |@@fileswith@pti@ns| so that we
% can track class loading. Package are tracked with an other macro
% (see just after).
%    \begin{macrocode}
\def\TD@@fileswith@pti@ns#1[#2]#3[#4]{%
  \ifx#1\@clsextension
    \TD@printClass{#3}
  \fi
  \TD@orig@@fileswith@pti@ns{#1}[#2]{#3}[#4]%
}%
\let\TD@@@fileswith@pti@ns\TD@@fileswith@pti@ns
\TD@switch{@fileswith@pti@ns}%
\TD@switch{@@fileswith@pti@ns}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% 
% \begin{macro}{\TD@@onefilewithoptions}
% By diverting |\@onefilewithoptions|, we can track all loaded
% packages. We write the dependency, and we look at the loaded package
% to see if we need some special requirements
%    \begin{macrocode}
\def\TD@@onefilewithoptions#1[#2][#3]#4{%
  \TD@printPackage{#1}%
  \ifthenelse{\equal{#1}{texdepends}}{%
%    \end{macrocode}
% The |texdepends| package is special : we know it has already been
% loaded (we are running code in it) but perhaps \LaTeX{} does not
% know it. So we try to honor the |debug| option.
%    \begin{macrocode}
    \TD@debug{Package '#1' detected}
    \@for\TD@package@option:=#2\do{%
      \ifthenelse{\expandafter\isundefined\csname TD@option@\TD@package@option\endcsname}{
        \TD@warningLine{Ignoring unknown option '\TD@package@option'}
      }{
        \ifthenelse{%
          \equal{\TD@package@option}{debug}%
          %\OR\equal{\TD@package@option}{debug}%
        }{
          \csname TD@option@\TD@package@option\endcsname%
        }{
          \TD@warningLine{Ignoring option '\TD@package@option'
            \MessageBreak #1 already loaded
          }
        }
      }
    }
  }{%
    \expandafter\let\expandafter\TD@divert
    \csname TD@PackageStart@#1\endcsname
    \ifx\TD@divert\relax
      \TD@debug{No preamble for package #1}
    \else
      \TD@info{Preamble for package #1}
      \TD@divert{#1}{#2}{#3}{#4}%
    \fi
    \TD@orig@@onefilewithoptions{#1}[#2][#3]{#4}%
    \expandafter\let\expandafter\TD@divert
    \csname TD@PackageEnd@#1\endcsname
    \ifx\TD@divert\relax
      \TD@debug{No postamble for package #1}
    \else
      \TD@info{Postamble for package #1}
      \TD@divert{#1}{#2}{#3}{#4}%
    \fi
  }%
}%
\TD@switch{@onefilewithoptions}%
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Tracking input files}
% \begin{macro}{\TD@@iinput}
% \begin{macro}{\TD@@input@}
% |\@iinput| and |\@input@| are diverted to track loaded files
%    \begin{macrocode}
\def\TD@@iinput#1{%
  \TD@printInput{#1}%
  \TD@orig@@iinput{#1}}%
\def\TD@@input@#1{%
  \IfFileExists{#1}{%
    \TD@printInput{#1}%
  }{}%
  \TD@orig@@input@{#1}}%
\TD@switch{@iinput}%
\TD@switch{@input@}%
\def\TD@verbatiminput#1{%
  \TD@printInput{#1}%
  \TD@orig@verbatiminput{#1}}%
\TD@PackagePostDivert{verbatim}{%
  \TD@switch{verbatiminput}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsubsection{Tracking output files}
% \begin{macro}{\TD@openout}
% \begin{macro}{\TD@poenout@eq}
% \begin{macro}{\TD@poenout@noeq}
% Note: that does not work. Currently, we parse the log file instead
% of using this. If someone has ideas\ldots
%    \begin{macrocode}
\let\TD@orig@openout\openout
\def\TD@openout#1{%
  \@ifnextchar={\TD@openout@eq#1}{\TD@openout@noeq#1}}
\def\TD@openout@eq#1=#2.#3{%
  \TD@printOut{#2.#3}%
  \TD@orig@openout#1=#2.#3%
}%
\def\TD@openout@noeq#1#2.#3{%
  \TD@printOut{#2.#3}%
  \TD@orig@openout#1#2.#3%
}%
 %\TD@switch{openout}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \subsubsection{Tracking bibliography files}
%    \begin{macrocode}
\def\TD@bibli@bbl{%
    \TD@printBblfile{\jobname}%
    \global\let\TD@bibli@bbl\relax%
}%
\def\TD@bibli@files#1{%
  \TD@bibli@bbl%
  \@for\TD@bibfile:=#1\do{%
    \TD@printBibfile{\TD@bibfile}%
  }%
} 
\def\TD@bibli@style#1{%
  \TD@bibli@bbl%
  %\@for\TD@bibstyle:=#1\do{%
  %  \TD@printBibstyle{\TD@bibstyle}%
  %}
  \TD@printBibstyle{#1}%
} 
\def\TD@bibliography#1{%
  \TD@bibli@files{#1}%
  \TD@orig@bibliography{#1}%
}%
\def\TD@bibliographystyle#1{%
  \TD@bibli@style{#1}%
  \TD@orig@bibliographystyle{#1}%
}%
\TD@docswitch{bibliography}%
\TD@switch{bibliographystyle}%
%    \end{macrocode}
% \subsubsection{Glossary and index files}
%    \begin{macrocode}
\def\TD@makeindex{%
  \TD@printIndex{\jobname}%
  \TD@printIndexSource{\jobname}{\jobname.idx}%
  \TD@orig@makeindex%
}%
\def\TD@makeglossary{%
  \TD@printGlossary{\jobname}%
  \TD@printGlossarySource{\jobname}{\jobname.glo}%
  \TD@orig@makeglossary%
}%
\TD@switch{makeindex}%
\TD@switch{makeglossary}%
%    \end{macrocode}
% \subsection{Diversion of package's macros}
% \subsubsection{Package graphics}
%    \begin{macrocode}
\def\TD@Gin@getbase#1{%
  \TD@orig@Gin@getbase{#1}%
  \ifx\Gin@ext\relax%
  \else%
  \TD@printFig{\Gin@base\Gin@ext}%
  \fi%
}%
\def\TD@Ginclude@eps#1{%
  \IfFileExists{#1}{%
    \TD@orig@Ginclude@eps{#1}%
  }{%
    \PackageWarning{texdepends}{Figure '#1' needed\MessageBreak 
      Skipping it this time (the last one however)\MessageBreak}%
    \TD@missingDepends%
    \TD@printRequiredFile{#1}%
  }%
}%
\def\TD@Ginclude@pdf#1{%
  \IfFileExists{#1}{%
    \TD@orig@Ginclude@pdf{#1}%
  }{%
    \PackageWarning{texdepends}{Figure '#1' needed\MessageBreak 
      Skipping it this time (the last one however)\MessageBreak}%
    \TD@missingDepends%
    \TD@printRequiredFile{#1}%
  }%
}%
\def\TD@graphicspath#1{%
  \TD@printGraphicspath{#1}%
  \TD@orig@graphicspath{#1}%
}%
\def\TD@Gread@eps#1{%
  \IfFileExists{#1}{%
    %\PackageWarning{texdepends}{Gread File '#1' exists}%
    \TD@orig@Gread@eps{#1}%
  }{%
    \PackageWarning{texdepends}{No '#1' file \MessageBreak
      using 1 for graphic dimensions}%
    \setbox\@tempboxa\hbox{\relax}%
    \def\Gin@llx{1}\let\Gin@lly\Gin@llx
    \Gin@defaultbp\Gin@urx{\wd\@tempboxa}%
    \Gin@defaultbp\Gin@ury{\ht\@tempboxa}%
  }%
}%
\def\TD@Gread@pdf#1{%
  \IfFileExists{#1}{%
    %\PackageWarning{texdepends}{Gread File '#1' exists}%
    \TD@orig@Gread@pdf{#1}%
  }{%
    \PackageWarning{texdepends}{No '#1' file \MessageBreak
      using 1 for graphic dimensions}%
    \setbox\@tempboxa\hbox{\relax}%
    \def\Gin@llx{1}\let\Gin@lly\Gin@llx
    \Gin@defaultbp\Gin@urx{\wd\@tempboxa}%
    \Gin@defaultbp\Gin@ury{\ht\@tempboxa}%
  }%
}%
\TD@PackagePostDivert{graphics}{%
  \TD@switch{graphicspath}%
  \TD@docswitch{Gin@getbase}%
  \TD@docswitch{Ginclude@eps}%
  \TD@docswitch{Ginclude@pdf}%
  \TD@docswitch{Gread@eps}%
  \TD@docswitch{Gread@pdf}%
}%
%    \end{macrocode}
% \subsubsection{Package figlatex}
%    \begin{macrocode}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% We do not want to fail when trying to load a missing subfig.
% \@Ginclude@rawtex
\def\TD@FL@includerawtexgraphics[#1]#2{%
  \IfFileExists{#2}{%
    \TD@orig@FL@includerawtexgraphics[#1]{#2}%
  }{%
    \PackageWarning{texdepends}{Figure '#2' needed\MessageBreak 
      Skipping it this time (the last one however)\MessageBreak}%
    \TD@missingDepends%
    \TD@printRequiredFile{#2}%
  }%
}%

\def\TD@Ginclude@rawtex#1{%
  \IfFileExists{#1}{%
    \TD@orig@Ginclude@rawtex{#1}%
  }{%
    \PackageWarning{texdepends}{Figure '#1' needed\MessageBreak 
      Skipping it this time (the last one however)\MessageBreak}%
    \TD@missingDepends%
    \TD@printRequiredFile{#1}%
  }%
}%

% \@Ginclude@figtex
\def\TD@Ginclude@figtex#1{%
  \IfFileExists{#1}{%
    %\PackageWarning{texdepends}{Ginclude File '#1' exists}%
    \TD@orig@Ginclude@figtex{#1}%
  }{%
    \ifthenelse{\isundefined{\FL@subfig@mainfigname}}{%
      \PackageWarning{texdepends}{Figure '#1' needed\MessageBreak 
        Skipping it this time (the last one however)\MessageBreak}%
    }{%
      \PackageWarning{texdepends}{SubFigure '#1' from
        \FL@subfig@mainfigname needed\MessageBreak 
        Skipping it this time (the last one however)\MessageBreak}%
    }
    \TD@missingDepends%
    \TD@printRequiredFile{#1}%
  }%
}%
% \@Ginclude@svgtex
\def\TD@Ginclude@svgtex#1{%
  \IfFileExists{#1}{%
    %\PackageWarning{texdepends}{Ginclude File '#1' exists}%
    \TD@orig@Ginclude@svgtex{#1}%
  }{%
    \ifthenelse{\isundefined{\FL@subfig@mainfigname}}{%
      \PackageWarning{texdepends}{Figure '#1' needed\MessageBreak
        Skipping it this time (the last one however)\MessageBreak}%
    }{%
      \PackageWarning{texdepends}{SubFigure '#1' from
        \FL@subfig@mainfigname needed\MessageBreak
        Skipping it this time (the last one however)\MessageBreak}%
    }
    \TD@missingDepends%
    \TD@printRequiredFile{#1}%
  }%
}%


% \@Gread@figtex
\def\TD@Gread@figtex#1{%
  \IfFileExists{#1}{%
    %\PackageWarning{texdepends}{Gread File '#1' exists}%
    \TD@orig@Gread@figtex{#1}%
  }{%
    \PackageWarning{texdepends}{No '#1' file \MessageBreak 
      using 1 for graphic dimensions}%
    \setbox\@tempboxa\hbox{\relax}%
    \def\Gin@llx{1}\let\Gin@lly\Gin@llx
    \Gin@defaultbp\Gin@urx{\wd\@tempboxa}%
    \Gin@defaultbp\Gin@ury{\ht\@tempboxa}%
  }%
}%

% \@Gread@svgtex
\def\TD@Gread@svgtex#1{%
  \IfFileExists{#1}{%
    %\PackageWarning{texdepends}{Gread File '#1' exists}%
    \TD@orig@Gread@svgtex{#1}%
  }{%
    \PackageWarning{texdepends}{No '#1' file \MessageBreak
      using 1 for graphic dimensions}%
    \setbox\@tempboxa\hbox{\relax}%
    \def\Gin@llx{1}\let\Gin@lly\Gin@llx
    \Gin@defaultbp\Gin@urx{\wd\@tempboxa}%
    \Gin@defaultbp\Gin@ury{\ht\@tempboxa}%
  }%
}%
% \FL@subfig@check
\def\TD@FL@subfig@check#1{%
  \TD@printRequiredFile{#1}%
  \TD@printSubfig{#1}%
}%
%
\TD@PackagePostDivert{figlatex}{%
  \TD@docswitch{FL@includerawtexgraphics}%
  \TD@docswitch{Ginclude@rawtex}%
  \TD@docswitch{Ginclude@figtex}%
  \TD@docswitch{Ginclude@svgtex}%
  \TD@docswitch{Gread@figtex}%
  \TD@docswitch{Gread@svgtex}%
  \TD@docswitch{FL@subfig@check}%
}%
%    \end{macrocode}
% \subsubsection{Package doc}
%    \begin{macrocode}
\def\TD@PrintIndex{%
  \TD@printIndexStyle{\jobname}{gind.ist}
  \TD@printIndexTarget{\jobname}{\jobname.ind}
  \TD@orig@PrintIndex%
}%
\def\TD@PrintChanges{%
  \TD@printGlossaryStyle{\jobname}{gglo.ist}
  \TD@printGlossaryTarget{\jobname}{\jobname.gls}
  \TD@orig@PrintChanges%
}%
\TD@PackagePostDivert{doc}{%
  \TD@docswitch{PrintIndex}%
  \TD@docswitch{PrintChanges}%
}%
%    \end{macrocode}
% \subsubsection{Package index}
%    \begin{macrocode}
\def\TD@def@index#1#2#3#4{%
  \TD@printIndex{#2}%
  \TD@printIndexSource{#2}{\jobname.#3}%  
  \TD@printIndexTarget{#2}{\jobname.#4}
  \TD@orig@def@index{#1}{#2}{#3}{#4}%
}%
\TD@PackagePostDivert{index}{%
  \TD@switch{def@index}%
}%
%    \end{macrocode}
% \subsubsection{Package makeidx}
%    \begin{macrocode}
\def\TD@printindex{%
  \TD@printIndexTarget{\jobname}{\jobname.ind}
  \TD@orig@printindex%
}%
\TD@PackagePostDivert{makeidx}{%
  \TD@docswitch{printindex}%
}%
%    \end{macrocode}
% \subsubsection{Package nomencl}
% We divert |makeglossary| again after loading this package as its
% redefines this macro (loosing our divertion). We also setup the
% glossary style for this package.
%    \begin{macrocode}
\def\TD@printglossary{%
  \TD@printGlossaryTarget{\jobname}{\jobname.gls}
  \TD@orig@printglossary%
}%
\TD@PackagePostDivert{nomencl}{%
  \TD@docswitch{printglossary}%
  \TD@switch{makeglossary}%
  \TD@printGlossaryStyle{\jobname}{nomencl.ist}
}%
%    \end{macrocode}
% \subsubsection{Package bibtopic}
%    \begin{macrocode}
% Pour le package bibtopic
\def\TD@btSect{%
  \@ifnextchar[{\TD@btSect@opt}{\TD@btSect@noopt}}
\def\TD@btSect@opt[#1]#2{%
  \TD@bibli@files{#2}%
  \TD@bibli@style{#1}%
  \TD@orig@btSect[#1]{#2}}
\def\TD@btSect@noopt#1{%
  \TD@bibli@files{#1}%
  \TD@orig@btSect{#1}}

\def\TD@@bt@write@auxfile{%
  \TD@printBblfile{\thebtauxfile}%
  \TD@orig@@bt@write@auxfile%
}%
\TD@PackagePostDivert{bibtopic}{%
  \global\let\TD@bibli@bbl\relax%
  \global\let\TD@biblio@rules@package\TD@biblio@rules@package@bibtopic%
  \TD@switch{@bt@write@auxfile}%
  \TD@printOut{btbbl.aux}%
  \TD@printRebuildRule{bibtopic}%
  \TD@docswitch{btSect}%
}%
%    \end{macrocode}
%    \begin{macrocode}
%</package>
%    \end{macrocode}
% \Finale
\endinput