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

About usage of \tag_if_active:T and variants #51

Open jfbu opened 6 months ago

jfbu commented 6 months ago

In current latex-lab-toc.dtx https://github.com/latex3/latex2e/blob/develop/required/latex-lab/latex-lab-toc.dtx I see

\cs_new_protected:Npn \@@_toc_contentsline_begin:nnn #1 #2 #3 %#1 level, #2 content, #3 destination
  {
   \tag_if_active:T
     {
%    \end{macrocode}
% We detect the intended level by checking the value of |toclevel@...|
...

but there is no usage of \tag_if_active:T in the end part

\cs_new_protected:Npn \@@_toc_contentsline_end:n #1 %#1 level name
  {
    \int_compare:nNnF { \use:c{toclevel@#1} } > {\use:c{c@tocdepth}}
...

I guess this is normal?

Where should I expect \tag_if_active:T to occur?

u-fischer commented 6 months ago

I guess this is normal?

Well yes and no ;-). It doesn't really harm that the \tag_if_active:T test is missing at the end (at the begin it is mostly there to avoid that all this code runs unneeded), but it would be more consistent to test in both places. But this part of the code will be replaced by tagging-sockets once they are available and then this inconsistency will vanish.

jfbu commented 6 months ago

I am planning to do this kind of code

\ExplSyntaxOn
\ifdefined\IfDocumentMetadataTF
\AtBeginDocument{%
  \IfDocumentMetadataTF{\tag_if_active:T{\Etoc@tagactivetrue\Etoc@etoctaggingtrue}}{}%
  }%
\fi
\ExplSyntaxOff

to set some Booleans at begin document which will influence whether I should worry about tagging. Very first use case is for the config points in \@starttoc as I don't use the latter, so I have to invoke these config points directly (also some etoc usages of \tableofcontents will not want any tagging).

Does it look ok?

I am worried that the \@starttoc config points may be used for other things than tagging.

u-fischer commented 6 months ago

Does it look ok?

The test looks fine (not sure if the \ifdefined\IfDocumentMetadataTF is really needed but it shouldn't harm).

I am worried that the \@starttoc config points may be used for other things than tagging.

I'm not sure that I understand what the problem is. But do not rely on \@starttoc@cfgpoint@before to stay. At the time the code was written sockets didn't exist yet. This code will be updated in the next months. Generally we will take care that tagging code is in its own socket, so that tagging can be activated/deactivated easily.

jfbu commented 6 months ago

I'm not sure that I understand what the problem is.

etoc does not use \@starttoc. It will execute the \@starttoc@cfgpoint@{before,after} (or their successors) manually ; at some internal places (emptiness checks for the TOC) it of course does not do that ; there also will be a user interface to disable tagging for special usages of etoc ; in brief these config points will be done conditionally on tagging. But I was not sure their would be there in kernel only for tagging matters. So in future, I was worried inhibiting execution if not tagging would have consequences.

But do not rely on \@starttoc@cfgpoint@before to stay. At the time the code was written sockets didn't exist yet. This code will be updated in the next months. Generally we will take care that tagging code is in its own socket, so that tagging can be activated/deactivated easily.

Ok. Point taken. But I need to prototype. For simple usage of etoc only for its \localtableofcontents things are already seemingly working fine. I will update my tagging branch when upstream LaTeX changes. I will probably do a release at least in time for TL2024 insisting tagging support is unstable on my side, but this way people can try out.

u-fischer commented 6 months ago

Ok. Point taken. But I need to prototype.

Oh that's fine. After all we are prototyping too ;-). I'm grateful for everyone who tries and gives feedback. And it would be interesting to see tagging examples of more complicated tocs made with etoc.