2

I tried to emulate someting like a matrix with the Latex3 "objects". It seems like I can nest prop "objects" into a tl "object" -- at least it does not throw an error.

However, I have no idea how I can access them again.

\ExplSyntaxOn

\tl_new:N \l_my_array_tl
\prop_new:N \l_my_dict_prop
\prop_new:N \l_my_dict_two_prop

% define a prop "object"
\prop_set_from_keyval:Nn \l_my_dict_prop {val1=some~value, val2=another~value, val3=a~third~value}

% put prop "objects" into the tl "object"
\tl_put_right:NV \l_my_array_tl \l_my_dict_prop
\tl_put_right:NV \l_my_array_tl \l_my_dict_prop

% now i am lost. How can I access the prop "object" from the tl "object"
% is this even possible? I'd like to save \tl_item:N \l_my_array_tl in \l_my_dict_two_prop

\ExplSyntaxOff

Is there a way of achieving such a matrix emulation?

2
  • 1
    you shouldn't "unpack" a prop with V. You get the inner structure inside the \tl-var and that is not usable for you. V should only be used with variables with simple values inside. Commented Feb 9 at 14:20
  • There is the starray package. Also this question
    – mbert
    Commented Feb 9 at 14:23

1 Answer 1

3

The fact that you get no error is irrelevant.

Apart from registers, TeX only knows how to store material in macros and \l_my_dict_prop is a macro, as is \l_myarray_tl.

If you add \tl_show:N \l_myarray_tl after the first \tl_put_right:NV instruction, you see

\l_my_array_tl=\s__prop \__prop_pair:wn val1\s__prop {some
value}\__prop_pair:wn val2\s__prop {another value}\__prop_pair:wn val3\s__prop
{a third value}.

which is essentially the same as the \l_my_dict_prop is defined.

Property lists are macros with a very specific structure: first \s__prop announces what the macro contains (this will be used, for instance, to raise errors if something is used improperly); then comes the data in the form

\__prop_pair:wn <key>\s__prop{value}

But no programmer (except the team) should ever rely on this particular format which might change in the future.

If you dump the contents of some boxes in the basement, you can't hope to recover the boxes later.

Depending on your needs, you might get away with a single property list, so long as you use keys in a suitable way to represent the various parts, which basically is the idea of the starray package.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .