Text FormattingReferences without Prefix

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
jbgrad
Posts: 5
Joined: Sat Nov 17, 2012 4:31 am

References without Prefix

Post by jbgrad »

Hi

After doing some searching online, I found that I could conveniently define:

Code: Select all

\makeatletter
\def\p@table{Table~}
\def\p@figure{Figure~}
\makeatother
However, there are times when I only want the \thefigure corresponding to a label, not \p@figure\thefigure, like \ref gives. Is there a ref-like command to do this, or a simple way to define my own command? Or if I could be pointed to the "official" version of \ref (I have no idea where it is defined) I could use it as a reference.

Thanks

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

References without Prefix

Post by cgnieder »

I guess the most convenient way is using cleveref:

Code: Select all

\documentclass{article}
\usepackage{cleveref}
\begin{document}

\begin{table}[ht]
 a table
 \caption{A Table}
 \label{tab:table}
\end{table}

Reference with name: \Cref{tab:table} or \cref{tab:table}
and without: \ref{tab:table}

\end{document}
Anyway, the definition of \ref can be found in a file called latex.ltx which you can find in the base directory of the TeX tree (tex/latex/base). There you'll find these lines:

Code: Select all

\def\G@refundefinedtrue{%
  \gdef\@refundefined{%
    \@latex@warning@no@line{There were undefined references}}}
\let\@refundefined\relax
\def\@setref#1#2#3{%
  \ifx#1\relax
   \protect\G@refundefinedtrue
   \nfss@text{\reset@font\bfseries ??}%
   \@latex@warning{Reference `#3' on page \thepage \space
             undefined}%
  \else
   \expandafter#2#1\null
  \fi}
\def\ref#1{\expandafter\@setref\csname r@#1\endcsname\@firstoftwo{#1}}
\def\pageref#1{\expandafter\@setref\csname r@#1\endcsname
                                   \@secondoftwo{#1}}
Regards
site moderator & package author
Post Reply