1

This is quite related to expl3: Is it possible to have a property list (l3prop) as value in a property list?

Instead I want to have something like

\pushmetadata{author}{author1}
\pushmetadata{author}{author2}
\pushmetadata{title}{title1}
\pushmetadata{title}{title2}
...

and

\getmetadata{author}{1}

to get back the value in the sequence.

And meanwhile a way iterating/getting some sequence.

1

It is possible to put seq in prop, but due to the nature of expl3 containers, if one takes the sequence out from the property list and modify it, the changes will not reflect on the original sequence stored in the property list. It is still possible, however, to overwrite the entire sequence in the property list with an updated version. But one can imagine that there is huge overhead.

A clever design is to use command names as a "property list", where LaTeX does the key-val association for you. An example is shown below:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{expl3}

\begin{document}

\ExplSyntaxOn

\cs_set:Npn \__get_seq_name:n #1 {
  g__meta_#1_seq
}

\newcommand{\pushmetadata}[2]{
  \seq_if_exist:cF {\__get_seq_name:n {#1}} {
    \seq_new:c {\__get_seq_name:n {#1}}   
  }
  \seq_gput_right:cn {\__get_seq_name:n {#1}} {#2}
}

\newcommand{\getmetadata}[2]{
  \seq_item:cn {\__get_seq_name:n {#1}} {#2}
}

\ExplSyntaxOff

\pushmetadata{author}{John Doe}
\pushmetadata{author}{Doe Jane}
\pushmetadata{title}{title1}
\pushmetadata{title}{title2}

\par\getmetadata{author}{1}
\par\getmetadata{author}{2}
\par\getmetadata{title}{1}
\par\getmetadata{title}{2}

\end{document}
1
  • It is clever! Thank you. – jiewuza Oct 31 '20 at 2:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.