1

I am checking out these questions/answers:

By default, you get numbers in your image:

\documentclass[preview]{standalone}
\begin{document}
\begin{equation}
L = 2
\end{equation}
\end{document}

enter image description here

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:

enter image description here

But this is the actual image shape (colored the background yellow instead of transparent):

enter image description here

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:

  1. Make the bounding box "tight" around the edges, so there is very little if any extra padding around the edges.
  2. Also, make the image sized so the font size appears naturally sized at a particular image width.
  3. 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:

  1. Remove the padding?
  2. Remove the numbering (at a global level) (if there is something better than using amsmath or the other polluting things, some global setting perhaps outside of the scope of your equation).
  3. Scale the image to the right size so the font appears at the proper height (this will probably take some experimentation I'm guessing).
Lance
  • 1,799

1 Answers1

2

Use $\displaystyle L=2$ otherwise you are making a full width display not something the natural size of the expression

David Carlisle
  • 757,742
  • How do you do a large equation with \displaystyle then? Something multiline like https://gist.github.com/lancejpollard/7848d2f9e0ed2e0ca640388d736019df – Lance Feb 06 '24 at 09:59
  • @Lance any (non numbered) display, multline*, align* or whatever but displays are always full width anyway so that isn't an issue there. But that gist doesn't have a multi line display, it has two single line equations with text between – David Carlisle Feb 06 '24 at 10:13