I am using the answer given here to customize tags for amsmath
environments.
However, with the cleveref
package, types other than equation
generate warnings:
LaTeX Warning: cref reference format for label type `matrix' undefined on input 58
LaTeX Warning: cref reference format for label type `matrix' undefined on input 68
and the equation reference is preceded by ??
corresponding to an undefined type.
I can specify the type as equation
in the label tag to avoid this warning.
Is there a way to do this in the preamble without having to modify each label?
Setting \crefalias{align}{equation}
did not work.
The example I used for testing is
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{etoolbox}
\usepackage{cleveref}
\crefname{equation}{Eq.}{Eqs.}
\Crefname{equation}{Equation}{Equations}
\newcounter{matrix}
\renewcommand*{\thematrix}{M\arabic{matrix}}
\makeatletter
\def\@equationname{equation}
\newenvironment{m}[1]{%
\def\mymathenvironmenttouse{#1}%
\ifx\mymathenvironmenttouse\@equationname%
\refstepcounter{matrix}%
\else
\patchcmd{\@arrayparboxrestore}{equation}{matrix}{}{}% doesn't change output?
\patchcmd{\print@eqnum}{equation}{matrix}{}{}%
\patchcmd{\incr@eqnum}{equation}{matrix}{}{}%
% \def\print@eqnum{\tagform@\thematrix}% instead of etoolbox' \pathcmd
% \def\incr@eqnum{\refstepcounter{matrix}\let\incr@eqnum\@empty}% instead of etoolbox' \pathcmd
\fi
\csname\mymathenvironmenttouse\endcsname%
}{%
\ifx\mymathenvironmenttouse\@equationname%
\tag{\thematrix}%
\fi
\csname end\mymathenvironmenttouse\endcsname%
}
\makeatother
\begin{document}
\begin{equation} \label{eq:2}
y = x
\end{equation}
The next matrix equation is \cref{eq:m1}.
\begin{m}{equation}
y = \sqrt x \label{eq:m1}
\end{m}
\begin{align}
\alpha &= \beta \label{eq:1} \\
\delta &= \gamma \label{eq:4}
\end{align}
The previous standard equation is \cref{eq:2} and align is \cref{eq:1,eq:4}.
The next matrix equations (align) are \cref{eq:m2,eq:m3}.
\begin{m}{align}
y &= \sqrt x \label{eq:m2} \\
z &= y^2 \label[equation]{eq:m3}
\end{m}
\begin{m}{alignat}{3}
y & = \sqrt x & \quad y^2 &= x & \quad z &= c \label[equation]{eq:m4} \\
p & = q/r & & & & \label{eq:m5}
\end{m}
The previous matrix equations (alignat) are \cref{eq:m4,eq:m5}.
\end{document}
I would also like to remove the excess space after the matrix
m
environment.