Robert Donahue writes:
 >      What is $next_pair_pr_rx and $any_next_pair_pr_rx3 ???
 > 
 >      Clearly they're global variables that get somewhere before
 > d&do_cmd_ion gets called and they're there for my benefit.

  There are a few things like that, but I've found very little that I
understand how to use other than the $next_pair_... and
$any_next_pair_... variables; I use my own regex for picking off
optional parameters.  I also found that there aren't many of them;
when it comes to picking off the second, third, fourth parameters,
you're on your own.  Here are some definitions I use (note that some
replace pre-defined definitions, but I find these work a little better 
and don't cause anything to break in my documents):

  my $cmark = "(?:$comment_mark)?";
  # <<2>>...<<2>>
  $next_pair_rx = "^[\\s\n%]*$O(\\d+)$C([\\s\\S]*)$O\\1$C";
  $any_next_pair_rx3 = "[\\s\n%]*$O(\\d+)$C([\\s\\S]*)$O\\3$C";
  $any_next_pair_rx5 = "[\\s\n%]*$O(\\d+)$C([\\s\\S]*)$O\\5$C";
  $any_next_pair_rx7 = "[\\s\n%]*$O(\\d+)$C([\\s\\S]*)$O\\7$C";
  $any_next_pair_rx9 = "[\\s\n%]*$O(\\d+)$C([\\s\\S]*)$O\\9$C";
  # <#2#>...<#2#>
  $next_pair_pr_rx = "^[\\s\n%]*$OP(\\d+)$CP([\\s\\S]*)$OP\\1$CP$cmark";
  $any_next_pair_pr_rx3 = "[\\s\n%]*$OP(\\d+)$CP([\\s\\S]*)$OP\\3$CP$cmark";
  $any_next_pair_pr_rx5 = "[\\s\n%]*$OP(\\d+)$CP([\\s\\S]*)$OP\\5$CP$cmark";
  $any_next_pair_pr_rx7 = "[\\s\n%]*$OP(\\d+)$CP([\\s\\S]*)$OP\\7$CP$cmark";
  $any_next_pair_pr_rx9 = "[\\s\n%]*$OP(\\d+)$CP([\\s\\S]*)$OP\\9$CP$cmark";

  When forming the regex to pick off arguments, there are two
approaches:  Pick off each parameter individually and set them aside,
or pick them off all at once.  I tend to use the later myself:

        sub do_cmd_something {
            local($_) = @_;
            # create the RX to use:
            my $rx = "$next_pair_pr_rx$any_next_pair_pr_rx3";
            # strip the parameters and assign to variables:
            s/$rx//;
            my($first,$second) = ($2, $4);
            # -or- modify in place:
            # (this reverses them and inserts a space)
            s/$rx/\4 \2/;
            ...

  If you modify the input string in place, remember to return $_.
Otherwise, remember to include $_ at the end of the return value.
  The numbering of regex groups is significant.  For the first
parameter, use $next_pair_pr_rx, and for subsequent parameters use
$any_next_pair_pr_rxN, where N is (param# * 2) + 1.  The parameter
text is in group (param# + 1) * 2 and the "br_id" (bracket ID; each
pair of curly braces in the document gets a unique ID #) is (param# *
2) + 1.  The br_id values can be useful for generating index entries;
look for make_index_entry and do_cmd_index in the main latex2html
script.
  I use the regex "^\\s*(\\[([^]]*)\\])?" to detect optional
parameters in my do_cmd_... functions; this isn't fully general but
works for my documents.  (Except for \item[...], but I didn't write my 
own there!)  I use this instead of $next_pair_... in my do_cmd_... and 
do_env_... functions; the optional arg is param. 1, and the required
args start at 2.  So it might look like this:

sub do_env_methoddesc{
    local($_) = @_;
    # Predefined $opt_arg_rx & $optional_arg_rx don't work because they
    # require the argument to be there.
    my $opt_arg_rx = "^\\s*(\\[([^]]*)\\])?";
    my $rx = "$opt_arg_rx$any_next_pair_rx3$any_next_pair_rx5";
    ...

  Ok, ok, this is getting pretty long....


  -Fred

--
Fred L. Drake, Jr.
[EMAIL PROTECTED]
Corporation for National Research Initiatives
1895 Preston White Drive    Reston, VA  20191

Reply via email to