-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple macro syntax #52
Comments
Thinking about it more, it seems I want latex macro-like functionality, but with a semantic focus more than a typographical one. The macro expansion could be handled by any sort of filter, but having a predefined syntax in the spec means anyone writing such a filter would have a simple node in the AST, that is well defined, and standardized, with basic functionality like text replacement covered by the base syntax. I feel like this gives the end user incredible flexibility, which is hard to achieve in any markdown flavor. Additionally, it opens the space up to text-based syntax, that crucially is user-defined, and thus not English first. |
If you look at my motivating article "Beyond Markdown," you'll see that I envision this kind of extension through four basic constructions that are already in djot:
With these four things and filters, you have quite a lot of flexibility without any additional syntax. |
@lcnhb What do you want which you can't get with possibly nested spans and divs and filters?
were treated as equivalent to
but it is indistinguishable from a reference link followed by a span, so perhaps some separator character like
which could be extended to divs too:
An actual macro functionality where you can define macros in-text leads to clutter and a lot of (for humans) confusion between what is definitions and what is content, and since I use Pandoc/Markdown in preference to LaTeX to get away from not seeing the text for all the markup I advice strongly against such. What I do use is my own string templating (pre)processor (which I will put online as soon as I have got some decent documentation written) which takes a hint from lightweight markup languages in preferring punctuation to keywords and is vaguely similar to Bash parameter expansion, e.g.:
Now the difference between the template processor and a macro processor is of course that with the former variables and functions are defined outside the template file by a script which imports the template engine class and passes the functions to the constructor as a data structure of function references written in the same language as the template engine. Variables are passed as a data structure of strings/numbers/booleans to the template expansion method and/or the constructor. Templates can be passed to the expansion method either as strings or as pre-parsed objects, allowing the calling program to parse a template once and fill it in several times with different data sets. The templating engine is separate from Pandoc; it can be used for any text to be further processed with any program, but since it is written in pure MoonScript/Lua it can also be used from inside a Pandoc filter, typically defining templates as verbatim spans or blocks, either in the body or the metadata, which after expansion are passed to the Pandoc Lua API's |
Jumping off what was said here, it seems that the bare {foo} attribute syntax could be a simple way for an in markdown macro definition! Just like reference links the foo would just be a label for whatever was defined in the label definition
{foo}: bar
One could even imagine going further and having label functions ie macros, used like {foo(arg1,arg2)}
And then defined as
{foo(arg1,arg2)}: do something with (arg1) and (arg2)
The only thing is that this would be very useful in the math context but of course clashes with latex syntax..
The text was updated successfully, but these errors were encountered: