我遇到过一种情况,需要调用文档另一部分的数据,将其放在三列制表环境中。需要对数据进行排序,并删除重复项。
在整个文档的其余部分中,我一直在使用寄存器,但在这种情况下,数据需要以三列显示。
我相信此代码应该能够将定义的数据放入制表环境中,但它无法编译:
\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
如何在 ConTeXt 的制表环境中存储寄存器数据?
答案1
您可以使用 toks 寄存器来实现您想要的功能。我编写的宏也避免了重复的条目,就像寄存器一样。在这种情况下无法进行排序。
\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