🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.text
Article #419

LaTeX: defining macros with optional arguments?

#419
From: Brandon S. Allbery
Date: Fri, 28 Jul 1989 02:04
52 lines
2746 bytes
Here I go, delving into something I should probably keep out of...

I want to reimplement my troff indexing scheme in LaTeX, now that I have it up
and running (and found a copy of the manual).  (This is the same one I offered
to others; I'll post the troff version soon, since I've received a few
requests for it.  I should note that some parts of it look a bit weird because
troff is broken on this system; it should work on other systems, however.)

(BTW, I'm curious as to why LaTeX doesn't have a multilevel-index mechanism
already.  It seems common enough in many technical books I've seen.)

The troff macros look like:

	.sX primary-head [secondary-head [-]]

which inserts an index entry for "primary-head, secondary-head" and, if the
secondary-head is non-null, inserts a "see" entry for "secondary-head
primary-head" unless the third argument is blank.

Under LaTeX, I see this happening as follows:

	\tag{primary}[secondary]	-- insert index entries
	\tag*{primary}[secondary]	-- insert main index entry
						but suppress "see" entry

I would like these to output the tags in "secondary primary" form into the
text body as well, unless another optional (first) argument is provided; in
that case, output the first argument instead:

	\tag[printedform]{primary}[secondary]
					-- insert index entries and print
						"printedform" in text body

	\tag*[printedform]{primary}[secondary]
					-- as above, but suppress "see" entry

My main problem is that I can't quite get a handle on what magic incantations
one uses to trap * and optional arguments in LaTeX macros.  The manual doesn't
go in-depth on hacking LaTeX, and I haven't been able to figure out what the
stuff in latex.tex is doing.  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?

(I'll probably post the result of this when I'm done, since someone out there
might be able to find a use for hierarchical indexes.)

Thanks in advance,
++Brandon
  Brandon S. Allbery @ telotech, inc.   (I do not speak for telotech.  Ever.)
*This article may only be redistributed if all articles listed in the header's*
*  References: field, and all articles listing this one in their References:  *
*		       fields, are also redistributed.			      *
Technical Details
Message-ID: <1989Jul28.020403.15263@telotech.uucp>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cwjcc!hal!ncoast!telotech!bsa

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cwjcc!hal!ncoast!telotech!bsa
From: bsa@telotech.uucp (Brandon S. Allbery)
Newsgroups: comp.text
Subject: LaTeX: defining macros with optional arguments?
Message-ID: <1989Jul28.020403.15263@telotech.uucp>
Date: 28 Jul 89 02:04:03 GMT
Followup-To: poster
Distribution: na
Organization: Telotech, Inc.
Lines: 52