I was able to embed an EPS file in the source so that the compiler generates the image that the document re-imports. EPS files have different formats and some of them fail because they are binary, so it’s a dicey process.
what worked
I started with a large JPG which I was importing this way:
\includegraphics[width=18mm]{big.jpg}
Looked nice but quite wasteful as the whole JPG ends up inside the PDF only to be scaled down to 18mm wide. So I needed to resample it. But I also need to distribute the tex doc and really can’t be dealing with distributing multiple files. EPS files can be simple ascii text and they can be embedded in the code. So I ran ImageMagick to shrink the image and produce an EPS file:
$ convert big.jpg -geometry 100x small.eps
The the scaling option (width=18mm) can now be omitted: \includegraphics{small.eps}
. It was the right size but blurry. WTF? I don’t know the problem exactly but I recall that ImageMagick has some shitty defaults that ignore attributes of the original image, thus forcing users to figure out what parameter to provide in order to maintain original attributes.
I could not be bothered to investigate. So I made the image 50% bigger than needed and made latex rescale it (sloppy but works):
$ convert big.jpg -geometry 150x medium.eps
In LaTeX: \includegraphics[width=18mm]{medium.eps}
Job done. But sloppy because I should not have to make the image bigger than displayed and then downscale it in LaTeX to avoid blurr.
better, but fails
So I used #GIMP to shrink the image. GIMP is a different kind of shit-show because it crashes Wayland, but I was finally able to scale the image faster than GIMP could crash and GIMP did a good job. That is, the EPS file was the right size and without getting blurry. Thus the resampling was proper.
But the EPS file produced by GIMP is not ascii text. It has some characters that fuck up the ability to embed the image in the source code. Fuck me. There are different EPS flavors and even a badly documented eps2eps
tool.
Perhaps I have to use GIMP to scale to a PPM and then ImageMagick to convert the PPM to EPS without scaling. Assuming that works, an annoyance remains: an EPS ascii text file from ImageMagick has many lines which requires a lot of scrolling to reach the LaTeX code after it’s embedded in the code. Are there any other non-binary image formats apart from (e)ps?
PDF is a one. A PDF can also be binary or ascii. If the effort is made to ensure an ascii PDF, I think the downside is the final document is no longer versatile (can only be PDF not PostScript).
SVG is another ascii image format but I’m not confident LaTeX handles it well.
I am tempted to follow this approach to make a definitively ascii EPS file. But it would be useful if there were a way to make an EPS file that has no more than 20 or so linefeeds.
There is an inline-images
package… I might fiddle with that if the EPS gives too much issue.
Update
I looked more into ImageMagick. The complexity is staggering because there are six approaches to minifiscation:
-sample -resample -scale -resize -adaptive-resize -thumbnail
Resizing turns out to serve my purpose well. But then there are 30 different filters listed by convert -list filter
. So I tried them all:
convert -list filter| while read fltr; do convert source.jpg -filter "$fltr" -resize 215x "$fltr"215x.eps; done
montage *215x.eps -tile 8x miff:- | display -
They all looked the same AFAICT and all were decent. So I just used the default filter in the end. I’m glad I could ditch GIMP given how badly it behaves on Wayland. The encoding from ImageMagick is very safe for embedding in LaTeX docs, as it seems to use only HEX symbols (0-9,a-f). Here is a sample:
4D4D48454342413E3D3F3F40403F3B3A3C3D40413E393835322D26211B1C1B191C1B1C1A
1A19171314172828292B3844474C4B5256554B44474B555B5C5A585857585C63676F777F
868C8D9096999CA0A2A3A6A7A7A9AAACADAFB1B1B1B2B4B6BABCBDBEBEBFBEBEC285302F
442F11120D0E1B32230F14201B0D101B23231418293E42514A6A4653605B393F4B523C4C
OTOH, it’s so limited that an image of approximately ~18x25 mm ends up taking almost 1600 lines of text in the document.
GIMP’s output is apparently also ascii. I don’t know how to test that other than to grep it for something arbitrary and see if grep prints that the file is binary. The encguess
command prints US-ASCII
. GIMP uses a broader range of ASCII which is normally preferred but something causes pdflatex to choke on it.
Yeah, I meant Xorg X11. I have both, Wayland and X installed on my primary PC for years. I still use X as my daily driver for the reasons I mentioned earlier, but like exploring Wayland, too.
Btw, I like to use LyX as a WYSIWYG editor for LaTeX like documents. It has it’s own format, can insert images quite well and exports into various formats, inluding PDF and LaTeX. It probably won’t help much with image rendering tho.