MCPcopy Create free account
hub / github.com/ipython/ipython / format_latex

Method format_latex

IPython/core/magic.py:548–573  ·  view source on GitHub ↗

Format a string for latex inclusion.

(self, strng)

Source from the content-addressed store, hash-verified

546 print(oinspect.getdoc(func))
547
548 def format_latex(self, strng):
549 """Format a string for latex inclusion."""
550
551 # Characters that need to be escaped for latex:
552 escape_re = re.compile(r'(%|_|\$|#|&)',re.MULTILINE)
553 # Magic command names as headers:
554 cmd_name_re = re.compile(r'^(%s.*?):' % ESC_MAGIC,
555 re.MULTILINE)
556 # Magic commands
557 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % ESC_MAGIC,
558 re.MULTILINE)
559 # Paragraph continue
560 par_re = re.compile(r'\\$',re.MULTILINE)
561
562 # The "\n" symbol
563 newline_re = re.compile(r'\\n')
564
565 # Now build the string for output:
566 #strng = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',strng)
567 strng = cmd_name_re.sub(r'\n\\bigskip\n\\texttt{\\textbf{ \1}}:',
568 strng)
569 strng = cmd_re.sub(r'\\texttt{\g<cmd>}',strng)
570 strng = par_re.sub(r'\\\\',strng)
571 strng = escape_re.sub(r'\\\1',strng)
572 strng = newline_re.sub(r'\\textbackslash{}n',strng)
573 return strng
574
575 def parse_options(self, arg_str, opt_str, *long_opts, **kw):
576 """Parse options passed to an argument string.

Callers 1

magicMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected