class_docstr: Format tokens as LaTeX code. This needs the `fancyvrb` and `color`
  standard packages.
  
  Without the `full` option, code is formatted as one ``Verbatim``
  environment, like this:
  
  .. sourcecode:: latex
  
      \begin{Verbatim}[commandchars=\\\{\}]
      \PY{k}{def }\PY{n+nf}{foo}(\PY{n}{bar}):
          \PY{k}{pass}
      \end{Verbatim}
  
  The special command used here (``\PY``) and all the other macros it needs
  are output by the `get_style_defs` method.
  
  With the `full` option, a complete LaTeX document is output, including
  the command definitions in the preamble.
  
  The `get_style_defs()` method of a `LatexFormatter` returns a string
  containing ``\def`` commands defining the macros needed inside the
  ``Verbatim`` environments.
  
  Additional options accepted:
  
  `style`
      The style to use, can be a string or a Style subclass (default:
      ``'default'``).
  
  `full`
      Tells the formatter to output a "full" document, i.e. a complete
      self-contained document (default: ``False``).
  
  `title`
      If `full` is true, the title that should be used to caption the
      document (default: ``''``).
  
  `docclass`
      If the `full` option is enabled, this is the document class to use
      (default: ``'article'``).
  
  `preamble`
      If the `full` option is enabled, this can be further preamble commands,
      e.g. ``\usepackage`` (default: ``''``).
  
  `linenos`
      If set to ``True``, output line numbers (default: ``False``).
  
  `linenostart`
      The line number for the first line (default: ``1``).
  
  `linenostep`
      If set to a number n > 1, only every nth line number is printed.
  
  `verboptions`
      Additional options given to the Verbatim environment (see the *fancyvrb*
      docs for possible values) (default: ``''``).
  
  `commandprefix`
      The LaTeX commands used to produce colored output are constructed
      using this prefix and some letters (default: ``'PY'``).
  
      .. versionadded:: 0.7
      .. versionchanged:: 0.10
         The default is now ``'PY'`` instead of ``'C'``.
  
  `texcomments`
      If set to ``True``, enables LaTeX comment lines.  That is, LaTex markup
      in comment tokens is not escaped so that LaTeX can render it (default:
      ``False``).
  
      .. versionadded:: 1.2
  
  `mathescape`
      If set to ``True``, enables LaTeX math mode escape in comments. That
      is, ``'$...$'`` inside a comment will trigger math mode (default:
      ``False``).
  
      .. versionadded:: 1.2
  
  `escapeinside`
      If set to a string of length 2, enables escaping to LaTeX. Text
      delimited by these 2 characters is read as LaTeX code and
      typeset accordingly. It has no effect in string literals. It has
      no effect in comments if `texcomments` or `mathescape` is
      set. (default: ``''``).
  
      .. versionadded:: 2.0
  
  `envname`
      Allows you to pick an alternative environment name replacing Verbatim.
      The alternate environment still has to support Verbatim's option syntax.
      (default: ``'Verbatim'``).
  
      .. versionadded:: 2.0
