summaryrefslogtreecommitdiff
path: root/support/latex-make/figlatex.dtx
blob: 313ef515f548416daa689b41ad198d521633f36f (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
%    \iffalse meta-comment
%%
%% File: figlatex.dtx Copyright (C) 2002--2005 V. Danjean, A. Legrand
%%    Vincent.Danjean@ens-lyon.org
%%    Arnaud.Legrand@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{figlatex.dtx}
%</dtx>
%<package>\NeedsTeXFormat{LaTeX2e}%
%<package>\ProvidesPackage{figlatex}%
%<config> \ProvidesFile{figlatex.cfg}%
%<compat> \ProvidesPackage{texgraphicx}%
%    \fi
%         \ProvidesFile{figlatex.dtx}
[2020/06/01 v2.4.0 Fix support for new latex]
% \iffalse
%<*driver>
\documentclass{ltxdoc}
\usepackage[latin1]{inputenc}
\usepackage[french,english]{babel}
\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{figlatex.dtx}
  \PrintIndex
  \PrintChanges
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{figlatex.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{figlatex} package\thanks{This file
%        has version number \fileversion, last
%        revised \filedate.}}
% \author{Arnaud \textsc{Legrand}\and Vincent \textsc{Danjean}}
% \date{\filedate}
% \maketitle
% \begin{abstract}
% This package allows \LaTeX\space to load XFig and SVG figures (or
% subfigures) with the |\includegraphics| command.  
% \end{abstract}
% \CheckSum{207}
%
% \changes{v0.1.1}{2005/03/28}{Version 0.1.1 at last}
% \changes{v0.1.2}{2005/03/29}{Manage index/glossary}
% \changes{v0.1.3}{2008/01/28}{Better support for subfig with texdepends}
% \changes{v0.1.4}{2011/09/25}{Support for svg with texdepends}
% \changes{v2.2.0}{2016/02/09}{No changes in figlatex.dtx}
% \changes{v2.2.1}{2016/02/09}{No changes in figlatex.dtx}
% \changes{v2.2.2}{2016/02/09}{No changes in figlatex.dtx}
% \changes{v2.2.3}{2017/01/08}{No changes in figlatex.dtx}
% \changes{v2.2.4}{2018/05/29}{Add missing required package 'ifthen'}
% \changes{v2.2.4}{2018/05/29}{Fix python syntax for python3}
% \changes{v2.2.5}{2018/09/04}{No changes in figlatex.dtx}
% \changes{v2.2.5}{2018/10/17}{No changes in figlatex.dtx}
% \changes{v2.4.0}{2020/06/01}{Fix path handling for subfig and new
% core LaTeX}
%
% \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{\|}
%
% \section{Introduction}
%
% \subsection{General}
% \DescribeMacro{\includegraphics}
% This package allows to load XFig figures from \LaTeX\space sources with
% the |\includegraphics| command from the |graphicx| package:
% \begin{verbatim}
% \includegraphics[width=\linewidth]{myfig.fig}
% \end{verbatim}
%
% This package does not convert by itself XFig figures (see package
% |texdepends| for that). It only diverts the loading functions so
% that \LaTeX\space includes the |.pstex_t| or the |.pdftex_t|.
%
% \subsection{Options}
% Available options for this package:
% \begin{description}
% \item[debug~:] \DescribeOption{debug}more messages written while compiling
% \end{description}
%
% \DescribeFile{figlatex.cfg}
% \DescribeMacro{\debug}
% When the package is loaded, it tries to read a |figlatex.cfg|
% file. This file can contains |\debug| to
% enable this option site wide.
%
% \subsection{Subfigures}
%
% Sometimes, several figures made with XFig should be similar. It is
% possible to make only one XFig figure and then create subfigures
% which contains only a subset of the depths of the original figure.
%
% \StopEventually{
% }
% \section{Implementation}
%
% \subsection{figlatex}
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% Options definitions
% \begin{option}{debug}
%    \begin{macrocode}
\newif\ifFL@debug
\DeclareOption{debug}{%
  \global\FL@debugtrue%
}
%    \end{macrocode}
% \end{option}
% 
% We load the config file if it exists.
% Commands for the config file are local.
%    \begin{macrocode}
{
%    \end{macrocode}
% \begin{macro}{\debug}
%    \begin{macrocode}
  \def\debug{%
    \ExecuteOptions{debug}%
  }
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
  \InputIfFileExists{figlatex.cfg}{%
    \typeout{***************************************^^J%
             * Local config file figlatex.cfg used *^^J%
             ***************************************}
  }{%
    \typeout{Found no configuration file for figlatex}
  }
}
%    \end{macrocode}
% Run the options
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
% and requires some packages
%    \begin{macrocode}
\RequirePackage{ifthen}
\RequirePackage{ifpdf}
\RequirePackage{graphicx}
\RequirePackage{xstring}
%    \end{macrocode}
% XFig uses heavily the color package
%    \begin{macrocode}
\RequirePackage{color}
\RequirePackage{epstopdf}
%    \end{macrocode}
% \begin{macro}{\FL@dmessage}
%   Write the message only if debug is set
%    \begin{macrocode}
\def\FL@dmessage#1{% 
  \ifFL@debug%
    \message{#1}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Ginclude@rawtex}
%   |.pstex_t| or |.pdftex_t| are loaded with |\input|
%    \begin{macrocode}
\def\Ginclude@rawtex#1{%
  \FL@dmessage{<#1>}%
  \bgroup%
  \def\@tempa{!}%
  \ifx\Gin@scaley\@tempa%
    \let\Gin@scaley\Gin@scalex%
  \else%
    \ifx\Gin@scalex\@tempa\let\Gin@scalex\Gin@scaley\fi%
  \fi%
  \hbox{%
    \Gscale@box{\Gin@scalex}[\Gin@scaley]{%
      \def\Gin@scalex{1}%
      \let\Gin@scaley\Gin@exclamation% needed for pdflatex
      \FL@dmessage{<loading rawtex #1>}%
      \input{#1}}}%
  \egroup}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Ginclude@figtex}
%   |.fig| are loaded with |\includegraphics| after modifying the name
%    \begin{macrocode}
\def\Ginclude@figtex#1{%
  \message{<#1>}%
  \bgroup%
  \xdef\FL@filename{#1}%
  \filename@parse{\FL@filename}%
  \xdef\FL@filename{\filename@area\filename@base.\FL@figext}%
  \FL@dmessage{<****loading fig \FL@filename>}%
  \FL@includerawtexgraphics[]{\FL@filename}%
  \egroup}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Gread@figtex}
%   |.fig| bounding box is the same as the corresponding |.pstex_t| or |.pdftex_t|
%    \begin{macrocode}
\newcommand{\Gread@figtex}[1]{%
  %\typeout{Oh, file exists #1}%
  \Gread@rawtex{#1}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Ginclude@svgtex}
%   |.svg| are loaded with |\includegraphics| after modifying the name
%    \begin{macrocode}
\def\Ginclude@svgtex#1{%
  \message{<#1>}%
  \bgroup%
  \xdef\FL@filename{#1}%
  \filename@parse{\FL@filename}%
  \xdef\FL@filename{\filename@area\filename@base.\FL@svgext}%
  \FL@dmessage{<****loading svg \FL@filename>}%
  \FL@includerawtexgraphics[]{\FL@filename}%
  \egroup}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Gread@svgtex}
%   |.svg| bounding box is the same as the corresponding |.pstex_t| or |.pdftex_t|
%    \begin{macrocode}
\newcommand{\Gread@svgtex}[1]{%
  %\typeout{Oh, file exists #1}%
  \Gread@rawtex{#1}%
}
%    \end{macrocode}
% \end{macro}
% Declare the right things depending whether we build a DVI or a PDF file.
%    \begin{macrocode}
\ifpdf
%    \end{macrocode}
% PDF part
%    \begin{macrocode}
  \def\FL@figext{pdftex_t}%
  \def\FL@svgext{pdftex_t}%
%    \end{macrocode}
% To read bounding box information:
%    \begin{macrocode}
  \let\Gread@rawtex\Gread@pdf%
  \DeclareGraphicsRule{.pdftex}{pdf}{*}{}%
  \DeclareGraphicsRule{.pdftex_t}{rawtex}{.pdftex}{}%
  \DeclareGraphicsRule{.fig}{figtex}{.pdftex}{}%
  \DeclareGraphicsRule{.svg}{svgtex}{.pdftex}{}%
\else
%    \end{macrocode}
% DVI part
%    \begin{macrocode}
  \def\FL@figext{pstex_t}%
  \def\FL@svgext{pstex_t}%
%    \end{macrocode}
% To read bounding box information:
%    \begin{macrocode}
  \let\Gread@rawtex\Gread@eps%
  \DeclareGraphicsRule{.pstex}{eps}{*}{}%
  \DeclareGraphicsRule{.pstex_t}{rawtex}{.pstex}{}%
  \DeclareGraphicsRule{.fig}{figtex}{.pstex}{}%
  \DeclareGraphicsRule{.svg}{svgtex}{.pstex}{}%
\fi
%    \end{macrocode}
%   This command is not really necessary here (code could be added in
%   |\Ginclude@figtex|). However, it's very convinient for the
%   |texdepends| package.
%    \begin{macrocode}
\newcommand{\FL@includerawtexgraphics}[2][]{%
  \includegraphics[#1]{#2}%
}
%    \end{macrocode}
% Addition of the |subfig=name| key for the options of the 
% |\includegraphicx[..]{..}| macro.
%    \begin{macrocode}
\def\FL@exclamation{!}%
\let\FL@subfig@name\FL@exclamation%
\define@key{Gin}{subfig}{%
  \typeout{using subfig #1}%
  \def\FL@subfig@name{#1}%
}
\def\FL@sepdefault{_}%
%    \end{macrocode}
% We should ckeck if the \#1 file exists (XXX.subfig)
% This is not yet done but texdepends divert this macro
% to record the dependency
%    \begin{macrocode}
\def\FL@subfig@check#1{%
}
%    \end{macrocode}
% We divert |\Gin@getbase| to modify the file name if the |subfig| key
% is used.
%    \begin{macrocode}
\def\FL@Gin@getbase#1{%
  \typeout{In getbase #1 with \FL@subfig@name / \FL@exclamation}%
  \ifx\FL@subfig@name\FL@exclamation%
  \else%
  \typeout{getbase lets go (\filename@area)(\filename@base)(#1)}%
  \IfStrEq*{#1}{.fig}{%
    % If we're including a subfig
    \IfFileExists{\filename@area\filename@base#1}{%
      % If the original .fig file exists, just change the name so that
      % it comprises the full path (file has been looked into
      % texgraphics, etc.)
      % Warning: the found filename is quoted :-(
      \StrBetween[1,2]{\@filef@und}{"}{"}[\FL@filename@unquoted]
      \filename@parse{\FL@filename@unquoted}%
      % Check if the subfig file exists
      \FL@subfig@check{\filename@area\filename@base.subfig}%
    }{%
      % Else, write a warning (LaTeX will warn as well but it doesn't
      % hurt)
      \PackageWarning{figlatex}{No file 
        '\filename@area\filename@base#1'}%
    }
    % Add the subfig suffix to the fig name.
    \edef\filename@base{\filename@base\FL@sepdefault\FL@subfig@name}%
  }{%
  }%
  \IfStrEq*{#1}{.svg}{%
    % If we're including a subfig
    \IfFileExists{\filename@area\filename@base#1}{%
      % If the original .svg file exists, just change the name so that
      % it comprises the full path (file has been looked into
      % texgraphics, etc.)
      % Warning: the found filename is quoted :-(
      \StrBetween[1,2]{\@filef@und}{"}{"}[\FL@filename@unquoted]
      \filename@parse{\FL@filename@unquoted}%
      % Check if the subfig file exists
      \FL@subfig@check{\filename@area\filename@base.subfig}%
    }{%
      % Else, write a warning (LaTeX will warn as well but it doesn't
      % hurt)
      \PackageWarning{figlatex}{No file 
        '\filename@area\filename@base#1'}%
    }
    % Add the subfig suffix to the svg name.
    \edef\filename@base{\filename@base\FL@sepdefault\FL@subfig@name}%
  }{%
  }%
  \fi%
  \FL@orig@Gin@getbase{#1}%
}
\let\FL@orig@Gin@getbase\Gin@getbase
\let\Gin@getbase\FL@Gin@getbase

%\@namedef{Gin@rule@.fig}#1{%
  
%}
%    \end{macrocode}
%    \begin{macrocode}
%</package>
%    \end{macrocode}
% The sample config file |figlatex.cfg|\ldots
%    \begin{macrocode}
%<*config>
%    \end{macrocode}
%    \begin{macrocode}
 %\debug
%    \end{macrocode}
%    \begin{macrocode}
%</config>
%    \end{macrocode}
% \subsection{texgraphicx}
%    \begin{macrocode}
%<*compat>
%    \end{macrocode}
% |texgraphicx.sty| was only a wrapper arround |figlatex.sty|. Now, an
% error is generated.
%    \begin{macrocode}
\PackageError{texgraphicx}{'texgraphicx' is now 
  gone\MessageBreak%
  Please, switching to 'figlatex' 
  package\MessageBreak}{}
\ProcessOptions
%    \end{macrocode}
%    \begin{macrocode}
%</compat>
%    \end{macrocode}
% \Finale
\endinput