[l2h] Re: Latex2HTML and Prettyref

Ross Moore ross@ics.mq.edu.au
Thu, 24 Jan 2002 06:46:43 +1100 (EST)


> 
> Dear Ross,
> 
> I could do with a little bit of help.  I've tried to help myself by
> searching the latex2html mailling list archives, but I can't seem to
> find a working server for them at the moment.
> 
> I need an implementation of prettyref.sty for latex2html.  I have come
> up with a fairly feeble framework for prettyref.perl, which half works
> but does some things I don't understand. 
> 
> If you could help by pointing me to some developer documentation, or
> to an existing implementation of prettyref.perl, or offering any
> advice which can get me further along, it would be most appreciated.
> 
> What I don't understand is the arg list passed to the do_cmd_prettyref
> function; I assumed I would be getting, in response to the latex code

It doesn't pass a list of arguments, it passes (a pointer to) the full
stream following the call to the TeX macro.
The (implementation) of the macro must extract its own arguments,
since TeX is capable of matching any pattern at all.
Even with LaTeX there's the possibility of having `optional'
arguments, so you cannot assume a simple sequence #1 #2 #3, etc.


> \prettyref{sec:mysection}, do_cmd_prettyref(sec:mysection).  In my


To see what happens with  \prettyref{sec:mysection}
run the job with  -verbosity 9 .

You will get log-messages showing:

*** Translating commands ***\prettyref<#1#>sec:mysection<#1#>
.prettyref
IN: \prettyref<#1#>sec:mysection<#1#>

So the call to &do_cmd_prettyprint will receive:

  @_  <---  <#1#>sec:mysection<#1#>

The pattern  /^sec/  does not match.
You need to extract the argument first, then apply your test
to the container with the extracted argument.


The usual way of doing this is:

    my($label);
    $label = &missing_braces unless (
        (s/$next_pair_pr_rx/$label =$2;''/eo)
        ||(s/$next_pair_rx/$label =$2;''/eo));

which caters for 2 levels of processing, and gives a warning-message
in case \prettyref is called without a braced argument.
(Note that successfully finding the argument removes it from $_.)

Now you should apply your tests to $label, not to $_ .


> code below, I get "Unknown Prefix sec:mysection" as the output when
> run from latex2html, but "Section sec:mysection" if I invoke it
> directly.
 
 
sub do_cmd_prettyref {
   local($_) = @_;
   my($text, $label)=('','');
   $label = &missing_braces unless (
        (s/$next_pair_pr_rx/$label =$2;''/eo)
        ||(s/$next_pair_rx/$label =$2;''/eo));
   local(@s) = split(/:/, $label);

  SWITCH: {
     if ($label =~ /^fig/) {
       $text = "Figure"; last SWITCH;
     }
     if ($label =~ /^sec/) {
       $text = "Section"; last SWITCH;
     }
     if ($label =~ /^tab/) {
       $text = "Table"; last SWITCH;
     }
   $text = "Unknown Prefix";
 
   }
 
   join(' ', $text, $_);
}

This now should work correctly;
viz.  http://www-texdev.mpce.mq.edu.au/SCHUTZ/prtest/

> Thanks in advance for any pointers.

Hope this helps,

	Ross Moore


> Regards,
> 
> -- 
> Jon Schutz			      Email: Jon.Schutz@YourAmigo.com
> 				         Ph: +61 (0)8 8211 9211
> Chief Technology Officer	        Fax: +61 (0)8 8211 6356
> YourAmigo Pty Ltd		        Mob: +61 (0)427 004 875
>