I am checking out these questions/answers:
- Compile a LaTeX document into a PNG image that's as short as possible
- How do I turn off equation auto numbering
- What's the best (and quickest) way to insert LaTeX equations into PowerPoint?
By default, you get numbers in your image:
\documentclass[preview]{standalone}
\begin{document}
\begin{equation}
L = 2
\end{equation}
\end{document}
So one of those links lead to this solution:
\documentclass[preview]{standalone}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
L = 2
\end{equation*}
\end{document}
Which gives:
But this is the actual image shape (colored the background yellow instead of transparent):
It looks like it's slightly cut off at the bottom, and it's also extremely wide.
I would like to accomplish 3 primary objectives:
- Make the bounding box "tight" around the edges, so there is very little if any extra padding around the edges.
- Also, make the image sized so the font size appears naturally sized at a particular image width.
- Make it so the PNG is high resolution (so on retina displays that probably means 2x pixel density?). So there is no blurryness.
For (2) and (3), by that I mean if we have a viewport which is 800px wide in the browser, and the same L = 2 equation. I would like to see a roughly 80px wide image (160px if double resolution, then scaled down). So the generated image should be 80px wide or so, like this:
Then from there, I can use whatever browser / HTML / CSS logic to center and display the image in a nice way.
How can I do this from the command line (i.e. in an automated way)?
The 2 commands I used to generate the yellow image were from the first linked answer:
pdflatex test.tex
convert -density 300 test.pdf -quality 90 file.png
# then convert to yellow bg
convert file.png -background '#f0f000' -layers flatten file.png
So how do you:
- Remove the padding?
- Remove the numbering (at a global level) (if there is something better than using
amsmathor the other polluting things, some global setting perhaps outside of the scope of your equation). - Scale the image to the right size so the font appears at the proper height (this will probably take some experimentation I'm guessing).



pdfcrop -margin 3 in-name.pdf out-name.pdffrom https://tex.stackexchange.com/a/247690/26407 crops the PDF nicely, is that the best approach for that part? – Lance Feb 06 '24 at 09:10texdoc ltximg– Pablo González L Feb 06 '24 at 16:24