latex3 / latex2e

The LaTeX2e kernel
https://www.latex-project.org/
LaTeX Project Public License v1.3c
1.9k stars 263 forks source link

longtable v4.20 breaks the ltcaption package #1377

Open axelsommerfeldt opened 3 months ago

axelsommerfeldt commented 3 months ago

Brief outline of the bug

The longtable* environment offered by the ltcaption package is working fine with longtable v4.19 but not with v4.20.

See also: https://gitlab.com/axelsommerfeldt/caption/-/issues/177

Minimal example showing the bug

\RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}

\usepackage{longtable,ltcaption}

\begin{document}

\begin{longtable*}{r}
Hello\\
\end{longtable*}

\begin{longtable}{r}
Hello\\
\caption{A table}\\
\end{longtable}

\end{document}

Log file (required) and possibly PDF file

test.log

u-fischer commented 3 months ago

hm, yes, longtable no longer uses \refstepcounter and sets the target for the hyperlinks in another place and so your patch no longer does anything at all. Imho you could define your longtable* environment like this:

\documentclass{article}

\usepackage{longtable}
%\usepackage{ltcaption}
\makeatletter
\newcounter{caption@starLT}
\newenvironment{longtable*}
 {\addtocounter{table}{-1}%
  \stepcounter{caption@starLT}%
  \def\theHtable{LT*\thecaption@starLT}%
  \longtable}
 {\endlongtable} 

\usepackage{hyperref} 
\begin{document}

\begin{longtable*}{r}
Hello\\
\end{longtable*}

\begin{longtable*}{r}
Hello\\
\end{longtable*}

\begin{longtable}{r}
Hello\\
\caption{A table}\\
\end{longtable}

\end{document}
davidcarlisle commented 3 months ago

@axelsommerfeldt sorry about that, I suppose some decades ago, the plan was for me to adjust longtable so that ltcaption wasn't needed, I suppose we should still consider that....

davidcarlisle commented 3 months ago

https://www.latex-project.org/cgi-bin/ltxbugs2html?pr=tools%2F3387

axelsommerfeldt commented 3 months ago

Imho you could define your longtable* environment like this:

Unfortunately it's not as easy as this. The longtable* feature is not the only feature which got broken with the new longtable version. The ltcaption resp. caption package needs to have control over the counter to be able to support longtables for other types than figure, \ContinuedFloat for longtables etc.

This could be implemented in the past by patching \refstepcounter within the re-definition of \LT@array (an ugly solution but when I have done this the longtable package was basically unmaintained), but I don't see any way to accomplish this with the current version of longtable.

As a short time solution I propose putting the code

\@kernel@refstepcounter{table}
\tl_gset:Ne \@currentHref {table.\cs_if_exist_use:N\theHtable}

into an extra macro so the ltcaption resp. caption package can patch this extra macro.

u-fischer commented 3 months ago

can patch this extra macro.

Sorry but if we ever want to get proper tagging in captions etc we really need to reduce the number of patches ;-) . Could you show an example of something that is broken? Then I will look if there is a better solution. E.g. we probably can put the code in a socket that you can reassign.

u-fischer commented 3 months ago

The ltcaption resp. caption package needs to have control over the counter to be able to support longtables for other types than figure,

I do find the idea to make a longtable into a figure rather curious but I found a tex.sx question about that, so it looks as if some documents use that ;-). I can see that the new code broke this, but this can imho be fixed easily inside longtable: it only has to use internally \LTcaptype (or an internal \LT@captype which ltcaption could map through a hook) instead of table.

\ContinuedFloat for longtables etc.

I can not find any indication that \ContrinuedFloat is relevant for longtables. In my tests it simply errors ("outside float"). Could you provide an example?

davidcarlisle commented 3 months ago

@u-fischer it comes up from time to time the stalled v5 at my github has control over the counter as the last item on http://htmlpreview.github.io/?https://raw.githubusercontent.com/davidcarlisle/dpctex/master/longtable/ltbugs.html

Longtable originally increased the table counter to get a unique csname to save the data, and then caption was changed not to increase it, but then the internal counter was added, but I left the table counter. The worst part about that is not so much that it makes it inconnvenient to use figure but that if you have no caption at all the table counter is incremented with no visible use.

u-fischer commented 3 months ago

@davidcarlisle I quite like the idea of ltcaption to define longtable* for such "unnumbered" longtables and it would be nice to have that in longtable directly at some time. But for now I would like to handle at least the captype issue then ltcaption could restore its main two features that I broke with my remove-patches-from-hyperref plan ;-).

axelsommerfeldt commented 3 months ago

I do find the idea to make a longtable into a figure rather curious

It makes more sense when this feature is used with a different floating environment than "figure" or "table".

I can not find any indication that \ContrinuedFloat is relevant for longtables. In my tests it simply errors ("outside float").

It could be that I have implemented this is a branch which never made it into "master".

Could you provide an example?

Unfortunately I had to work last week-end but I'll try to compose a test document showing all longtable features offered by ltcaption and caption on next week-end.

u-fischer commented 2 months ago

@axelsommerfeldt in the develop branch there is now a longtable version which defines and uses \LTcaptype. An empty value is allowed and then the numbering is suppressed.

axelsommerfeldt commented 2 months ago

Unfortunately I had to work last week-end but I'll try to compose a test document showing all longtable features offered by ltcaption and caption on next week-end.

Finally an example document can now be found here: https://gitlab.com/axelsommerfeldt/caption/-/blob/master/test/longtable/example.tex?ref_type=heads

Regarding \ContinuedFloat for longtable: There is actually an implementation in caption.dtx but it's commented out and was never part of a release version of caption.sty.

github-actions[bot] commented 5 days ago

This issue has been automatically marked as stale because it has not had recent activity.