Skip to content

Hover Preview. Please try! #856

Description

@tamuratak

Hi,
I have implemented hover preview. When you put your mouse cursor on \begin{...} or $...$, then an equation rendered with MathJax hovers. I want this one to be merged to LaTeX-Workshop although it is now alpha version. Please try this branch. Additional libraries are not required.

oct-08-2018 19-11-30

implementation

  1. In HoverProvider, we send a string of equation to WebView using WebView.postMessage
  2. In WebView, with MathJax, we convert the string to a SVG string.
  3. We render the SVG string in a canvas element again.
  4. Wiht HTMLCanvasElement.toDataURL, we convert the image in the canvas element to a string of png dataURL.
  5. We send back the string to LaTeX-Workshop extension process with postMessage.
  6. We make a markdown string with the dataURL.
  7. Hover renders the markdown.
  8. We've done it!

Pros

  • Fast. It must be faster than you expect. Thanks to V8.
  • We do not need to install any other libraries and binaries. Implemented only in TypeScript and JavaScript.
  • No abusing of VSCode API. I believe.

Cons

  • We need WebView. We now use the WebView of pdf.js viewer for that purpose. When you close the preview tab, hover will not appear.
  • Hover API is very restricted. Additional features are impossible.

ToDo

  • Change colors of rendered equations to appropriate ones for each theme. Now only suited for light themes.
  • Zoom option for rendered euqations.
  • Others?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions