The declaration
\DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}
does
\DeclareRobustCommand\rm{\@fontswitch{\normalfont\rmfamily}{\mathrm}}
Let's see what happens when LaTeX finds $\rm a$
in the following minimal document:
\documentclass{article}
\begin{document}
$\rm a$
\end{document}
Let's start:
\rm ->\protect \rm
\rm
is a robust command, so this is its normal expansion. Now, since \protect
is \relax
, \rm
is expanded:
\rm ->\@fontswitch {\normalfont \rmfamily }{\mathrm }
Next \@fontswitch
is expanded:
\@fontswitch #1#2->\ifmmode \let \math@bgroup \relax
\def \math@egroup {\let \math@bgroup \@@math@bgroup
\let \math@egroup \@@math@egroup }#2\relax \else #1\fi
#1<-\normalfont \rmfamily
#2<-\mathrm
We see the arguments. Since we are in math mode, the "true" branch is followed, so the redefinitions of \math@bgroup
and \math@egroup
are performed and \mathrm
is expanded:
\mathrm ->\protect \mathrm
\mathrm ->\relax \ifmmode \else \non@alpherr \mathrm \fi
\use@mathgroup \M@OT1 \symoperators
\use@mathgroup #1#2->\relax \ifmmode \math@bgroup \expandafter
\ifx \csname M@\f@encoding \endcsname #1\else #1\fi \mathgroup #2\relax
\expandafter \math@egroup \fi
#1<-\M@OT1
#2<-\symoperators
Again, we're in math mode (\mathrm
has some code for disallowing its use outside of it); the tests are performed using the fact that the expansion of \f@encoding
is
\f@encoding ->OT1
Now it remains to expand \math@egroup
:
\math@egroup ->\let \math@bgroup \@@math@bgroup
\let \math@egroup \@@math@egroup
and the business is finished. Essentially, this is transformed into
${\mathrm{a}}$
If {\rm a}
is found in text mode, then it becomes essentially
{\normalfont\rmfamily a}
that is, the old behavior of the \rm
command is emulated.
This is why {\sf\sl a}
won't use a slanted sans serif font, but a serif slanted one: it becomes equivalent to
{\normalfont\sffamily\normalfont\slshape a}
Moral: never use the old font commands. You gain nothing and lose much of the flexibility of the new ones. Well, after 18 years they aren't really new.
The easiest solution is to put an explicit \captionsetup[type=table]
before \captionof{table}{...}
.
Apparently, \captionof
should not be used in floating environment at all, it seems to grab the wrong \@captype
content. In final, this will write a wrong anchor name to the .aux
file from which \autoref
grabs its information to determine the name.
Perhaps, the grouping together is not the best way at all.
The package cleveref
provides correct names, however!
\documentclass[12pt]{article}
\usepackage{capt-of}
\usepackage{subfig}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\usepackage{hyperref}
\addto\captionsngerman{\def\figurename{Abb.}}
\addto\extrasngerman{\def\figureautorefname{Abb.}}
\addto\extrasngerman{\def\tableautorefname{Tab.}}
\begin{document}
\begin{figure}
\centering
%Figure
\begin{tikzpicture}
\begin{axis}
\addplot coordinates{(1,1)};
\end{axis}
\end{tikzpicture}
\caption{CAPTION}
\label{figure}
%Table
\captionsetup{type=table}
\captionof{table}{CAPTION\label{tab:LABEL}}
\begin{tabular}{ccc}
akbvk & laknflfk& kanfkf \\
\end{tabular}
\end{figure}
Refering to the figure (\autoref{figure}) and refering to the table (\autoref*{tab:LABEL})
\end{document}
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 counterfoo
will produce the expansion of\p@foo\thefoo
when the\label
command is executed.\thefoo
justs prints the value of counter `foo'.Change
foo
tofigure
ortable
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 themakeatletter
andmakeatother
are required.