1

I would like to include all macros (or \newcommand's) that start with \figure and count them as floats in texcount. For context, have a look in here.

It works if I tell texcount to increment the float counter individually for each \newcommand:

%TC:macroword \figureMyNthPicture [float]

It would be convenient that each newcommand that would start with a string, like \figure, would be counted and the macrocount/macroword would only need to be defined once.

I have tried the following regex without success:

%TC:macroword ^\\figure [float]

Below is a MWE that works, but the macrocount/macroword is currently defined individually for every macro, which is undesired.

\documentclass[a4paper,12pt]{scrartcl}
\usepackage{graphicx}
%---------------------------------------
\begin{document}


% define figureA
\newcommand{\figureA}{
\begin{figure}
\includegraphics[width=\textwidth]{example-image-a} 
\end{figure}
}

%Count figure A in texcount
%TC:macroword \figureA [float]

%place figureA
\figureA


%define figureB
\newcommand{\figureB}{
\begin{figure}[!htb]
\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{example-image-B}
\end{figure}
}

%Count figure B in texcount
%TC:macroword \figureB [float]

%place figure B
\figureB


\end{document}
1
  • 1
    While it may convenient to have a regexp instead of the macro name, the program texcount cannot easily be tweaked to work with it. To select the rule to apply, the internal data structures use the macro name as a key to a lookup table. One would have to rewrite considerable parts of texcount to allow for the processing of regexps.
    – gernot
    Commented Sep 30, 2021 at 7:45

1 Answer 1

3

beware adding spurious white space from macros (there are missing % here) but rather than use lots of macros using a naming convention why not use a single macro with an argument so \myfigure{A} and \myfigure{B} ?

Then you only need to tell texcount about \myfigure you can define it as

\newcommand\myfigure[1]{\csname figure#1\endcsname}

and it will work with your existing defintions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .