@@ -2,6 +2,8 @@ import React, { memo, useEffect } from "react"
22import { useRemark } from "react-remark"
33import styled from "styled-components"
44import { visit } from "unist-util-visit"
5+ import rehypeKatex from "rehype-katex"
6+ import remarkMath from "remark-math"
57
68import { vscode } from "@src/utils/vscode"
79import { useExtensionState } from "@src/context/ExtensionStateContext"
@@ -75,6 +77,31 @@ const StyledMarkdown = styled.div`
7577 );
7678 }
7779
80+ /* KaTeX styling */
81+ .katex {
82+ font-size: 1.1em;
83+ color: var(--vscode-editor-foreground);
84+ font-family: KaTeX_Main, "Times New Roman", serif;
85+ line-height: 1.2;
86+ white-space: normal;
87+ text-indent: 0;
88+ }
89+
90+ .katex-display {
91+ display: block;
92+ margin: 1em 0;
93+ text-align: center;
94+ padding: 0.5em;
95+ overflow-x: auto;
96+ overflow-y: hidden;
97+ background-color: var(--vscode-textCodeBlock-background);
98+ border-radius: 3px;
99+ }
100+
101+ .katex-error {
102+ color: var(--vscode-errorForeground);
103+ }
104+
78105 font-family:
79106 var(--vscode-font-family),
80107 system-ui,
@@ -126,6 +153,7 @@ const MarkdownBlock = memo(({ markdown }: MarkdownBlockProps) => {
126153 const [ reactContent , setMarkdown ] = useRemark ( {
127154 remarkPlugins : [
128155 remarkUrlToLink ,
156+ remarkMath ,
129157 ( ) => {
130158 return ( tree ) => {
131159 visit ( tree , "code" , ( node : any ) => {
@@ -138,7 +166,7 @@ const MarkdownBlock = memo(({ markdown }: MarkdownBlockProps) => {
138166 }
139167 } ,
140168 ] ,
141- rehypePlugins : [ ] ,
169+ rehypePlugins : [ rehypeKatex as any ] ,
142170 rehypeReactOptions : {
143171 components : {
144172 a : ( { href, children } : any ) => {
0 commit comments