HTMLでLaTeX (MathJax)
MathJaxを用いて, HTML上でLaTeXコマンドを使えるようにする
以下の内容を <body> タグ内に追記する.
<script id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js">
</script>
<script>
MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
},
svg: {
fontCache: 'global'
}
};
</script>
インライン数式は,
\( \)または
$ $の間に書けば,
alignなどは,
\begin{align}
\Large
\int_0^{\frac{\pi}{2}} \dfrac{\sin{x}\cdot\sinh(\sin{x})}{\cos(\cos{x})+\cosh(\sin{x})}\ dx=\dfrac{\pi}{8}
\end{align}
のようにすれば,
\newcommandなどについても,
$$
\newcommand{\pdiff}[2]{\dfrac{\partial #1}{\partial #2}}
\newcommand{\diff}[2]{\dfrac{d #1}{d #2}}
\newcommand{\bm}[1]{\boldsymbol{#1}}
\newcommand{\ele}{\bm{e}}
\newcommand{\pmat}[1]{\left(\begin{matrix} #1 \end{matrix}\right)}
\newcommand{\mat}[1]{\begin{matrix} #1 \end{matrix}}
\newcommand{\sgn}[1]{\mathrm{sgn}\pare{#1}}
\newcommand{\vctr}[1]{\left(\begin{matrix} #1 \end{matrix}\right)}
\newcommand{\pare}[1]{\left( #1 \right)}
\newcommand{\bra}[1]{\left\{ #1 \right\}}
\newcommand{\squ}[1]{\left[ #1 \right]}
\newcommand{\bsqu}[1]{\Bigl[ #1 \Bigr]}
\newcommand{\abs}[1]{\left|#1\right|}
\newcommand{\relmiddle}[1]{\mathrel{}\middle#1\mathrel{}}
\newcommand{\set}[2]{\left\{ \rule{0pt}{10pt} \ #1 \relmiddle{|} #2\ \right\}}
\newcommand{\sset}[2]{\left\{ #1 \relmiddle{|} #2\right\}}
\newcommand{\seq}[2]{\left\{#1\right\}_{#2}}
\newcommand{\gsubgrp}[1]{\langle #1 \rangle}
\newcommand{\defarrow}{\stackrel{\mathrm{def}}{\Longleftrightarrow}}
\newcommand{\ord}[1]{\mathrm{ord}\pare{#1}}
\newcommand{\dt}{\Delta t}
$$
などと書けば, 自分で作成したコマンドが使えるようになる.
また, MathJax 3.0は拡張パッケージがいくつか用意されており, physicsパッケージなどもロードすれば使えるようになる.
コメント
コメントを投稿