]> git.lyx.org Git - lyx.git/blob - lib/chkconfig.ltx
Make sure a textclass.lst will exist even when configure.py fails. Part of Bug 2829...
[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 chkconfig.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
39 %%% Some useful macros.
40 %   Several commands are defined to test for packages:
41 %    \AddLayout{<layout>} adds an entry for <layout> in textclass.lst
42 %    \AddVariable{<name>}{<value>} creates a new variable chk_<name>,
43 %      and gives it the value <value>.
44 %    \TestDocClass{<name>}{<command>} if layout <name> has not already
45 %      been tested for, execute <command>. Note that you will
46 %      probably not need to use this directly, since the configure
47 %      script generates the needed macro calls automatically.
48 %    \TestPackage[<file>]{<name>} tests whether <name>.sty (or <file>,
49 %      if it is provided) exists.
50 %   Both commands call \AddVariable to give value 'yes' or 'no' to
51 %   the variable chk_<name>.
52 %%%
53
54 \newcommand{\prefix}{+} % the character used by grep to filter 'good' output
55
56 \newcommand{\AddLayout}[4][\default]{
57   \def\default{#2}
58   \immediate\write\layouts{"#2"   "#1"   "#3"   "#4"}}
59
60 \newcommand{\AddVariable}[2]{
61   \immediate\write\sed{s!@chk_#1@!#2!g}
62   \immediate\write\vars{chk_#1='#2'}}
63
64 \newcommand{\AddPackage}[1]{
65   \immediate\write\packages{#1}}
66
67 % Tests whether an item is present
68 % Syntax: \TestItem{<file>}{<name>}{<type>}{<ext>}{<iftrue>}{<iffalse>}
69 \newif\ifexists
70
71 \newcommand{\TestItem}[6][\default]{
72   \def\default{#2}
73   \def\files{#1}
74   \message{^^J\prefix checking for #3 #2 [#1]...}
75   \let\firstelement\relax
76   \existstrue
77   \@for\file:=\files\do{
78     \ifx\firstelement\relax
79        \edef\firstelement{\file}
80     \fi
81     \IfFileExists{\file}
82       {}
83       {\IfFileExists{\file.#4}{}{\existsfalse}}
84   }
85   \ifexists
86     \message{yes^^J}
87     \AddVariable{#2}{yes}
88     #5
89   \else
90     \message{no^^J}
91     \AddVariable{#2}{no}
92     #6
93   \fi}
94
95 \newcommand{\TestPackage}[2][\default]{
96   \TestItem[#1]{#2}{package}{sty}{\AddPackage{#2}}{}}
97
98 \newcommand{\TestDocClass}[2]{
99    \def\layoutname{#1}  % remember the name of the layout file
100    \@ifundefined{layout@#1}
101      {#2  % execute the command
102       \global\@namedef{layout@#1}{}}
103      {} % we have already tried this one.
104 }
105
106 \newcommand{\DeclareLaTeXClass}[2][\default]{
107   \TestItem[#1]{\layoutname}{document class}{cls}
108            {\AddLayout[\firstelement]{\layoutname}{#2}{true}}
109            {\AddLayout[\firstelement]{\layoutname}{#2}{false}}
110 }
111
112 % Only for compatibility. Will be removed later.
113 \let\DeclareSGMLClass=\DeclareDocBookClass
114
115 \newcommand{\DeclareDocBookClass}[2][\default]{
116   \message{^^J\prefix checking for docbook\space\space class \layoutname... }
117   \@ifundefined{hasdocbook}
118     {\message{no^^J}
119      \AddLayout[#1]{\layoutname}{#2}{false}}
120     {\message{yes^^J}
121      \AddLayout[#1]{\layoutname}{#2}{true}}
122 }
123
124 % Stolen from article.cls
125 \newcommand{\today}{\ifcase\month\or
126   January\or February\or March\or April\or May\or June\or
127   July\or August\or September\or October\or November\or December\fi
128   \space\number\day, \number\year}
129
130 % Initializes the files
131 \typeout{\prefix Inspecting your LaTeX configuration.}
132 \newwrite{\layouts} \immediate\openout \layouts = textclass.lst.tmp
133 \newwrite{\sed} \immediate\openout \sed  = chkconfig.sed
134 \newwrite{\vars} \immediate\openout \vars = chkconfig.vars
135 \newwrite{\packages} \immediate\openout \packages = packages.lst.tmp
136
137 \immediate\write\layouts{%
138 # This file declares layouts and their associated definition files.^^J%
139 # It has been automatically generated by configure^^J%
140 # Use "Options/Reconfigure" if you need to update it after a^^J%
141 # configuration change. Run ./configure manually to update the^^J%
142 # system wide version of this file.}
143
144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 %%%%% ACTUAL CONFIGURATION INSPECTION CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147
148 %%% Add any new package or document class here.
149
150 %%% First, we want the day on which the test has been run.
151 \AddVariable{date}{\today}
152
153 %%% Then, the version of LaTeX we are using
154 \message{^^J\prefix checking for LaTeX version... \fmtversion}
155 \AddVariable{fmtversion}{\fmtversion}
156
157 %%% And now, the list of available languages
158 % The trick is to know that \the\everyjob contains something like
159 %  \typeout{LaTeX2e <2001/06/01>}
160 %  \typeout{Babel <v3.7h> and hyphenation patterns for american, french, german, ngerman, nohyphenation, loaded.}
161 % All we have to do is to extract the list from there:
162 % (1) concatenate all the messages that are displayed everytime the
163 % format is loaded. The is done by redefining locally \typeout to
164 % append its argument to the macro \mesg.
165 \def\mesg{}
166 {\def\typeout#1{\xdef\mesg{\mesg #1}}
167  \the\everyjob}
168
169 % (2) strip the useless parts from \mesg. This uses the fact that TeX
170 % allows to define macros with parameters delimited by arbitrary text.
171 \def\strip#1patterns for #2, loaded.#3\endmark{\def\langs{#2}}
172 \expandafter\strip\mesg\endmark
173
174 % (3) handle the result
175 \message{^^J\prefix checking for available hyphenation patterns... \langs}
176 \AddVariable{languages}{\langs}
177
178 %%% Check for ec fonts. Most of this code has been shamelessely stolen
179 %%% from the file ltxcheck.tex in the LaTeX distribution. In particular,
180 %%% don't ask me how the macro \ecrm works...
181 \def\ecrm{%
182   \begingroup
183     \escapechar-1
184     \xdef\reserved@a{%
185       \noexpand\in@
186         {\expandafter\string\csname ecrm\endcsname}%
187         {\expandafter\expandafter\expandafter
188            \string\csname T1/cmr/m/n\endcsname}}%
189   \endgroup
190   \reserved@a}
191
192 \message{^^J\prefix checking for default encoding (this may take a long time)^^J}
193 \font\test=ecrm1000\relax
194
195 \ifx\test\nullfont
196   \message{^^J\prefix\prefix checking for ec fonts... no^^J}
197   \AddVariable{ec}{no}
198   \AddVariable{fontenc}{default}
199 \else
200   \message{^^J\prefix\space\space checking for ec fonts... yes^^J}
201   \message{^^J\prefix\space\space checking for ec support in LaTeX format...}
202   \ecrm
203   \ifin@
204     \message{yes^^J}
205     \AddVariable{ec}{yes}
206     \AddVariable{fontenc}{T1}
207     \message{^^J \prefix\space\space default encoding will be set to T1^^J}
208   \else
209     \message{no^^J}
210     \AddVariable{ec}{no}
211     \AddVariable{fontenc}{default}
212   \fi
213 \fi
214
215
216 %%% Document classes
217 % The list of layout files has been put in this file here by the
218 % configure script.
219 \input{chklayouts}
220
221
222 %%% Packages
223 \TestPackage{algorithm}
224 \TestPackage{array}
225 \TestPackage{babel}
226 \TestPackage{bibtopic}
227 \TestPackage{booktabs}
228 \TestPackage{color} % this one should be there if graphics.sty is there.
229 \TestPackage{dvipost}
230 \TestPackage{esint}
231 \TestPackage{fancybox}
232 \TestPackage{fancyhdr}
233 \TestPackage{wrapfig}
234 \TestPackage{framed}
235 \TestPackage{geometry}
236 \TestPackage{jurabib}
237 \TestPackage{latex8}
238 \TestPackage{listings}
239 \TestPackage{longtable}
240 \TestPackage{natbib}
241 \TestPackage{nomencl}
242 \TestPackage{pdfcolmk}
243 \TestPackage{prettyref}
244 \TestPackage{preview}
245 \TestPackage{rotating}
246 \TestPackage{setspace}
247 \TestPackage{soul}
248 \TestPackage{subfigure}
249 \TestPackage{textcomp}
250 \TestPackage{varioref}
251 \TestPackage{url}
252 \TestPackage{xcolor}
253
254
255 % The test for the graphics package is slightly more involved...
256 \newcommand\groption{dvips}
257 \TestItem{graphicx}{package}{sty}
258
259 %  Let's do some clever things to guess the default driver for the
260 %  graphicx package. The maintainer of the site might have declared it
261 %  in the file 'graphics.cfg'. Let's hope there are no strange commands
262 %  in there...
263   {\renewcommand\ExecuteOptions[1]{\renewcommand\groption{default}}
264    \InputIfFileExists{graphics.cfg}{}{}
265    \AddPackage{graphicx}}
266   {\renewcommand{\groption}{none}}
267
268 \message{^^J\prefix checking for graphics driver... \groption^^J}
269 \AddVariable{graphicsdriver}{\groption}
270
271 % psnfss is in fact the name of a set of style files, among which
272 % times.sty. If times.sty is here, we will assume that everything is
273 % fine.
274 \TestPackage[times.sty]{psnfss}
275 % not sure if these are in all versions of psnfss
276 \TestPackage{avant}
277 \TestPackage{bookman}
278 \TestPackage{chancery}
279 \TestPackage{charter}
280 \TestPackage{mathpazo}
281 \TestPackage{mathpple}
282 \TestPackage{mathptm}
283 \TestPackage{mathptmx}
284 \TestPackage{newcent}
285 \TestPackage{utopia}
286 % Other font packages
287 \TestPackage{ae}
288 \TestPackage{bera}
289 \TestPackage{ccfonts}
290 \TestPackage{cmbright}
291 \TestPackage{eco}
292 \TestPackage{fourier}
293 \TestPackage{lmodern}
294 \TestPackage{luximono}
295 \TestPackage{tipa}
296
297
298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299 %%%%% END ACTUAL CONFIGURATION INSPECTION CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301
302 % End of the LaTeX job
303 \immediate\closeout\layouts
304 \immediate\closeout\sed
305 \immediate\closeout\vars
306 \immediate\closeout\packages
307 \typeout{\prefix Inspection done.}
308 \typeout{\prefix Read the file doc/LaTeXConfig.lyx for more information.}
309
310 % Get the real \end command, that has been hidden by LaTeX
311 \@@end