class_docstr: Base class for implementing magic functions.
  
  Shell functions which can be reached as %function_name. All magic
  functions should accept a string, which they can parse for their own
  needs. This can make some functions easier to type, eg `%cd ../`
  vs. `%cd("../")`
  
  Classes providing magic functions need to subclass this class, and they
  MUST:
  
  - Use the method decorators `@line_magic` and `@cell_magic` to decorate
    individual methods as magic functions, AND
  
  - Use the class decorator `@magics_class` to ensure that the magic
    methods are properly registered at the instance level upon instance
    initialization.
  
  See :mod:`magic_functions` for examples of actual implementation classes.
class_docstr_tok: ["Base","class","for","implementing","magic","functions",".","Shell","functions","which","can","be","reached","as","%","function_name",".","All","magic","functions","should","accept","a","string",",","which","they","can","parse","for","their","own","needs",".","This","can","make","some","functions","easier","to","type",",","eg","`","%","cd","..","\/","`","vs.","`","%","cd","(","``","..","\/","''",")","`","Classes","providing","magic","functions","need","to","subclass","this","class",",","and","they","MUST",":","-","Use","the","method","decorators","`","@","line_magic","`","and","`","@","cell_magic","`","to","decorate","individual","methods","as","magic","functions",",","AND","-","Use","the","class","decorator","`","@","magics_class","`","to","ensure","that","the","magic","methods","are","properly","registered","at","the","instance","level","upon","instance","initialization",".","See",":","mod",":","`","magic_functions","`","for","examples","of","actual","implementation","classes","."]
docstr: Format a string for latex inclusion.
docstr_tok: ["Format","a","string","for","latex","inclusion","."]
code: def format_latex(self, strng):
      """Format a string for latex inclusion."""
  
      # Characters that need to be escaped for latex:
      escape_re = re.compile(r"(%|_|\$|#|&)", re.MULTILINE)
      # Magic command names as headers:
      cmd_name_re = re.compile(r"^(%s.*?):" % ESC_MAGIC, re.MULTILINE)
      # Magic commands
      cmd_re = re.compile(
          r"(?P<cmd>%s.+?\b)(?!\}\}:)" % ESC_MAGIC, re.MULTILINE
      )
      # Paragraph continue
      par_re = re.compile(r"\\$", re.MULTILINE)
  
      # The "\n" symbol
      newline_re = re.compile(r"\\n")
  
      # Now build the string for output:
      # strng = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',strng)
      strng = cmd_name_re.sub(
          r"\n\\bigskip\n\\texttt{\\textbf{ \1}}:", strng
      )
      strng = cmd_re.sub(r"\\texttt{\g<cmd>}", strng)
      strng = par_re.sub(r"\\\\", strng)
      strng = escape_re.sub(r"\\\1", strng)
      strng = newline_re.sub(r"\\textbackslash{}n", strng)
      return strng
  
imports: import os
  import re
  import sys
  from getopt import getopt, GetoptError
  from traitlets.config.configurable import Configurable
  from .None import oinspect
  from .error import UsageError
  from .inputtransformer2 import ESC_MAGIC, ESC_MAGIC2
  from ..utils.ipstruct import Struct
  from ..utils.process import arg_split
  from ..utils.text import dedent
  from traitlets import Bool, Dict, Instance, observe
  from logging import error
label_desc: Use image node_id 3 for calling the Magics obj's underlying member method code with example usage: obj.format_latex(strng) and returns: strng