Skip to content

reference commands are not correctly tagged #712

Open
@u-fischer

Description

@u-fischer

Reference command have currently two problems regarding tagging:

  • without hyperref they are not tagged at all.
  • \eqref is tagged as Lbl as it inherits tagging from the label in the equation.

The following resolves both (when hyperref it will replace the references with links, that is ok, but can be adjusted if needed)

\DocumentMetadata{uncompress,testphase={phase-III,math}}
\documentclass{article}
\usepackage{amsmath} 

\ExplSyntaxOn\makeatletter
\def\@kernel@target@exp#1{\cs_if_exist:cT
   {r@#1}{\tl_item:cn{r@#1}{4}}}

\NewSocket{tagsupport/ref/begin}{1}
\NewSocket{tagsupport/ref/end}{0}
\NewSocket{tagsupport/inlineinsert/begin}{1}
\NewSocket{tagsupport/inlineinsert/end}{0}

\NewSocketPlug{tagsupport/ref/begin}{kernel}
 {
  \leavevmode\tagmcend 
  \tagstructbegin{tag=Reference}
  \tag_struct_gput:nne 
   {\g__tag_struct_stack_current_tl}
   {ref_dest}{\@kernel@target@exp{#1}}
  \tagmcbegin{}
 }

\NewSocketPlug{tagsupport/ref/end}{kernel}
 {\tagmcend \tagstructend \tagmcbegin{}}

\AssignSocketPlug{tagsupport/ref/begin}{kernel} 
\AssignSocketPlug{tagsupport/ref/end}{kernel} 

\NewSocketPlug{tagsupport/inlineinsert/begin}{kernel}
  {\tagmcend \tagstructbegin{#1}\tagmcbegin{}}
\NewSocketPlug{tagsupport/inlineinsert/end}{kernel}
  {\tagmcend \tagstructend \tagmcbegin{}}

\AssignSocketPlug{tagsupport/inlineinsert/begin}{kernel} 
\AssignSocketPlug{tagsupport/inlineinsert/end}{kernel} 

\RenewDocumentCommand\ref{sm}
 {
  \UseTaggingSocket{ref/begin}{#2}
  \IfBooleanTF{#1}{\@kernel@sref{#2}}{\@kernel@ref{#2}}
  \UseTaggingSocket{ref/end}
 }

\DeclareRobustCommand{\eqref}[1]
  {
    \textup{%
    \AssignSocketPlug{tagsupport/inlineinsert/begin}{noop}%
    \AssignSocketPlug{tagsupport/inlineinsert/end}{noop}%  
    \tagform@{\ref{#1}}}
  }
\AtBeginDocument
 {
  \@namedef{maketag@@@}#1{%
    \ifmeasuring@
      \hbox{\m@th\normalfont#1}%
    \else
      \UseTaggingSocket{inlineinsert/begin}{tag=Lbl}%      
      \hbox{\m@th\normalfont#1}%
      \UseTaggingSocket{inlineinsert/end}%
    \fi
    } 
  }  
\ExplSyntaxOff\makeatother

\begin{document}

\section{section}\label{sec}

\ref{sec}
 
\begin{align}
x \label{eq}
\end{align}

\eqref{eq}
\end{document}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: generaltagpdf, ...bugSomething isn't working in code we maintain (directly)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions