• Docs >
  • Categorizing Mechanics
Shortcuts

Categorizing Mechanics

Categorize all characters into one of category codes.

Categorizer

TexSoup.category.categorize(text)[source]

Generator for category code tokens on text, ignoring comments.

Parameters:text (Union[str,iterator,Buffer]) – LaTeX to process
>>> chars = list(categorize(r'\bf{}%[ello+😂'))
>>> chars[0].category
<CategoryCodes.Escape: 1>
>>> chars[1].category
<CategoryCodes.Letter: 12>
>>> chars[3].category
<CategoryCodes.GroupBegin: 2>
>>> chars[4].category
<CategoryCodes.GroupEnd: 3>
>>> chars[5].category
<CategoryCodes.Comment: 15>
>>> chars[6].category
<CategoryCodes.BracketBegin: 19>
>>> chars[-2].category
<CategoryCodes.Other: 13>
>>> chars[-1].category
<CategoryCodes.Other: 13>
>>> print(*chars)
\ b f { } % [ e l l o + 😂
>>> next(categorize(r'''
... ''')).category
<CategoryCodes.EndOfLine: 6>