[l2h] \label inside \caption vanishes

Luc Van Eycken Luc.VanEycken@esat.kuleuven.ac.be
Thu, 22 Aug 2002 14:27:18 +0200


If a \label is included inside the \caption of a table, it vanishes unless
the table contents is converted to an image. Take for instants the
following LaTeX file:

   \documentclass{article}
   \begin{document}
   \begin{table}
     \caption{Test\label{testA}}
     \begin{tabular}{c}
       Some A text
     \end{tabular}
   \end{table}
   \begin{table}
     \caption{Test}\label{testB}
     \begin{tabular}{c}
       Some B text
     \end{tabular}
   \end{table}
   \begin{table}
     \caption{Test\label{testC}}
     Some C text
   \end{table}
   \end{document}

In the resulting HTML file you will find anchors for testB and testC, but
not for testA. If it's not an error, it's at least inconsistent behaviour.

Below you'll find a patch for latex2html-2002-2 to solve this problem
(by moving labels out of captions), but I am not sure if this is the best
solution.

Best regards,

Luc Van Eycken

--- latex2html-2002-2/latex2html.pin.orig	2002-08-18 07:15:01.000000000 +0200
+++ latex2html-2002-2/latex2html.pin	2002-08-22 12:21:41.000000000 +0200
@@ -8249,9 +8249,11 @@
     # associate the br_id of the caption with the argument of the caption
     $contents =~ s/$caption_rx(\n)?/do {
 	$key = $9; $caption = $10; $optional_caption = $3;
+	my $result = '';
+	$caption =~ s!(\\label\s*($O\d+$C)[^<]+\2)!$result .= $1; ''!ge;
 	$key = &filter_caption_key($key) if (defined &filter_caption_key);
 	$optional_captions{$key} = $optional_caption||$caption;
-	$captions{$key} = $10; ''}/ego;
+	$captions{$key} = $caption; $result }/ego;
 #	$captions{$9} = $10; $caption_mark }/ego;
     $key = $caption = $optional_caption = '';