Generalcustom macros

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
gabrielz
Posts: 1
Joined: Sun Jun 28, 2009 4:37 pm

custom macros

Post by gabrielz »

Hi,
I'm new to the forum and I hope I'm posting it in the right place.
I'm looking for a way to define a general command that will generate other macros. For example create a command called
"\newAnimal" that receives 2 arguments name and description and for the following input "\newAnimal{CAT}{9 souls animal}" generates the following macros \animalCAT which writes "CAT" in blue and \descriptionCAT writes "9 souls animal"

Thanks
Gaby

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

custom macros

Post by phi »

That's possible with \csname. The etoolbox package provides a simple wrapper for some of these tasks:

Code: Select all

\usepackage{etoolbox}
\newrobustcmd*{\newAnimal}[2]{%
  \csdef{animal#1}{\textcolor{blue}{#1}}%
  \csdef{description#1}{#2}%
}
Post Reply