ho-tex / zref

zref packages for LaTeX
LaTeX Project Public License v1.3c
5 stars 2 forks source link

`subcaption` tricks `zref-titleref` #21

Open gusbrs opened 3 weeks ago

gusbrs commented 3 weeks ago

Currently, the subcaption package seems to defeat zref-titleref for the caption names:

\documentclass{article}

\usepackage{zref-user}
\usepackage{zref-titleref}
\usepackage{subcaption}
\usepackage{hyperref}

\begin{document}

\section{Section}

\begin{table}
  Table
  \caption{Table}
  \label{tab:table}
  \zlabel{tab:table}
\end{table}

\end{document}

Produces the labels:

\newlabel{tab:table}{{1}{1}{Table}{table.caption.1}{}}
\zref@newlabel{tab:table}{\default{1}\page{1}\title{Section}}

Edit: Changing the respective load order changes the above results. If there are consequences of doing so for subcaption functionality, I don't know. If this indeed just a "load order issue", perhaps documenting it in the manual would be useful.

Edit 2: As far as I can tell from just reading code, this seems to be a load order issue. Also:

u-fischer commented 3 weeks ago

Yes changing the order helps.

But generally I think zref-titleref is (now) flawed. Instead of using its own command to store the title (\zref@titleref@current) and patching lots of external commands so that they update the title info it should use \@currentlabelname and make use of nameref. That would mean it would also support the growing number of packages and classes where commands set \@currentlabelname directly.

gusbrs commented 3 weeks ago

But generally I think zref-titleref is (now) flawed. Instead of using its own command to store the title (\zref@titleref@current) and patching lots of external commands so that they update the title info it should use \@currentlabelname and make use of nameref. That would mean it would also support the growing number of packages and classes where commands set \@currentlabelname directly.

I can only concur. That would be awesome, of course. ;-)

gusbrs commented 3 weeks ago

An idea, in the spirit of "the least possible fuss": provide a zref-nameref module which simply does:

\zref@newprop{name}{\@currentlabelname}
\zref@addprop\ZREF@mainlist{name}

Since \@currentlabelname is ensured by the kernel anyway nowadays, this is safe regardless of the presence of nameref. If nameref is loaded, it should just work, shouldn't it?

And not much to worry also if anyone around is relying on specific stuff from zref-titleref.