[Tex/LaTex] Cross reference of Table, Figure etc

cross-referencing

Preparing APS manuscripts, it is required that when "Table, Figure" appear at the beginning of a sentence, they should appear in their full form, otherwise, in abbreviated form as "Tab., Fig.".

Using \ref{} one needs to decide and type the referred names by hand; on the other hand, using \autoref{}, which though automatically brings the referred names, it can not, as far as I know, tell whether the names appear at the beginning of a sentence or not.

So, is there an automated way to meet the above-mentioned requirement, instead of everytime inputting by hand?

Best Answer

As long as in \nonfrenchspacing you can fork depending on the \spacefactor:

\documentclass{article}
\usepackage{hyperref}%
\makeatletter
\newcommand\sfcodefork{%
  \ifnum\the\spacefactor=1000 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
}%
\renewcommand\figureautorefname{\sfcodefork{Fig.\texorpdfstring{\null}{}}{Figure}}
\renewcommand\tableautorefname{\sfcodefork{Tab.\texorpdfstring{\null}{}}{Table}}

\makeatother

\begin{document}

\nonfrenchspacing

\section{A section}

\begin{figure}%
\rule{1cm}{1cm}%
\caption{caption of figure.}\label{label of figure}%
\end{figure}%

\begin{table}%
\begin{tabular}{ll}
left&right\\
\end{tabular}
\caption{caption of table.}\label{label of table}%
\end{table}%

References at beginning of sentence:
\autoref{label of figure} is referenced.
\autoref{label of table} is referennced. 

We can refer \autoref{label of figure} in the middle of a sentence.

We can refer \autoref{label of table} in the middle of a sentence.

\end{document}

enter image description here