
我使用該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