latex3 / tagging-project

Issues related to the tagging project
https://latex3.github.io/tagging-project/
LaTeX Project Public License v1.3c
23 stars 5 forks source link

Missing optional argument [label] for \UseHookWithArguments (or without arguments) #52

Closed jfbu closed 6 months ago

jfbu commented 6 months ago

Sorry If my search in lthooks-{code,doc}.pdf was too breve. I need something such as

\UseHookWithArguments{contentsline/text/before}[tagpdf]{4}{#1}{#4}{#5}{\@contentsline@destination}

etoc does not use \@dottedtocline except if kept in pure "compatiblity mode" (which means document uses basically only \tableofcontents and \localtableofcontents but nothing else from etoc).

To support tagging, etoc needs to use the tagging hooks at other places. But for example contentsline/text/before hook is used in the latex-lab code both by tagpdf and by hyperref. However etoc has for years handled the hyperref in its way for example providing \etoclink. Thus it would be very advantageous if I could recover from the hook only the tagpdf-labeled piece. Else, that will make supporting tagging much more difficult.

You will correct me if I am mistaken but I see no interface for that. Hence this feature request.


edit

"much more difficult" was a bit dramatic. I see code such as

\AddToHook{contentsline/text/before}[tagpdf]{%
  \tag_struct_begin:n{tag=Reference}%
  \tag_mc_begin:n{tag=Reference}}
\AddToHook{contentsline/text/after}[tagpdf]{%
  \tag_mc_end:}

and it seems I only have to copy this to my own usage where appropriate. But it does look less robust than having some means to recover this. In passing I realize the "arguments" in the example at top of this post were meant for use only by the hyperref labeled chunk inside the hook.

u-fischer commented 6 months ago

You are in the wrong repo, hooks belongs to latex2e. But as it is more about tagging I will transfer into the tagging project.

But beside this, I don't think that would be a good idea. Hooks are normally not reused in more than one place, but when it happens it should work as a whole.

But I understand that you want to reuse the tagging code and will think about how to store it for this purpose.

jfbu commented 6 months ago

You are in the wrong repo, hooks belongs to latex2e. But as it is more about tagging I will transfer into the tagging project.

sorry about the trouble of transferring

But beside this, I don't think that would be a good idea. Hooks are normally not reused in more than one place, but when it happens it should work as a whole.

But I understand that you want to reuse the tagging code and will think about how to store it for this purpose.

I need to apologize because I am ealizing now that it is not a good idea for me to reuse the tagging code. I perceive from the latex-lab-toc.dtx that is tailored for a certain way, in particular that the \numberline is executed inside the "text" part. But etoc has separated "number" from "text".

So what motivated this query is I am almost sure deprecated. Currently I will play with stuff such as

    \ifEtoc@tagging
      \Etoc@global\edef\etocthetaggedname{%
          \expandafter\noexpand\csname tag_mc_begin:n\endcsname{tag=Reference}%
          \unexpanded\expandafter{\etocthename}%
          \expandafter\noexpand\csname tag_mc_end:\endcsname
      }%
      \Etoc@global\edef\etocthetaggednumber{%
          \expandafter\noexpand\csname tag_struct_begin:n\endcsname{tag=Lbl}%
          \expandafter\noexpand\csname tag_mc_begin:n\endcsname{tag=Lbl}%
          \unexpanded\expandafter{\etocthenumber}%
          \expandafter\noexpand\csname tag_mc_end:\endcsname
          \expandafter\noexpand\csname tag_struct_end:\endcsname
      }%
      \Etoc@global\edef\etocthetaggedpage{%
          \expandafter\noexpand\csname tag_mc_begin:n\endcsname{tag=Reference}%
          \unexpanded\expandafter{\etocthepage}%
          \expandafter\noexpand\csname tag_mc_end:\endcsname
      }%

and I have yet to think where to put the \tag_struct_begin:n{tag=Reference}% and the \tag_struct_end:.

It is quite clear to me now I have not yet reached the suitably informed view, but this is done now.

I think I will set-up soon some github with etoc.sty, so people can try.

FrankMittelbach commented 6 months ago

As an additional note: the fact that tagging support is currently sometimes using general hooks is really temporary and due to the fact that initially that was the best and simplest way to make certain things work (without much extra work). However, we are now moving over to use sockets for this -- and in particular special "tagging sockets" that can be very fast enabled or disabled and then it may, for certain tagging code, become quite reasonable to be reused, even though most of the time each package will probably end up with its own support because of the subtle differences. You will see a first application of that in the new table support that will be released soon.

FrankMittelbach commented 6 months ago

As to the feature request: Ulrike already said that she thinks it wouldn't be a good idea and I very much agree. It would mean that at the point you use a hook, you create a dependency to other packages that write into the hook and that is bound to create (as a minimum) documentation issues and most likely coding issues in the future.

So I think we should close this issue (as it doesn't contain anything we would act upon) and instead perhaps add a discussion topic, once you actually provide a first implementation of your etoc with tagging support, so that people become aware of it and comment on it either here or in your repo.

jfbu commented 6 months ago

So I think we should close this issue (as it doesn't contain anything we would act upon) and instead perhaps add a discussion topic, once you actually provide a first implementation of your etoc with tagging support, so that people become aware of it and comment on it either here or in your repo.

etoc with tagging support is ready in a first version, I only need to post it online. I am sorry about creation of this issue it was probably a trick for my mind to reach the final goal. It had been months since I last looked at latex-lab and started thinking about etoc. Since then the latex-lab code had changed a bit. Fomr the very start I wanted to re-use upstream hooks, but I fully understand now I can't use directly the hooks in latex-lab-toc.dtx for reasons explained prior.

FrankMittelbach commented 6 months ago

Hi @jfbu. Looking forward to see your attempt to tag extended tocs.

jfbu commented 6 months ago

@u-fischer @FrankMittelbach I have created an etoc github repo which contains the current development version and test files. I don't have the tools to check for correctness but at least tagpdf reports no warnings. I know some pieces of the TOCs rendered via the fallback line styles should be declared as artefact but are not at this stage. In the test files for "compatibility mode", a priori, all is tagged using upstream LaTeX, only the "config points" for \@starttoc had to be manually reused, so output should be as good as for upstream LaTeX, apart from the document having multiple TOCs now.