I have the following latex code """ \newcounter{reqcounter}…
- User
I have the following latex code """ \newcounter{reqcounter} \newenvironment{requirements}{ \begin{enumerate} \renewcommand\labelenumi{\theenumi.\phantomsection\protect\addcontentsline{toc}{subsubsection}{\hspace{1em}\textnormal{\requirementtitle}}} \setcounter{enumi}{\value{reqcounter}} \newcommand\requirementtitle{} \newcommand\requirement[1]{\renewcommand\requirementtitle{##1}\item \textbf{##1}\label{req:\theenumi}} }{ \setcounter{reqcounter}{\value{enumi}} \end{enumerate} } """ And then I specify items with """ \requirement{{Regulation Compliance}}:\ requirement text """ how do I make it so I can crossref with hyperref so """ \hyperref[req:1]{Requirement: \ref{req:1}} """ would show "Requirement: Regulation Compliance" and could be clicked as a link to that requirement
- Assistant
To achieve this, you can use the \nameref command provided by the hyperref package. Here's how you can adjust your code:
First, import the hyperref package in your LaTeX document by adding the following line in your preamble:
\usepackage{hyperref}Next, change your \requirement macro by adding a
\hypertargetwith a label derived from the requirement title. You'll also want to update \label to reference that same unique name, so it can be cross-referenced later.Replace your \requirement macro with this one: