[Tex/LaTex] How exactly does \def\p@figure{Figure~} work

cross-referencingfloatslatex-basemacros

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 …)

Best Answer

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.