Probably you are using some kind of intelligent editor that tries to find
\label commands in the TeX source and offer a list of label names if you
are typing \ref. The problem is that the \label occurs inside a definition
and your editor only sees \label{fig_#3}, but ignores the calls of
\zfh. Your editor is not TeX, thus it does not know that \newcommands
starts a definition and that it must replace #3 by the third argument.
I do not know, which editor you are using, but I have some doubts that it can be taught easily, how to deal with \zfh. But maybe you can trick your editor by changing the
way, \zfh is called and also the \label inside the definition can perhaps be hidden.
\documentclass[10pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{float}
\newcommand*{\RemoveFigPrefix}{}%
\def\RemoveFigPrefix#1_{}
\newcommand*{\zfh}[2][2in]{%
\zfhLabel{#1}{#2}%
}
\newcommand*{\zfhLabel}{}
\edef\zfhLabel{%
\def\noexpand\zfhLabel##1##2%
\expandafter\noexpand\csname label\endcsname
}\zfhLabel#3{%
\begin{figure}[H]% see comments
\centering % see comments
\includegraphics[height=#1]{./FT/#2}
\caption{\RemoveFigPrefix#3}
\csname label\endcsname{#3}%
\end{figure}%
}
\begin{document}
\listoffigures
\section*{Section with figures}
\zfh[1in]{zzz.pdf}\label{fig_XCaption}
\zfh[1in]{foo.pdf}\label{fig_YPic}
Two figures \ref{fig_XCaption} and \ref{fig_YPic}.
\end{document}
Some explanations:
Some macro definitions are done using TeX's \def, because it allows more powerful parameter texts. But it does not check, whether the command is already defined, it
just overwrites a previous meaning of the macro. Therefore the \newcommand lines
are added that give LaTeX a chance to issue an error message, if the macro is already defined.
The \label inside the definition is hidden using \csname and \endcsname.
These commands construct command tokens:
\csname label\endcsname => \label
If the editor reads \zfh{...}{...}\label{...} then it will understand \label{...}. But we want to
reuse the argument of \label for the caption. Therefore the \label{...} is a
required part of the syntax of \zfh and gets consumed during the execution of \zfh.
Nevertheless \zfh will eventually call \label{...}.
To make the definition of \zfh easier, the definition is split up in two macros.
The first scans for the optional argument and the first mandatory argument;
the second macro \zfhLabel takes care of the \label{...} part. In the definition
of \zfhLabel there is another \label that might confuse the editor (Or not,
because the curly braces are missing, but who knows for sure?):
\def\zfhLabel#1#2\label#3{%
This is obfuscated by
\edef\zfhLabel{%
\def\noexpand\zfhLabel##1##2%
\expandafter\noexpand\csname label\endcsname
}\zfhLabel#3{%
There is no need to understand this for a beginner. The more experienced will see that the first definition of \zfhLabel is just a temporary definition that constructs
the part of the final definition of \zfhLabel.
Let's us hope that your editor now finds all correct \label commands with the changes
in the TeX source code above, ignores the
\label inside definitions and presents you a complete label list, if you want to reference a figure.
fig_#3andref{fig_XCaption}without a space in both cases. Also you should use\centeringrather than\begin{center}in this context to avoid extra vertical space, and finally it is best not to use[H]which is only really as a last-resort final edit for difficult figures, it should never be used as here hidden in another markup for a range of figures. – David Carlisle Jul 10 '12 at 21:32\protect\detokenizeis nothing I would recommend. – egreg Jul 10 '12 at 21:46\ref{fig_ #3}is not possible. #3 is not known outside of\zfh– Jul 11 '12 at 06:24