> David: When parsing C code, how do you treat #define lines, and the
> words they define? They are also user-defined "macros".
In LaTeX (and some in TeX)...
\input{file} (where "file" may or may not have an extension)
\include{file} (again)
\usepackage{file} (again)
\input file (with no curly braces)
and a few other obscure examples.
> TeX people: How do you define a macro?
Very difficult question to answer... In all of the following, note that
line breaks are treated like any other whitespace.
In TeX:
\def\macroname{macro definition}
where {macro definition} itself could be a macro... that is, curly
braces are not required for single macros...
\def\macroname\anothermacro
The trouble is that there are lots of other "\def"-like macros, like
\xdef. Additionally, there are lots of different things that can come
after \macroname. So a good start would be something like...
\def\macroname[^}]*{macro def}
and note that "macro def" could span many lines.
A more complicated one is \let...
\let\something\another
The macro \let is much like a "hard link". That is, it causes
"\something" to get set to whatever is currently in "\another". That
lets me change "\another" while retaining its old functionality in
"\something."
So if \let\something\another defines a "hard link" between \something
and \another, then \def\something{\another} or \def\something\another
provides a "symlink" (or something like it). In the \def case, if I
change \another, then the function of \something also changes.
Unfortunately, I'm leaving out lots of other interesting and often used
cases that make use of \expandafter and \csname. There's probably no way
to handle those well.
In LaTeX:
\newcommand\macroname{macro definition}
\newcommand\macroname[5]{for a macro with 5 arguments}
\newcommand\macroname[5][default]{for macro with 5 arguments where the
first is an optional argument that defaults to "default"}
You also have...
\newcommand*
\renewcommand
\renewcommand*
\providecommand
\providecommand*
which have the same syntax as the above.
Oh, and I'm leaving out...
\newenvironment{envname}{before stuff}{after stuff}
which acts just like \newcommand (with the optional arguments and
everything). In fact, internally it's two \newcommands that create
macros \envname and \endenvname. There is a \renewenvironment as well.
Having something that can comprehensively handle LaTeX is probably
shooting too far right now. Having something that just handles the basic
sectioning commands might be a more tractable task.
--TEd
--
Ted Pavlic <[email protected]>
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---