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.

223packages hyperref and rhxterm 211a+   (204)  211b
\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.

224sourcefile 224  (197)  226a
\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 440.

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}

226asourcefile 224+   (197)  224  226b
\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.

226bsourcefile 224+   (197)  226a  227
\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.

227sourcefile 224+   (197)  226b  228a
%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.

228asourcefile 224+   (197)  227  228b
\def\currentfile{\projectname.tex}

Defines:
currentfile, used in chunks 222b, 228b, 229, and 336.

Uses projectname 127.

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

228bsourcefile 224+   (197)  228a  229
\def\nwfilename#1{%
  \edef\currentfile{\stripoffnwextension#1}%
  \rhxnwfilename#1.nw.end}
\def\stripoffnwextension#1.nw{#1}

Uses currentfile 228a.

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

229sourcefile 224+   (197)  228b  231
\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 228a and currentlhead 222b.

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

231sourcefile 224+   (197)  229
\def\hiddenhypertarget#1{\hyper@anchorstart{#1}\hyper@anchorend}