I have plenty of equations in my Tex which were labeled with (\ref{eqn: bla}
) which I now want to change to \eqref{eqn: bla}
. Is there a fast way to do this rather than manually doing it?
2
2
If there wouldn't be manual (...)
parentheses, one could use a \ref
wrapper command that checks whether the reference label name contains eqn:
and use \eqref
accordingly. But alas,... this is no solution for the (...)
case.
Note I am not sure this will work in conjunction with cleveref
or hyperref
.
\documentclass{article}
\usepackage{xstring}
\usepackage{amsmath}
\let\origref\ref % Prevent recursive definition
\makeatletter
\renewcommand{\eqref}[1]{%
\textup{\tagform@{\origref{#1}}}%
}
\makeatother
\renewcommand{\ref}[1]{%
\IfSubStr{#1}{eqn:}{%
\eqref{#1}%
}{%
\origref{#1}%
}%
}
\begin{document}
\section{First} \label{sec:first}
\begin{equation}
E=mc^2 \label{eqn: bla}
\end{equation}
\section{Second} \label{sec:second}
In section \ref{sec:first} we have equation \ref{eqn: bla}
\end{document}
-
2
-
@bissi -- i don't know whether this will cause you to rethink, but it's worth mentioning that
\eqref
enforces\upshape
, including the parentheses, so that they will not be sloped in xrefs in theorems and other italic environments. how\ref
is styled is dependent on the document class. and may or may not be compatible in appearance. – barbara beeton Sep 25 '15 at 19:40
search/replace
:\ref{eqn:
by\eqref{eqn:}
if your equation labels follow this pattern. A dirty way (not recommended (really)):\let\ref\eqref
(Don't do this!!!) – user31729 Sep 25 '15 at 17:59eqn: bla
isn't recommended too ;-) – user31729 Sep 25 '15 at 18:01(\ref{eq->\eqref{eq
and than redefine\eqref
to eat the 2nd parenthese) – touhami Sep 25 '15 at 18:44regexp
would be easier? Withsed
orperl
... – user31729 Sep 25 '15 at 18:50