hmf / storch

GPU accelerated deep learning and numeric computing for Scala 3.
https://storch.dev
Apache License 2.0
0 stars 0 forks source link

Add support for Laika Math expressions #1

Open hmf opened 1 year ago

hmf commented 1 year ago

The original code changes the Laika templates to add the katex renderer (see default.template.html) The problem is that Laika updates may make changes to the templates, so we have to change these too otherwise we run the risk of missing on new features and bug corrections.

Can we use a Laika plugin for this?

References:

hmf commented 1 year ago

Options:

Links:

Explanation:

hmf commented 1 year ago

Hack: add script to header of all files.

<!DOCTYPE html>
<html lang="${?laika.site.metadata.language}">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="generator" content="Laika 0.18.1 + Helium Theme" />
    <title>${cursor.currentDocument.title}</title>
...
    @:heliumInitPreview(container)
    <script> /* for avoiding page load transitions */ </script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css" integrity="sha384-vKruj+a13U8yHIkAyGgK1J3ArTLzrFGBbBc0tDp4ad/EyewESeXE/Iv67Aj8gKZ0" crossorigin="anonymous">
    <!-- The loading of KaTeX is deferred to speed up page rendering -->
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.js" integrity="sha384-PwRUT/YqbnEjkZO0zZxNqcxACrXe+j766U2amXcgMg5457rve2Y7I6ZJSm2A0mS4" crossorigin="anonymous"></script>
    <!-- To automatically render math in text elements, include the auto-render extension: -->
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous"
        onload="renderMathInElement(document.body);"></script>
    <script>
      document.addEventListener("DOMContentLoaded", function() {
          renderMathInElement(document.body, {
            // customised options
            // • auto-render specific keys, e.g.:
            delimiters: [
                {left: '$$', right: '$$', display: true},
                {left: '$', right: '$', display: false},
            ],
            // • rendering keys, e.g.:
            throwOnError : false
          });
      });
    </script>
  </head>