24.5 Treatment of Source Files

All source files in ALLPROSE have the extension .nw. The standard extension is defined through the command nwextension below and should be used in source text via the command srcextension.

The command extension is generally used for writing extensions in source text.

219packages hyperref and rhxterm 207a+   (199)  207b
\def\nwextension{nw}
\def\srcextension#1{\extension{#1}\extension{\nwextension}}
\def\extension#1{\if\relax#1\relax\else\textsf{.#1}\fi}

The file myalps.lsf (list of source files) will be generated by sourcefile and includesourcefiles during the compilation of the documentation via the programs LATEX and PDFLATEX. The command sourcefile writes out

\SourceFile {DIR/FILENAME}

to the file myalps.lsf. It will, however do this only once per file, since the first time it is executed it defines a new TEX-command with the filename prefixed by an exclamation mark and in later executions checks the existence of that command. Thus the file myalps.lsf will contain no identical lines.

Note that we use gdef below, because sourcefile might appear inside an environment.

Convention 12 The argument of the commands srcfile, genfile, sourcefile, and generatedfile should expand to character tokens.

Braces {, }, backslashes, \, percent signs, %, number signs, #, underscores, _, and spaces can not be part of filenames.

Because hyperref is used, parentheses, (, and in particular ) are also not allowed in the argument. The hyperref package simply cuts off the target identifier after a ) character.

220sourcefile 220  (192)  222a
\def\sourcefile#1{\srcfile{#1}%
  \@ifundefined{!#1.\nwextension}{%
    \addtocontents{lsf}{\protect\SourceFile\protect{#1\protect}}%
    {\def\rhxhypertarget##1##2{\hypertarget{##1}{}}%
     \rhxhyperfile{#1}{\rhxhypertarget}{s}{}}%
    \expandafter\gdef\csname!#1.\nwextension\endcsname{}}{}}
\def\includesourcefiles{%
  \IfFileExists{undocumented}{\input{undocumented}}{}%
  \@starttoc{lsf}}

Uses undocumented 436.

The command SourceFile should not appear in any .tex file but only in the generated file myalps.lsf. When executed, it will include the corresponding file (with extension .nw.tex).

Convention 13 As an exception, source files that originally have the extension .tex.nw or .bib.nw will not be included via the SourceFile command.

So there is no harm if, for example, the files allprose.tex.nw or myalps.bib.nw appears in the argument of the sourcefile command.

Note the makeatother in the following code chunk. The LATEX command \@starttoc{lsf} from above gives @ the TEX category code 11 (letter) before including the files. Here is a copy of that code from latex.ltx.

\def\@starttoc#1{%  
  \begingroup  
    \makeatletter  
    \@input{\jobname.#1}%  
    \if@filesw  
      \expandafter\newwrite\csname tf@#1\endcsname  
      \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax  
    \fi  
    \@nobreakfalse  
  \endgroup}

222asourcefile 220+   (192)  220  222b
\def\SourceFile#1{\edef\SourceFileExtension{\SFExtension#1..end}%
  \def\MaybeSkip##1{##1}
  \DoNothingIfExtensionIs{tex}{#1}
  \MaybeSkip{\DoNothingIfExtensionIs{bib}{#1}}
  \MaybeSkip{\@SourceFile{#1}}}
\def\DoNothingIfExtensionIs#1#2{%
  \def\skip@extension{#1}%
  \ifx\skip@extension\SourceFileExtension
    \typeout{---: SKIPPED #2.\nwextension.tex}%
    \def\MaybeSkip##1{}%redefine temporarily
  \fi}
\def\SFExtension#1.#2.#3end{#2}
\def\@SourceFile#1{\makeatother
  \IfFileExists{#1.\nwextension.tex}%
    {\typeout{---: INCLUDE #1.\nwextension.tex}\input{#1.\nwextension}}
    {\PackageWarning{allprose}{MISSING #1.\nwextension.tex}}}

If a source file is mentioned in the text, it should be tagged by srcfile; if it is a generated file, it should be tagged by genfile. Since every source file in a project supported by ALLPROSE has the extension .nw, that extension must not be put into the srcfile or sourcefile commands. The argument of srcfile must follow Convention 12.

222bsourcefile 220+   (192)  222a  223
\def\srcFileStyle#1{#1\raisebox{1ex}{\footnotesize{\srcextension{}}}}
\def\srcfile#1{\srcFileStyle{\rhxhyperfile{#1}{\hyperlink}{sf}{}}}

Defines:
srcFileStyle, never used.

The commands srcfile and genfile are built on an auxiliary command rhxhyperfile which expands its first argument completely.

223sourcefile 220+   (192)  222b  224a
%parameters:
% 1-text that appears in the text and the index.
% 2-\hypertarget or \hyperlink,
% 3-sf or gf (for source file or generated file),
% 4-index style. Only |defineTermPage is reasonable.
\def\rhxhyperfile{\expandfirst\@rhxhyperfile}
\def\@rhxhyperfile#1#2#3#4{#2{#3:#1}{\path{#1}}\index{#1@\protect\path{#1}#4}}
\def\expandfirst#1#2{\edef\temp{#2}\expandafter#1\expandafter{\temp}}

NOWEAVE produces the complete path of the file into the argument of nwfilename at the beginning of the generated .nw.tex file. See also target texfiles in Section 28.9). The command nwfilename is modified to produce a new section and index entries.

For the definition of currentfile (used in Section 24.4), we build on the fact that each generated .nw.tex file starts with

\nwfilename{FILENAME.nw}\nwbegindocs{0}

where FILENAME is the full path of the current file starting at PROJECTROOT and without its .nw extension.

Let us first initialize it.

224asourcefile 220+   (192)  223  224b
\def\currentfile{\projectname.tex}

Defines:
currentfile, used in chunks 218b, 224b, 225, and 332.

Uses projectname 124.

Then we save the current definition of nwfilename and redefine it.

224bsourcefile 220+   (192)  224a  225
\def\nwfilename#1{%
  \edef\currentfile{\stripoffnwextension#1}%
  \rhxnwfilename#1.nw.end}
\def\stripoffnwextension#1.nw{#1}

Uses currentfile 224a.

The following commands basically set ifAldorSource to true or false according to the extension of the filename given in the argument of nwfilename.

225sourcefile 220+   (192)  224b  227
\newif\ifAldorSource\AldorSourcefalse
\def\rhxnwfilename#1.#2.nw#3.end{\def\tempa{#2}%
  \def\tempb{as}\ifx\tempa\tempb\AldorSourcetrue\else\AldorSourcefalse\fi
  \rhxstartfile{\currentfile}}
\def\rhxstartfile#1{%
  \hiddenhypertarget{sf:#1}
  \index{#1@\protect\path{#1}|defineTermPage}%
  \markboth{\currentlhead}{#1}%
  \pagestyle{allprose}%
}

Uses currentfile 224a and currentlhead 218b.

Unfortunately,

\hypertarget{}{#1}

introduces an unwanted vertical space before the beginning of a section although it prints nothing. Thus, we had to use some internal commands of the hyperref package directly. Its RCS ID string reads:

Id: hyperref.dtx 6.71 2000/10/04 rahtz Exp rahtz

227sourcefile 220+   (192)  225
\def\hiddenhypertarget#1{\hyper@anchorstart{#1}\hyper@anchorend}