Giter Club home page Giter Club logo

hugo-mod-katex's Introduction

hugo-mod-katex

Render LaTeX in Markdown content without too much of a hassle.

KaTeX is a Javascript library by Emily Eisenberg and Sophie Alpert that is loaded on demand.

The module includes the necessary Javascript and font files for self-hosting.

Syntax

Inline LaTeX

LaTeX notation surrounded by the dollar sign $ or parenthesis with two preceding backslashes (\\( and \\)) gets rendered in line with the surrounding text. But there are two caveats:

  • Before KaTeX’s Javascript has access to the page, the content is processed by Hugo’s Markdown renderer, of course. Because there is some overlap between LaTeX and Markdown markup, the LaTeX may get distorted.

  • A literal dollar sign may be interpreted by KaTeX as a delimiter for inline LaTeX.

The module provides the shortcodes math and chem to prevent this. Instead of using dollars we use {{< math >}}Z_n = X_n + Y_n\quad X_n,Y_n,Z_n\in\mathbf{R}{{< /math >}} or {{< chem >}}\ce{H_{2}O(l)}{{< /chem >}} and can be sure that the underlines _ are not rendered into bogus emphasis by Hugo.

LaTeX blocks

LaTeX notation surrounded by two dollar signs $$ or squared brackets with two preceding backlashes (\\[ and \\]) are rendered into blocks (display mode). But there are also two caveats: The mentioned markup overlap and the need to write every formula into one line.

The module provides the render-codeblock-math and the render-codeblock-chem hooks which add the new code block identifiers math and chem. Inside these code blocks we can type normal LaTeX without constraints:

```math
\begin{equation}
B_{n,p}(k) = {n \choose k} p^k (1-p)^{n-k}
\end{equation}
```

Styling

The latex expressions get wrapped into HTML tags so we can style them according to our layout:

  • The shortcodes add a span-tag with the class math-inline or chem-inline.

  • The render-hooks add a div-tag with the class math-block or chem-block.

Include the LaTeX renderer

To include KaTeX into your pages you need to add the partial katex/tags.html at the end of your HTML body. The KaTeX library files are added to a page if the shortcode or the render hook is called once, or if the parameters math: true or chem: true are present in the front-matter.

hugo-mod-katex's People

Contributors

bowman2001 avatar renovate[bot] avatar

Watchers

 avatar

hugo-mod-katex's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

gomod
go.mod
  • go 1.20
npm
package.json
  • copy-webpack-plugin ^12.0.0
  • katex ^0.16.7
  • webpack ^5.82.1
  • webpack-cli ^5.1.1

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.