1

I'm not sure if there's better terminology for this, but how does one create 'sub-commands' within an environment (preferably in plain TeX)?

An example is the itemize environment, where \item is the 'sub-command':

\begin{itemize}
\item Enter item here
\item etc.
\end{itemize}

As an example, how could I make it so typing \subcmd Some text here (or \subcmd <anything>) makes the Some text here (or <anything>) in italics? (just an example)

5
  • 5
    plain tex doesn't define environments, in latex \item is globally defined, it just raises an error if used in an incorrect context. Please clarify your question, do you also want \begin and \end definitions for plain TeX? Apr 22 at 23:42
  • 1
    The standard \item <anything> doesn't affect the typesetting of <anything>. \item typesets a label or whatever, but <anything> isn't an argument so it isn't affected by anything \item does by way of font changes, for example. You could add a font switch into the definition of \item, but it would apply until you gave another switch or the local group ended. (In effect, this would mean \item turned <anything> italic, but that wouldn't be how things were actually structured underneath.
    – cfr
    Apr 23 at 0:00
  • 1
    you have tagged this as plain-tex but of the three commands you show, \begin and \item are not defined in plain, and \end will terminate the job. Apr 23 at 0:22
  • 1
    LaTeX with its obnoxious \begin{foo}, \end{foo} got tangled up in this plain TeX question probably by mistake.
    – wipet
    Apr 23 at 5:32
  • It is unclear what you mean with "subcommand". You can define a command that is only usable inside an environment, but I am unsure whether this is actually what you want. Where do you want to use \subcmd ? Please try to come up with a more elaborate example that shows the intended use. Apr 24 at 17:39

1 Answer 1

4

If you want to define a macro which behaves differently in different context then you can use TeX group, then define this macro, then use it and finaly close the TeX group. For example:

\def\items #1{\begingroup
   \let\itemP=\item
   \def\item{\itemP{#1}}%
}
\def\enditems{\par\endgroup}


\items {$\bullet$}
\item First
\item second
\enditems

\items {--}
\item one
\item two
\enditems

\items {$\sim$}
\item A
\item B
\enditems

\item * Normal
\item * plain \TeX
\item * item

\bye

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