Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tut.cis.ohio-state.edu!ucbvax!TRIUMFCL.BITNET!ASND From: ASND@TRIUMFCL.BITNET (Donald Arseneau) Newsgroups: comp.text.tex Subject: "Indirect" definitions in TeX Message-ID: <3ABAC1810600429C@Post-Office.UH.EDU> Date: 9 Mar 91 07:52:00 GMT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 34 Malcolm Beattie writes: > I would like to be able to do something like: > ... > \define\makemark#1{\define\label#1{\the\chap.\the\sect}} > ... > \makemark{fred} % Here, e.g. \chap = 6 and \sect = 7 > ... > Of course, this doesn't work because the #1 in \define\label#1 > doesn't get replaced by \makemark's first parameter, but instead > gets interpreted as a new local parameter for \label itself. Actually, it gets interpreted as part of the SYNTAX for \label; \makemark{fred} redefines \label as if you typed \define\label fred{... when what you want is \define\labelfred. This happens because the command name is tokenized when it is first read in, not when #1 gets processed. The soultion is to use \csname to create the right commandname; but take care not to redefine \csname itself! : \define\makemark#1{\expandafter\define\csname label#1\endcsname{... I left out the definition because I suspect that what Malcolm tried won't work as expected. We need to expand \the\chap.\the\sect when \makemark is performed, not when the \labelfred is used. I don't really know what \define in AMS-TeX does; maybe it is equivalent to TeX's \edef, which is what we really want! but I suspect it does a normal \def, which would cause \labelfred to always report the current section, not the correct cross reference. Thus, I would use: \def\makemark#1{\expandafter\edef\csname label#1\endcsname{\the\chap.\the\sect}} Donald Arseneau asnd@triumfcl.bitnet