Showing posts with label autoref. Show all posts
Showing posts with label autoref. Show all posts

Thursday, March 19, 2009

Removing hyperref's space inside \autoref

Many journals (e.g., any of the Royal Society journals) prefer sections to be identified with the section symbol (§) rather than the word "section" followed by a space. If you use \auotref, one of the wonderful macros provided by the hyperref package, then you'll want to do something like...
\renewcommand*\sectionautorefname{\S}
Unfortunately, \autoref will still insert a space between the section symbol (\S, which renders as §) and the section number. So, as discussed in a comp.text.tex posting, you'll need to be more clever and do something like (the ~ character is the "tilde", which is on the upper-left of most keyboards; it's a LaTeX "tie"—a non-breaking space)...
\def\Snospace~{\S{}}
\renewcommand*\sectionautorefname{\Snospace}
instead. That will eat the space that \autoref inserts after the section. Voila!

Thursday, October 16, 2008

Fixing bug in hyperref's autoref: amsmath-type equations under items get "item" label

Earlier this year, in a comp.text.tex posting, I discussed a bug I found in hyperref. That bug was then fixed in hyperref 6.77a, but there are still plenty of old packages hanging around that have this bug (for example, the hyperref from TeXLive 2007 on my system that I still haven't upgraded to TeXLive 2008).

The problem happens when
  • amsmath (or mathtools) is loaded.
  • An equation (or any other type of displayed-math environment) environment with labels occurs INSIDE an enumerated item.
  • You try to use \autoref to generate a reference to one of those equation labels later.
The \autoref macro will not properly return an "Equation" label (e.g., "Equation 1"). Instead, it will return an "item" label (e.g., "item 1").

To fix this problem, I use these lines of code just after I load hyperref in my preamble:
\makeatletter
\newcommand{\AMShreffix}[1]{%
    \expandafter\let\csname old#1\expandafter\endcsname%
        \csname #1\endcsname%
    \expandafter\renewcommand\csname #1\endcsname{%
        \@hyper@itemfalse\csname old#1\endcsname}}
\makeatother
\AMShreffix{equation}
\AMShreffix{align}
\AMShreffix{gather}
The \AMShreffix (i.e., AMS-href-fix) macro "fixes" the displayed-math environment that you pass it. This example fixes equation, align, and gather. If you want to fix alignat too, add a \AMShreffix{alignat} at the end of those lines. Make similar changes for your other displayed-math environments (e.g., flalign and multline too).

That fix changes all of the improper "item" labels back into proper "Equation" labels.

Thursday, August 23, 2007

LaTeX for generating Behavioral Ecology manuscript

UPDATE: Check out a more complete math-oriented template/example, that I posted as behavecol_math_template.tex. This is ready to use out of the box. It has comments. It is setup for AMS math. It has table, figure, and autoreferencing examples too.

IMPORTANT NOTE: If using amsmath environments, be sure to check out my information on making lineno compatible with amsmath environments.

UPDATE: I have put behavecol_template.tex and behavecol.bst on-line so that you don't have to do any of the following to get them.

The Oxford Journal Behavioral Ecology is not setup for LaTeX manuscript submissions. This baffles me.

So, I spent some time putting together some macros and a BibTeX style file to get up and running with this journal.

First, a template (that uses the article document class), which fixes incompatibilities between figcaps, caption, and anything that uses \ref (see behavecol_template.tex for what is below, or see behavecol_math_template.tex for a more complete example):
\documentclass[12pt]{article}

\usepackage[paper=letterpaper,margin=1.5in]{geometry}
\usepackage{setspace}\doublespacing

\usepackage{graphicx}

\usepackage[%
labelsep=newline,
justification=RaggedRight,
singlelinecheck=false,
labelfont=bf,
tableposition=top,
]{caption}
\captionsetup[table]{textfont=bf,position=above}
\makeatletter
\let\oldmakecaption\@makecaption
\makeatother

\usepackage[figon,printfigures]{figcaps}
\def\figurecapname{Figure legends}
\def\tablepagename{Tables}
\def\figurepagename{Figures}

\makeatletter
% This lets figcaps work with \ref
% However, forces \label outside of \caption
\def\phantomsection{\relax}
\let\oldfigurepage\@figurepage
\def\@figurepage{%
\@ifundefined{tf@pof}{}{%
\let\oldlabel\label%
\let\oldinput\@input%
\def\@input{\def\label{\oldlabel}\oldinput}%
\phantomsection%
\addcontentsline{toc}{section}{\figurepagename}}%
\oldfigurepage%
}
\let\@makefcaption\@makecaption
\let\oldtablepage\@tablepage
\def\@tablepage{%
\@ifundefined{tf@pot}{}{%
\clearpage%
\phantomsection%
\addcontentsline{toc}{section}{\tablepagename}}%
\oldtablepage%
}
\makeatother
\usepackage[subrefformat=subparens,labelformat=parens]{subfig}
\captionsetup[subfloat]{position=top}

\setcounter{secnumdepth}{0}

% Lines are numbered, starting at 1
% (add pagewise to reset at each page)
%\usepackage[modulo,pagewise,mathlines]{lineno}
\usepackage[modulo,mathlines]{lineno}
\modulolinenumbers[1]
\firstlinenumber{1}
\linenumbers

\usepackage{natbib}
\bibliographystyle{behavecol}
\setcitestyle{%
authoryear,round,semicolon,%
aysep={},%
yysep={,},%
notesep={, }%
}

\usepackage{tocbibind}
\def\tocbibname{\refname}

\usepackage{varioref}
\labelformat{equation}{\textup{(#1)}}
\labelformat{enumi}{\textup{(#1)}}

\usepackage[%
pdftitle={},
pdfsubject={},
pdfauthor={},
pdfkeywords={},
pdfstartview=FitH,
bookmarks=true,bookmarksopen=true,
breaklinks=true,
colorlinks=false,
pdfpagelabels=true,hypertexnames=true,
plainpages=false,naturalnames=false,
%draft,
]{hyperref}

% \Autoref is for the beginning of the sentence
\let\orgautoref\autoref
\providecommand{\Autoref}
{\def\equationautorefname{Equation}%
\def\figureautorefname{Figure}%
\def\subfigureautorefname{Figure}%
\def\Itemautorefname{Item}%
\def\tableautorefname{Table}%
\orgautoref}

% \Autorefs is plural for the beginning of the sentence
\providecommand{\Autorefs}
{\def\equationautorefname{Equations}%
\def\figureautorefname{Figures}%
\def\subfigureautorefname{Figures}%
\def\Itemautorefname{Items}%
\def\tableautorefname{Tables}%
\orgautoref}

% \autoref is used inside a sentence
% (renew of the standard autoref)
\renewcommand{\autoref}{\Autoref}

% \autorefs is plural for inside a sentence
\providecommand{\autorefs}{\Autorefs}

\let\oldsection\section
\newcommand{\uppercasesection}[2][]{%
\oldsection[#1]{\MakeUppercase{#2}}}
\newcommand{\uppercasesectionstar}[1]{%
\oldsection*{\MakeUppercase{#1}}}
\makeatletter
\def\section{%
\@ifstar{\uppercasesectionstar}%
{\@dblarg{\uppercasesection}}}
\makeatother

\hypersetup{%
pdftitle=
{The title},
}
\title{The title}
\author{}
\date{}

\begin{document}

\maketitle

\begin{abstract}
% ...The abstract...
\textit{Key words:} Keywords separated with comma+space,
List ends with period.
\hypersetup{%
pdfkeywords=
{Keywords separated with comma+space,
List ends with period},
}
\end{abstract}
\newpage

% ...The document...

% The following line loads the references
\bibliography{the_bib_database_name}

\end{document}
Of course, remember to put table captions before the actual table insertion. In fact, it is important that the inside of a table environment has caption first, then label OUTSIDE of the caption, then the actual table content. Additionally, subfigures should be inserted (within a figure environment) with something like:
\subfloat[]{
% ... something like an \includegraphics ...
\label{fig:a}
}
Also, when you're ready to submit, get rid of the % on the %draft, line of the hyperref options. This will turn off all hyper linking, which will prevent strange little unlinked boxes from being drawn in your autogenerated proof.

Next, the bibliography style file, which I may end up posting later separately. As of right now, it has to be constructed from pieces. First, save the following as behavecol.dbj (see behavecol_full.dbj for more details):
%% Driver file to produce behavecol.bst from merlin.mbs
%% Generated with makebst, version 4.1 (2003/09/08)
%% Produced on 2007/08/23 at 12:02
%%
\input docstrip

\preamble
----------------------------------------
*** Bibliography style for _Behavioral Ecology_. ***

\endpreamble

\postamble
End of customized bst file
\endpostamble

\keepsilent

\askforoverwritefalse
\def\MBopts{\from{merlin.mbs}{%
ay,nat,nm-rvx,ed-rev,jnrlst,keyxyr,dt-beg,yr-per,note-yr,jxper,%
jttl-rm,thtit-a,vnum-x,pp-last,num-xser,btit-rm,bt-rm,add-pub,%
pre-edn,in-col,pp,abr,ednx,ord,jabr,xand,etal-xc,nfss,}}
\generate{\file{behavecol.bst}{\MBopts}}
\endbatchfile
and then run latex behavecol.dbj. Next, save the following to behavecol.patch:
--- behavecol.bst 2007-08-29 12:07:40.000000000 -0400
+++ behavecol_new.bst 2007-08-29 12:08:01.000000000 -0400
@@ -89,7 +89,7 @@
FUNCTION {output.nonnull}
{ 's :=
output.state mid.sentence =
- { ", " * write$ }
+ { ". " * write$ }
{ output.state after.block =
{ add.period$ write$
newline$
@@ -144,6 +144,9 @@
FUNCTION {add.blank}
{ " " * before.all 'output.state :=
}
+FUNCTION {add.semicolon}
+{ ";" * before.all 'output.state :=
+}

FUNCTION {date.block}
{
@@ -248,7 +251,7 @@
{ "in" }

FUNCTION {bbl.pages}
-{ "pp." }
+{ "p." }

FUNCTION {bbl.page}
{ "p." }
@@ -260,10 +263,10 @@
{ "Tech. Rep." }

FUNCTION {bbl.mthesis}
-{ "Master's thesis" }
+{ "[Master's thesis]" }

FUNCTION {bbl.phdthesis}
-{ "Ph.D. thesis" }
+{ "[PhD thesis]" }

FUNCTION {bbl.first}
{ "1st" }
@@ -488,6 +491,16 @@
}
if$
}
+FUNCTION {format.book.pages}
+{ pages "pages" bibinfo.check
+ %duplicate$ empty$ 'skip$
+ empty$ 'skip$
+ { add.semicolon
+ add.blank
+ pages "pages" bibinfo.check
+ " " * bbl.pages * }
+ if$
+}
FUNCTION {format.note}
{
note empty$
@@ -950,6 +963,10 @@
}
if$
}
+FUNCTION {format.university.address}
+{ school "school" bibinfo.warn format.org.or.pub
+}
+
FUNCTION {format.publisher.address}
{ publisher "publisher" bibinfo.warn format.org.or.pub
}
@@ -1148,12 +1165,11 @@
author format.key output
format.date "year" output.check
date.block
- format.title
- "title" output.check
- new.block
+ format.title "title" output.check
+ add.blank
bbl.mthesis format.thesis.type output.nonnull
- school "school" bibinfo.warn output
- address "address" bibinfo.check output
+ format.university.address output
+ format.book.pages output
new.block
format.note output
fin.entry
@@ -1178,12 +1194,11 @@
author format.key output
format.date "year" output.check
date.block
- format.title
- "title" output.check
- new.block
+ format.title "title" output.check
+ add.blank
bbl.phdthesis format.thesis.type output.nonnull
- school "school" bibinfo.warn output
- address "address" bibinfo.check output
+ format.university.address output
+ format.book.pages output
new.block
format.note output
fin.entry
Then run
patch < behavecol.patch
from the same directory that you ran the DBJ command in. That should generate the behavecol.bst file that is needed for the above template to work.

Wednesday, July 18, 2007

Protype for simplifying changing cleveref defaults

UPDATE: I have created crefntheoremdefaults.tex, which does this same stuff to the ntheorem package. You have to be sure to include the crefdefaults.tex file first. The files crefntheoremdefault_constants.tex and crefntheoremdefault_formats.tex play a similar role as the analogous ones below.

I think the package cleveref is great. In fact, I think it has much of what has been missing from LaTeX for a long time. See its documentation for more information about the package.

My only gripe about cleveref is that it is tedious to change something like all of the default "eq." and "eqs." to "Eq." and "Eqs.", respectively. So I put together these scripts as a kind of proof of concept (they also setup cleveref to handle table references, something that is not done by default at the moment):

The first script, crefdefaults.tex, is simply crefdefault_constants.tex concatenated with crefdefault_formats.tex. Therefore,
\input{crefdefaults.tex}
is equivalent to
\input{crefdefault_constants.tex}
\input{crefdefault_formats.tex}
However, if the poorman option is used and the corresponding sed script is applied, the resulting file will need to have the content of crefdefault_formats.tex removed; crefdefault_constants.tex should not be removed. In other words, if you are planning on using poorman, use the 2-line include and comment the crefdefault_formats.tex line out of the script that results from the sed script.

What's the outcome of this? I can now do
\renewcommand{\crefenumilabelformat}[3]{\textup{(#2#1#3)}}
in order to change every item reference so that it is surrounded by upright round braces. Additionally, changing "eq." to "Eq." and "eqs." to "Eqs." is as simple as it was in hyperref (for use with \autoref); that is, it is these two lines:
\renewcommand{\crefequationname}{Eq.}
\renewcommand{\crefpluralequationname}{Eqs.}
Unfortunately, the output of the poorman sed filter is a little messy. However, if these are someday integrated into cleveref, that could be fixed. There are other shortcuts built into crefdefaults.tex as well. It probably requires documentation, but it's just a prototype for now.

Good idea? Bad?

Monday, July 09, 2007

\cref* and \crefrange*: temporarily disable cleveref hyperlinks

UPDATE: I've e-mail chatted with the author of cleveref, and it sounds like the changes below (the * macros and the new defaults) may get built into the next release. So that's exciting. The author has recently sent me new versions of cleveref that include these suggestions. Only time will tell when it's on CTAN. So that's exciting.

I've also had a chance to reflect on the poorman option of cleveref. It's an interesting idea. When loaded with this option, cleveref will generate a sed script that the author can use on the source files that will change each of the cleveref macros into old-fashioned references with everything typed out. That is, if you have a journal that does not support cleveref, you run sed on your source code before uploading it, and your journal works with the resulting files that are stripped of cleveref code. That's pretty clever.

I think that by the 1.0 version of cleveref package, it will be ready to replace hyperref's \autoref macro.

One thing that hyperref gives you that cleveref does not are starred versions of the referencing commands that disable hyperlinks. For example, in hyperref, \ref* and \autoref* work exactly like \ref and \autoref but are not hyperlinked. That's nice. Of course, there is no \Autoref or \autorefs or \Autorefs.

A major nice thing that cleveref does is let you format your expanded references with more detail than hyperref. For example, you can make an equation reference expand as "Equation (1)" where the "1" gets linked while having a figure reference expand as "Fig. 1" with the whole "Fig. 1" linked. Of course, this assumes that you've loaded both cleveref and hyperref, like this:
\usepackage{hyperref}
\usepackage[hyperref]{cleveref}
Additionally, cleveref does give the equivalent of those special versions of \autoref. cleveref supports single and multiple references, including reference ranges.

So consider the following, which gives you all the nice stuff about cleveref but also adds starred versions of its macros:
\makeatletter

% \cref and \cref*
\let\origcref\cref
\newcommand{\crefstar}[1]
{\begin{NoHyper}\origcref{#1}\end{NoHyper}}
\renewcommand{\cref}{\@ifstar{\crefstar}{\origcref}}

% \crefrange and \crefrange*
\let\origcrefrange\crefrange
\newcommand{\crefrangestar}[2]
{\begin{NoHyper}\origcrefrange{#1}{#2}\end{NoHyper}}
\renewcommand{\crefrange}
{\@ifstar{\crefrangestar}{\origcrefrange}}

% \Cref and \Cref*
\let\origCref\Cref
\newcommand{\Crefstar}[1]
{\begin{NoHyper}\origCref{#1}\end{NoHyper}}
\renewcommand{\Cref}
{\@ifstar{\Crefstar}{\origCref}}

% \Crefrange and \Crefrange*
\let\origCrefrange\Crefrange
\newcommand{\Crefrangestar}[2]
{\begin{NoHyper}\origCrefrange{#1}{#2}\end{NoHyper}}
\renewcommand{\Crefrange}
{\@ifstar{\Crefrangestar}{\origCrefrange}}

\makeatother
So there you go! That nearly beats \autoref!

Why nearly? Unfortunately, cleveref breaks some Springer journal document classes. The author also doesn't claim that it does or does not support item labels (he mentions that it may or may not, so it's uncertain). Finally, I don't like the default choices for some of the label formats. For example, you shouldn't ever start a sentence with an abbreviation, and the parentheses that go around equation numbers should be surrounded by \textup to keep them from looking silly in an italicized theorem environment. That's why I'm saying that by the 1.0 version (it was 0.6 since June of 2007), it should be a pretty awesome package... especially if the modifications above are built into the package.

Thursday, June 28, 2007

Preamble for Journal of Mathematical Biology

Update 5: The updated svglov2.clo and svglov3.clo are not needed if the preamble is used below (i.e., if the \RequirePackage{fix-cm} line is added before the documentclass line.

Update 4: See the section that redefines \autoref. Changed definition to support starred commands that are unlinked.

Update 3: See the section starting with the comment "%% Level 1 Subsections". It forces subsections to show up like sections in the PDF bookmarks; this is a (strange) JMB convention. In the comment I make some suggestions for improvements.

Update 2: See the small commented section "%%%% Table Support". If the LaTeX code is uncommented there, there is no need for the \noalign{\smallskip} stuff around \hline horizontal table rules. It uses the tabls package to do this.

Update 1: I've mirrored this content on my web page.

I'd like to combine some of the previous posts. I've been trying to fix and modernize some of the Springer LaTeX support files for the Journal of Mathematical Biology (JMB). I've come up with these...

  • svglov2.clo - document class option for svjour2.cls. I used fix-cm to get rid of some of the warnings about not being able to scale the Computer Modern fonts. This is not needed if the preamble below is used (i.e., with the fix-cm line before the documentclass line).

  • svglov3.clo - document class option for svjour3.cls. I used fix-cm to get rid of some of the warnings about not being able to scale the Computer Modern fonts. This is not needed if the preamble below is used (i.e., with the fix-cm line before the documentclass line).

  • spmpsci.bst - BiBTeX bibliography style file for JMB. The original version of this did not reverse the first and last name of the editors as required; I fixed that.

  • spmpscinat.bst - natbib compatible BiBTeX bibliography style file for JMB. Be sure to include natbib with numbers and sort&compress options.
I recommend using a preamble like this one...
%%%% Journal of Mathematical Biology (JMB) setup

% Allow Computer Modern fonts to be scaled (must be before svjour3)
\RequirePackage{fix-cm}

% Use running heads
\documentclass[runningheads]{svjour3}

% The journal's name
\journalname{Journal of Mathematical Biology}

% use Times fonts
\usepackage{mathptmx}

% flush right qed marks (Halmos square),
% e.g., at end of proof
\smartqed

% Use natbib for \citet, \citep, etc.
% (JMB: numbered citations that are sorted
% and compressed)
\usepackage[numbers,sort&compress]{natbib}
%\bibliographystyle{spmpsci}
\bibliographystyle{spmpscinat}

%%%% Some useful packages

% Allow for smarter labeling of enumerations
% and itemizations (consider using enumitem instead)
\usepackage{paralist}

% Provides \labelformat, which changes how \ref
% references look
\usepackage{varioref}

% Mathematical symbols, etc.
\usepackage{amssymb,amsfonts,amsmath}

%%%% Table Support

% UNCOMMENT THE FOLLOWING LINES TO GET RID OF
% \noalign{\smallskip} STUFF AROUND \hline's IN
% TABLES
%
% % The following three lines remove the need for
% % the \noalign{\smallskip} around the \hline's
% % in the _Journal of Mathematical Biology_ LaTeX
% % template
% \usepackage{tabls}
% \addtolength\extrarulesep{\smallskipamount}
% \addtolength\extrarulesep{1pt}

%%%% Graphics and Figure Support

% Use subfig for subfigures
\usepackage[nearskip=-3pt,captionskip=4pt,
listofformat=subsimple,
labelformat=simple]{subfig}

% Make sure subfigures have parentheses around
% them everywhere
\renewcommand\thesubfigure{(\alph{subfigure})}

% Use graphicx for including graphics
\usepackage{graphicx}

% When picture environments are used, use
% pict2e for better resolution and flexibility
\usepackage{pict2e}

%%%% Hyperlink and Autoreference Support

%% Level 1 Subsections
%
% JMB does this weird thing where all
% subsection-level PDF bookmarks are displayed as
% section-level bookmarks. Strangely, they do
% *NOT* turn on the ``bookmarksnumbered'' hyperref
% option. I think their articles would be MUCH more
% readable with all level-1 bookmarks if they were
% prefixed by their section number. I'm sure they'd
% argue that since the sections are linked within
% the document, this is not needed.
%
% (note: another option is to set tocdepth=2 and turn
% on the ``bookmarksopen'' hyperref option)
%
% Anyway, the following redefines \addcontents line
% to setup the bookmarks like JMB articles. Must do
% this after hyperref because it redefines
% \addcontentsline. Therefore, just use an
% AtBeginDocument.
%
\usepackage{ifthen}
\AtBeginDocument{%
\let\orgaddcontentsline\addcontentsline
\renewcommand{\addcontentsline}[3]{
\ifthenelse{\equal{#1}{toc}}
{\ifthenelse{\equal{#2}{subsection}}
{\orgaddcontentsline{#1}{section}{#3}}
{\orgaddcontentsline{#1}{#2}{#3}}}
{\orgaddcontentsline{#1}{#2}{#3}}}}

% Include hyperref for link support
% Include hyperref for link support
%\usepackage[dvipdfmx, % If need dvipdfmx
%\usepackage[dvips, % If need dvips
\usepackage[% % Fine in most cases
pdfpagelabels,hypertexnames=true,
plainpages=false,
naturalnames=false]{hyperref}

% Configure the hyperlink color
\usepackage{color}
\definecolor{darkblue}{rgb}{0,0.1,0.5}
\hypersetup{colorlinks,
linkcolor=darkblue,
anchorcolor=darkblue,
citecolor=darkblue}

% In the future, it would be nice to use the package
%
% cleveref
%
% Right now, it breaks svjour3 and svjour2, so we just
% have to use autoref and labelformat :(.

% Make sure \autoref puts parentheses around
% equations and enumeration items (similar to \eqref)
% NOTE: This allows us to use \ref instead of \eqref
\labelformat{equation}{\textup{(#1)}}
\labelformat{enumi}{\textup{(#1)}}

% Make sure equations are numbered by section
\numberwithin{equation}{section}

%% We need to redefine \autoref. We should use
%% abbreviations inside the sentence and full names
%% at the beginning of sentences. Additionally,
%% need to handle the plural cases.

% \Autoref is for the beginning of the sentence
\let\orgautoref\autoref
\providecommand{\Autoref}
{\def\equationautorefname{Equation}%
\def\figureautorefname{Figure}%
\def\subfigureautorefname{Figure}%
\def\sectionautorefname{Section}%
\def\subsectionautorefname{Section}%
\def\subsubsectionautorefname{Section}%
\def\Itemautorefname{Item}%
\def\tableautorefname{Table}%
\orgautoref}

% \Autorefs is plural for the beginning of the sentence
\providecommand{\Autorefs}
{\def\equationautorefname{Equations}%
\def\figureautorefname{Figures}%
\def\subfigureautorefname{Figures}%
\def\sectionautorefname{Sections}%
\def\subsectionautorefname{Sections}%
\def\subsubsectionautorefname{Sections}%
\def\Itemautorefname{Items}%
\def\tableautorefname{Tables}%
\orgautoref}

% \autoref is used inside a sentence
% (this is a renew of the standard)
\renewcommand{\autoref}
{\def\equationautorefname{Eq.}%
\def\figureautorefname{Fig.}%
\def\subfigureautorefname{Fig.}%
\def\sectionautorefname{Sect.}%
\def\subsectionautorefname{Sect.}%
\def\subsubsectionautorefname{Sect.}%
\def\Itemautorefname{item}%
\def\tableautorefname{Table}%
\orgautoref}

% \autorefs is plural for inside a sentence
\providecommand{\autorefs}
{\def\equationautorefname{Eqs.}%
\def\figureautorefname{Figs.}%
\def\subfigureautorefname{Figs.}%
\def\sectionautorefname{Sects.}%
\def\subsectionautorefname{Sects.}%
\def\subsubsectionautorefname{Sects.}%
\def\Itemautorefname{items}%
\def\tableautorefname{Tables}%
\orgautoref}

This lets you do cool things like... (hyperlinks depicted in blue)

\ref{eq:1} produces linked "(1)"
\ref*{eq:1} produces unlinked "(1)"
\autoref{eq:1} produces linked "Eq. (1)"
\autoref*{eq:1} produces unlinked "Eq. (1)"
\Autoref{eq:1} produces linked "Equation (1)"
\autoref{sec:2} produces linked "Sect. 2.1"
\Autoref{sec:2} produces linked "Section 2.1"
\Autorefs{sec:1} and \ref{sec:2} produces linked "Sections 1 and 2.1"
\autorefs{sec:1} and \ref{sec:2} produces linked "Sects. 1 and 2.1"
\autoref{item:1} produces linked "item (i)"
\autorefs{item:1} and \ref{item:2} produces linked "items (i) and (ii)"
\citep{SK86} produces linked "[61]"
\citep[p.~41]{SK86} produces linked "[61, p. 41]"
\citep{Cha76,SK86} produces linked "[14, 61]"
\citep[e.g.,][]{SK86,Cha76} produces linked "[e.g., 14, 61]"
\citeauthor{SK86} produces linked "Stephens and Krebs"
\citet{SK86} produces linked "Stephens and Krebs [61]"

Wednesday, June 27, 2007

paralist, varioref, and hyperref: a happy combination

Consider the following...
\usepackage{varioref}
\labelformat{equation}{\textup{(#1)}}
This uses the clever varioref package to alter how equation references are displayed. The reference will be displayed with parentheses around the reference and the whole thing will be forced upright (so things don't look stupid in an italicized theorem environment). For example, for an equation labeled "eq:1" and a figure labeled "fig:1", I get these results:
\ref{eq:1} produces "(1)"
\ref{fig:1} produces "1"
This removes the need for \eqref from amsmath; just use \ref instead. Now, let's add hyperref:
\usepackage{hyperref}
So,
\ref{eq:1} produces a linked "(1)"
\ref*{eq:1} produces an unlinked "(1)"
\ref{fig:1} produces a linked "1"
\ref*{fig:1} produces an unlinked "1"
\autoref{eq:1} produces a linked "Equation (1)"
\autoref*{eq:1} produces an unlinked "Equation (1)"
\autoref{fig:1} produces a linked "Figure 1"
\autoref*{fig:1} produces an unlinked "Figure 1"
So this gives us the equivalent of an unlinked "\eqref*" through \ref*. Now, let's add paralist...
\usepackage{paralist}
\labelformat{equation}{\textup{(#1)}}
and an enumerate environment with automatic bracketed lowercase roman numeral numbering...
\begin{enumerate}[(i)]
\item This is item one. \label{item:1}
\item This is item two. \label{item:2}
\end{enumerate}
The \label macros can be associated with any enumerate item, even without paralist. The package paralist allows us to easily customize the displayed labels (enumitem is nice alternative). So, we get an enumerated output like...
 (i) This is item one.
(ii) This is item two.
Now we get...
\ref{item:1} produces a linked "(i)"
\ref*{item:1} produces an unlinked "(i)"
\autoref{item:1} produces a linked "item (i)"
\autoref*{item:1} produces an unlinked "item (i)"

Isn't life sweet? Notice the similarities between these things and stuff provided by prettyref and typedref. I think hyperref's autoref with the flexibility provided by varioref is a nice way to replace those old goodies.

Now can someone convince the Journal of Mathematical Biology to start using a bibliography style compatible with natbib? That would truly make me happy...