How to create new counter of equation
This can be done using a newenvironment
and the amsmath
to help with the tagging
I have defined the matriz
environment in terms of the equation
environment, and tagged
it with a new counter; you can use \label
and \eqref
as usual.
\documentclass{article}
\usepackage{amsmath}
\newcounter{matriz}
\newenvironment{matriz}{\refstepcounter{matriz}\equation}{\tag{M\thematriz}\endequation}
\begin{document}
\begin{equation}
y = x
\end{equation}
\begin{equation}
y = \frac{1}{x}
\end{equation}
The of next matriz equation is 1. \eqref{test}
\begin{matriz}\label{test}
y = \sqrt x
\end{matriz}
\end{document}
amsmath
with more than equation
I'd go a broader approach …
The following codes uses the environment m
and its mandatory argument to use any amsmath
environment (that introduces displayed math-mode) in combination with the matrix
counter.
The etoolbox
helps to redefine the macros \print@eqnum
and \incr@eqnum
. An alternative is given in the commented part of the code.
Without cmhughes’ solution the actual equation
environment still uses \print@eqnum
with \theequation
but \incr@eqnum
with matrix
.
Code
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{etoolbox}
\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}
y = x
\end{equation}
\begin{equation}
y = \frac{1}{x}
\end{equation}
The of next matriz equation is \ref{eq:M1}.
\begin{m}{equation}
y = \sqrt x \label{eq:M1}
\end{m}
\begin{equation}
y = \frac{1}{x}
\end{equation}
\begin{m}{align}
y & = \sqrt x \\
z & = y^2
\end{m}
\begin{m}{alignat}{3}
y & = \sqrt x & \quad\text{col2l} & = \text{col2r} & \quad\text{col3l} & = \text{col3r} \\
z & = y^2 & & & &
\end{m}
\begin{m}{equation}
y = \sqrt x
\end{m}
\end{document}
Output
Sans-amsmath
solution (without eqnarray
)
Code
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\newcounter{matrix}
\renewcommand*{\thematrix}{M\arabic{matrix}}
\makeatletter
\newenvironment{matriz}{%
\def\@eqnnum{{\normalfont \normalcolor (\thematrix)}}%
\def\equation{$$\refstepcounter{matrix}}%
\equation%
}{%
\endequation%
}
\makeatother
\begin{document}
\begin{equation}
y = x
\end{equation}
\begin{equation}
y = \frac{1}{x}
\end{equation}
The of next matriz equation is \ref{eq:m1}.
\begin{matriz}\label{eq:m1}
y = \sqrt x
\end{matriz}
\begin{equation}
y = x
\end{equation}
\begin{matriz}
y = \sqrt x
\end{matriz}
\end{document}