I have in my preamble the following code that creates the boxalign* environment, which is a boxed align* environment.
\makeatletter % Code for the boxalign* environment
% \newcommand\boxalign*autorefname{Box}
\@fleqntrue{}
\usepackage{empheq}
\newenvironment{boxalign*}{\@fleqntrue\empheq[box=\fbox]{align*}}{\endempheq}
\@fleqnfalse{}
\makeatother
However, I want to refer to this box, but hyperref doesn't recognize the environment and therefore doesn't create the hyperlink. For instance:
\documentclass{article}
\usepackage{hyperref}
\usepackage{mathtools}
\makeatletter % Code for the boxalign* environment
% \newcommand\boxalignautorefname{Box}
@fleqntrue{}
\usepackage{empheq}
\newenvironment{boxalign}{@fleqntrue\empheq[box=\fbox]{align*}}{\endempheq}
@fleqnfalse{}
\makeatother
\begin{document}
\begin{boxalign}\label{eq:linear_equation}
y &= ax + b \
\frac{y - b}{a} &= x
\end{boxalign}
This \hyperref[eq:linear_equation]{hyperref} doesn't work.
\end{document}
I saw this post that seemed to have an answer to my problem, which is why I tried adding the \newcommand\boxalign*autorefname{Box} line, but it didn't work (so I commented it out).
How can I do this?
align*environment isn't numbered, I don't know much about the implementation of links within documents orhyperrefbut I'm pretty sure that something like\refstepcounterneeds to be called forhyperrefto be able to link to it. Removing the*to getalignmakes the link work but then you have a numbered environment which I assume you don't want – Willoughby Apr 10 '21 at 20:10\label{}on standard text (so, unnumbered) I thought it wouldn't be a problem. Anyway, it does work if I usealign, but as you guessed, I don't want the numbers since I use this boxed environment as an aside in anotheralignenvironment... – Thibaut B. Apr 10 '21 at 20:25\labelon 'standard text' it picks up the last time\refstepcounterwas called, (its actually a bit smarter than this I think, again I don't know much about the implementation of references). This means that it will pick up the section or subsection number for example. If you try to use\labelwithout first using something like section you get an error – Willoughby Apr 10 '21 at 20:30