is an option for selections that specifies a list of strings to be associated with a selection.
TaggingRules
is an option for selections that specifies a list of strings to be associated with a selection.
Details
- TaggingRules provides a way of storing additional information with a selection, for example, to be used by other programs in processing a notebook. It can be set to a list of one or more strings.
- With the default setting TaggingRules<||>, no additional information is associated with the selection.
- Typically, structured metadata is broken up into pieces that can be identified using keys in the form "key"value. The key can then be individually queried using AbsoluteCurrentValue[obj,{TaggingRules,"key"}].
- Another typical method for storing highly structured data is to use subkeys inside of keys. For example, "key"<|"key1"data1,"key2"data2,…|>. The subkeys can then be queried using AbsoluteCurrentValue[obj,{TaggingRules,"key","subkey"}]. Subkeys can have their own subkeys to an arbitrary depth.
- TaggingRules can be set at the cell, notebook, and global level.
- TaggingRules<|key1val1,…|> effectively merges the keyi with any keys inherited from a more general scope. The fully merged set of keys and values can be read using AbsoluteCurrentValue. Specifying keys and values as a list instead of an association will cause inherited keys to be ignored.
Examples
open all close allBasic Examples (2)
Apply TaggingRules at the cell level:
Cell["XXXX", "Text", TaggingRules -> <|"taggingrule01" -> "value1", "taggingrule02" -> "value2"|>]Use nested rules as TaggingRules:
Cell["XXXX", "Text", TaggingRules -> <|"group01" -> <|"taggingrule01" -> "value1", "taggingrule02" -> "value2"|>|>]Reference specific TaggingRules values using CurrentValue:
ExpressionCell[Dynamic[CurrentValue[{TaggingRules, "values"}]], "Output", TaggingRules -> <|"values" -> <|"subvalues" -> "result"|>|>]Reference nested values directly by using subselectors in CurrentValue:
ExpressionCell[Dynamic[CurrentValue[{TaggingRules, "values", "subvalues"}]], "Output", TaggingRules -> <|"values" -> <|"subvalues" -> "result"|>|>]Scope (5)
Basic Uses (3)
Apply TaggingRules at the notebook level:
DocumentNotebook[{TextCell["ABCD"], TextCell["EFGH"]}, TaggingRules -> <|"taggingrule01" -> "value1", "taggingrule02" -> "value2"|>]Apply TaggingRules at the global level:
SetOptions[$FrontEndSession, TaggingRules -> <|"taggingrule01" -> "value1", "taggingrule02" -> "value2"|>]Restore TaggingRules to its default value:
SetOptions[$FrontEndSession, TaggingRules -> Inherited]If a tagging rule key does not exist, CurrentValue returns Inherited for its value:
CurrentValue[EvaluationCell[], {TaggingRules, "missing key"}]Inheritance (2)
TaggingRules{} clears all rules at the scope at which it is set:
Style[Style[Dynamic[AbsoluteCurrentValue[TaggingRules]], TaggingRules -> {}], TaggingRules -> {"rule" -> "value"}]TaggingRules specified as an Association will be merged with inherited rules:
Style[Style[Style[Dynamic[AbsoluteCurrentValue[TaggingRules]], TaggingRules -> <|"inner" -> "inner value"|>], TaggingRules -> <|"outer" -> "outer value"|>], TaggingRules -> {}]Specifying the inner value as a list will ignore inherited rules:
Style[Style[Style[Dynamic[AbsoluteCurrentValue[TaggingRules]], TaggingRules -> {"inner" -> "inner value"}], TaggingRules -> <|"outer" -> "outer value"|>], TaggingRules -> {}]Rules with the same name but differing values will be overwritten upon inheritance:
Style[Style[Style[Dynamic[AbsoluteCurrentValue[TaggingRules]], TaggingRules -> <|"key" -> "inner"|>, TaggingRules -> <|"key" -> "outer"|>]], TaggingRules -> {}]If the value is an Association, then the associations are instead merged:
Style[Style[Style[Dynamic[AbsoluteCurrentValue[TaggingRules]], TaggingRules -> <|"key" -> <|"subkey2" -> "inner"|>|>], TaggingRules -> <|"key" -> <|"subkey1" -> "outer"|>|>], TaggingRules -> {}]Applications (1)
TaggingRules can be used like a DynamicModule variable that spans cells:
CurrentValue[EvaluationNotebook[], {TaggingRules, "InputFieldState"}] = "initial string";InputField[Dynamic@CurrentValue[EvaluationNotebook[], {TaggingRules, "InputFieldState"}]]Dynamic[CurrentValue[EvaluationNotebook[], {TaggingRules, "InputFieldState"}]]Tech Notes
Related Guides
History
Introduced in 1999 (4.0) | Updated in 2021 (12.3)
Text
Wolfram Research (1999), TaggingRules, Wolfram Language function, https://reference.wolfram.com/language/ref/TaggingRules.html (updated 2021).
CMS
Wolfram Language. 1999. "TaggingRules." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/TaggingRules.html.
APA
Wolfram Language. (1999). TaggingRules. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TaggingRules.html
BibTeX
@misc{reference.wolfram_2026_taggingrules, author="Wolfram Research", title="{TaggingRules}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/TaggingRules.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_taggingrules, organization={Wolfram Research}, title={TaggingRules}, year={2021}, url={https://reference.wolfram.com/language/ref/TaggingRules.html}, note=[Accessed: 13-June-2026]}