Is it possible to set the page height of a LaTeX PDF to the height of the rendered content? I am using pdflatex to render simple equations and such, and I want to create a PDF that is exactly as tall as the equation, so I can render it nicely in the browser. How can I do that?
Asked
Active
Viewed 84 times
1 Answers
0
Yes, it is possible to set the page height of a LaTeX PDF to match the height of the rendered content. Use the standalone Document Class, which is designed for this purpose. It creates a document with a page size that fits exactly to the content.
Here's a basic example:
\documentclass{standalone}
% Add any packages here
\begin{document}
% Your equation or content here
\end{document}
You might need to adjust the margins manually if your content has elements that might not be correctly calculated for the bounding box (like large symbols, etc.). However, for most standard equations and text, standalone handles this automatically.
chadoulis
- 702
- 1
- 6
- 21
standaloneclass? – cfr Jan 04 '24 at 05:44\documentclass[border=1pt]{standalone} \begin{document} $\displaystyle 1+1=2$ \end{document}a try. – Mico Jan 04 '24 at 06:10only MacOSX is supported, not darwin 14.1 (from sw_vers -productVersion: 14.1.1). I am on the M3 Macbook Pro, does standalone install there? I also want to specify the width, just not the height. – Lance Jan 04 '24 at 06:33\documentclass{article}, you can set\pagestyle{empty}and then crop the resulting PDF file. (There's a question here that says how to do that.) – barbara beeton Jan 04 '24 at 13:16\documentclass[varwidth=10cm]{standalone}– samcarter_is_at_topanswers.xyz Jan 04 '24 at 13:31