I'm trying to create a referenceable "system" environment that basically displays an equation with a custom counter. Then I want to reference the environment with autoref
, so as to have "System (S1)" as output when I reference it.
\newcounter{system}\setcounter{system}{0}
\newenvironment{system}{\refstepcounter{system}\begin{equation*}}{\hfill(S\arabic{system})
\end{equation*}}
\hyperref[system]{System~\ref{system}}
\def\systemautorefname{System}
\begin{system}
\dot x=u(x),
\label{s1}
\end{system}
However, when I do
\autoref{s1}
I get an error saying that the reference s1
is undefined. What am I missing?
Best Answer
Some remarks:
s1
, the referencessystem
. The label name must match, the example below usess1
.equation*
indicates that probably packageamsmath
is used.amsmath
\tag
can be used to print the equation number.\p@system
helps to get the parentheses around the number, when it is referenced.\label
outside environmentequation
with the name as option to the environmentsystem
to avoid trouble with the redefinition of\label
inside environments ofamsmath
.\ref
avoids the link inside a link in the line with\hyperref
.Example: