[texhax] referencing figures, prepend word "Fig"

Andy Farnell padawan12 at obiwannabe.co.uk
Tue Apr 8 23:23:25 CEST 2008



That works precisely as needed.

And with some study I can understand and modify it too.

Thankyou very much Hartmut.

Andy


On Tue, 8 Apr 2008 23:09:45 +0200 (CEST)
Hartmut Henkel <hartmut_henkel at gmx.de> wrote:

> 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:
> 
> \documentclass{article}
> 
> \newcommand{\origref}{}
> \let\origref\ref
> 
> \newcommand{\splitref}{}
> \def\splitref #1:#2\relax{{%
>   \def\a{#1}%
>   \def\fig{fig}%
>   \def\tab{tab}%
>   \ifx\a\fig Fig.~\origref{\a:#2}\fi
>   \ifx\a\tab Tbl.~\origref{\a:#2}\fi
> }}
> 
> \def\ref#1{\splitref #1\relax}
> 
> \begin{document}
> \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}.
> \end{document}
> 
> Regards, Hartmut


-- 
Use the source


More information about the texhax mailing list