% This is chkconfig.ltx, a script which tries to autodetect and
%    document your LaTeX configuration. 
% Author: Jean-Marc Lasgouttes (Jean-Marc.Lasgouttes@inria.fr)
% with minimal changes by Asger Alstrup (alstrup@diku.dk).
%
% This script can be run with LaTeX to update the files
% layouts/textclass.def and doc/LaTeXConfig.lyx

\IfFileExists{minimal.cls} %we prefer to use `minimal' because it is faster
 {\documentclass{minimal}}
 {\documentclass{article}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Initialization part (ignore)
%%% Several commands are defined to test for packages:
%%%  \AddLayout{<layout>} adds an entry for <layout> in textclass.def
%%%  \TestDocClass{<name>}{<desc>}{<location>} tests whether <name>.cls
%%%   exists and creates a new entry with \AddLayout if this is the
%%%   case. The description in <desc> is added to the right section of the
%%%   doc. The location in <location> is used if the documentclass is not
%%%   available 
%%%  \TestPackage[<file>]{<name>}{<desc>}{<location>} tests whether the
%%%   package <name> exists. Its options are similar to those of
%%%   \TestDocClass, except that it accept an optional argument <file>,
%%%   which is the name of the file to test (by default <name>.sty). No
%%%   action is performed beside writing the description in the LyX file.
%%% The contents of the LyX file can be formatted using the following
%%% commands:
%%%  \layout{<layout>} begins a new paragraph with layout <layout>.
%%%  \textit, \emph, textsf and textbf can be used as in a normal LaTeX
%%%   file (except that they have been redefined to do the right thing!).
%%%  & is used to quote a lyx command.

\catcode`\&=\active \let&=\string

