Skip to content

Register

yex.control.Register(array, index) #

Bases: yex.control.control.Unexpandable

A wrapper so we can pass out references to entries in a Array, and have them update the original values.

Source code in yex/control/register.py
19
20
21
def __init__(self, array, index):
    self.array = array
    self.index = array._check_index(index)

__call__(parser) #

Equivalent to set_from_parser(), if self.array.set_on_call is True; returns self.value if self.array.set_on_call is False.

Note that because the definition of self.value, this may have the side-effect of clearing the register if the array is Box.

Source code in yex/control/register.py
60
61
62
63
64
65
66
67
68
69
70
71
def __call__(self, parser: 'yex.parse.Parser'):
    r"""
    Equivalent to set_from_parser(), if self.array.set_on_call is
    True; returns self.value if self.array.set_on_call is False.

    Note that because the definition of self.value, this may have the
    side-effect of clearing the register if the array is Box.
    """
    if self.array.set_on_call:
        self.set_from_parser(parser)
    else:
        return self.value

get_the(parser) #

Returns the list of tokens to use when we're representing this register with \the (see p212ff of the TeΧbook).

It is acceptable to return a string; it will be converted to a list of the appropriate character tokens.

Source code in yex/control/register.py
73
74
75
76
77
78
79
80
81
def get_the(self, parser: 'yex.parse.Parser'):
    r"""
    Returns the list of tokens to use when we're representing
    this register with \the (see p212ff of the TeXbook).

    It is acceptable to return a string; it will be
    converted to a list of the appropriate character tokens.
    """
    return str(self.value)

set_from_parser(parser) #

Sets the value from the tokeniser "parser".

Source code in yex/control/register.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def set_from_parser(self, parser: 'yex.parse.Parser'):
    """
    Sets the value from the tokeniser "parser".
    """

    try:
        previous = self.value
    except KeyError:
        previous = None

    self.array.doc.remember_restore(self.identifier, previous)

    parser.eat_optional_char('=')

    self.array.set_from_parser(
            index = self.index,
            parser = parser,
            )