# Generating a table from key-value pairs

I want to automatically generate a table from a comma separated list of key-value pairs such as {{x=1,y=2},{x=3,y=1},{x=2,y=3}}. In each "row" the "keys" are always the same (they become the column headers in the table), but the values can change. Given this particular list of key-value pairs the code below produces the following:

which is exactly what I want. Unfortunately marginally more complicated input for the values, such as {{x=1,y=$\overrightarrow{AB}$},{x=3,y=1},{x=2,y=3}}, breaks my code. My code does generate the expected output:

but before it does this I get compilation errors such as:


\end{document}


• Thanks jfbu. I am always impressed with the power of xinttools. I had tried to deal with the ='s like you have but couldn't get it to work. What does first defining \newcommand*\AndrewExtractKey {} and then \def\AndrewExtractKey #1#2=#3,{#1#2} do? – Andrew Mar 24 '16 at 23:09
• @Andrew the first \newcommand* is to check à la LaTeX whether the macro name is already in use, so at least we are warned we are trying to overwrite something. Then we switch to \def in order to use a delimited parameter text. By the way, both \AndrewExtractKey and \AndrewExtractValue should have been defined \long in order for the value part to be allowed to have an empty line or a \par. The thing with #1#2 is to get rid of initial spaces, this is a bit superfluous here in a tabular. – user4686 Mar 25 '16 at 7:03