Document Classes ⇒ Help with "\autoref" of "hyperref"
Help with "\autoref" of "hyperref"
Hello all,
I am using "\autoref" from "hyperref" which is a great command. I have couple of things on mind that I cannot implement. I will set my examples for referencing an equation. The items start with the most important...
1. The other thing, and it mainly applies to Equation. How can I change it to produce the equation number between parentheses. In other word, I would like "\autoref{eq_1}" to produce "Equation (1)", not "Equation 1"...
2. I would like to be able to set an options that if the "\autoref" is used at the beginning of a sentence, "Equation" would be generated. Otherwise, generate "Eq.". This is standard practice in many scientific journals, but I imagine this would be hard to fix...
I would appreciate your help...
Jamil M. Renno
Virginia Tech
I am using "\autoref" from "hyperref" which is a great command. I have couple of things on mind that I cannot implement. I will set my examples for referencing an equation. The items start with the most important...
1. The other thing, and it mainly applies to Equation. How can I change it to produce the equation number between parentheses. In other word, I would like "\autoref{eq_1}" to produce "Equation (1)", not "Equation 1"...
2. I would like to be able to set an options that if the "\autoref" is used at the beginning of a sentence, "Equation" would be generated. Otherwise, generate "Eq.". This is standard practice in many scientific journals, but I imagine this would be hard to fix...
I would appreciate your help...
Jamil M. Renno
Virginia Tech
If there is no way, we will make one...
Hanibal
Hanibal
NEW: TikZ book now 40% off at Amazon.com for a short time.
- countbela666
- Posts: 64
- Joined: Thu Apr 26, 2007 2:44 pm
Help with "\autoref" of "hyperref"
Hello Jamil,
Here a minimal working example (MWE) that implements both features:
Regards
Marcel
If you are using amsmath, you can put the following code into your preamble (after loading amsmath and hyperref):renno wrote: 1. How can I change it to produce the equation number between parentheses. In other word, I would like "\autoref{eq_1}" to produce "Equation (1)", not "Equation 1"...
Code: Select all
\makeatletter
\def\tagform@#1{\maketag@@@{\ignorespaces#1\unskip\@@italiccorr}}
\let\orgtheequation\theequation
\def\theequation{(\orgtheequation)}
\makeatother
This is really hard to implement. Another possibility would be to use two different commands: \Autoref{...} for the beginning of a sentence and \autoref{...} for a reference inside a sentence. You could implement this as follows:renno wrote: 2. I would like to be able to set an options that if the "\autoref" is used at the beginning of a sentence, "Equation" would be generated. Otherwise, generate "Eq.".
Code: Select all
\let\orgautoref\autoref
\providecommand{\Autoref}[1]{\def\equationautorefname{Equation}\orgautoref{#1}}
\renewcommand{\autoref}[1]{\def\equationautorefname{Eq.}\orgautoref{#1}}
Code: Select all
\documentclass{report}
\usepackage{amsmath,hyperref}
\makeatletter
\def\tagform@#1{\maketag@@@{\ignorespaces#1\unskip\@@italiccorr}}
\let\orgtheequation\theequation
\def\theequation{(\orgtheequation)}
\makeatother
\let\orgautoref\autoref
\providecommand{\Autoref}[1]{\def\equationautorefname{Equation}\orgautoref{#1}}
\renewcommand{\autoref}[1]{\def\equationautorefname{Eq.}\orgautoref{#1}}
\begin{document}
\chapter{Example}
\begin{equation}a^2+b^2=c^2 \label{foo}\end{equation}
\Autoref{foo} shows \dots
\begin{equation}a^2+b^2=c^2 \label{bar}\end{equation}
As shown in \autoref{bar} \dots
\end{document}
Marcel
Listen to me children of the night, beyond the doors of darkness you will find
a thousand worlds for you to see here, take my hand and follow me...
a thousand worlds for you to see here, take my hand and follow me...
Help with "\autoref" of "hyperref"
Dear Marcel,
Thank you very much. The code works perfectly and this produces exactly what I wanted. I augmented the code to produce "Figure" and "Fig." for figures and sub-figures at the beginning of a sentence and in a sentence respectively.
I am including the modified code for everybody's convenience...
% ======================================================
% \Autoref is for the beginning of the sentence
\let\orgautoref\autoref
\providecommand{\Autoref}[1]
{
\def\equationautorefname{Equation}
\def\figureautorefname{Figure}
\def\subfigureautorefname{Figure}
\orgautoref{#1}
}
% \autoref is used inside the sentence to produce Fig., and Eq. for figures, subfigures, and equations
\renewcommand{\autoref}[1]
{
\def\equationautorefname{Eq.}
\def\figureautorefname{Fig.}
\def\subfigureautorefname{Fig.}
\orgautoref{#1}
}
% ====================================================
Thanks again Marcel for the great response...
Have a good one...
Thank you very much. The code works perfectly and this produces exactly what I wanted. I augmented the code to produce "Figure" and "Fig." for figures and sub-figures at the beginning of a sentence and in a sentence respectively.
I am including the modified code for everybody's convenience...
% ======================================================
% \Autoref is for the beginning of the sentence
\let\orgautoref\autoref
\providecommand{\Autoref}[1]
{
\def\equationautorefname{Equation}
\def\figureautorefname{Figure}
\def\subfigureautorefname{Figure}
\orgautoref{#1}
}
% \autoref is used inside the sentence to produce Fig., and Eq. for figures, subfigures, and equations
\renewcommand{\autoref}[1]
{
\def\equationautorefname{Eq.}
\def\figureautorefname{Fig.}
\def\subfigureautorefname{Fig.}
\orgautoref{#1}
}
% ====================================================
Thanks again Marcel for the great response...
Have a good one...
If there is no way, we will make one...
Hanibal
Hanibal
Help with "\autoref" of "hyperref"
Hello all,
Just a follow up on my last follow up. The last code I posted causes unnecessary spaces before Figure, Fig., Equation, Eq. because of having each definition on a new line. The following works...
% ====================================================
% \Autoref is for the beginning of the sentence
\let\orgautoref\autoref
\providecommand{\Autoref}[1]{\def\equationautorefname{Equation}
\def\figureautorefname{Figure}\def\subfigureautorefname{Figure}\orgautoref{#1}}
% \autoref is used inside the sentence to produce Fig., and Eq. for figures, subfigures, and equations
\renewcommand{\autoref}[1]{\def\equationautorefname{Eq.}
\def\figureautorefname{Fig.}\def\subfigureautorefname{Fig.}\orgautoref{#1}}
% ====================================================
Sorry for any confusion...
I will be more careful from now on...
Just a follow up on my last follow up. The last code I posted causes unnecessary spaces before Figure, Fig., Equation, Eq. because of having each definition on a new line. The following works...
% ====================================================
% \Autoref is for the beginning of the sentence
\let\orgautoref\autoref
\providecommand{\Autoref}[1]{\def\equationautorefname{Equation}
\def\figureautorefname{Figure}\def\subfigureautorefname{Figure}\orgautoref{#1}}
% \autoref is used inside the sentence to produce Fig., and Eq. for figures, subfigures, and equations
\renewcommand{\autoref}[1]{\def\equationautorefname{Eq.}
\def\figureautorefname{Fig.}\def\subfigureautorefname{Fig.}\orgautoref{#1}}
% ====================================================
Sorry for any confusion...

I will be more careful from now on...
If there is no way, we will make one...
Hanibal
Hanibal
- countbela666
- Posts: 64
- Joined: Thu Apr 26, 2007 2:44 pm
Help with "\autoref" of "hyperref"
If you mask every end of a line with a comment inside the new macros, it should be working as well:
Regards
Marcel
Code: Select all
% \Autoref is for the beginning of the sentence
\let\orgautoref\autoref
\providecommand{\Autoref}[1]
{%
\def\equationautorefname{Equation}%
\def\figureautorefname{Figure}%
\def\subfigureautorefname{Figure}%
\orgautoref{#1}%
}
% \autoref is used inside the sentence to produce Fig., and Eq. for figures, subfigures, and equations
\renewcommand{\autoref}[1]
{%
\def\equationautorefname{Eq.}%
\def\figureautorefname{Fig.}%
\def\subfigureautorefname{Fig.}%
\orgautoref{#1}%
}
Marcel
Listen to me children of the night, beyond the doors of darkness you will find
a thousand worlds for you to see here, take my hand and follow me...
a thousand worlds for you to see here, take my hand and follow me...
Re: Help with "\autoref" of "hyperref"
Dear Marcel,
Thank you very much for the valuable comment. I was not aware of this at all...
Have a good day...
Thank you very much for the valuable comment. I was not aware of this at all...
Have a good day...
If there is no way, we will make one...
Hanibal
Hanibal
Re: Help with "\autoref" of "hyperref"
Three quick things...
1. Just to verify, it looks like the parentheses modification should give the same result as surrounding the equation number in an \eqref. That is, the parentheses will always show up in roman normal shape, right?
2. Another idea. You could use these ideas to implement macros \autorefs and \Autorefs. Then you could do something like...
\Autorefs{eq_1} and \eqref{eq_2} show stuff.
which would produce:
Equations (1) and (2) show stuff.
3. Does anyone know if \eqref* acts like \ref*? If not, would a good way to create an \eqref* be to define the command as eqref surrounded in a NoHyper environment?
Thanks!
--Ted
1. Just to verify, it looks like the parentheses modification should give the same result as surrounding the equation number in an \eqref. That is, the parentheses will always show up in roman normal shape, right?
2. Another idea. You could use these ideas to implement macros \autorefs and \Autorefs. Then you could do something like...
\Autorefs{eq_1} and \eqref{eq_2} show stuff.
which would produce:
Equations (1) and (2) show stuff.
3. Does anyone know if \eqref* acts like \ref*? If not, would a good way to create an \eqref* be to define the command as eqref surrounded in a NoHyper environment?
Thanks!
--Ted
Help with "\autoref" of "hyperref"
countbela666 wrote: If you are using amsmath, you can put the following code into your preamble (after loading amsmath and hyperref):Code: Select all
\makeatletter \def\tagform@#1{\maketag@@@{\ignorespaces#1\unskip\@@italiccorr}} \let\orgtheequation\theequation \def\theequation{(\orgtheequation)} \makeatother
Maybe this is a better idea:
Code: Select all
\usepackage{varioref}
...
\labelformat{equation}{\textup{(#1)}}
Additionally, you can do this for enumeration counters too. Consider this example (that makes use of paralist):
Code: Select all
\usepackage{paralist}
\usepackage{varioref}
...
\labelformat{enumi}{\textup{(#1)}}
...
\begin{enumerate}[(i)]
\item This is a test. \label{item:1}
\item This is another test. \label{item:2}
\end{enumerate}
...
Now we refer to \autoref{item:1} and \ref{item:2}.
Code: Select all
Now we refer to item (i) and (ii).
Help with "\autoref" of "hyperref"
It is better to drop the [1] and #1 stuff since \orgautoref handles that by itself. Consider the following, which defines a command that takes NO ARGUMENTS: This works exactly the same as above. HOWEVER, it ALSO allows for the starred forms of \*utoref to work. For example, will produce an UNLINKED version (and yet still expanded) version of: That is, the former produces
Code: Select all
% \Autoref is for the beginning of the sentence
\let\orgautoref\autoref
\providecommand{\Autoref}{%
\def\equationautorefname{Equation}%
\def\figureautorefname{Figure}%
\def\subfigureautorefname{Figure}%
\orgautoref}
% \autoref is used inside the sentence to produce Fig., and Eq. for figures, subfigures, and equations
\renewcommand{\autoref}{%
\def\equationautorefname{Eq.}%
\def\figureautorefname{Fig.}%
\def\subfigureautorefname{Fig.}%
\orgautoref}
Code: Select all
\Autoref*{eq:1} is below.
Code: Select all
\Autoref{eq:1} is below.
and the latter produces (where blue indicates where a hyperlink would be)Equation (1) is below.
Equation (1) is below.
Re: Help with "\autoref" of "hyperref"
The preamble I've posted at (scroll the page until you see the LaTeX code):
http://www.tedpavlic.com/post_preamble_ ... th_bio.php
uses a combination of all of these things. In fact, this thread was motivation for much of it. It was customized for a particular journal, but the first couple lines can be removed and it can be used elsewhere.
http://www.tedpavlic.com/post_preamble_ ... th_bio.php
uses a combination of all of these things. In fact, this thread was motivation for much of it. It was customized for a particular journal, but the first couple lines can be removed and it can be used elsewhere.