Lets take this string:
\boxed{\includegraphics[width=0.4\textwidth]{FIGURE.pdf}}
that generates this figure:
Now lets say that I need to crop the blank margins of the figure keeping the figure's size.
I though I could do it with something like:
\boxed{\includegraphics[trim = L B R T, clip, scale=x]{FIGURE.pdf}}
Where L, B, R, and T are respectively the left, bottom, right and top trimming values and x is the scaling value.
The following example should better explain my question:
\boxed{\includegraphics[width=0.4\textwidth]{FIGURE.pdf}}\quad %
\boxed{\includegraphics[scale=0.238]{FIGURE.pdf}}\\
\boxed{\includegraphics[trim = 65 20 150 20, clip, width=0.4\textwidth]{FIGURE.pdf}}\quad %
\boxed{\includegraphics[trim = 65 20 150 20, clip, scale=0.238]{FIGURE.pdf}}
The previus code generates the following layout:
As you can see, using scale value instead of width lets me crop the figure keeping its size.
My question is: how can I get the exact (more or less) value of the scale parameter without go by trial and error? (My idea is to write some Emacs Lisp code to change the LaTeX code accordingly.)
I am open to any idea or suggestion.
Note. In most cases I use external software to crop my images (pdfcrop, briss etc.) but, sometimes, as in this case, they don't work so I need to trim manually.




\Gscale@boxin this answer does what you want. – Phelype Oleinik May 22 '19 at 20:49\Gscale@boxshould help me. – Gabriele May 22 '19 at 21:13