2

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?

Lance
  • 1,799
  • 1
    Let me make sure I understand your formatting objective: You want to display a document that's cropped to the exact height (and, presumably, width) of a given equation. Is this understanding correct? – Mico Jan 04 '24 at 05:42
  • 4
    Maybe use the standalone class? – cfr Jan 04 '24 at 05:44
  • I assume a certain width, I only need to specify the height of the document to be the content height. – Lance Jan 04 '24 at 05:45
  • 1
    Give \documentclass[border=1pt]{standalone} \begin{document} $\displaystyle 1+1=2$ \end{document} a try. – Mico Jan 04 '24 at 06:10
  • 1
    only 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
  • I vote to leave open, because standalone is a solution here, but may not work on the OPs computer. So a specific answer may still be missing. Hence it's only a duplicate in parts. – MS-SPO Jan 04 '24 at 07:51
  • 2
    standalone is just a latex class it will work on any system that has tex, – David Carlisle Jan 04 '24 at 09:00
  • If you're using \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
  • 1
    @Lance You can define a fixed width with standalone: \documentclass[varwidth=10cm]{standalone} – samcarter_is_at_topanswers.xyz Jan 04 '24 at 13:31
  • @Lance the standalone class should be part of all commonly used tex distributions. You shouldn't have to install it and the message you show does not look like anything the package manager of your distribution would show you. – samcarter_is_at_topanswers.xyz Jan 04 '24 at 13:32

1 Answers1

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