Skip to content

Commit e5ab012

Browse files
authored
Merge pull request #87 from sikepuri-algorithm/create-latex-playground
Create LaTeX Playground
2 parents c91e8d2 + f8b47fe commit e5ab012

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

docs/03extras/05tex/index.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,29 @@ import Tabs from "@theme/Tabs";
66
import TabItem from "@theme/TabItem";
77
import installTexLive from "./install_texlive.mov";
88
import typesetTex from "./typeset_tex.mp4";
9+
import InteractiveCodeEditor from "@site/src/components/InteractiveCodeEditor/InteractiveCodeEditor";
910

1011
# $\LaTeX$ の導入
1112

1213
なぜか周りに $\LaTeX$ を使っている人が多いので、$\LaTeX$ 環境の構築方法を解説しておきます。
1314

15+
## LaTeX のプレイグラウンド
16+
17+
$\LaTeX$ のプレイグラウンドを作ってみました。機能には制限がありますが、雰囲気は味わえるかと思います。
18+
19+
<InteractiveCodeEditor
20+
language="latex"
21+
defaultValue={`\
22+
\\documentclass{article}
23+
\\begin{document}
24+
Hello World!
25+
$$
26+
a^2 + b^2 = c^2
27+
$$
28+
\\end{document}\
29+
`}
30+
></InteractiveCodeEditor>
31+
1432
## TeXLive のインストール
1533

1634
[Visual Studio Code をインストールの項](/docs/03extras/02vscode/)を参考に VSCode をインストールしておいてください。

src/components/InteractiveCodeEditor/InteractiveCodeEditor.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function InteractiveCodeEditor({
1414
defaultCSS,
1515
defaultJavaScript,
1616
}: {
17-
language: "html" | "markdown" | "HTML-CSS-JavaScript";
17+
language: "html" | "markdown" | "HTML-CSS-JavaScript" | "latex";
1818
defaultValue?: string;
1919
defaultHTML?: string;
2020
defaultCSS?: string;
@@ -59,6 +59,28 @@ export default function InteractiveCodeEditor({
5959
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.css"/>
6060
<link rel="stylesheet" href="https://cdn.jsdelivr.net/github-markdown-css/2.2.1/github-markdown.css"/>
6161
`;
62+
63+
function latexRender(value: string) {
64+
const header = `\
65+
<!DOCTYPE html>
66+
<html lang="ja">
67+
<head>
68+
<meta charset="UTF-8" />
69+
<script type="module">
70+
import { LaTeXJSComponent } from "https://cdn.jsdelivr.net/npm/latex.js/dist/latex.mjs";
71+
customElements.define("latex-js", LaTeXJSComponent);
72+
</script>
73+
</head>
74+
<body>
75+
<latex-js baseURL="https://cdn.jsdelivr.net/npm/latex.js/dist/">\
76+
`;
77+
const footer = `\
78+
</latex-js>
79+
</body>
80+
</html>\
81+
`;
82+
return header + value + footer;
83+
}
6284
return (
6385
<>
6486
<div className={styles.playgroundContainer}>
@@ -119,6 +141,8 @@ export default function InteractiveCodeEditor({
119141
? code
120142
: language === "markdown"
121143
? markdownDefaultValue + md.render(code)
144+
: language === "latex"
145+
? latexRender(code)
122146
: `<style>${css}</style>${html}<script>${js}</script>`
123147
}
124148
title="Live Code"

0 commit comments

Comments
 (0)