
パッケージを使用して、環境preview
からいくつかの画像を生成しますequation
。各画像の幅と高さが必要です。preview
パッケージは何らかのブラック マジックを行っており、ある時点でそれらの値を知る必要があると思います (?)。それらをテキスト ファイルに順番に保存することは可能ですか?
\documentclass{article}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{equation}
\begin{document}
\begin{equation}
x^2 = 2
\end{equation}
\begin{equation}
\int_0^x \sin t\, dt = 0
\end{equation}
\end{document}
答え1
文書化されたコードを詳しく調べたところ、フックに何らかのマテリアルを追加するのがそれを実行する方法であることpreview.sty
がわかりました(私が求めているのは、オプションが行うこととほぼ同じです)。私が探していた寸法は の寸法です。\pr@ship@end
auctex
\pr@box
寸法をセンチメートルにする必要があるので、変換マクロを使用しました。他の回答では。
\documentclass{article}
\usepackage{amsmath}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{equation*}
\makeatletter
% Conversion utility (https://tex.stackexchange.com/a/37317/8425)
\begingroup
\catcode `P=12 % digits and punct. catcode
\catcode `T=12 % digits and punct. catcode
\lowercase{%
\def\x{\def\rem@pt##1.##2PT{##1\ifnum##2>\z@.##2\fi}}}
\expandafter\endgroup\x%
\def\strip@pt{\expandafter\rem@pt\the}
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1\relax\relax}
% Answer to the question
\newwrite\file
\immediate\openout\file=snippet-list.txt
\g@addto@macro\pr@ship@end{%
\immediate\write\file{%
\convertto{cm}{\the\dimexpr\ht\pr@box+\dp\pr@box\relax}
\convertto{cm}{\the\wd\pr@box}}}
\begin{document}
Test
\begin{equation*}
x^2 = 2
\end{equation*}
Test
\begin{equation*}
\int x^2\, dx = \frac{x^3}{2}
\end{equation*}
\closeout\file
\end{document}
snippet-list.txt
私は
0.42175 12.12537
0.86165 12.12537