# Proposal for new/old macro implementation

```Hi!

```
I was investigating the macro system for the last days to find a way to implement it in a cleaner way than it is at the moment. The main well known problems with the current approach:
```
```
1. Macro definitions are shared among all open document, i.e. one big global macro table 2. Macro instantiations have a fixed arity which must be known on creation 3. Macros which are not defined yet, will be turned into InsetMathUnknown and will stay like that, even if the macro is defined later 4. A buffer local macro table is not possible because the macro instantiation needs the arity. But the current buffer is not accessible everywhere where macros are instantiated.
```
```
I have worked out a prototype for a new macro implementation which goes along the lines which is still visible in some "#ifdef 0" code in MathData:
```
```
The idea is to make the macro rendering much more dynamic. An InsetMathMacro object should not require its arity on creation, only the macro name (it starts with arity 0 in fact). Every \foo command during parsing, where foo is not known, is converted into a InsetMathMacro("foo") (so not into InsetMathUnknown anymore). The following arguments become InsetMathBraces.
```
```
Now during drawing (or more precisely the metric call) of MathArray the current buffer is known (and with it the valid macro definition for that buffer). The MathArray compares the arity of the macro with the number of arguments inside the InsetMathMacro. If it differs, either following braces are moved into the InsetMathMacro (if the former is bigger), or arguments in the InsetMathMacro are converted into braces and removed from the InsetMathMacro (if the latter is bigger).
```
```
With this one can easily change macro arities, remove macros (then all arguments are converted into braces) and so on. Because the drawing process is the only place where macros must be looked up, it is also easy to put an independent macro table into every buffer (which falls back to the master document's macro table and then to the global one).
```
Schimmi

```

dynamicmacros.patch
Description: Binary data

PGP.sig
Description: Signierter Teil der Nachricht