\section{Finding {\TeX} definitions}
<<*>>=
procedure rcsinfo () 
  return "$Id: texdefs.nw,v 1.18 2008/10/06 01:03:05 nr Exp nr $" ||
         "$Name: v2_12 $"
end
procedure main(args)
  go()
end
<<*>>=
procedure postpass(name, arg)
  static kind, idchars, definers, newcommand
  initial { kind := "bogus"; idchars := &letters ++ '@' 
            definers := ["def", "newdimen", "newif", "newcount", "newwrite", 
                         "newbox", "global\\def", "long\\def", "gdef" ]
            newcommand := ["newcommand", "renewcommand"]
          }
  case name of {
    "begin" : arg ? kind := tab(upto(' ')|0)
    "text" : if kind == "code" then arg ? {
        if =("\\" || !definers || "\\") then 
            writedefn("\\" || (tab(many(idchars)) | move(1)))
        else if =("\\" || !newcommand || "{") then 
            writedefn(tab(upto('}')))
       }
  }
  return
end

procedure prepass(name, arg)
  if name == "end" then writedefn(&null) # force newline
end
