Counting of selected words

LaTeX provides built-in macros to handle counters and that is how the sectioning numbering, page numbers and floats are handled. In I posted a reply which is very similar to what you want to do and which I have adapted to include counters.






%% adding the data now
\RA Lactarius fallax      | velvety milk cap |edible |potentially risky;  
\RA Lactarius camphoratus | candy cap        |edible |aromatic qualities;
\RA Suillus pungens       | slippery Jack    |edible |poor taste;
\RA Lactarius affinis     | kindred milk     |edible |unpalatable;
\RA Calocybe carnea       | pink fairhead    |edible |potentially risky;
\RA Amateta ocreata       | death angel      |inedible |highly poisonous;   

%% typesetting the table
  Species & Common name & Edibility & Remarks\\
  \@for\i:=\alist \do{\csname\i\endcsname}

\caption{Some mushrooms from Wikipedia}

Number of mushrooms in database is \textbf{\thecnt}


The idea is that everytime you add a plant (in my examples is mushrooms), you first add it to a database macro (just a comma delimited list really) and you increment the counter. Pretty much similar to when you adding something to an index. Depending on the structure of the document, the code can be adapted to hold an image, increment a number, sort alphabetically etc. In the example we just display the names in a table.

LateX provides the command \newcounter and \stepcounter and some other for counting.


    % step counter
    \stepcounter{plants}% use \refstepcounter if you want
        % to use the number with the \ref-\label-mechanism
    % new line
    % optionally print counter
%   \theplants. 
    % print name


Sum: \theplants

To specify my answer I need more information about you project. Please provide a minimal working example (MWE).

You can use the .idx file for counting:


%For multiple index
\makeindex[name=ch, title=Chemical index]
\makeindex[name=pl,title=Plant Index]


This is my test document. It contains a total of \ref{plants-number} plants. Plant 
1\index[pl]{plant 1} has chemicals 1\index[ch]{chemical 1} and 2\index[ch]{chemical 2}. 
Another plant\index[pl]{plant 2} continas the chemicals 2\index[ch]{chemical 2} and 
3\index[ch]{chemical 3}.

List of plants:
Plant 3\index[pl]{plant 3}
plant 4\index[pl]{plant 4}
plant 5\index[pl]{plant 5}

\indexprologue{\small Index of plants}

\indexprologue{\small Index of chemicals}

% We'll count the number of plants and of chemicals
% Define suitably \indexentry

% Let's count the plants

% Let's count the chemicals



The final code will produce no text, but only a reference to the last counted plant; this reference may be used anywhere (but, of course, this requires at least two runs of LaTeX).

Note: there's no need to give a \makeindex command and \printindex command if you have only entries marked \index[pl] and \index[ch].