Hi Joel, Your MWE fails to compile for me because \datatypeA is not defined.
On 24 Sep 2024, at 00:19, Joel via ntg-context
wrote: I have some code like this--it is a very reduced minimum-working example, from 10,000+ lines of code:
fileA.tex------------------------------
\datatypeA{fish}{an animal that lives in the sea} \datatypeA{bear}{a big animal with claws and fur} \datatypeA{squid}{a sea creature with many legs}
fileB.tex------------------------------
\datatypeB{fish}{an animal that lives in the sea} \datatypeB{bear}{a big animal with claws and fur} \datatypeB{squid}{a sea creature with many legs}
main.tex------------------------------
\datatypeA[2]{\startitemize \item #1 #2 \stopitemize} \datatypeA[B]{#1 -- #2}
Did you mean to \def or \define \datatypeA and \datatypeB here?
\define[8]\activity{ \subject{#1} #2 \startitemize \item #3 \item #4 \item #5 \item #6 \item #7 \stopitemize #8 }
\define[2]\balloongame{ \activity{Balloon Toss Game}{Instructions}{scissors}{plates}{construction paper}{#1}{#2}{\input fileA} } \define[2]\fishinggame{ \activity{Fun Fishing Game}{Instructions}{scissors}{plates}{construction paper}{#1}{#2}{\input fileB} }
\starttext
\balloongame{balloons}{tape} \fishinggame{crayons}{glue}
\stoptext
Basically, I have different classroom activities, defined as macros. \balloongame gives all details to the teacher about a "Balloon Toss Game" and \fishinggame defines a "Fun Fishing Game". (code has been reduced and simplified significantly).
The main issue I have is I have data being stored in filesA.tex, fileB.tex, etc. (there are often a dozen such files). Note that strangly the datasets are all identical, but a different file is called, and the only difference in the dataset is they call different macros. So "Balloon Game" pulls the list, but displays them in datatypeA format, the other game takes the same data, but its in a different file, and since the macros are different, it displays the information differently.
Basically, I have tons of data files sharing basically the same information, but each one defined inside the file as using a different macro, according to how the information is to be displayed (maybe sometimes as a list, sometimes in a table, etc.)
This method seems horribly inefficient. I should be able to store that data in one file, but display the data in different ways. The problem is if I use one format, like this...
\datatype{fish}{an animal that lives in the sea} \datatype{bear}{a big animal with claws and fur} \datatype{squid}{a sea creature with many legs}
...how do I get that dataset to be included, but displayed in a different format each time?
There is a facility called a dataset which allows you to store key-value pairs. Use \definedataset to create one: \definedataset [animals] [ ] then in your data file populate it using: \setdataset [animals] [fish] [desc={an animal that lives in the sea}] \setdataset [animals] [bear] [desc={a big animal with claws and fur}] \setdataset [animals] [squid] [desc={a sea creature with many legs}] To retrieve a single value you use: \datasetvariable {animals} {fish} {desc} If you want to be able to retrieve the name of the animal and do something with it then populate the dataset using an anonymous table instead: \setdataset [animals] [name=fish,desc={an animal that lives in the sea}] \setdataset [animals] [name=bear,desc={a big animal with claws and fur}] \setdataset [animals] [name=squid,desc={a sea creature with many legs}] And retrieve using: The first animal I saw was a \datasetvariable{animals}{1}{name} which is \datasetvariable{animals}{1}{desc}. The second animal I saw was a \datasetvariable{animals}{2}{name} which is \datasetvariable{animals}{2}{desc}. etc To mimic the \input{fileA} behaviour where you get the whole file included at that point, you can use \processdataset to iterate through the whole set. Unfortunately, it's not very well documented in the Wiki. You need to use a setup to do the formatting, so something like: \startsetups[formatA] \startitemize \item \datasetentry{name} \datasetentry{desc} \stopitemize \stopsetups \processdataset[animals][formatA] Even this might not be right because it does the \startitemize ... \stopitemize once per database entry. You probably only want that done once for all the rows in fileA. If you can fix the MWE then we can probably help more. Lastly, and at the risk of confusing you further, Context has the ability to process XML data and it may make more sense for you to create the main datafile as XML.
My thinking is perhaps constantly redefine the macro \datatype, but that seems still inefficient and prone to lead to errors in the code. Is that the best solution?
Any suggestion for the most proper way to go about displaying the information from this file, but in different ways in the document?
NOTE: My event code already uses 8 of the #1 #2 variables, so there's not really room to include that information there.
--Joel
— Bruce Horrocks Hampshire, UK