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.

294aglobal variables 294a  (293 474b 503 536b)  295a
my ($inCodeChunk)=0;
294boutput code chunks lines without modification 294b  (293)
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.

295aglobal variables 294a+   (293 474b 503 536b)  294a  295c
my ($inVerbatim)=’’;

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

Uses inVerbatim 295a and verbatim 210.

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.

295cglobal variables 294a+   (293 474b 503 536b)  295a  296a
my ($inSnippet)=’’;

Defines:
inSnippet, used in chunk 297.

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.

296aglobal variables 294a+   (293 474b 503 536b)  295c  296b
my ($initialSnippetSpaces)=-1;

Defines:
initialSnippetSpaces, used in chunk 297.

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.

296bglobal variables 294a+   (293 474b 503 536b)  296a  474a
my (@snippetContents)=();

Defines:
snippetContents, never used.
297output translated lines of code snippet environments 297  (293)
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 298, initialSnippetSpaces 296a, and inSnippet 295c.