I need to (temporarly) redefine \includegraphics command for trimming purposes. This is my MWE:
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage[abs]{overpic}
\pagestyle{empty}
\begin{document}
\begin{figure}[h]
\centering
\resizebox*{1\textwidth}{!}{\begin{overpic}[grid,unit=1pt]{lemon.jpg}
\end{overpic}}\relax
\includegraphics[trim = 0 100 0 100, clip, width=1\textwidth]{lemon.jpg}
\caption{\label{myfig}My caption.}
\end{figure}
\end{document}
In this example I have a picture inserted with the overpic environment that create a grid on my figure. This allow my to find, quickly, the values to pass to the trim parameter of the \includegraphics command.
To make this operation much less "overkill" I tried to redefine the \includegraphics command this way:
\renewcommand*{\includegraphics}[2][]{\resizebox*{1\textwidth}{!}{%
\begin{overpic}[grid,unit=1pt]{#2}\end{overpic}}\relax}
but it doesn't work. I get this error:
! TeX capacity exceeded, sorry [grouping levels=255]....
I know you may find it yet "overkill" but I have my goog reasons to do that.(This would allow me to pass this redefinition by command line, keeping my .tex untouched)
My answer(s) is "how can I redefine the \includegraphics command to insert this sort of grid in my figures? What's wrong in my code?"
I took the idea from this post: https://latex.org/forum/viewtopic.php?t=7783
Edit. I can't understand why if i define this command(s)
\newcommand{\vacua}[1]{}
\newcommand*{\myincludegraphics}[2][]{\resizebox*{1\textwidth}{!}{%
\begin{overpic}[grid,unit=1pt]{#2}\end{overpic}}\relax\vacua{#1}}
the string:
\myincludegraphics[trim = 0 100 0 100, clip, width=1\textwidth]{lemon.jpg}
generates my picture with the grid correctly. But if i do:
\newcommand{\myignore}[1]{}
\let\includegraphics\undefined %% I undefine "\includegraphics"
\newcommand*{includegraphics}[2][]{\resizebox*{1\textwidth}{!}{%
\begin{overpic}[grid,unit=1pt]{#2}\end{overpic}}\relax\myignore{#1}}
with the string:
\includegraphics[trim = 0 100 0 100, clip, width=1\textwidth]{lemon.jpg}
I keek getting the same error.

[grid,unit=1pt,#1], not i do not remember if overpic passes args onto includegraphics like this, it should be in the manual. Not at pc so cannot help. – daleif Oct 14 '18 at 17:57