konn / vscode-generic-input-method

Generic Input Method for VSCode, mainly focusing on Unicode Symbol input for Theorem Provers, and YaTeX-like image completion for LaTeX

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generic Input Method for VSCode

Visual Studio Marketplace Visual Studio Marketplace

This extension provides a generic input method within VSCode. It can be used as a YaTeX-like image completion for LaTeX or Unicode Math input for theorem provers such as Agda or Lean.

Features

  • YaTeX-like image-completion for LaTeX
    • Since version 0.0.8, LaTeX-related functionalities are moved to CaTeX extension.
  • Unicode Math input for Markdown
  • Ability to configure your own custom input methods!
  • Automatic configuration update

Demos

Unicode Math Input

GIF Anime

Configuration

You can define and/or modify input methods in generic-input-method.input-methods. This must be an array of input method. Each input method is defined as follows:

{
  // Unique name for the input method
  "name": "Example Math Input",

  // Languages where the IM is activated.
  "languages": ["markdown", "latex"],

  // Characters to trigger conversion
  "triggers": ["\\"],

  // How to render each items?
  // Available: "string" or "snippet"; other extension can add more.
  // `string` just prints the content of "body" property.
  // See `defaults/images.json` for examples.
  // You can also define custom expander for render.
  "renderMode": "string",

  // Suffix for a text-editor command;
  // you can invoke it as `extension.complete.custom.example-math`.
  "commandName": "custom.example-math",

  // An array of items or a reference to the default dictionary.
  "dictionary": [
    // Default Math dictionary shipped with this extension
    "defaults/math.json",

    // Push `\||-` to input `\Vvdash`.
    // Shows `⊪` as a preview.
    { "label": "|||-", "body": "\\Vvdash", "description": "⊪" }
  ]
}

Currently, you can only refer to the default dictionaries shipped with the generic-input-method extension.

External API

This extension provides an API to un/register custom input methods.

Registering a new Input Method dynamically

import { extensions, ExtensionContext } from "vscode";

function async activate(context: ExtensionContext) {
  let ims = extensions.getExtension("mr-konn.generic-input-method");
  if (gim) {
    const api: any = await gim.activate();
    const im: any = {
      name: "My Great IM Dynamically Registered",
      languages: ["redtt"],
      triggers: ["\\"],
      dictionary: ["defaults/math.json", { label: "to", body: "→" }]
    };
    api.registerInputMethod(im);
  }
}

See CaTeX and redtt-diagnostics for an example usage.

Invoking Input Method Forcedly

You can use api.invokeInputMethod(editor?, nameOrIM?) to invoke an input method, regardless of the language of editor.

TODOs

  • Cool screenshot GIFs
  • Underlining converted input
  • Contextual completion based on scopes
  • Split LaTeX-related input methods as an external extension?

About

Generic Input Method for VSCode, mainly focusing on Unicode Symbol input for Theorem Provers, and YaTeX-like image completion for LaTeX

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:TypeScript 100.0%