0

It's one hour that I'm trying to change the name of reference from "Equation 1" to "(eq.1)". I found the following code

\usepackage{hyperref}
\def\equationautorefname~#1\null{Equation (#1)\null}

but it does not change anything. I thought it was a conflict with amsmath, but even eliminating it, it does not work. How can I implement that without loosing cross-reference link or without simply writing ref comand between parenthesis?

As stiffly requested, there's an example code.

\documentclass{article}
\usepackage[english]{babel}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}

\begin{document}

There is the equation \autoref{eq:test}\ \begin{equation} \label{eq:test} 1+1=2 \end{equation}

\end{document}

Result: enter image description here

ahahfilip
  • 35
  • 5

2 Answers2

3

With a current LaTeX you can make use of \labelformat and actually don't need autoref:

\documentclass{article}

\usepackage{amsmath} \usepackage{hyperref}

\labelformat{equation}{(eq.~#1)} \def\equationautorefname#1{}%for autoref, gobble the space \begin{document}

\begin{equation}    
    E=mc^2  \label{eq:einstein}
\end{equation}

See the great equation \ref{eq:einstein}, \autoref{eq:einstein}.

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • It kinda works, but I have the package \usepackage[english]{babel} that write down "Equation (eq.1)" and not only "(eq.1)". I'll upload a good example to the main post now. – ahahfilip Dec 07 '22 at 20:30
  • 1
    sorry but I won't expand my answer. Next time provide an example directly. – Ulrike Fischer Dec 07 '22 at 20:42
  • Don't mind, thank you anyway! At least I'm closer to the answer due to your contribute :) – ahahfilip Dec 07 '22 at 20:47
  • I just realized that using \ref instead of \autoref does the tricks using your solution! :P Thanks again! :) – ahahfilip Dec 08 '22 at 12:58
1

This answer is based on schtandard's answer who said

A bit of a dirty hack, but this works as long as hyperref does not change its \autoref implementation.

a

\documentclass{article}

\usepackage{amsmath} \usepackage{hyperref}

\renewcommand\equationautorefname{(eq.}

%From https://tex.stackexchange.com/a/584601/161015 \makeatletter \AtBeginDocument{% \let\plain@equationautorefname\equationautorefname \def\equationautorefname{\plain@equationautorefname@autoref@insert@tagform}% \def@autoref@insert@tagform~#1\null{,#1)\null}% } \makeatother

\begin{document}

\begin{equation}    
    E=mc^2  \label{eq:einstein}
\end{equation}

See the great equation \autoref{eq:einstein}.

\end{document}

Simon Dispa
  • 39,141