Some inline math
Created
June 13, 2021 00:32
-
-
Save NickyMeuleman/3e1ae1119d40f553b69341cd1b67faa1 to your computer and use it in GitHub Desktop.
Ideal KaTeX MDX usecase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { CodeBlock } from "../components/CodeBlock"; | |
import { MathBlock } from "../components/MathBlock"; | |
import TeX from "@matejmazur/react-katex"; | |
export default { | |
pre: ({ children }) => <>{children}</>, | |
inlineCode: ({ children }) => <code>{children}</code>, | |
inlineMath: ({ children }) => <TeX>{children}</TeX>, | |
code: CodeBlock, | |
math: MathBlock | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @jsx jsx */ | |
import React from "react"; | |
import TeX from "@matejmazur/react-katex"; | |
import { jsx } from "theme-ui"; | |
const CodeBlock: React.FC<IProps> = ({ | |
children, | |
title, | |
...props | |
}) => { | |
return ( | |
<React.Fragment> | |
{title && <div sx={{ variant: `styles.MathBlock.title` }}>{title}</div>} | |
<div sx={{ variant: `styles.MathBlock` }}> | |
<TeX block>{children}</TeX> | |
</div> | |
</React.Fragment> | |
) | |
} | |
}; | |
export { MathBlock }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment