[l2h] Support for subfigure.sty

s.m. d. sssmmmddd at gmail.com
Tue Sep 9 08:17:45 CEST 2008


Hi all,

Hope the list isn't dead :)

I tried to make a perl stylesheet for subfigure (included below), so
it can work with latex2html... So far I'm OK with the results, which
you can see here:
http://www.imageox.com/image/339487-test_subfi.png  (pdf)
http://www.imageox.com/image/339488-test_subfi.png  (html)

except that I have a couple of questions, to make the conversion look better:
- In the PDF output, the subcaptions begin with "(a)" etc, in the HTML
those are missing - is there any way to include them in the HTML
output as well at the same position?
- In the "Figure" caption in html, the links are written as "1(a)" etc
- any quick way to get rid of the "1"?
- Any way to position A NAME anchors right next to the images in the HTML code?
- Any way I can access the \width= value in the perl script, because
I'd like to use that to format image sizes in percentages, that is,
I'd like width=0.31\linewidth to convert to <IMG WIDTH=31% ... > ?

Thanks for any responses ....

/// latex code //////////////////

Another test:

\begin{figure}[ht]
\centering
\subfigure[\small{Testsub 01} ]{ \label{fig:01subfig1}
\includegraphics[width=0.31\linewidth]{files/test.png} }
\subfigure[Testsub 02 ]{%
\includegraphics[width=0.31\linewidth]{files/test.png}
\label{fig:01subfig2} }
\subfigure[\large{Testsub 03} ]{%
\includegraphics[width=0.31\linewidth]{files/test.png}
\label{fig:01subfig3} }
\label{fig:01}
\caption[Test] {caption one \subref{fig:01subfig1}, two
\subref{fig:01subfig2}, three \subref{fig:01subfig3} times. }
\end{figure}


Another test: åøæÅÆØ \newline


//// subfigure.perl  ///////////////////////

# $Id: subfigure.perl
#

package main;


# unfortunately, no access to A NAME anchors inside, so cannot position them
# next to images...
# no access to \linewidth either, to scale images by percent
# here try to extract ALL subfigure data in first pass, else cannot
format table properly
sub do_cmd_subfigure {
    local($_) = @_;
    local($pa,$pb,$rest,$j, $opt, $optpat, $opttag, $htmlclosetag, $tags);
    local($tmpa, $mytag, $leftfrag, $rigtfrag, $stimg, $stcap, $imgbrace);
    local($tfig, $toptarg, @tfigels, $cnt, $row1, $row2);

    local($_) = @_;

    my @subfigs = split(/\\subfigure/, $_);
    my $olen = scalar(@subfigs); #length of array

    #we know we want two rows, build them simultaneously
    $cnt = 1;
    $row1 = "<TR align=\"center\" valign=\"middle\">\n";
    $row2 = "<TR align=\"center\" valign=\"middle\">\n";
    foreach $tfig (@subfigs){
        # do we have [] optional arguments
        if ($tfig =~ m/\[(.*?)\]/) {$toptarg = 1;} else {$toptarg = 0;}
        print " tfig $cnt $toptarg $tfig \n";
        my @tt = split(/\]/, $tfig);

        if ($toptarg) #have opt args
            { splice @tfigels, 2*$cnt-2, 0, substr @tt[0], 1;
              splice @tfigels, 2*$cnt-1, 0,  @tt[1];
              $row1 .= "<TD class=\"subfigimg\"> " .
@tfigels[2*$cnt-1] . " </TD>\n";
              $row2 .= "<TD class=\"subfigcpt\"> " .
@tfigels[2*$cnt-2] . " </TD>\n"; }
        else # no opt args, all is in @tt[0], but its an img
            { splice @tfigels, 2*$cnt-2, 0, "";
              splice @tfigels, 2*$cnt-1, 0,  @tt[0];
              $row1 .= "<TD class=\"subfigimg\"> " .
@tfigels[2*$cnt-1] . " </TD>\n";
              $row2 .= "<TD class=\"subfigcpt\"> " .
@tfigels[2*$cnt-2] . " </TD>\n"; }

        $cnt++;
    }
    $row1 .= "</TR>\n";
    $row2 .= "</TR>\n";

    my $ret = "\n" . $row1 . $row2;
    #$ret = "\n<TABLE width=\"100%\" border=\"1\"> " . $ret .
"</TABLE>\n"; #100% doesn't work
    $ret = "\n<TABLE width=\"600px\"> " . $ret . "</TABLE>\n";

    print " do_subfigure x1 \n===$olen - $ret=== \n";

    $ret
}


# works - if it doesn't, go just with \renewcommand{\subref}{\ref},
does the trick
sub do_cmd_subref {

    local($_) = @_;
    local($opt, $optpat, $pa, $pb, $pc, $pd, $pe);

    #get if any optional arguments - should be none
    ($opt, $optpat) = &get_next_optional_argument;

    #get brace reference - command argument
    $pa = "";
    $pb = &missing_braces unless (
    (s/$next_pair_pr_rx/$pa=$1;$pb=$2;''/eo));

    #just reformat the subref command as the ref command and send as output
    $pe = "\\ref${OP}$pa${CP}$pb${OP}$pa${CP}" . $_;

    #print "\n do_cmd_subref " . join("---", $opt, $optpat, $pa, $pb,
$pe) . " \n";

    $pe;
}

1;				# Not really necessary...


More information about the latex2html mailing list