Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

I am using \label in conjunction with \ref for my equations. For example

\begin{equation} 
\label{eq:grav} F=\frac{G m_{1} m_{2}}{r^{2}}
\end{equation}

as shown in equation \ref{eq:grav}

which prints the number for the order the equation is placed (with reference to the other equations in the document).

I would like it to print the word "equation" as well as just the number, since I always need to say it's an equation it would be nice not to have to type it out manually all the time. Same with figures.

Is there a way to define this in the preamble?

share|improve this question

marked as duplicate by Alan Munn, Kurt, Qrrbrbirlbel, Speravir, mafp Mar 21 '13 at 2:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
You can use cleveref for this. There is a duplicate in the site. –  Harish Kumar Mar 21 '13 at 0:24
    
@HarishKumar link please? –  Magpie Mar 21 '13 at 0:24
1  
2  
Just a suggestion: usually equations are cited using parenthesis, so you can use \eqref{} from the package amsmath instead of \ref{}. –  Sigur Mar 21 '13 at 0:51
3  
Perhaps a better suggestion for a duplicate is: How to get more complete references. And for a comprehensive review of almost all the packages: Cross-reference packages: which to use, which conflict?. –  Alan Munn Mar 21 '13 at 0:55
show 1 more comment

2 Answers

up vote 2 down vote accepted
\documentclass{report}
\usepackage{hyperref} %% to turn the links clickable and load this before cleveref
\usepackage{cleveref}

% each of the following has two versions
%   \crefname{environmentname}{singular}{plural}, to be used mid-sentence
%   \Crefname{environmentname}{singular}{plural}, to be used at the beginning of a sentence
\crefname{table}{table}{tables}
\Crefname{table}{Table}{Tables}
\crefname{figure}{figure}{figures}
\Crefname{figure}{Figure}{Figures}
\crefname{equation}{equation}{equations}
\Crefname{Equation}{Equation}{Equation}
\begin{document}

\begin{figure}[!htb]
  \centering
  \rule{20pt}{20pt}
  \caption{My figure}
  \label{fig:myfig}
\end{figure}

\begin{equation}
\label{eq:grav} F=\frac{G m_{1} m_{2}}{r^{2}}
\end{equation}

\begin{itemize}
  \item Use \cref{fig:myfig} mid sentence.
  \item \Cref{fig:myfig} is appropriate for the beginning of a sentence and~\cref{eq:grav}. \Cref{eq:grav} is printing \verb|Equation| rather than \verb|equation|.
\end{itemize}


\end{document}

enter image description here

share|improve this answer
    
Hmm that didn't work until I tried compiling a copy of your exact example which did work. It seems to be not able to print them in my own document though. ARe there any package conflicts that could cause this? –  Magpie Mar 21 '13 at 2:13
    
@Magpie Without knowing which packages you have in your preamble, it is difficult to say. May be you reduce your document to a MWE and ask a new follow up question? –  Harish Kumar Mar 21 '13 at 2:17
add comment

Mine is similar to that offered by Harish Kumar, except I offer a few added options. What I provide below is a style file, eqcite.sty

