Difference between revisions of "Command/setdataset"

From Wiki
Jump to navigation Jump to search
(better stuff)
m (No more foo/bar examples.)
Line 26: Line 26:
 
== Description ==  
 
== Description ==  
  
This command is used to store key-value tables in a table previously defined with {{cmd|definedataset}}. The first argument is the data set name, the last argument is a list of key-value pairs of data that should be saved. By default the first table is saved at
+
This command is used to store key-value tables in a table previously defined with {{cmd|definedataset}}. The first argument is the data set name, the last argument is a list of key-value pairs of data that should be saved.  
A middle argument is optional. If provided, it provides the name (or numerical index) at which the key-value table is stored in the dataset; if omitted, the first anonymous table is stored at index 1, the next at index 2, and so on.
+
 
 +
A middle argument is optional. If provided, it specifies the name (or numerical index) at which the key-value table is stored in the dataset; if it is omitted, the first anonymous table is stored at index 1, the next at index 2, and so on.
  
 
== Usage ==
 
== Usage ==
Line 34: Line 35:
 
\definedataset[somedataset]
 
\definedataset[somedataset]
  
% Store a table at point 1
+
% Store an anonymous table. It will be stored at point 1.
\setdataset[somedataset][foo=first, bar=second]
+
\setdataset[somedataset][wantscake=yes, wantsdeath=no]
  
 
% Store a table by name
 
% Store a table by name
 
\setdataset[somedataset][catnames][cat1=Georgina, cat2=George]
 
\setdataset[somedataset][catnames][cat1=Georgina, cat2=George]
  
% Store an anonymous table at point 2
+
% The next anonymous table is stored at point 2.
 
\setdataset[somedataset][name=Hans Hagen]
 
\setdataset[somedataset][name=Hans Hagen]
 +
 +
% We can overwrite existing tables, even anonymous ones
 +
\setdataset[somedataset][1][wantscake=Yes please., wantsdeath=No thanks.]
  
 
% Retrieve a stored datum.
 
% Retrieve a stored datum.
This is the \datasetvariable{somedataset}{1}{foo} datum.
+
Do you want cake? \datasetvariable{somedataset}{1}{wantscake}.
% --> This is the first datum.
+
% --> Do you want cake? Yes please.
 
 
 
</texcode>
 
</texcode>
  
Line 54: Line 57:
 
* {{cmd|datasetvariable}}
 
* {{cmd|datasetvariable}}
 
* More detailed explanations and examples can be found in the Key-Value Assignments article, under the section [[System_Macros/Key_Value_Assignments#Multi-pass data|Multi-pass data]].
 
* More detailed explanations and examples can be found in the Key-Value Assignments article, under the section [[System_Macros/Key_Value_Assignments#Multi-pass data|Multi-pass data]].
 
  
 
== Help from ConTeXt-Mailinglist/Forum ==
 
== Help from ConTeXt-Mailinglist/Forum ==

Revision as of 21:27, 8 May 2012

\setdataset

Syntax

\setdataset[...][...][...,...=...,...]
[...] name
[...] name
[...,...=...,...]


Description

This command is used to store key-value tables in a table previously defined with \definedataset. The first argument is the data set name, the last argument is a list of key-value pairs of data that should be saved.

A middle argument is optional. If provided, it specifies the name (or numerical index) at which the key-value table is stored in the dataset; if it is omitted, the first anonymous table is stored at index 1, the next at index 2, and so on.

Usage

\definedataset[somedataset]

% Store an anonymous table. It will be stored at point 1.
\setdataset[somedataset][wantscake=yes, wantsdeath=no]

% Store a table by name
\setdataset[somedataset][catnames][cat1=Georgina, cat2=George]

% The next anonymous table is stored at point 2.
\setdataset[somedataset][name=Hans Hagen]

% We can overwrite existing tables, even anonymous ones
\setdataset[somedataset][1][wantscake=Yes please., wantsdeath=No thanks.]

% Retrieve a stored datum.
Do you want cake? \datasetvariable{somedataset}{1}{wantscake}.
% --> Do you want cake? Yes please.

See also

Help from ConTeXt-Mailinglist/Forum

All issues with: