I would like to define a TeX 'macro-building' command (let us call it \buildmacro) that takes as argument a string of 'normal' characters (e.g., Title) and which satisfies the followings:
- the command
\buildmacro{Title}defines the counter with the nameTitleXcounterand initializes it to 0. when issuing at some point in the file the TeX command
\Title{<arg>}, this will have the effect of increasing the counterTitleXcounterand then putting the value<arg>into a new TeX macro with the name\Title-<x>, where<x>is the current value value ofTitleXcounter;here,
<arg>is a piece of TeX code (that can contain text, maths, paragraphs of any other TeX commands).
Consider the following minimal example:
\documentclass{article}
\usepackage{ifthen}
\def\buildmacro#1{...}% the definition of \buildmacro
\begin{document}
\buildmacro{Title}
% 'Read' several titles
\Title{The first title}
\Title{The second title}
\Title{The third title}
\newcount\tempcount
\tempcount=1\relax
% 'List' all the Titles
\whiledo{\the\tempcount<\numexpr \thetitleXcounter+1\relax}
{%
\textsc{\csname title-\the\tempcount\endcsname}\par
\advance\tempcount by 1\relax
}
\end{document}
I 'played' with \csname and \endcsname, \expandafter, \def, \gdef and the \long versions, but with no 'luck'.
Edited (in order to answer some of the comments):
The purpose of this is to have a simple mechanism to create a set of indexed commands with the same root-name (similar to a list of commands). One can always use the \csname <...> \endcsname construct to issue the commnds.




-or a number. You need to stick to letters, basically. (@if@is currently a letter or whatever is also OK. But that means a catcode change to make it a letter. Same for expl3 syntax with_and:being allowed.) Moreover,\titleis a core LaTeX command. – cfr Jun 12 '16 at 01:34\newcommandand friends in LaTeX, namely they check you aren't overwriting stuff which is already defined. If you want to overwrite stuff, use\renewcommandor whatever. – cfr Jun 12 '16 at 01:37\newcommand\cmdmaker[2]{\expandafter\newcommand\csname #1\endcsname{\textbf{#2}}}, where the usage would be like\cmdmaker{firstone}{Look at this!}with you being able to use\firstonein the body of your.texfile. But I really don't get the point/goal of the counter stuff.... – jon Jun 12 '16 at 02:15\csname <...> \endcsnameconstruct. Of course,\titlewas an unfortunate choice, but we can uppercase it to\TITLE, so there is no conflict. – digital-Ink Jun 12 '16 at 07:431etc. catcode 11 is easy, but I think,you get into troubles when defining some macro number argument, i.e.[1]etc. – Jun 12 '16 at 09:27\csname ... \endcsnameor change catcodes, things are different. Usually, people don't want to require that in the end-user interface. – cfr Jun 12 '16 at 13:12