Skip to content

yex.box.Leader

yex.box.Leader(glue=None, vertical=False, doc=None, name=None, ch=' ', **kwargs) #

Bases: yex.box.gismo.Gismo

Lines of dots across the middle of an index or whatever.

At present this is only a wrapper for Glue, so all leaders will be blank.

Attributes:

Name Type Description
glue Glue

the glue we're wrapping. If the constructor is given glue=None, we construct a new Glue using **kwargs and wrap that, instead. If it's str, we look up the param with the given name and use Glue of that length; in this case, you must also provide doc to the constructor.

vertical bool

True if this Leader is vertical, False (which is the default) if it's horizontal.

name str or None

the name to be displayed in showbox. If you leave this as None, no glue will be supplied; however, if name is None and glue is a str, name will be taken from that str.

length yex.box.rule.Dimen or None

the length of this box (which is the width if we're horizontal, and the height if we're vertical), overriding the glue. This is None unless we've been through wrapping.

Source code in yex/box/leader.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def __init__(self,
             glue: Union['yex.value.Glue', None] = None,
             vertical:bool = False,
             doc: 'yex.document.Document' = None,
             name: Union[str, None] =None,
             ch: str =' ',
             **kwargs,
             ):

    self.name = None
    self.length = None
    self.vertical = vertical
    self.ch = ch
    self._contents = []

    if glue is None:
        self.glue = yex.value.Glue(**kwargs)
    elif isinstance(glue, yex.value.Glue):
        self.glue = glue
    elif isinstance(glue, str):
        assert doc is not None

        self.glue = doc[glue]
        self.name = glue
    else:
        raise TypeError(glue)

    for name in [
            'space', 'stretch', 'shrink',
            ]:
        setattr(self, name, getattr(self.glue, name))

__getstate__() #

The value, in terms of simple types.

Usually
  • "ch": self.ch
  • "leader": self.glue
  • "vertical": self.vertical

However, if we're horizontal and self.ch is a single space:

since Leaders occur all over the place in the final output, where they're almost always finite with no stretch or shrink, we represent that as a special case: just the integer size of the space.

Otherwise, this is the same as the getstate() of the glue.

Source code in yex/box/leader.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def __getstate__(self):
    r"""
    The value, in terms of simple types.

    Usually:
        * "ch": self.ch
        * "leader": self.glue
        * "vertical": self.vertical

    However, if we're horizontal and self.ch is a single space:

    since Leaders occur all over the place in the final output,
    where they're almost always finite with no stretch or shrink,
    we represent that as a special case:
    just the integer size of the space.

    Otherwise, this is the same as the __getstate__() of the glue.
    """

    result = self.glue.__getstate__()

    if self.ch==' ' and not self.vertical:
        if len(result)==1:
            result = result[0]
    else:
        result = {
                'leader': result,
                'ch': self.ch,
                }

        if self.vertical:
            result['vertical'] = self.vertical

    return result