26.4 Translation of aldordoc Active Commands

In an aldordoc verbatim context, i. e., in the scope of the adsnippet and adusage environments and the adcode command, certain LATEX commands retain their meaning. These commands are called active commands and will be expanded.

The following list contains all the active commands.

Basically, the function adtranslateActiveCommands splits the given string on active commands.

The active commands are copied unmodified to the output or translated to an internal form in the case of the interface-only command adname.

The other parts of the given string are escaped appropriately so that they appear in the output in a verbatim form. This escaping is done via the function escapeForVerb.

Note that the \ is not considered to be an escape character so that for example

\adcode|x/\\adname{bit?}(0,a)|

will be correctly translated into

\verb|x/\|\adinternalusename{bit?}{bit?}{bit?}{}{bit?}\verb|(0,a)|

and appear as x/\bit?(0,a).

A problematic situation could look like this

\adcode|x/\adname{b}|

which is currently translated into

\verb|x/|\adinternalusename{b}{b}{b}{}{b}

and basically means x/b. If, however, adname is a function that is applied to b and it was actually meant as

x /\ adname {b}

then there should be at least one space between \ and adname.

Convention 19 The commands adthistype and adthisname can optionally be immediately followed by {}. These braces are considered to be terminators of the command and will not appear in the output.

The two lines

\adcode|if \adthistype{} then ...|  
\adcode|if \adthistype then ...|

are translated into

\verb|if |\adthistype{}\verb| then ...|  
\verb|if |\adthistype\verb| then ...|

and thus result in identical output.

Note that we work here with the same regular expression for a type constructor as in Section 38.1.

313constructor name regular expression 313  (304 314 497a 510)  497b
[A-Z][a-zA-Z0-9]*[a-z][a-zA-Z0-9]*
314adtranslateActiveCommands 314  (326)
sub adtranslateActiveCommands {
    my ($str, $escape, @escargs) = @_;
    my ($ret) = ’’;
    my ($b, $o, $type, $name, $c);
    my ($indexkey, $indextext);
    my ($hyperlabelname, $hyperlabelsignature);
    my ($latextext, $signature);
    my ($texcommand);

    while ($str=~/(\\ad(this)?(type|name))/) {
        $texcommand = $1;
        $this = $2;
        $ret .= &{$escape}($‘, @escargs);
        $str = "$’"; # must copy {
        if ($this ne ’’) { # \adthisname and \adthistype
            $ret .= $texcommand;
            if ($str =~ /^{}/) {
                $str = $’;
                $ret .= ’{}’;
            }
        } elsif ($texcommand eq ’\adtype’) {
            if ($str =~ /^({constructor name regular expression 313})/) {
                $ret .= "\\adtype$1";
                $str = $’;
            } else {
                print STDERR "adtranslateActiveCommands:\n";
                print STDERR "\\adtype{TYPE} must match regular expression\n";
                print STDERR "\\\\adtype{constructor name regular expression 313}\n";
                die "Found: $str";
            }
        } else { # The \adname case.
            $str = "$texcommand$str";
            ($translated, $str) = &adtranslateInterfaceOnlyCommand($str);
            $ret .= $translated;
        }
    }
    $ret .= &{$escape}($str, @escargs);
    return $ret;
}

Defines:
adtranslateActiveCommands, used in chunks 298 and 301a.

Uses adtranslateInterfaceOnlyCommand 304.