0

I have a situation where I need data to be called in another part of the document to be placed in a three-column tabulate environment. The data needs to be sorted, with duplicates removed.

Throughout the rest of the document, I've been using registers, but in this one situation, the data needs to be presented in three columns.

This code, I believe, should be able to put the data defined into the tabulate environment, but it won't compile:

\defineregister[animals][pagenumber=no, indicator=no, before=, n=1]

\def\defineanimal{\animals}

\defineanimal{\VL elephant \VL desert \VL Africa \VL\NR}
\defineanimal{\VL zebra \VL desert \VL Africa \VL\NR}
\defineanimal{\VL whale \VL ocean \VL none \VL\NR}

\starttext
    \starttabulate[l|l|l]
        \HL
        \VL animal \VL habitat \VL continent \VL\NR
        \HL
        \placeregister[animals]
        \HL
    \stoptabulate
\stoptext

How do I store register data inside a tabulate environment in ConTeXt?

1
  • This is not how you use a register. What problem are you actually trying to solve? Aug 26, 2018 at 21:51

1 Answer 1

6
+300

You can achieve what you want using a toks register. The macro I wrote also avoids duplicated entries, just like a register. Sorting is not possible in this case.

\newtoks\animallist

\define[1]\defineanimal{%
  \ifcsname animal_list_\detokenize{#1}\endcsname\else
    \setvalue{animal_list_\detokenize{#1}}{}%
    \appendtoks
      #1
    \to \animallist
  \fi
}

\defineanimal{\VL elephant \VL desert \VL Africa \VL\NR}
\defineanimal{\VL zebra \VL desert \VL Africa \VL\NR}
\defineanimal{\VL whale \VL ocean \VL none \VL\NR}
\defineanimal{\VL elephant \VL desert \VL Africa \VL\NR}

\starttext
    \starttabulate[l|l|l][distance=none]
        \HL
        \VL animal \VL habitat \VL continent \VL\NR
        \HL
        \the\animallist
        \HL
    \stoptabulate
\stoptext

enter image description here

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.