Skip to content

Commit bf133e7

Browse files
committed
localized katex rendering operational
1 parent f0c1a7f commit bf133e7

File tree

8 files changed

+147
-56
lines changed

8 files changed

+147
-56
lines changed
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: "Something is Coming"
3+
date: 2020-06-09
4+
tags:
5+
- Demo
6+
- AI
7+
---
8+
9+
import ExamplePage, {MyFunction3}from "./void"
10+
11+
One of my favorite formulas is <MyFunction3 />. It's not gamourous. It's
12+
not exceptional. But it's beautiful. There's beauty in this simplicity. Something else beautiful is coming. You'll see.
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from 'react';
2+
3+
import 'katex/dist/katex.min.css';
4+
import { BlockMath, InlineMath } from 'react-katex';
5+
6+
export const MyFunction3 = () => (
7+
<InlineMath>
8+
{'a^2 + b^2 = c^2'}
9+
</InlineMath>
10+
)
11+
12+
const ExamplePage = () => (
13+
<div
14+
style={{
15+
// width: '40%',
16+
margin: '0 auto'
17+
}}
18+
>
19+
<h1>
20+
<InlineMath>
21+
{'\\text{React-}\\KaTeX \\space \\text{usage examples}'}
22+
</InlineMath>
23+
</h1>
24+
<h2>
25+
<code>{'<InlineMath />'}</code>
26+
</h2>
27+
This is an in-line expression <InlineMath math={'\\int_0^\\infty x^2 dx'} />{' '}
28+
passed as <code>math prop</code>. This is an in-line{' '}
29+
<InlineMath math={'\\int_0^\\infty x^2 dx'} /> expression passed as{' '}
30+
<code>children prop</code>.
31+
<h2>
32+
<code>{'<BlockMath />'}</code>
33+
</h2>
34+
<BlockMath math={'\\int_0^\\infty x^2 dx'} />
35+
<BlockMath>{`A =
36+
\\begin{pmatrix}
37+
1 & 0 & 0 \\\\
38+
0 & 1 & 0 \\\\
39+
0 & 0 & 1 \\\\
40+
\\end{pmatrix}`}</BlockMath>
41+
<h2>Error handling</h2>
42+
<BlockMath math={'\\int_0^\\infty x^2 dx \\inta'} errorColor={'#cc0000'} />
43+
<BlockMath
44+
math="\\int_{"
45+
renderError={err => <b>Custom error message: {err.name}</b>}
46+
/>
47+
<BlockMath math="\sum_{" />
48+
<BlockMath
49+
math={'\\sum_{'}
50+
renderError={err => <b>Custom error message: {err.name}</b>}
51+
/>
52+
<BlockMath math={123} />
53+
<BlockMath
54+
math={123}
55+
renderError={err => <b>Custom error message: {err.name}</b>}
56+
/>
57+
</div>
58+
);
59+
60+
// ReactDOM.render(<ExamplePage />, document.getElementById('root'));
61+
// https://github.com/iksena/math-quiz/blob/master/src/Containers/
62+
63+
export default ExamplePage

examples/2020-06-09--Math/index.mdx

-11
This file was deleted.

examples/2020-06-09--Math/void.js

-11
This file was deleted.

gatsby-config.js

+12-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
require(`dotenv`).config({
2-
path: `.env`,
3-
})
41

52
module.exports = {
63
pathPrefix: "",
@@ -84,20 +81,20 @@ module.exports = {
8481
],
8582
},
8683
},
87-
{
88-
resolve: `gatsby-transformer-remark`,
89-
options: {
90-
plugins: [
91-
{
92-
resolve: `gatsby-remark-katex`,
93-
options: {
94-
// Add any KaTeX options from https://github.com/KaTeX/KaTeX/blob/master/docs/options.md here
95-
strict: `ignore`
96-
}
84+
{
85+
resolve: `gatsby-transformer-remark`,
86+
options: {
87+
plugins: [
88+
{
89+
resolve: `gatsby-remark-katex`,
90+
options: {
91+
// Add any KaTeX options from https://github.com/KaTeX/KaTeX/blob/master/docs/options.md here
92+
strict: `ignore`
9793
}
98-
],
99-
},
94+
}
95+
],
10096
},
97+
},
10198
`gatsby-plugin-offline`,
10299
`gatsby-plugin-netlify`,
103100
],

package-lock.json

+55-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626
"gatsby-plugin-netlify": "^2.1.3",
2727
"gatsby-plugin-offline": "^2.2.4",
2828
"gatsby-plugin-sitemap": "^2.2.19",
29-
"gatsby-remark-katex": "^3.3.4",
30-
"gatsby-transformer-remark": "^2.8.15",
29+
"gatsby-remark-katex": "^3.3.6",
30+
"gatsby-transformer-remark": "^2.8.19",
3131
"gh-pages": "^3.0.0",
3232
"katex": "^0.11.1",
3333
"p5": "^1.0.0",
3434
"react": "^16.13.1",
3535
"react-dom": "^16.13.1",
36+
"react-katex": "^2.0.2",
3637
"react-p5": "^1.3.2",
3738
"react-p5-wrapper": "^2.0.0"
3839
},

src/components/layout.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import Header from "./header"
88
import Footer from "./footer"
99
import CodeStyles from "../styles/code"
1010
import SkipNavLink from "./skip-nav"
11-
import "katex/dist/katex.min.css"
11+
// import "katex/dist/katex.min.css"
12+
// require(`katex/dist/katex.min.css`)
1213

1314
type LayoutProps = { children: React.ReactNode; className?: string }
1415

0 commit comments

Comments
 (0)