code: def tokenize_math(text):
      r
      if text.startswith('$') and (
         text.position == 0 or text.peek(-1) != '\\' or text.endswith(r'\\')):
          starter = '$$' if text.startswith('$$') else '$'
          return TokenWithPosition(text.forward(len(starter)), text.position)
docs: r"""Prevents math from being tokenized.
  
      :param Buffer text: iterator over line, with current position
  
      >>> b = Buffer(r'$\min_x$ \command')
      >>> tokenize_math(b)
      '$'
      >>> b = Buffer(r'$$\min_x$$ \command')
      >>> tokenize_math(b)
      '$$'