Path: utzoo!attcan!utgpu!watmath!iuvax!uxc.cso.uiuc.edu!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.text Subject: Re: LaTeX: defining macros with optional arguments? Message-ID: <18799@mimsy.UUCP> Date: 28 Jul 89 14:12:57 GMT References: <1989Jul28.020403.15263@telotech.uucp> Reply-To: chris@mimsy.umd.edu.UUCP (Chris Torek) Distribution: na Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 43 In article <1989Jul28.020403.15263@telotech.uucp> bsa@telotech.uucp (Brandon S. Allbery) writes: >... I can't quite get a handle on what magic incantations one uses to >trap * and optional arguments in LaTeX macros. Stars are found with \@ifstar, and optional arguments with \@ifnextchar[; some documentation for these can be found near line 1500 of latex.tex. Essentially, one defines \foo as \def\foo{\@ifstar{\@starredfoo}{\@regularfoo}} for starred things, and \def\bar{\@ifnextchar[{\@bar}{@bar[defaultarg]} for things that have optional arguments with defaults. >The manual doesn't go in-depth on hacking LaTeX, latex.tex is actually more informative than {\em The \LaTeX book}. >Can someone explain to me (in words of one syllable or less ;-) how one >goes about processing *-commands and optional arguments in home-grown >LaTeX macros? Only a little of TeX can be explained this way :-) . However, it is worth noting here that in raw TeX, one can get funny characters into macros in two ways: either set the \catcode of the characters to 11 (`letter'), or use something like \expandafter\def\csname w&e*i+r-d\endcsname{foo} \csname ...\endcsname turns `...' into a control sequence regardless of what is in the `...'. The \expandafter makes TeX `pick up' the \def, hold on to it, read the next token (\csname), expand it (gobbling up the ...\endcsname), and then act on the \def. \expandafter can be very strange; see {\em The \TeX book}, in particular Appendix D. LaTeX has some internal macros to `sanitise' these \csname tricks (\@namedef, \@nameuse). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris