Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svelte-katex

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-katex

A Svelte component that uses KaTeX to render math.

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
214
decreased by-13.71%
Maintainers
1
Weekly downloads
 
Created
Source

Svelte KaTeX Component

A Svelte component that uses KaTeX to render math.

QuickStart

Install the Svelte KaTeX component

npm i svelte-katex

KaTeX Stylesheet

Just like in KaTeX, we will need to add a stylesheet. Refer to the KaTeX Documentation for more details, or add the following into the head element.

<!--in the head element of app.html-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.2/dist/katex.min.css" integrity="sha384-MlJdn/WNKDGXveldHDdyRP1R4CTHr3FeuDNfhsLPYrq2t0UBkUdK2jyTnXPEK1NQ" crossorigin="anonymous">

Import and use

<script>
  import Katex from 'svelte-katex'
</script>
// display math example
<!--inline math example-->
<Katex>ax^2+bx+c=0</Katex>
<!--display math example-->
<Katex displayMode>ax^2+bx+c=0</Katex>

Curly braces

Curly braces are used throughout Svelte as well as LaTeX markup. For numbers (e.g. \sqrt{2}) the svelte-katex component will still work.

Dynamic behavior

For letters, like \sqrt{x}, Svelte will try to find a definition for the variable x. For example,

<script>
  const x = 2;
</script>
<!--This will typeset $\sqrt{2}$-->
<Katex>\sqrt{x}</Katex>
Static behavior

An error will be thrown if x was not defined in the earlier example, To typeset \sqrt{x}, we will have to use a workaround:

<Katex>\sqrt{'{x}'}</Katex>

Maybe a component isn't the best approach?

A functional approach

While we provide this component, we think using a function is a better way to handle math in Svelte.

This can be done with the mathlifier library, or with just the KaTeX library itself with katex.renderToString.

See the two methods and a comparison at Svelte Math

Keywords

FAQs

Package last updated on 09 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc