26.1 The Special Cases

While processing the input file, the following variable indicates whether a code chunk has been detected. Its value is set to 1 by entering a code chunk and reset to 0 by leaving the chunk.

298aglobal variables 298a  (297 478b 507 539b)  299a
my ($inCodeChunk)=0;
298boutput code chunks lines without modification 298b  (297)
if (/^<<.*>>=/) {$inCodeChunk=1; print; next;}
if ($inCodeChunk) {
    if (/^\@($|\s)/) {$inCodeChunk=0;}
    print; next;
}

Verbatim environments are left untouched by this script. For aldordoc, a verbatim environemt is a LATEX environment whose name contains the string verbatim. On entry into such an environment, the following variable is set to the actual name of the environment. The end of the environment is recognized by \end{VERBNAME} where VERBNAME is the current value of the following variable. Outside a verbatim environment the value of this variable is the empty string.

299aglobal variables 298a+   (297 478b 507 539b)  298a  299c
my ($inVerbatim)=’’;

Defines:
inVerbatim, used in chunk 299b.
299boutput lines in verbatim environments without modification 299b  (297)
if (/^\s*\\begin{([^}]*verbatim[^}]*)}/) {$inVerbatim=$1; print; next;}
if ($inVerbatim ne ’’) {#in verbatim mode
    if (/^\s*\\end{$inVerbatim}/) {$inVerbatim=’’;}
    print; next;
}

Uses inVerbatim 299a and verbatim 214.

Another type of environments that are treated in an almost verbatim fashion are code environments. They represent pieces (snippets) of Aldor code inside documentation. The following variable is treated in exactly the same way as the variable inVerbatim above.

299cglobal variables 298a+   (297 478b 507 539b)  299a  300a
my ($inSnippet)=’’;

Defines:
inSnippet, used in chunk 301.

The first content line of an adsnippet-like environment determines how many initial spaces will be removed from the environment. The value is initially set to 1. After the first line has been investigated its value should reflect the number of initial spaces that can be removed from any line.

300aglobal variables 298a+   (297 478b 507 539b)  299c  300b
my ($initialSnippetSpaces)=-1;

Defines:
initialSnippetSpaces, used in chunk 301.

Basically, the text inside the environment should appear in almost verbatim form. The only difference is that aldordoc active commands are executed inside adsnippet-like environments, i. e., the output of such environments may contain hyperlinks. The function adtranslateAdsnippetText takes care of the active commands.

After every line of the content of an adusage or adsnippet environment (except the last one) we add code (\mbox{}\\) in order to start a new line. We, therefore, first collect the lines into the Perl array snippetContents and then join the lines with the above code as a delimiter and, of course, a newline.

300bglobal variables 298a+   (297 478b 507 539b)  300a  478a
my (@snippetContents)=();

Defines:
snippetContents, never used.
301output translated lines of code snippet environments 301  (297)
if (/^\s*\\begin{ad(usage|snippet)}/) {$inSnippet=$1; print; next;}
if ($inSnippet ne ’’) {#in snippet mode
    if (/^\s*\\end{ad$inSnippet}/) {
        $inSnippet=’’;
        $initialSnippetSpaces = -1;
        print join("\\mbox{}\\\\\n", @snippetContents) . "\n";
        @snippetContents=();
        print;
        next;
    }
    if ($initialSnippetSpaces < 0) {
        /^(\s*)/;
        $initialSnippetSpaces = length($1);
    }
    chomp; # remove trailing newline;
    s/^\s{0,$initialSnippetSpaces}//; # remove leading spaces
    push @snippetContents, &adtranslateAdsnippetText($_);
    next;
}

Uses adtranslateAdsnippetText 302, initialSnippetSpaces 300a, and inSnippet 299c.