%%% A few crude macros to format LyX files
\newcommand\layout[1]{^^J^^J&\layout& #1^^J}
\renewcommand{\textit}[1]{^^J&\shape& italic^^J#1^^J&\shape& default^^J}
\renewcommand{\emph}{\textit}
\renewcommand{\textsf}[1]{^^J&\family& sans^^J#1^^J&\family& default^^J}
\renewcommand{\textbf}[1]{^^J&\series& bold^^J#1^^J&\series& default^^J}

%%% Macros to test for packages
\newcommand{\defaulttext}{\layout{Standard}\textit{None.}}
\newcommand\CTAN[1]{You will find it on CTAN in the directory \textsf{#1}.}
\let \founditems=\defaulttext
\let \missingitems=\defaulttext
\newcommand\AddToText[2]{
  \ifx#1\defaulttext
    \xdef#1{#2}
  \else
    \xdef#1{#1 #2}
  \fi}
\newcommand{\WriteLineAux}[2]{\immediate\write#1{#2}\egroup}
\newcommand{\WriteLine}{\bgroup
\catcode 10 = 12% ^^J is a normal character
\endlinechar = 10% ^^J at the end of every input line
\newlinechar = 10% ^^J breaks line in \write
\catcode 32 = 12 % space is a normal character
\WriteLineAux}
\newcommand{\AddLayout}[1]{\WriteLine{\layouts}{#1 #1.layout}}
\newcommand{\TestDocClass}[3]{
  \IfFileExists{#1.cls}
    {\typeout{*** checking for document class #1...   yes}
     \AddLayout{#1}
     \AddToText{\founditems}{\layout{Itemize}#2}}
    {\typeout{*** checking for document class #1...   no}
     \AddToText{\missingitems}{\layout{Itemize}#2 ^^J#3}}}

\newcommand{\TestPackage}[4][@]{{
  \ifx@#1
    \newcommand{\pname}{#2} \newcommand{\pfile}{#2.sty}
  \else
    \newcommand{\pname}{#2} \newcommand{\pfile}{#1}
  \fi  
  \IfFileExists{\pfile}
    {\typeout{*** checking for package \pname...   yes}
     \AddToText{\founditems}{\layout{Itemize}#3}}
    {\typeout{*** checking for package \pname...   no}
     \AddToText{\missingitems}{\layout{Itemize}#3 ^^J#4}}}}

%%% Initializes the files
\newwrite{\layouts}
\newwrite{\config}
\immediate \openout \layouts = layouts/textclass.def
\immediate \openout \config = doc/LaTeXConfig.lyx
\WriteLine{\config}{%
&#This file was created by \jobname.tex. DO NOT EDIT.
&#LyX 0.10 (C) 1995 1996 Matthias Ettrich and the LyX Team 
&\lyxformat 2.10
&\textclass article
&\language default
&\fontscheme default
&\epsfig dvips
&\papersize a4paper
&\paperfontsize 10
&\baselinestretch 1.00
&\secnumdepth 3
&\tocdepth 3
&\paragraph_separation indent
&\quotes_language english
&\quotes_times 2
&\paperorientation portrait
&\papercolumns 1
&\papersides 1
&\paperpagestyle plain
}%

\WriteLine{\layouts}{%
&# This file declares layouts and their associated definition files
&# (include directory relative to the place where this file is).
&# It has been automatically generated by \jobname.ltx
&# Re-run `latex \jobname.ltx' if you need to update it after a
&#    configuration change.}%

\nofiles %no auxiliary output files.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% End of initialization part



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Configuration detection script
\begin{document}

\WriteLine{\config}{
 \layout{Title}&\fill_top &\fill_bottom Inventory of your LaTeX configuration}

\WriteLine{\config}{ 
 \layout{Standard}\textit{This file has been automatically generated 
 by \jobname.ltx. Do not edit.}
 \layout{Standard}This file describes the different LaTeX add-ons that 
 LyX can handle. Below you'll find two sections: first a list of the 
 add-ons that have been found, and second, the ones that are missing. 
 You may want to grab them at your nearest CTAN mirror if you need 
 their functionality. Note that most of these packages will be 
 available if you use a modern TeX distribution such as teTeX.
 \layout{Standard}Note that only detected document classes can be 
 selected as document layouts in LyX. The detection of the other items, 
 however, does not yet affect the options available inside LyX.
 \layout{Standard}If you decide to install one of the missing items, 
 you should tell LyX about it. After the installation, please issue 
 the command \textsf{latex \jobname.ltx} from your LyX system-directory  
 (by default \textsf{/usr/local/lib/lyx}) and check this file again to 
 see if the new package was recognized.}

\AddLayout{article}
\AddLayout{report}
\AddLayout{book}
\AddLayout{linuxdoc}
\AddLayout{letter}

\TestDocClass{paper}
 {The document class \textsf{paper} provides an alternative to the 
 standard \textsf{article} class. It provides similar functionality, 
 but you might prefer this layout with sans serif sections, headings, 
 and more.)}
 {\CTAN{macros/latex/contrib/supported/paper/paper/}}

\TestDocClass{amsart}
 {The document class \textsf{amsart} is an alternative to the class 
 \textsf{article}. It is part of the AMS-LaTeX package and is used for 
 typesetting of mathematics with a look the American Mathematical 
 Society has developed. They recommend it for the preparation of 
 manuscripts intended for publication both in the Society's books and 
 journals, and also in other mathematical literature. The Society 
 requests that published documents prepared with AMS-LaTeX include 
 an acknowledgment of its use. LyX support is still limited.}
 {\CTAN{fonts/ams/amslatex/inputs/}}

\TestDocClass{dinbrief}
 {The document class \textsf{dinbrief} can be used to type letters 
 according to German conventions.}
 {\CTAN{macros/latex/contrib/supported/dinbrief/}}

\TestDocClass{iletter}
 {The document class \textsf{iletter} can be used to type letters 
 according to Italian conventions.}
 {It must be installed from the \textsf{tex/} subdirectory 
 of LyX source distribution.}

\TestPackage{a4}
 {The package \textsf{a4} changes the margins of your document to suit 
 the European A4 page dimensions with smaller margins that the 
 default A4 format.}
 {\CTAN{macros/latex/contrib/supported/ntgclass/}}

\TestPackage{a4wide}
 {The package \textsf{a4wide} is another package that allows setting of  
 the margins of your document to A4 paper. With this package, the 
 margins are very wide, though.}
 {\CTAN{macros/latex/contrib/other/misc/}}

\TestPackage{babel}
 {The package \textsf{babel} allows you to customize your document 
 for your favorite language (see the Layout/Document dialog). In 
 particular,  it handles hyphenation and automatic translation of 
 all labels like \textsf{Chapter} and \textsf{Table of contents}. 
 This package is not needed if you only plan to write in English, 
 except if you want to use non-English quotes.}
 {\CTAN{macros/latex/packages/babel/}}

\TestPackage{fancyhdr}
 {The package \textsf{fancyhdr} (which used to be known as 
 \textsf{fancyheadings}) is used when you select the 
 \textsf{fancy} page style in the document layout dialog. It 
 provides alternate headers and footers to your pages.}
 {\CTAN{macros/latex/contrib/supported/fancyhdr/}}

\TestPackage{graphics}
 {The package \textsf{graphics} is needed by LyX to insert Postscript 
 figures. You will also need the program Ghostview to see them on screen.}
 {\CTAN{macros/latex/packages/graphics/}}

\TestPackage[times.sty]{psnfss}
 {The package \textsf{psnfss} allows you to change the fonts used by 
 LyX to one of the 35 classical Postscript fonts of basic Postscript 
 printers.}
 {\CTAN{macros/latex/packages/psnfss/}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Clean up and end

%% output the found and not found sections

\WriteLine{\config}{\layout{Section}Items that are present on your system}
\WriteLine{\config}{\founditems}

\WriteLine{\config}{\layout{Section}Items that are \textit{not} 
present on your system}
\WriteLine{\config}{\missingitems}

%% close files
\immediate\closeout\layouts
\immediate\closeout\config

\typeout{*** checking done.}
\typeout{*** check the file doc/LaTeXConfig.lyx for more information.}

\end{document}
