[Tex/LaTex] How to embed Javascript in LaTeX Beamer

beamerjavascript

I'm wondering if it is possible to add javascript animations in LaTeX Beamer, e.g. figures created with C3 or D3? As far as I remember the animate packages uses javascript in order to display (and probably run) the videos embedded in the document. There is a post on embedding JavaScript in LaTeX on StackExchange, but the post focuses on document-level Javascript in a PDF (no mentions on including third party libraries such as D3).

Best Answer

The answer to this question is embedded in the comments above. At the moment, there is no way to use JavaScript libraries like D3 and C3 as is; however, you could do similar things, if you wanted to write the code from scratch or modify those libraries to use the PDF object model OR export their graphics for use in LaTeX (see d3js/SVG Export demo)

Notes:

  1. LaTeX allows us to create PDF or PostScript (.ps) files
  2. PDF has its own document object model (DOM) (as referenced in the Acrobat JavaScript Scripting Guide p. 22). In other words, PDF supports JavaScript, but not the Browser DOM, which is the way the Browser displays lines, text and images on a page.
  3. D3 and C3 use the browser's DOM to draw on the page