Skip to content

Instantly share code, notes, and snippets.

@h20y6m
Created October 10, 2020 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h20y6m/afc265a668205ee8a0b718bc17ce8799 to your computer and use it in GitHub Desktop.
Save h20y6m/afc265a668205ee8a0b718bc17ce8799 to your computer and use it in GitHub Desktop.
別行立て数式環境のみのタイプセット
%#!platex
%
% 別行立て数式環境のみのタイプセット
% https://oku.edu.mie-u.ac.jp/tex/mod/forum/discuss.php?d=2952
%
\documentclass[dvipdfmx]{jsreport}
%%%%%%%%%%%%%%%%%%%% BEGIN CODE %%%%%%%%%%%%%%%%%%%%
\ExplSyntaxOn
\box_new:N \l__onlyeq_one_box
\box_new:N \g__onlyeq_all_box
\bool_new:N \g__onlyeq_end_bool
% 数式環境を|\l__onlyeq_one_box|で組む
\cs_new:Npn \__onlyeq_hook_before:
{
\vbox_set:Nw \l__onlyeq_one_box
}
\cs_new:Npn \__onlyeq_hook_after:
{
\vbox_set_end:
% 出来上がった|\l__onlyeq_one_box|を|\g__onlyeq_all_box|に追加する
\vbox_gset:Nn \g__onlyeq_all_box
{
\vbox_unpack_drop:N \g__onlyeq_all_box
\box_use_drop:N \l__onlyeq_one_box
\pagebreak[0]
}
}
\hook_gput_code:nnn { shipout/before } { onlyeq }
{
% 途中ページの出力内容を破棄する
\bool_if:NF \g__onlyeq_end_bool
{ \shipout_discard: }
}
\hook_gput_code:nnn { enddocument } { onlyeq }
{
\clearpage
\pagestyle{empty}
% 最後に|\g__onlyeq_all_box|に入れておいた数式を出力する
\bool_gset_true:N \g__onlyeq_end_bool
\vbox_unpack_drop:N \g__onlyeq_all_box
}
% 環境へのフックを追加する
\cs_new:Npn \__onlyeq_set_hook:n #1
{
\hook_gput_code:nnn { env/#1/before } { onlyeq }
{ \__onlyeq_hook_before: }
\hook_gput_code:nnn { env/#1/after } { onlyeq }
{ \__onlyeq_hook_after: }
}
% equation環境へのフックを追加する
\__onlyeq_set_hook:n { equation }
\__onlyeq_set_hook:n { equation* }
\ExplSyntaxOff
%%%%%%%%%%%%%%%%%%%% END CODE %%%%%%%%%%%%%%%%%%%%
\usepackage{amsmath,amssymb}
\begin{document}
\TeX{} Wiki \LaTeX{}入門より
\section{簡単な数式の例 (1)}
日本で漱石が「吾輩は猫である」を発表したころ,
ドイツではAlbert Einsteinが特殊相対論を発表した。
この理論によれば,エネルギー$E$と質量$m$は
\begin{equation}
E = mc^{2}
\end{equation}
で関係づけられる。
ここに$c$は光速で,
\begin{equation}
c = 299{,}792{,}458 \, \mathrm{m/s}
\end{equation}
である。
\section{簡単な数式の例 (2)}
次の数式を作ってみましょう。
\begin{equation}
\frac{\pi}{2} =
\left( \int_{0}^{\infty} \frac{\sin x}{\sqrt{x}} dx \right)^2 =
\sum_{k=0}^{\infty} \frac{(2k)!}{2^{2k}(k!)^2} \frac{1}{2k+1} =
\prod_{k=1}^{\infty} \frac{4k^2}{4k^2 - 1}
\end{equation}
\section{複雑な数式}
たとえば行列を書いてみます。
\begin{equation*}
A = \begin{pmatrix}
a_{11} & \ldots & a_{1n} \\
\vdots & \ddots & \vdots \\
a_{m1} & \ldots & a_{mn}
\end{pmatrix}
\end{equation*}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment