xaml-math
xaml-math copied to clipboard
Refactor C#-defined command system
For now, when defining a command in C# code, I need to add it to two places:
-
TexFormulaParser.commands
hash set. -
TexFormulaParser.ProcessCommand
method.
It looks like a lot of duplication comes from this, and also this system is not user-extendable.
What I imagine is the following:
- We need to declare one command dictionary, no name duplication should ever be used.
- Create a
TexCommand
class and allow the implementation to deal with parsed arguments etc. - Add an external
RegisterCommand
API for our users to define their own commands in C#.
We could create a Command delegate that returns an Atom, store the namesof supported commands and their methods in a dictionary and invoke the command in the "ProcessCommand" method. However, if we want users to create their own commands, use the atoms we create and manipulate other aspects of the library, we have to make them go public.
Well, yep, you're right about the public Atoms, I haven't thought about that yet. That'll be little stressful, I'll need to think more. I don't wanna to publicize all our internal stuff, because that means that any changes to that stuff will be API-breaking.
@Polina7 let's begin with simpler commands: everything except \left
, \right
, and \color*
.