First, what is the proper terminology for a "string" in TeX/LaTeX that is an argument for a macro? e.g., \macro{somestring} Obviously somestring is a token, set of tokens, string, argument, etc. I will call it a string since I do not know what else to call it. I'm not thinking it is another macro but sort of "inert" text.
What I want to be able to do is parse a string that represents macros in LaTeX but codified in a very simple way:
The best way to describe it is to give an example
The follow string
x4y3[cgreen, t4[-3,4,a90]]
represents setting properties
x-position = 4
y-position = 3
color = greentest = 4 with x offset -3, y offset 4 and angle 90
[ ]= optional (optional list of optional specifiers in no particular order)
It should be VERY self explanatory how I went from the condensed string to the properties it represents. If not stare at the string for a few hours. You should be able to read the string and tell exactly what it means after knowing what the indicator symbols are. (this is no different than what xparse does with it's specification string except mine is a little more complex)
Now the hard part, I want to be able to parse that string into a series of macros that set data.
As you can probably guess it, the string represents something to do with placing a graphic at a location.
If you want to have some interpretation for
x4y3[cgreen, t4[-3,4,a90]]
to make you feel better: Place a green circle at coordinates(4,3) with a piece of text "4" offset (-3,4) from it and rotated 90 degrees.
To do this cleanly and efficiently I would like to create macros that are called for each corresponding macro in the string
\def\x#1{}
\def\y#1{}
\def\c#1{}
\def\t#1#2{}
So we could see the string as simply calling \x{-3}\y{4}\c{green}\t{4}{-3,4,a90}
So as you can see the string is just a "condensed" version of a macro. The string simply is a command value pair with possible optional arguments.
One could almost simply go in and add \'s and brackets to get the command.
For example,
pseudo-code:
parse_string{
foreach token in command-list
write '\'token'{'next_token'}'
}
But I would like to add commands/macros that have more than one character (the smallest token size would take precedence) AND do other things like default values.
Anyways, as usual this is relatively straightforward in most procedural programming languages but I'm sure I'll spend the next few weeks trying to figure out how to do it in TeX/LaTeX and then 10k lines of code later I'll probably end up with a buggy as hell version.
It should be VERY self explanatory.,If you want to have some interpretation for x4y3[cgreen, t4[-3,4,a90]] to make you feel better:etc. Do you really need such a tone? – percusse Mar 16 '12 at 20:59\mymacro{x2y3[...]}that gets recognized by your program, and appends its correct interpretation in some environment, like\begin{myenv}...\end{myenv}. As well, you have to remove allmyenvfrom previous run of your C# program. In LaTeX, you can put\def\mymacro#1{}so that the orinigal snippet gets ignored and\newenvironment{myenv}{}{}so that themyenvcontents get processed. This is how I would do it myself, just in C++ instead of C#. – yo' Mar 16 '12 at 21:49\mymacro{...}in your C# program. An I really don't understand what you want. You want to parse some code but you don't want a parser? – yo' Mar 16 '12 at 22:21pgfmathpackage of PGF/TikZ which actually adds this. – Martin Scharrer Mar 21 '12 at 12:54