class_docstr_tok: ["Format","tokens","as","LaTeX","code",".","This","needs","the","`","fancyvrb","`","and","`","color","`","standard","packages",".","Without","the","`","full","`","option",",","code","is","formatted","as","one","``","Verbatim","``","environment",",","like","this",":","..","sourcecode",":",":","latex","\\begin","{","Verbatim","}","[","commandchars=\\\\\\","{","\\","}","]","\\PY","{","k","}","{","def","}","\\PY","{","n+nf","}","{","foo","}","(","\\PY","{","n","}","{","bar","}",")",":","\\PY","{","k","}","{","pass","}","\\end","{","Verbatim","}","The","special","command","used","here","(","``","\\PY","``",")","and","all","the","other","macros","it","needs","are","output","by","the","`","get_style_defs","`","method",".","With","the","`","full","`","option",",","a","complete","LaTeX","document","is","output",",","including","the","command","definitions","in","the","preamble",".","The","`","get_style_defs","(",")","`","method","of","a","`","LatexFormatter","`","returns","a","string","containing","``","\\def","``","commands","defining","the","macros","needed","inside","the","``","Verbatim","``","environments",".","Additional","options","accepted",":","`","style","`","The","style","to","use",",","can","be","a","string","or","a","Style","subclass","(","default",":","``","'default","'","``",")",".","`","full","`","Tells","the","formatter","to","output","a","``","full","''","document",",","i.e",".","a","complete","self-contained","document","(","default",":","``","False","``",")",".","`","title","`","If","`","full","`","is","true",",","the","title","that","should","be","used","to","caption","the","document","(","default",":","``","``","``",")",".","`","docclass","`","If","the","`","full","`","option","is","enabled",",","this","is","the","document","class","to","use","(","default",":","``","'article","'","``",")",".","`","preamble","`","If","the","`","full","`","option","is","enabled",",","this","can","be","further","preamble","commands",",","e.g",".","``","\\usepackage","``","(","default",":","``","``","``",")",".","`","linenos","`","If","set","to","``","True","``",",","output","line","numbers","(","default",":","``","False","``",")",".","`","linenostart","`","The","line","number","for","the","first","line","(","default",":","``","1","``",")",".","`","linenostep","`","If","set","to","a","number","n",">","1",",","only","every","nth","line","number","is","printed",".","`","verboptions","`","Additional","options","given","to","the","Verbatim","environment","(","see","the","*","fancyvrb","*","docs","for","possible","values",")","(","default",":","``","``","``",")",".","`","commandprefix","`","The","LaTeX","commands","used","to","produce","colored","output","are","constructed","using","this","prefix","and","some","letters","(","default",":","``","'PY","'","``",")",".","..","versionadded",":",":","0.7","..","versionchanged",":",":","0.10","The","default","is","now","``","'PY","'","``","instead","of","``","'","C","'","``",".","`","texcomments","`","If","set","to","``","True","``",",","enables","LaTeX","comment","lines",".","That","is",",","LaTex","markup","in","comment","tokens","is","not","escaped","so","that","LaTeX","can","render","it","(","default",":","``","False","``",")",".","..","versionadded",":",":","1.2","`","mathescape","`","If","set","to","``","True","``",",","enables","LaTeX","math","mode","escape","in","comments",".","That","is",",","``","'","$","...","$","'","``","inside","a","comment","will","trigger","math","mode","(","default",":","``","False","``",")",".","..","versionadded",":",":","1.2","`","escapeinside","`","If","set","to","a","string","of","length","2",",","enables","escaping","to","LaTeX",".","Text","delimited","by","these","2","characters","is","read","as","LaTeX","code","and","typeset","accordingly",".","It","has","no","effect","in","string","literals",".","It","has","no","effect","in","comments","if","`","texcomments","`","or","`","mathescape","`","is","set",".","(","default",":","``","``","``",")",".","..","versionadded",":",":","2.0","`","envname","`","Allows","you","to","pick","an","alternative","environment","name","replacing","Verbatim",".","The","alternate","environment","still","has","to","support","Verbatim","'s","option","syntax",".","(","default",":","``","'Verbatim","'","``",")",".","..","versionadded",":",":","2.0"]
code: def format_unencoded(self, tokensource, outfile):
      # TODO: add support for background colors
      t2n = self.ttype2name
      cp = self.commandprefix
  
      if self.full:
          realoutfile = outfile
          outfile = StringIO()
  
      outfile.write(
          "\\begin{" + self.envname + "}[commandchars=\\\\\\{\\}"
      )
      if self.linenos:
          start, step = self.linenostart, self.linenostep
          outfile.write(
              ",numbers=left"
              + (start and ",firstnumber=%d" % start or "")
              + (step and ",stepnumber=%d" % step or "")
          )
      if self.mathescape or self.texcomments or self.escapeinside:
          outfile.write(
              ",codes={\\catcode`\\$=3\\catcode`\\^=7\\catcode`\\_=8}"
          )
      if self.verboptions:
          outfile.write("," + self.verboptions)
      outfile.write("]\n")
  
      for ttype, value in tokensource:
          if ttype in Token.Comment:
              if self.texcomments:
                  # Try to guess comment starting lexeme and escape it ...
                  start = value[0:1]
                  for i in xrange(1, len(value)):
                      if start[0] != value[i]:
                          break
                      start += value[i]
  
                  value = value[len(start) :]
                  start = escape_tex(start, cp)
  
                  # ... but do not escape inside comment.
                  value = start + value
              elif self.mathescape:
                  # Only escape parts not inside a math environment.
                  parts = value.split("$")
                  in_math = False
                  for i, part in enumerate(parts):
                      if not in_math:
                          parts[i] = escape_tex(part, cp)
                      in_math = not in_math
                  value = "$".join(parts)
              elif self.escapeinside:
                  text = value
                  value = ""
                  while text:
                      a, sep1, text = text.partition(self.left)
                      if sep1:
                          b, sep2, text = text.partition(self.right)
                          if sep2:
                              value += escape_tex(a, cp) + b
                          else:
                              value += escape_tex(a + sep1 + b, cp)
                      else:
                          value += escape_tex(a, cp)
              else:
                  value = escape_tex(value, cp)
          elif ttype not in Token.Escape:
              value = escape_tex(value, cp)
          styles = []
          while ttype is not Token:
              try:
                  styles.append(t2n[ttype])
              except KeyError:
                  # not in current style
                  styles.append(_get_ttype_name(ttype))
              ttype = ttype.parent
          styleval = "+".join(reversed(styles))
          if styleval:
              spl = value.split("\n")
              for line in spl[:-1]:
                  if line:
                      outfile.write(
                          "\\%s{%s}{%s}" % (cp, styleval, line)
                      )
                  outfile.write("\n")
              if spl[-1]:
                  outfile.write(
                      "\\%s{%s}{%s}" % (cp, styleval, spl[-1])
                  )
          else:
              outfile.write(value)
  
      outfile.write("\\end{" + self.envname + "}\n")
  
      if self.full:
          encoding = self.encoding or "utf8"
          # map known existings encodings from LaTeX distribution
          encoding = {
              "utf_8": "utf8",
              "latin_1": "latin1",
              "iso_8859_1": "latin1",
          }.get(encoding.replace("-", "_"), encoding)
          realoutfile.write(
              DOC_TEMPLATE
              % dict(
                  docclass=self.docclass,
                  preamble=self.preamble,
                  title=self.title,
                  encoding=encoding,
                  styledefs=self.get_style_defs(),
                  code=outfile.getvalue(),
              )
          )
  
file_path: catboost/contrib/python/Pygments/py2/pygments/formatters/latex.py
imports: from __future__ import division
  from pygments.formatter import Formatter
  from pygments.lexer import Lexer
  from pygments.token import Token, STANDARD_TYPES
  from pygments.util import get_bool_opt, get_int_opt, StringIO, xrange, iteritems
label_desc: Use image node_id 4 for calling the LatexFormatter obj's underlying member method code with example usage: obj.format_unencoded(tokensource, outfile) without return types