# How exactly does \def\p@figure{Figure~} work?

I took this line from my thesis style and added it into my document (preceded by \makeatletter) and what it does that whenever I used \ref{figureid} instead of putting just the figure number, it puts "Figure 1".

I can do the same thing for tables, by having \def\p@table{Table~) but what I don't know is what exactly is:

\p@figure
\p@table


I assume they're used internally by ref, but is there anything more (such as \p@(object) is always used as the beginning of something ...)

-
Great question! Finally I understand what's happening in this post and the answers to this post. (Also nice answers so far.) – Hendrik Vogt Nov 23 '10 at 15:13

These are LaTeX kernel macros that are associated with environments. In simple terms anything that is enclosed with a \begin{foo}...\end{foo} is an environment. For example a figure or a table.

Every time you insert a table a counter is incremented. This counter let us call it foo has an associated macro named \p@foo. This macro expands to a printed reference prefix' of counter foo.

Any \ref to a value created by counter foo will produce the expansion of \p@foo\thefoo when the \label command is executed. \thefoo justs prints the value of counter foo'.

Change foo to figure or table and it will make more sense.

The \def part defines the macro. You can for example say \def\milan{Milan Ramaiyan} and every time you type \milan it will expand too .. Milan Ramaiyan. The @ symbol is just a special symbol used by TeX and LaTeX to avoid overriding commands accidentally. It needs special treatment and that is why the makeatletter and makeatother are required.

-

In addition to Yiannis fine explanation: you may even extend these \p@ macros such as \p@figure to become more than just a prefix. source2e.pdf gives hints in section 53.2 An extension of counter referencing.

This modification

\makeatletter
\renewcommand*\refstepcounter[1]{\stepcounter{#1}%
\protected@edef\@currentlabel
{\csname p@#1\expandafter\endcsname\csname the#1\endcsname}}
\makeatother


allows you to define \p@figure with an argument, which allows more sophistocated formatting. And it's still backwards compatible to the original version. An arbitrary example:

\renewcommand*{\p@figure}[1]{\emph{figure~(#1)}}


gives see figure (1). This way you may add a prefix and a suffix plus formatting.

-

A packaged alternative to Stefan's answer is to use the fncylab package, which makes the change he mentions and also defines a \labelformat macro to manipulate \p@counters easily. For example, \labelformat{equation}{(#1)} makes \ref act like \eqref when applied to labels on equations. (I have this activated by default in my documents, actually. The bare number is rarely useful.)

-

I used \usepackage{hyperref} and applied \autoref{tab:minimum-cut-set}. It would generate "Table 1.2" (for instance) what we want to see. However, for algorithm, although "Algorithm" capitalizes but it shows "algorithm 2.1" (for instance).

The caption table, figure are shown properly. Only algorithm occurs the issue as I have mentioned above.

-
Welcome to TeX.sx! A tip: You can use backticks  to mark your inline code as I did in my edit. :)` – Paulo Cereda May 9 '12 at 16:12