]> git.lyx.org Git - lyx.git/blob - lib/chkconfig.ltx
A few modifications for next version.
[lyx.git] / lib / chkconfig.ltx
1 % This is chkconfig.ltx, a script which tries to autodetect and
2 %    document your LaTeX configuration. 
3 % Author: Jean-Marc Lasgouttes (Jean-Marc.Lasgouttes@inria.fr)
4 % with minimal changes by Asger Alstrup (alstrup@diku.dk).
5 %
6 % This script should only be run from the configure script to update
7 % the files textclass.lst and doc/LaTeXConfig.lyx
8 %
9 % This script is in fact a complete rewrite of the original chkconfig
10 % script. Expect bugs.
11
12 %%% If you want to add new packages/documentclasses to be recognized,
13 %%% read the explanation that follow and jump to the section 'Actual
14 %%% inspection code' below. You do not need to understand the ugly
15 %%% LaTeX code below to help improving chklatex.ltx :-)
16 %%%
17 %%% If you want to add the new package <name>, all you need most of
18 %%% the times is a two-steps work: 
19 %%% 1- Add the command \TestPackage{<name>}. The syntax is:
20 %%%    \TestPackage[<file>]{<name>}, which  tests whether <name>.sty
21 %%%    (or <file>, if this optional parameter is provided) exists. 
22 %%% 2- Add a description for <name> in doc/LaTeXConfig.lyx.in,
23 %%%    containing in particular a line like
24 %%%         Found   @chk_<name>@
25 %%%    This line will be replaced at configure time by the proper text.
26 %%%
27 %%% For document classes, things are even simpler, since you do not
28 %%% need to edit this file. Just put your layout file in some place
29 %%% where LyX can find it and add if you wish a description in
30 %%% LaTeXConfig.lyx.in, as described above.
31
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 %%%%%%%%%%%%%%%%%%%%%%% Initialization part (skip) %%%%%%%%%%%%%%%%%%%%%
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35
36 % we do not want to stop on errors
37 \nonstopmode\makeatletter
38 % Have we been called from the configure script?
39 \ifx\srcdir\undefined
40  \message{%
41 **** WARNING: For proper results, you should not run this script directly.^^J%
42 **** Please use the `configure' script.^^J}
43  \newcommand\srcdir{.}
44 \else
45   \def\input@path{{\srcdir/}}
46 \fi
47
48 %%% Some useful macros.
49 %   Several commands are defined to test for packages:
50 %    \AddLayout{<layout>} adds an entry for <layout> in textclass.lst
51 %    \AddVariable{<name>}{<value>} creates a new variable chk_<name>,
52 %      and gives it the value <value>.
53 %    \TestDocClass[<file>]{<name>} tests whether <name>.cls (or <file>,
54 %      if it is provided) exists and creates a new entry with
55 %      \AddLayout if this is the case. Note that you will probably not
56 %      need to use this directly, since the configure script generates
57 %      the needed macro calls automatically.
58 %    \TestPackage[<file>]{<name>} tests whether <name>.sty (or <file>,
59 %      if it is provided) exists. 
60 %   Both commands call \AddVariable to give value 'yes' or 'no' to
61 %   the variable chk_<name>.  
62 %%%
63 \newcommand{\prefix}{+} % the character used by grep to filter 'good' output
64 \newcommand{\AddLayout}[3][=]{
65   \ifx=#1
66     \immediate\write\layouts{"#2"   "#2"   "#3"}
67   \else
68     \immediate\write\layouts{"#2"   "#1"   "#3"}
69   \fi}
70 \newcommand{\AddVariable}[2]{
71   \immediate\write\sed{s!@chk_#1@!#2!g}
72   \immediate\write\vars{chk_#1='#2'}}
73 \newcommand{\AddPackage}[1]{
74   \immediate\write\packages{#1}}
75 % Tests whether an item is present
76 % Syntax: \TestItem{<file>}{<name>}{<type>}{<ext>}{<iftrue>}{<iffalse>}
77 \newif\ifexists
78 \newcommand{\TestItem}[6]{
79   \ifx=#1
80     \def\files{#2}
81     \message{^^J\prefix checking for #3 #2 [#2.#4]...}
82   \else
83     \def\files{#1}
84     \message{^^J\prefix checking for #3 #2 [#1]...}
85   \fi
86   \let\firstelement\relax
87   \existstrue
88   \@for\file:=\files\do{
89     \ifx\firstelement\relax
90        \edef\firstelement{\file}
91     \fi
92     \IfFileExists{\file}
93       {}
94       {\IfFileExists{\file.#4}{}{\existsfalse}}
95   }
96   \ifexists
97     \message{yes^^J}
98     \AddVariable{#2}{yes}
99     #5
100   \else
101     \message{no^^J}
102     \AddVariable{#2}{no}
103     #6
104   \fi}
105 \newcommand{\TestPackage}[2][=]{
106   \TestItem{#1}{#2}{package}{sty}{\AddPackage{#2}}{}}
107 \newcommand{\TestDocClass}[1]{
108    \def\layoutname{#1}  % remember the name of the layout file
109    \@ifundefined{layout@#1}
110      {\bgroup
111         \catcode`\#=9  % consider # as a space
112         \input{layouts/#1.layout}  % read the layout file
113       \egroup
114       \global\@namedef{layout@#1}{}} 
115      {} % we have already tried this one.
116 }
117 \newcommand{\DeclareLaTeXClass}[2][=]{
118   \TestItem{#1}{\layoutname}{document class}{cls}
119            {\AddLayout[\firstelement]{\layoutname}{#2}}{}
120   \expandafter\endinput
121 }
122 \newcommand{\DeclareLinuxDocClass}[2][=]{
123   \message{^^J\prefix checking for linuxdoc class \layoutname... }
124   \@ifundefined{haslinuxdoc}
125     {\message{no^^J}}
126     {\message{yes^^J}
127      \AddLayout[#1]{\layoutname}{#2}}
128   \expandafter\endinput
129 }
130 % Only for compatibility. Will be removed later.
131 \let\DeclareSGMLClass=\DeclareDocBookClass
132
133 \newcommand{\DeclareDocBookClass}[2][=]{
134   \message{^^J\prefix checking for docbook\space\space class \layoutname... }
135   \@ifundefined{hasdocbook}
136     {\message{no^^J}}
137     {\message{yes^^J}
138      \AddLayout[#1]{\layoutname}{#2}}
139   \expandafter\endinput
140 }
141
142 % Stolen from article.cls
143 \newcommand{\today}{\ifcase\month\or
144   January\or February\or March\or April\or May\or June\or
145   July\or August\or September\or October\or November\or December\fi
146   \space\number\day, \number\year}
147
148 % Initializes the files
149 \typeout{\prefix Inspecting your LaTeX configuration.}
150 \newwrite{\layouts} \immediate\openout \layouts = textclass.lst
151 \newwrite{\sed} \immediate\openout \sed  = chkconfig.sed
152 \newwrite{\vars} \immediate\openout \vars = chkconfig.vars
153 \newwrite{\packages} \immediate\openout \packages = packages.lst
154
155 \immediate\write\layouts{%
156 # This file declares layouts and their associated definition files.^^J%
157 # It has been automatically generated by configure^^J%
158 # Use "Options/Reconfigure" if you need to update it after a^^J%
159 # configuration change. Run ./configure manually to update the^^J%
160 # system wide version of this file.}
161
162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 %%%%% ACTUAL CONFIGURATION INSPECTION CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165
166 %%% Add any new package or document class here.
167
168 %%% First, we want the day on which the test has been run.
169 \AddVariable{date}{\today}
170
171 %%% Then, the version of LaTeX we are using
172 \message{^^J\prefix checking for LaTeX version... \fmtversion}
173 \AddVariable{fmtversion}{\fmtversion}
174
175 %%% Check for ec fonts. Most of this code has been shamelessely stolen
176 %%% from the file ltxcheck.tex in the LaTeX distribution. In particular,
177 %%% don't ask me how the macro \ecrm works...
178 \def\ecrm{%
179   \begingroup
180     \escapechar-1
181     \xdef\reserved@a{%
182       \noexpand\in@
183         {\expandafter\string\csname ecrm\endcsname}%
184         {\expandafter\expandafter\expandafter
185            \string\csname T1/cmr/m/n\endcsname}}%
186   \endgroup
187   \reserved@a}
188
189 \message{^^J\prefix checking for default encoding (this may take a long time)^^J}
190 \font\test=ecrm1000\relax
191 \ifx\test\nullfont
192   \message{^^J\prefix\prefix checking for ec fonts... no^^J}
193   \AddVariable{ec}{no}
194   \AddVariable{fontenc}{default}
195 \else
196   \message{^^J\prefix\space\space checking for ec fonts... yes^^J}
197   \message{^^J\prefix\space\space checking for ec support in LaTeX format...}
198   \ecrm
199   \ifin@
200     \message{yes^^J}
201     \AddVariable{ec}{yes}
202     \AddVariable{fontenc}{T1}
203     \message{^^J \prefix\space\space default encoding will be set to T1^^J}
204   \else
205     \message{no^^J}
206     \AddVariable{ec}{no}
207     \AddVariable{fontenc}{default}
208   \fi
209 \fi
210
211
212 %%% Document classes
213 % The list of layout files has been put in this file here by the
214 % configure script.
215 \input{chklayouts}
216
217
218 %%% Packages
219 \TestPackage{a4}
220 \TestPackage{a4wide}
221 \TestPackage{babel}
222 \TestPackage{color} % this one should be there if graphics.sty is there.
223 \TestPackage{fancyhdr}
224 \TestPackage{floatflt}
225 \TestPackage{setspace}
226 \TestPackage{subfigure}
227 \TestPackage{geometry}
228 \TestPackage{linuxdoc-sgml}
229 \TestPackage{longtable}
230 \TestPackage{algorithm}
231 \TestPackage{rotating}
232 \TestPackage{latex8}
233 \TestPackage{url}
234
235 % The test for the graphics package is slightly more involved...
236 \newcommand\groption{dvips}
237 \TestItem={graphics}{package}{sty}
238 %  Let's do some clever things to guess the default driver for the
239 %  graphics package. The maintainer of the site might have declared it
240 %  in the file 'graphics.cfg'. Let's hope there are no strange commands
241 %  in there...
242   {\renewcommand\ExecuteOptions[1]{\renewcommand\groption{default}}
243    \InputIfFileExists{graphics.cfg}{}{}
244    \AddPackage{graphics}}
245   {\renewcommand{\groption}{none}}
246 \message{^^J\prefix checking for graphics driver... \groption^^J}
247 \AddVariable{graphicsdriver}{\groption}
248
249 % psnfss is in fact the name of a set of style files, among which
250 % times.sty. If times.sty is here, we will assume that everything is
251 % fine. 
252 \TestPackage[times.sty]{psnfss}
253
254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
255 %%%%% END ACTUAL CONFIGURATION INSPECTION CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257
258 % End of the LaTeX job
259 \immediate\closeout\layouts
260 \immediate\closeout\sed
261 \immediate\closeout\vars
262 \immediate\closeout\packages
263 \typeout{\prefix Inspection done.}
264 \typeout{\prefix Read the file doc/LaTeXConfig.lyx for more information.}
265 % Get the real \end command, that has been hidden by LaTeX
266 \@@end