@ From: Greg Gamble <[EMAIL PROTECTED]>
@ 
@ Hi,
@ 
@   I used the patch posted by Bob Daley on 28 April i.e. to
@   insert
@ 
@     $text = $img_params...
@ 
@   in sub purify_caption. While it did no harm, it did not fix my 
@   problem: the lack of figure numbers when the caption contains 
@   maths.
@ 
@   My supervisor observed there was a problem with captions with l2h
@   whenever the package `amsmath' was used. I suspect if I didn't use
@   the package then Bob Daley's patch would work for me ... but I use
@   the `amsmath' package quite extensively. Can someone supply a patch
@   that will work with `amsmath'? ... or is the problem now comprehensively
@   fixed in later versions? I'm still using l2h98.1p1 after finding
@   too many problems with p2 p3 and even p4.

Greg:
        Try using l2h98.1p5.  I find that it works much better than previous
versions.  I also use amsmath.  Despite the better performance of l2h98.1p5
it still did not fix all my difficulties.  My problems (which are admittedly
rare) stemmed from the problem that I could generate OK figure numbers for
(nearly all) my figures by putting in sufficiently many \protect commands in
the captions, BUT since elements of my captions were dependent on the value of
counters set within the figure itself (did I say very rare) and since L2H
processes the caption at a time different than when it processes the figure,
the captions themselves came out wrong.  Other problems were the result of the
fact that many of my figures have the same captions except for the evaluation
of some Latex macros, BUT L2H munged the caption so that ^A replaced these
macro calls and so both figures would have the "same caption".
        Given all this I decided to rewrite the extraction of figure numbers.
My rewrite is based on the fact that:
        1) Latex already has decided what number this figure is
        2) if the figure has a \label command then it is recorded in the .aux
        file
        3) L2H already has this information stored in $latex_labels.
The patch requires only a few lines of code, so here goes (line numbers are for
the l2h98.1p5 code):

In Sub extract_captions:
Add after "local($env) = @_;" (line 7378)
    local($default_number);
Add after "if ($env eq 'figure') {" (line 7388)
        $default_number =  $latex_labels{$figure_label} if ($figure_label);
Add after "elsif ($env eq 'table') {" (line 7394)
        $default_number =  $latex_labels{$table_label} if ($table_label);
Add before "@tmp = split(/$;/, eval ("\$encoded_$env" . "_number{\$_}"));" (line 7447)
        $number = $default_number;
        if (!$number) {
Add after "$number = "" if ($number eq "-1");" (line 7449)
        }

In Sub extract_labels:
Change "($_, $anchors);" (line 7492) to
    ($_, $anchors, $label);

In Sub do_env_figure:
Add after "local ( $border, $attribs );" (line 10039)
    local($figure_label);
Change "($_,$anchors) = &extract_labels($_); # extract labels" (line 10042) to
    ($_,$anchors,$figure_label) = &extract_labels($_); # extract labels

In Sub do_env_table:
Add after "local ( $border, $attribs );" (line 10130)
    local($table_label);
Change "($_,$anchors) = &extract_labels($_); # extract labels" (lines 10148 and 10158) 
to
        ($_,$anchors,$table_label) = &extract_labels($_); # extract labels

NOTES:
        1) If the figure does not have a \label command, then the current method
of number extraction is used.  Thus only figures for which the current method
fails to provide a number need add gratuitous unique labels.
        2) Currently tables and figures are handled differently insofar as for
figures &extract_captions is called before &translate_environments (which
removes \label commands and invokes do_cmd_label) and for tables the order is
reversed, so in order for my method to be invoked for tables (the current method
works fine for MY table captions) one would need to change the order fo these
two in do_env_table.
        3) The change to extract_labels will return the argument of the LAST
\label command in the figure/table environment.  This should work OK since any
\label command will be assigned the same figure/label number by Latex.


@   BTW The `align*' environment supplied by `amsmath' is far nicer than
@   `eqnarray*' ... but to get correct centering of the environment via

I agree.  I like "align" much better than "eqnarray".   In fact I have to use
eqnarray with \nonumber of every line instead of eqnarray*.  Otherwise, I get
uncontrolled shifts in the text and/or runaway centering.

        Hope this is useful.

        Bob Daley

Reply via email to