Giter Club home page Giter Club logo

remarkable-katex's Introduction

CI License: MIT

Overview

This is a Remarkable plugin that converts LaTeX math expressions between $...$ (inline) or $$...$$ (block) delimiters into math HTML. It should not interfere with any other Markdown processing.

I use this to perform server-side math expression rendering for my blog, Keystroke Countdown. The post Metalsmith Plugins for Server-side KaTeX Processing talks about the implementation of this package as well as a Jupyter IPython notebook plugin that does similar processing.

To Use

Install this package using npm:

% npm install [-s] remarkable-katex

Assuming you already have Remarkable installed, one way to use would be like so:

CommonJS

var Remarkable = require('remarkable');
var plugin = require('remarkable-katex');
var md = new Remarkable();
md.use(plugin);

ES6

import { Remarkable } from 'remarkable';
import rkatex from 'remarkable-katex';

var md = new Remarkable();
md.use(rkatex);

Configuration

Accepts a delimiter option that defines the 1-character delimiter to use when recognizing KaTeX spans. Default is the $ character.

{delimiter: '$'}

Dependencies

  • KaTeX -- performs the rendering of the LaTeX commands.

Tests

There are a set of Vows in index.test.js. To run:

% npm test

NOTE: if this fails, there may be a path issue with vows executable. See package.json.

remarkable-katex's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

remarkable-katex's Issues

complete example or source of your blog

hello,
good work with developing a great plugin! I'm excited to try it out, however I am having trouble properly displaying the rendered formulas

I include the plugin in my react project just as you instructed here, however the formula does not render properly, for instance for the input

$$\sqrt{a}$$

I get this html

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math>
<semantics>
	<mrow>
		<msqrt>
			<mrow>
				<mi>
					a
				</mi>
			</mrow>
		</msqrt>
	</mrow>
	<annotation encoding="application/x-tex">
		\sqrt{a}
	</annotation>
</semantics></math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.8491550000000001em;"></span><span class="strut bottom" style="height:1.04em;vertical-align:-0.190845em;"></span><span class="base displaystyle textstyle uncramped"><span class="mord sqrt"><span class="sqrt-sign" style="top:-0.009155000000000024em;"><span class="style-wrap reset-textstyle textstyle uncramped"></span></span><span class="vlist"><span style="top:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:1em;"></span></span><span class="mord displaystyle textstyle cramped"><span class="mord mathit">a</span></span></span><span style="top:-0.769155em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:1em;"></span></span><span class="reset-textstyle textstyle uncramped sqrt-line"></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:1em;"></span></span></span></span></span></span></span></span></span>

And renders as

screen shot 2018-03-16 at 7 53 47 pm

I am guessing stylesheet or client side javascript might be missing, I'm not entirely sure how to inclue all that using remarkable

Could you maybe share source of your blog or some more complete example?

open (escaped) curly brace will not parse

Open curly brace (without a matching "closing" brace) will break the parse even when escaped.

I need something like this:
Screen Shot 2021-05-12 at 11 16 33

I'm getting the string from a json file like this:
$\\left\\{ \\begin{matrix}a + b + b = c \\\\ a + b = c\\end{matrix}\\right.$ won't parse

$\\left[ \\begin{matrix}a + b + b = c \\\\ a + b = c\\end{matrix}\\right.$ parses correctly

Changing the parser on lines 100 and 102 like this will make it work:

while (pos < max) {
      const char = state.src.charAt(pos);
      if (char === '{' && state.src.charAt(pos-1) !== '\\') {
        escapedDepth += 1;
      } else if (char === '}' && state.src.charAt(pos-1) !== '\\') {
        escapedDepth -= 1;
        if (escapedDepth < 0) { return false; }

I'm not very familiar with katex/math so i'm not sure if it would break something else, but i can make a PR with the change if that's ok!

Nested math parsed incorrectly

$\colorbox{aqua}{$F=ma$}$ currently parses as two math chunks, $\colorbox{aqua}{$ and $}$, which is not correct.

Would you be willing to either add, or review a PR to add, proper brace handling so that this properly parses? For an example of how this can be done, see https://github.com/KaTeX/KaTeX/blob/master/contrib/auto-render/splitAtDelimiters.js

This bug is currently hampering the actual KaTeX documentation, which uses your plugin (!). See KaTeX/KaTeX#2280 (review)

how could i implemet render tikz-pictures

hi, thinks for this project, is it could render this
$$\begin{tikzpicture}[scale=1.0544]\small
\begin{axis}[axis line style=gray,
samples=120,
width=9.0cm,height=6.4cm,
xmin=-1.5, xmax=1.5,
ymin=0, ymax=1.8,
restrict y to domain=-0.2:2,
ytick={1},
xtick={-1,1},
axis equal,
axis x line=center,
axis y line=center,
xlabel=$x$,ylabel=$y$]
\addplot[red,domain=-2:1,semithick]{exp(x)};
\addplot[black]{x+1};
\addplot[] coordinates {(1,1.5)} node{$y=x+1$};
\addplot[red] coordinates {(-1,0.6)} node{$y=e^x$};
\path (axis cs:0,0) node [anchor=north west,yshift=-0.07cm] {0};
\end{axis}
\end{tikzpicture}$$

just like https://upmath.me/,
https://github.com/parpalak/upmath.me

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.