latex3 / tagging-project

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

scrwfile package incompatible #696

Closed mbertucci47 closed 6 days ago

mbertucci47 commented 2 months ago

The scrwfile package redefines \@starttoc in a way that breaks tagging. The example

\DocumentMetadata
  {
    lang=en-US,
    pdfversion=2.0,
    pdfstandard=ua-2,
    testphase={phase-III,math,table,title,firstaid}
  }
\documentclass{article}
\usepackage{scrwfile}
\TOCclone[Summary Contents]{toc}{stoc}
%\usepackage{hyperref}
\addtocontents{stoc}{\protect\value{tocdepth}=1}

\begin{document}

\tableofcontents
\section{A section}
\subsection{A subsection}
\listofstoc

\end{document}

warns

Package tagpdf Warning: something is wrong with the mcid--rerun

and the tags for the TOC are empty. Note the \TOCclone and \listofstoc are not necessary to show the issue.

u-fischer commented 2 months ago

I think that is a bug in the ltproperties. Unlike the standard \label properties are not written if \if@filesw is false as there is an additional test and so the tagging code can not write the needed labels. It works fine if I remove the additional test:

\ExplSyntaxOn\makeatletter
\cs_set_protected:Npn \__property_record:nn #1#2
  {
    %\legacy_if:nT { @filesw }
     % {
        \protected@write \@auxout {}
          {
            \token_to_str:N \new@label@record 
              {#1}
              { \clist_map_function:nN {#2} \__property_record_value:n }
          }
      %}
  }
\ExplSyntaxOff
\DocumentMetadata
  {
    lang=en-US,
    pdfversion=2.0,
    pdfstandard=ua-2,
    testphase={phase-III,math,table,title,firstaid}
  }
\documentclass{article}
\usepackage{scrwfile}
\TOCclone[Summary Contents]{toc}{stoc}
%\usepackage{hyperref}
\addtocontents{stoc}{\protect\value{tocdepth}=1}

\begin{document}

\tableofcontents
\section{A section}
\subsection{A subsection}
\listofstoc

\end{document}

I would suggest to remove that test. Does that sounds ok @josephwright @FrankMittelbach ?

josephwright commented 2 months ago

@u-fischer But the whole point of @filesw is to avoid writing anything to the secondary files ...

u-fischer commented 2 months ago

@josephwright if you use \@fileswfalse in the preamble then both \label and \RecordProperties do not write. But if you set the boolean only locally, then \label still works:

\documentclass{article}
%\makeatletter \@fileswfalse \makeatother
\begin{document}
\section{abc}
{\makeatletter \@fileswfalse \makeatother
\label{blub}\RecordProperties{bla}{page}}
\end{document}

So the behaviour is inconsequent.

FrankMittelbach commented 2 months ago

I would suggest to remove that test. Does that sounds ok @josephwright @FrankMittelbach ?

yes that sounds ok to me (despite Joseph's missgivings :-))

The normal LaTeX interface consists of three parts: the switch \if@filesw, \nofilesand a redefinition of \protected@write if \nofiles is used.

So for normal LaTeX behavior the test around \protected@write is pointless as that command is silenced by \nofiles, thus the outer test can go.

In the package Markus uses the fact that the switch turns of opening and closing aux files for writing, but without \nowfiles the \protected@writestill "writes" which is necessary for his approach, ie writing of auxiliary files is not stopped but changed by the package and @filesw is kind of misused.

My suggestion to people is using this package here is to switch to morewrites as as that can handle arbitrary many additional file streams and just 3 more and does not depend on altered latex internals. It might be a bit slower though (not tested) but it works well.