# Numbering objects for cross-reference

Let's say I have different kinds of food nested like this:

1 Fruit
1.1 Apple
1.2 Orange

2 Vegetable
2.1 Tomato
2.2 Onion

The ordering of the foods matter and I don't want to refer to them by name, just numbering. For example, in my latex code, I would like to write something like Food \ref{onion} and then it would print Food 2.2. Furthermore, when I later realize that a tomato is actually a fruit and move it to the fruit list, Food \ref{onion} would print Food 2.1.

How can I set up this? I'm only familiar with cross-referencing for sections and equations.

EDIT: The list is "secret" and should not appear in the document, i.e., nowhere am I starting an enumerate. To give some context, I'm writing a recipe that can't refer to the ingredients explicitly. The person just receives the recipe and ingredient boxes labeled "Food 1.1," "Food 1.2," etc.

• Welcome to TeX.SE.
– Mico
Jun 22, 2020 at 15:45

(rewrote the answer completely after the OP clarified that the underlying enumerated nests are 'secret' or 'invisible')

Something like this? Note that I've highlighted the output of \ref{onion}.

\documentclass{article}
\renewcommand{\theenumii}{\arabic{enumii}} % default is \alph
\makeatletter
\renewcommand\p@enumii{\theenumi.} % prefix to be used in cross-references
\@addtoreset{enumii}{enumi} % reset 'enumii' whenever 'enumi' is incremented
\makeatother

\begin{document}
%% \refstepcounter and \label directives create no visible output
\refstepcounter{enumi}  \label{fruit}
\refstepcounter{enumii} \label{apple}
\refstepcounter{enumii} \label{orange}
\refstepcounter{enumii} \label{tomato}% 'tomato' is a fruit...
\refstepcounter{enumi}  \label{vegetable}
\refstepcounter{enumii} \label{onion}

\ref{fruit} \ref{apple} \ref{orange} \ref{tomato}

\ref{vegetable} \ref{onion}

\end{document}

• Hi, someone requested I clarify, and I edited the original post. I want the list to be secret and not printed in the document. Jun 22, 2020 at 15:46
• This is complicated but it works! Thanks. Jun 22, 2020 at 17:54
• @Hybardd - For the \label-\ref cross-referencing mechanism to work, in turn, there has got to be a counter that's incremented via a \refstepcounter instruction. Hence the plethora of \refstepcounter directives which increment the counters enumi and enumii.
– Mico
Jun 22, 2020 at 18:00