[texhax] referencing figures, prepend word "Fig"

Hartmut Henkel hartmut_henkel at gmx.de
Tue Apr 8 23:09:45 CEST 2008

On Tue, 8 Apr 2008, Andy Farnell wrote:

> When I started writing I was unsure of whether to use the word
> "figure", "diagram", "fig" or whatever, so I decided to defer that
> decision until later. Throughout the text all references are given as
> \ref{fig:foobar}, or \ref{tab:atable} and so forth.
> Now, I want to automatically prepend the word "Fig" or "Table" to each
> reference depending on the three characters that appear before the
> colon.

here is a rough example:



\def\splitref #1:#2\relax{{%
  \ifx\a\fig Fig.~\origref{\a:#2}\fi
  \ifx\a\tab Tbl.~\origref{\a:#2}\fi

\def\ref#1{\splitref #1\relax}

\begin{figure} \caption{foo} \label{fig:foo} \end{figure}
\begin{table}  \caption{bar} \label{tab:bar} \end{table}

In \ref{fig:foo} we see---nothing. Same in \ref{tab:bar}.

Regards, Hartmut

More information about the texhax mailing list