E Core Modules

E.14 LaTeXML::Core::KeyVals

Key-Value Pairs in LaTeXML


Provides a parser and representation of keyval pairs LaTeXML::Core::KeyVals represents parameters handled by LaTeX’s keyval package. It extends LaTeXML::Common::Object.



Access the value associated with a given key. This is useful within constructors to access the value associated with $key in the argument $arg. Example usage in a copnstructor:

<foo attrib=’&GetKeyVal(#1,’key’)’>


Access the entire hash. Can be used in a constructor like: Can use in constructor: <foo %&GetKeyVals(#1)/>



keysets, options)); >>

Creates a new KeyVals object with the given parameters. All arguments are optional and the simples way of calling this method is my $keyvals = LaTeXML::Core::KeyVals->new().

prefix is the given prefix all key-value pairs operate in and defaults to 'KV'. If given, prefix should be a string.

keysets should be a list of keysets to find keys inside of. If given, it should either be reference to a list of strings or a comma-seperated string. This argument defaults to '_anonymous_'.

Furthermore, the KeyVals constructor accepts a variety of options that can be used to customize its behaviour. These are setAll, setInternals, skip, skipMissing, hookMissing, open, close, punct and assign.

setAll is a flag that, if set, ensures that keys will be set in all existing keysets, instad of only in the first one.

setInternals is a flag that, if set, ensures that certain ’xkeyval’ package internals are set during key digestion.

skip should be a list of keys to be skipped when digesting the keys of this object.

skipMissing allows one way of handling keys during key digestion that have not been explictilty declared using DefKey or related functionality. If set to undef or 0, an error is thrown upon trying to set such a key, if set to 1 they are ignored. Alternatively, this can be set to a key macro which is then extended to contain a comman-separated list of the undefined keys.

hookMissing allows to call a specific macro if a single key is unknown during key digestion.

The options open, close, punct and assign optionally contain the tokens used for the respective meanings.

KeyVals Accessors (intended for internal usage)

my $prefix = $keyvals->getPrefix()

Returns the Prefix property.

my @keysets = $keyvals->getKeySets()

Returns the KeySets property.

my $setall = $keyvals->getSetAll()

Returns the SetAll property.

my $setinternals = $keyvals->getSetInternals()

Returns the SetInternals property.

my @skip = $keyvals->getSkip()

Returns the Skip property.

my $skipmissing = $keyvals->getSkipMissing()

Returns the SkipMissing property.

my $hookmissing = $keyvals->getHookMissing()

Returns the HookMissing property.

my @tuples = $keyvals->getTuples()

Returns the Tuples property representing


Sets the tuples which should be a list of five-tuples (array references) representing the key-value pairs this KeyVals object is seeded with. See the getTuples function on details of the structure of this list. rebuild is called automatically to populate the other caches. Typically, the tuples is set by readFrom.

my @cachedpairs = $keyvals->getCachedPairs()

Returns the CachedPairs property.

my %cachedhash = $keyvals->getCachedHash()

Returns the CachedHash property.

my $open = $keyvals->getOpen()

Returns the Open property.

my $close = $keyvals->getClose()

Returns the Close property.

my $punct = $keyvals->getPunct()

Returns the Punct property.

my $assign = $keyvals->getAssign()

Returns the Assign property.

Resolution to KeySets

my @keysets = $keyvals->resolveKeyValFor($key)

Finds all KeyVal objects that should be used for interacting with the given key. May return undef if no matching keysets are found. Use the parameters keysets, setAll and skipMissing to customize the exact behaviour of this function.

my $canResolveKeyVal = $keyvals->canResolveKeyValFor($key)

Checks if this KeyVals object can resolve a KeyVal for key. Ignores setAll and skipMissing parameters.

my $keyval = $keyvals->getPrimaryKeyValOf($key, @keysets)

Gets a single KeyVal parameter to be used for interacting a a single key, given that it resolves to keysets. Always returns a single KeyVal object, even if no keysets are found.

Changing contained values

$keyvals->addValue($key, $value, $useDefault, $noRebuild)

Adds the given value for key at the end of the given list of values and rebuilds all internal caches. If the useDefault flag is set, the specific value is ignored, and the default is set instead.

If this function is called multiple times the noRebuild option should be given to prevent constant rebuilding and the rebuild function should be called manually called.

$keyvals->setValue($key, $value, $useDefault)

Sets the value of key to value, optionally using the default if useDefault is set. Note that if value is a reference to an array, the key is inserted multiple times. If value is undef, the values is deleted.


Rebuilds the internal caches of key-value mapping and list of pairs from from main list of tuples. If skip is given, all values for the given key are omitted, and the given key is deleted.

Parsing values from a gullet

$keyvals->readFrom($gullet, $until, %options)

Reads a set of KeyVals from gullet, up until the until token, and updates the state of this KeyVals object accordingly.

Furthermore, this methods supports several options.

When the silenceMissing option is set, missing keys will be completely ignored when reading keys, that is they do not get recorded into the KeyVals object and no warnings or errors will be thrown.


Reads a single keyword from gullet. Intended for internal use only.

KeyVals Accessors

my $value = $keyvals->getValue($key);

Return a value associated with $key.

@values = $keyvals->getValues($key);

Return the list of all values associated with $key.

%keyvals = $keyvals->getKeyVals;

Return the hash reference containing the keys and values bound in the $keyval. Each value in the hash may be a single value or a list if the key is repeated.

@keyvals = $keyvals->getPairs;

Return the alternating keys and values bound in the $keyval. Note that this may contain multiple entries for a given key, if they were repeated.

%hash = $keyvals->getHash;

Return the hash reference containing the keys and values bound in the $keyval. Note that will only contain the last value for a given key, if they were repeated.

$haskey = $keyvals->hasKey($key);

Checks if the KeyVals object contains a value for $key.

Value Related Reversion

$expansion = $keyvals->setKeysExpansion;

Expand this KeyVals into a set of tokens for digesting keys.

$keyvals = $keyvals->beDigested($stomach);

Return a new LaTeXML::Core::KeyVals object with both keys and values digested.

$reversion = $keyvals->revert();

Revert this object into a set of tokens representing the original sequence of Tokens that was used to be read it from the gullet.

$str = $keyvals->toString();

Turns this object into a key=value comma seperated string.