Following this question I asked a few years ago, I'm looking for a way to find the width of the largest picture (in width) in my document.
Typically, this requires a for loop and some TeX programming. Since my compilation process already includes 3 parsing steps (required to compute the last page number and bibliography items with biber), this isn't really a problem for me if this requires yet another one. If I can rely on an existing compilation pass, that would be even greater though.
Any idea how I can write this parser? My solution would have to use some regexes and manual parsing using Python, but I would like to avoid to require yet another engine.
Why this parser? Let me explain what I want by an example.
Considering
a full screen screenshot displayed with
\includegraphicswith a with specified by\textwidth.another screenshot taken on the same computer, but cropped to a specific size (e.g. to only have a specific dialog or a subset of the first image to focus on something specific).
The idea is to get the size of the first picture to be able to determine the ratio I need to specify to the second picture (how to compute it in the \includegraphics statement? do we have support for some mathematics computation in this context?).
In this use case, the first picture is the one one, but I would like to be able to specify the pictures kept to determine which one is the largest (in width, with a special tag for example).
As you can see, the way the pictures are presented here above in this question are incorrect. I want the second picture representing only the dialog from the first image to be the same size as it is in the first image. Typically, this is what I want (screenshot taken on LibreOffice Writer):
As you can see the dialog in the second image has the same width size as the first image (I don't know if we can call dpi in this context).



0.75\textwidth? Or do you want to show the all at the same resolution (dpi)? – Michael Palmer Sep 03 '17 at 22:41graphicxkeys probably means the LaTeX format. Likely you're using 2e. – cfr Sep 04 '17 at 00:39\pdfimageresolution=300in the preamble. Higher numbers mean more pixels per inch, that is, smaller image size. No need for any other computations. – Michael Palmer Sep 04 '17 at 13:09\pdfimageresolutionsetting. You can delete the stored DPI information from your picture usingexiftool, like so:exiftool -all= mygreatpic.png(note the space after=). After that, your\pdfimageresolutionsetting should take effect. – Michael Palmer Sep 04 '17 at 13:23\pdfimageresolutionmight break the other images I have included, and I don't know whether this command is available in the engine I use (xelatex). – wget Sep 04 '17 at 13:47convertfrom theimagemagicklibrary:for pic in *.png; do convert -units PixelsPerInch $pic -density 300 $pic; done. Either experiment with the DPI number, or define a custom scaling factor inside LaTeX\newcommand{\myscale}{0.75}, which you then use with every screenshot:\includegraphics[scale=\myscale]{screenshot1}. – Michael Palmer Sep 04 '17 at 14:06\saveboxtrickery as well as anyone, but there really is no need for it here; the impression only arose because you didn't think through your problem. All you need is a consistent DPI setting, which you manually tweak until your widest picture fits into\textwidth. – Michael Palmer Sep 04 '17 at 14:11\pdfimageresolution, you might go to the extreme of testing it. How about putting in a little work yourself to solve your own problems? – Michael Palmer Sep 04 '17 at 14:13! Undefined control sequence. <recently read> \pdfimageresolution. Actually digging in my own class implementation is what I do from the beginning, but sbox/mboxes are still not very clear for me in this context. Parsing a *TeX file isn't something I already performed either. – wget Sep 04 '17 at 14:45\myscaleparameter for\includegraphicsuntil it looks right, and apply the same settings to all other pictures. If you need to guard against outsize pictures,\usepackage[export]{adjustbox}, which then allows you to say\includegraphics[scale=\myscale,max height=\textheight, max width=\textwidth]{pic}. – Michael Palmer Sep 04 '17 at 15:01