File: mode_magic.py

package info (click to toggle)
macaulay2-jupyter-kernel 0.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,852 kB
  • sloc: python: 148; makefile: 20
file content (26 lines) | stat: -rw-r--r-- 685 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import metakernel

class ModeMagic(metakernel.Magic):
    modes = {
        "standard": "Standard",
        "webapp": "WebApp",
        "texmacs": "TeXmacs"
    }

    def line_mode(self, mode):
        """
        %mode MODE - switch top level mode

        Possible modes:
           webapp (html + mathjax) (default)
           texmacs (html + mathml)
           standard (plain text)
        """

        mode = mode.lower()
        if mode in self.modes:
            self.kernel.mode = mode
            self.kernel.do_execute_direct(
                f"changeJupyterMode {self.modes[mode]}")
        else:
            raise ValueError(f"expected one of {list(self.modes.keys())}")