0

I'm trying make my own command for a requirements document. I'm now looking for a way to reference my requirements. This should be possible by using \ref and the later on with the hyerref package.

The returned string of the \ref command shall be the Requirement-ID (#1).

But I have no idea how to make this happen. Could anyone please help?

Thanks & bye, aronadaal

\documentclass[a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=2cm]{geometry}
\setlength\parindent{0pt}

\newcommand{\req}[2]{ %
  \begingroup%
    \textbf{#1}\label{req:#1}~#2\newline %
  \endgroup%
} %

\begin{document}


\req{MY.REQ.ID.42}{a lot of text... and so on}

Please have a look at \ref{req:MY.REQ.ID.42}

\end{document}
1
  • What about making a new command that wraps \ref in the same way that your \req command wraps \label?
    – Thruston
    Apr 1, 2015 at 12:40

1 Answer 1

4
\documentclass[a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=2cm]{geometry}
\setlength\parindent{0pt}

\makeatletter
\newcommand{\req}[2]{%
  \begingroup
    \textbf{#1}\def\@currentlabel{#1}\label{req:#1}~#2\newline
  \endgroup
}
\makeatother
\begin{document}


\req{MY.REQ.ID.42}{a lot of text... and so on}

Please have a look at \ref{req:MY.REQ.ID.42}

\end{document}

enter image description here

1
  • Thank you. I already tried "\def\@currentlabel" but I forgot to put the command between the makeat...
    – aronadaal
    Apr 2, 2015 at 10:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .