I'd like to create a command which is currently beyond my capabilities so I was wondering if anyone around here could help me out.
What I'm looking to do is define a new command similar to the following:
\cmd{reference001}{Title}{text A}{text B}{text C}
This command would then create a new command called \reference001
which would display:
However, I would also like the \cmd
command to define other new commands that will display only the parts of the input. E.g., it should generate a \reference001title
command that will display Title
and a \reference001partB
that will display text B
, etc.
Importantly, I'd really like to have numbers in my command name (which is possible as presented in this answer). I've put together what I've tried so far below, but I'm having trouble getting rid of all errors and particularly, with getting numbers to work as part of the command names.
To accomplish this, I've also looked at defining a custom label/ref system (via this question) which would be a perfectly valid solution for my purposes too. E.g., the \cmd
above would then create multiple labels which could be referenced as \ref{reference001}
, \ref{reference001partA}
, etc. However I couldn't get that to work either.
\documentclass{article}
\newcommand{\cmd}[5]{
\expandafter\newcommand\csname #1\endcsname{
\textbf{#2}
\textbf{\textit{Part A:}} #3
\textbf{\textit{Part B:}} #4
\textbf{\textit{Part C:}} #5
}
\expandafter\newcommand\csname #1title\endcsname{#2}
\expandafter\newcommand\csname #1partA\endcsname{#3}
\expandafter\newcommand\csname #1partB\endcsname{#4}
\expandafter\newcommand\csname #1partC\endcsname{#5}
}
\begin{document}
\cmd{reference}{Title}{text A}{text B}{text C}
\reference
\referencepartA
\referencepartB
\referencepartC
\end{document}
\newcommmand
is a typo\ref001
.\documentclass[12pt]{article} \usepackage{etoolbox} \begin{document} \csdef{ref001}{this is a test} \csuse{ref001} \end{document}
\newcommand
it is a restriction on the tex syntax with standard catcode.\reference123
is\reference
followed by the three tokens1
,2
,3
.