File tree Expand file tree Collapse file tree 3 files changed +70
-23
lines changed Expand file tree Collapse file tree 3 files changed +70
-23
lines changed Original file line number Diff line number Diff line change @@ -4,30 +4,9 @@ import TabItem from "@theme/TabItem";
4
4
import Editor from "@monaco-editor/react" ;
5
5
import IframeOutput from "@site/src/components/IframeOutput" ;
6
6
import mdToHTML from "@site/src/components/mdToHTML" ;
7
+ import latexToHTML from "@site/src/components/latexToHTML" ;
7
8
import styles from "./styles.module.css" ;
8
9
9
- function latexRenderer ( value : string ) : string {
10
- const header = `\
11
- <!DOCTYPE html>
12
- <html lang="ja">
13
- <head>
14
- <meta charset="UTF-8" />
15
- <script type="module">
16
- import { LaTeXJSComponent } from "https://cdn.jsdelivr.net/npm/latex.js/dist/latex.mjs";
17
- customElements.define("latex-js", LaTeXJSComponent);
18
- </script>
19
- </head>
20
- <body>
21
- <latex-js baseURL="https://cdn.jsdelivr.net/npm/latex.js/dist/">\
22
- ` ;
23
- const footer = `\
24
- </latex-js>
25
- </body>
26
- </html>\
27
- ` ;
28
- return header + value + footer ;
29
- }
30
-
31
10
function HtmlCssJavascriptEditor ( {
32
11
defaultHTML,
33
12
setHTML,
@@ -175,7 +154,7 @@ export default function InteractiveCodeEditor({
175
154
: language === "markdown"
176
155
? mdToHTML ( code )
177
156
: language === "latex"
178
- ? latexRenderer ( code )
157
+ ? latexToHTML ( code )
179
158
: language === "html-css"
180
159
? `<style>${ css } </style>${ code } `
181
160
: `<style>${ css } </style>${ code } <script>${ js } </script>` }
Original file line number Diff line number Diff line change
1
+ export default function latexToHTML ( value : string ) : string {
2
+ const header = `\
3
+ <!DOCTYPE html>
4
+ <html lang="ja">
5
+ <head>
6
+ <meta charset="UTF-8" />
7
+ <script type="module">
8
+ import { LaTeXJSComponent } from "https://cdn.jsdelivr.net/npm/latex.js/dist/latex.mjs";
9
+ customElements.define("latex-js", LaTeXJSComponent);
10
+ </script>
11
+ </head>
12
+ <body>
13
+ <latex-js baseURL="https://cdn.jsdelivr.net/npm/latex.js/dist/">\
14
+ ` ;
15
+ const footer = `\
16
+ </latex-js>
17
+ </body>
18
+ </html>\
19
+ ` ;
20
+ return header + value + footer ;
21
+ }
Original file line number Diff line number Diff line change
1
+ import React , { useState } from "react" ;
2
+ import useDocusaurusContext from "@docusaurus/useDocusaurusContext" ;
3
+ import Layout from "@theme/Layout" ;
4
+ import Editor from "@monaco-editor/react" ;
5
+ import IframeOutput from "@site/src/components/IframeOutput" ;
6
+ import { Grid , Box } from "@mui/material" ;
7
+ import latexToHTML from "@site/src/components/latexToHTML" ;
8
+
9
+ const defaultLatex = `\
10
+ \\documentclass{article}
11
+ \\begin{document}
12
+ Hello World!
13
+ \\[
14
+ a^2 + b^2 = c^2
15
+ \\]
16
+ \\end{document}
17
+ \
18
+ ` ;
19
+
20
+ export default function Home ( ) : JSX . Element {
21
+ const { siteConfig } = useDocusaurusContext ( ) ;
22
+ const [ latex , setLatex ] = useState < string > ( defaultLatex ) ;
23
+ return (
24
+ < Layout
25
+ title = { `Hello from ${ siteConfig . title } ` }
26
+ description = "This is a playground of LaTeX"
27
+ >
28
+ < Box p = { 2 } mt = { 2 } >
29
+ < Grid container direction = "row" spacing = { 2 } >
30
+ < Grid item xs = { 6 } >
31
+ < Editor
32
+ height = "80vh"
33
+ defaultLanguage = "html"
34
+ defaultValue = { defaultLatex }
35
+ onChange = { ( value ) => {
36
+ setLatex ( value ) ;
37
+ } }
38
+ />
39
+ </ Grid >
40
+ < Grid item xs = { 6 } >
41
+ < IframeOutput height = "80vh" > { latexToHTML ( latex ) } </ IframeOutput >
42
+ </ Grid >
43
+ </ Grid >
44
+ </ Box >
45
+ </ Layout >
46
+ ) ;
47
+ }
You can’t perform that action at this time.
0 commit comments