Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reference commands are not correctly tagged #712

Open
u-fischer opened this issue Sep 23, 2024 · 0 comments
Open

reference commands are not correctly tagged #712

u-fischer opened this issue Sep 23, 2024 · 0 comments

Comments

@u-fischer
Copy link
Member

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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant