Shortcuts

Utilities

Tokens

class TexSoup.utils.TokenWithPosition[source]

Enhanced string object with knowledge of global position.

lstrip(*args, **kwargs)[source]

Strip leading whitespace for text.

>>> t = TokenWithPosition('  asdf  ', 2)
>>> t.lstrip()
'asdf  '
rstrip(*args, **kwargs)[source]

Strip trailing whitespace for text.

>>> t = TokenWithPosition('  asdf  ', 2)
>>> t.rstrip()
'  asdf'
class TexSoup.utils.CharToLineOffset(src)[source]

Utility to convert absolute position in the source file to line_no:char_no_in_line. This can be very useful if we want to parse LaTeX and navigate to some elements in the generated DVI/PDF via SyncTeX.

>>> clo = CharToLineOffset('''hello
... world
... I scream for ice cream!''')
>>> clo(3)
(0, 3)
>>> clo(6)
(1, 0)
>>> clo(12)
(2, 0)