Following up on this answer, I've decided to just make this a new environment. Below is my MWE using packages xparse and tikz:
\documentclass[10pt,a4paper]{article}
\usepackage{xparse,tikz}
\NewDocumentEnvironment{overdraw}{ o o m +b } {
{ % begin "\begin{overdraw}"
\begin{tikzpicture}
\node[anchor=south west, inner sep = 0] (image) at (0,0) {
\includegraphics{#3}
}; % add image at coordinate (0, 0)
\IfNoValueTF{#2} {
\IfNoValueTF{#1} {
\begin{scope}[x={(image.south east)},y={(image.north west)}]
% If Optional Arg #1 is empty
} { \begin{scope}[x={(image.south east)/#1},y={(image.north west)}] }
% #1 not empty
} % If Optional Arg #2 is empty
{ \begin{scope}[x={(image.south east)/#1},y={(image.north west)/#2}] }
% #2 not empty
} % end "\begin{overdraw}"
{ % begin "\end{overdraw}"
\end{scope}
\end{tikzpicture}
} % end "\end{overdraw}"
}
\begin{document}
\begin{overdraw}{sample.jpg}
\draw[red,ultra thick,rounded corners] (0.62,0.65) rectangle (0.78,0.75);
\end{overdraw}
\end{document}
Compiling this returns an error message that goes:
pdfTeX warning (ext4): destination with the same identifier (name{page.1}) has
been already used, duplicate ignored
<to be read again>
\relax
l.16 \newpage
[1]
! Package tikz Error: A node must have a (possibly empty) label text.
See the tikz package documentation for explanation.
Type H <return> for immediate help.
...
l.20 \end
{overdraw}
?
! Emergency stop.
...
l.20 \end
{overdraw}
End of file on the terminal!
What does \newpage have to do with anything I wrote? Is there any way to fix this problem?
EDIT: The package repository in full can be found HERE at Github. Passers-by are welcome to leave comments and notes on tips for managing and developing a good package :D



\includegraphics{#3};}should be\includegraphics{#3}};. – Ignasi May 28 '19 at 07:40