Can i make a macro in a class file that take a string like argument and call a local macro? I want to make the following:


    { \ifthenelse
          {You have to define #1. Use this macro: \textbackslash#1}
\AtBeginDocument {\warning{somename}}

Then, if in the document file i didnt define \@somename i will have a warning saying that to me.

Any ideas?

  • \csname @#1\endcsname – Manuel Apr 20 '18 at 22:49
  • 2
    Welcome! Are we in a package or class file? What should the definition of the new macro be? Please provide a complete minimal working example (code for a small document) which shows us how you'd like to use these macros - how will \@date then be used, for example? – cfr Apr 20 '18 at 23:40
  • Why not using \makeatletter\newcommand{\warning}[1]{\@ifundefined{@#1}{Booo!!!}{Yay!!!}}\makeatother? That's what \@ifundefined is made for... – user31729 Apr 21 '18 at 5:07
  • Define/initialize \@somename as the warning and do the redefinition with \somename to have the real string instead of the former warning. – Johannes_B Apr 21 '18 at 6:30

The LaTeX kernel already provides this:

\makeatletter % not in a class or package file
    {You have to define '#1'. Use this macro: \texttt{\symbol{`\\}#1}}

\makeatother % not in a class or package file


Note that the first argument to \@ifundefined should be a string of characters representing the macro name (no initial backslash).


I would use the etoolbox pacakge:

enter image description here



        You have to define #1. Use the macro {\ttfamily\string\DefinePerson}.%

\DefinePerson{Steve Jobs}
\DefinePerson{Bill Gates}

    \Warning{Steve Jobs}%
    \Warning{Warren Buffet}%

Hi there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.