\ProvidesPackage {eqcite} [2006/11/29]
%
% by Steven B. Segletes, for the public domain.
%
% eqcite prints out the preferred reference format for equation
% citations, e.g., equation 1 as opposed to eqn(1), eq.(1), etc. 
%
% Advantages of using eqcite:
% 1) Ability to quickly change from `equation x' to `eqn(x)' through
%    whole document, with a single line change (\EqTypeB).  This is 
%    useful when converting from tech report to manuscript formats;
% 2) Saves typing:
%    With the eqcite package, type        `\eqcite{eq:myeqn}'
%    vs. the traditional LaTeX approach of `equation~\ref{eq:myeqn}'  .
%
%
% A number of format types are predefined:
%
% EqTypeA : equation x, equations x and y   (ARL report standard)
% EqTypeB : eqn(x)    , eqns (x) and (y)
% EqTypeC : eq(x)     , eqs (x) and (y)
% EqTypeD : eqn.(x)   , eqns. (x) and (y)
% EqTypeE : eq.(x)    , eqs. (x) and (y)
% EqTypeF : eqn (x)   , eqns (x) and (y)
% EqTypeG : eq (x)    , eqs (x) and (y)
%
% Other format types are easily added.
%
% Usage:
%
% % In Preamble:
% \usepackage{eqcite}
% \EqTypex  % where `x' is A, B, etc.  defaults to EqTypeA
%
% % In Document:
% \Eqcite{ref} ...
% ... \eqcite{ref} ...
% \Eqcites{ref1}, \andeqcite{ref2}, and \andeqcite{ref3} ...
% ... \eqcites{ref1}, \andeqcite{ref2}, and \andeqcite{ref3}...
%
% where ref is the LaTeX reference, for example, eq:myeqn  .
%
% A literal option [l] is available to use the the argument as the
% actual equation number, rather than as an equation reference:
%
% \eqcite[l]{13}
%
% This literal option can be used with the following calls:
% \Eqcite, \eqcite, \Eqcites, \eqcites and \andeqcite.
%
%
% EqTypeA : equation x, equations x and y
\newcommand\EqTypeA{
  \def\Eqname{Equation}
  \def\eqname{equation}
  \def\Eqsname{Equations}
  \def\eqsname{equations}
  \def\eqsep{~}
  \def\eqssep{~}
  \def\eqldelimit{}
  \def\eqrdelimit{}
}
% EqTypeB : eqn(x), eqns (x) and (y)
\newcommand\EqTypeB{
  \def\Eqname{Eqn}
  \def\eqname{eqn}
  \def\Eqsname{Eqns}
  \def\eqsname{eqns}
  \def\eqsep{}
  \def\eqssep{~}
  \def\eqldelimit{(}
  \def\eqrdelimit{)}
}
% EqTypeC : eq(x), eqs (x) and (y)
\newcommand\EqTypeC{
  \def\Eqname{Eq}
  \def\eqname{eq}
  \def\Eqsname{Eqs}
  \def\eqsname{eqs}
  \def\eqsep{}
  \def\eqssep{~}
  \def\eqldelimit{(}
  \def\eqrdelimit{)}
}
% EqTypeD : eqn.(x), eqns. (x) and (y)
\newcommand\EqTypeD{
  \def\eqname{Eqn.}
  \def\eqname{eqn.}
  \def\Eqsname{Eqns.}
  \def\eqsname{eqns.}
  \def\eqsep{}
  \def\eqssep{~}
  \def\eqldelimit{(}
  \def\eqrdelimit{)}
}
% EqTypeE : eq.(x), eqs. (x) and (y)
\newcommand\EqTypeE{
  \def\Eqname{Eq.}
  \def\eqname{eq.}
  \def\Eqsname{Eqs.}
  \def\eqsname{eqs.}
  \def\eqsep{}
  \def\eqssep{~}
  \def\eqldelimit{(}
  \def\eqrdelimit{)}
}
% EqTypeF : eqn (x), eqns (x) and (y)
\newcommand\EqTypeF{
  \def\Eqname{Eqn}
  \def\eqname{eqn}
  \def\Eqsname{Eqns}
  \def\eqsname{eqns}
  \def\eqsep{~}
  \def\eqssep{~}
  \def\eqldelimit{(}
  \def\eqrdelimit{)}
}
% EqTypeG : eq (x), eqs (x) and (y)
\newcommand\EqTypeG{
  \def\Eqname{Eq}
  \def\eqname{eq}
  \def\Eqsname{Eqs}
  \def\eqsname{eqs}
  \def\eqsep{~}
  \def\eqssep{~}
  \def\eqldelimit{(}
  \def\eqrdelimit{)}
}
% Default to Equation Type A format
\EqTypeA
%
% For citing an equation at the beginning of a sentence
\newcommand\Eqcite[2][]{%
  \if l#1%
    \Eqname\eqsep\eqldelimit#2\eqrdelimit
  \else%
    \Eqname\eqsep\eqldelimit\ref{#2}\eqrdelimit
  \fi
}
% For citing an equation in the middle of a sentence
\newcommand\eqcite[2][]{%
  \if l#1%
    \eqname\eqsep\eqldelimit#2\eqrdelimit
  \else%
    \eqname\eqsep\eqldelimit\ref{#2}\eqrdelimit
  \fi
}
% For citing the first of multiple equations at the beginning of a sentence
\newcommand\Eqcites[2][]{%
  \if l#1%
    \Eqsname\eqssep\eqldelimit#2\eqrdelimit
  \else%
    \Eqsname\eqssep\eqldelimit\ref{#2}\eqrdelimit
  \fi
}
% For citing the first of multiple equations in the middle of a sentence
\newcommand\eqcites[2][]{%
  \if l#1%
    \eqsname\eqssep\eqldelimit#2\eqrdelimit
  \else%
    \eqsname\eqssep\eqldelimit\ref{#2}\eqrdelimit
  \fi
}
% For citing an equation number without the leading word equation, eqn, etc.
% Used in conjuction with \Eqcites and \eqcites
\newcommand\andeqcite[2][]{%
  \if l#1%
    \eqldelimit#2\eqrdelimit
  \else%
    \eqldelimit\ref{#2}\eqrdelimit
  \fi
}
%
% For backward compatibility to equagen.sty
\let\equagen\eqcite
\let\Equagen\Eqcite
\let\equagens\eqcites
\let\Equagens\Eqcites
\let\andequagen\andeqcite

\endinput

First, you can specify the EqType, where the type could be "equation", "eqn" etc. Then, it offers, plural, singular, capitalized, conjunctive, and literal options for the cite.

share|improve this answer
    
Ohh this looks more like the sort of thing I need. How/where do I implement it? –  Magpie Mar 21 '13 at 1:58
1  
@Magpie You extract the code and call it eqcite.sty. Then in your tex file, you say \usepackage{eqcite}. Then you start using its commands in your file. Since I didn't upload to CTAN, you can't get it auto-installed. Thus, this file needs to be put in your localtexmf directory structure, or else kept in the directory where you are compiling your code. –  Steven B. Segletes Mar 21 '13 at 2:02
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.