20

I want to create a command \eqref*, which is the same like \eqref, but without a clickable link. There are similar commands for \ref (\ref*) and \autoref (\autoref*) which achieve this behaviour, but not for \eqref.

\newcommand{\myeqref}[1]{(\ref*{#1})}

Would work, but I don't like the naming, and there is an additional problem: \eqref writes numbers upright even in italic math environment, \ref doesn't do this.

Any help is appreciated.

[ Edit: for search engines: eqref, eqref*, eqrefstar, starred eqref, eqrefasterisk, asterisked eqref, eqref star, eqref asterisk ]

petertex
  • 303

3 Answers3

14

Here's a solution that borrows from Joseph Wright's LaTeX3 solution to Defining starred versions of commands (* macro)

% arara: pdflatex
\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\let\oldeqref\eqref
\makeatletter
\RenewDocumentCommand\eqref{s m}{%
  \IfBooleanTF#1%
  {\textup{\tagform@{\ref*{#2}}}}% If a star is seen
  {\oldeqref{#2}}%                 If no star is seen
}
\makeatother

\usepackage{hyperref}
\begin{document}
\begin{equation}
a=b \label{1}
\end{equation}

\begin{itemize}
  \item starred version: \eqref*{1} 
  \item unstarred version: \eqref{1}
\end{itemize}

\end{document}
cmhughes
  • 100,947
10

This doesn't exactly answer your question, as I defined \Eqref instead of a starred \eqref. I just copied the definition of \eqref from amsmath.sty, and added a * to the \ref used there.

\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\makeatletter
\newcommand{\Eqref}[1]{\textup{\tagform@{\ref*{#1}}}}
\makeatother
\begin{document}
\begin{equation}
a=b \label{1}
\end{equation}

\Eqref{1} \eqref{1}

\end{document}
Torbjørn T.
  • 206,688
4

Solution: Thanks to Torbjørn T. and oerpli, here's a(nother) solution:

\makeatletter
\def\eqref{\@ifstar\@eqref\@@eqref}
\def\@eqref#1{\textup{\tagform@{\ref*{#1}}}}
\def\@@eqref#1{\textup{\tagform@{\ref{#1}}}}
\makeatother 

And a working example:

\documentclass{article}
\usepackage{amsmath}
\newtheorem{theorem}{theorem}
\usepackage{hyperref}

\makeatletter
\def\eqref{\@ifstar\@eqref\@@eqref}
\def\@eqref#1{\textup{\tagform@{\ref*{#1}}}}
\def\@@eqref#1{\textup{\tagform@{\ref{#1}}}}
\makeatother 

\begin{document}

\begin{equation}
a=b \label{1}
\end{equation}

\begin{theorem}
A standard ref is italic in math mode: \ref{1} \\
A standard ref* is also italic in math mode: \ref*{1} \\
An eqref is upright: \eqref{1}\\
And so is the new eqref*: \eqref*{1} 
\end{theorem}

\end{document}
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
petertex
  • 303