2

When I open a file in jupyterlab. The left sidebar will disappear the file browser. file browser

But I want to open the toc. I try to write a javascript to simulate click the toc button in sidebar, but it doesn't work. There are any configuration or script can open toc?

  • You can move the TOC to the right sidebar by right-clicking on the item in sidebar and clicking "Switch Sidebar Side". – krassowski Oct 01 '22 at 08:46

1 Answers1

0

JupyterLab 4.0 will include toc:show-panel command, and in earlier versions you can activate ToC using activateById() method from JupyterFrontEnd.IShell interface using table-of-contents identifier.

You can try it out on jupyterlab-plugin-playground with the following code:

import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application';
import { NotebookPanel, INotebookTracker } from '@jupyterlab/notebook';


const plugin: JupyterFrontEndPlugin<void> = {
  id: 'toc-show:plugin',
  autoStart: true,
  requires: [INotebookTracker],
  activate: (app: JupyterFrontEnd, notebookTracker: INotebookTracker) => {
    alert('TOC-show extension activated!'); // you can remove this
    notebookTracker.currentChanged.connect((_: any, notebookPanel: NotebookPanel | null) => {
      if (notebookPanel) {
        // JupyterLab 3.x:
        app.shell.activateById('table-of-contents');
        // JupyterLab 4.0+:
        // app.commands.execute('toc:show-panel');
      }
    });
  },
};

export default plugin;

For packaging/installing it as a permanent extension you can follow the JupyterLab extension tutorial.

In future it might be possible to recreate this functionality from ipylab but currently it does not implement signal handlind.

krassowski
  • 13,598
  • 4
  • 60
  • 92