Follow up to Get write18 to accept / expand command
I want to crop a pdf and print it. My \the\pdfshellescape
is 1, so my shell-escape is working. My MWE is
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\newcommand{\filename}{}
\newcommand{\croppedfilename}{}
\newcommand{\includecroppedgraphics}[1]{%
\makeatletter
\filename@parse{#1}
\renewcommand{\filename}{#1}
\renewcommand{\croppedfilename}{\filename@area\filename@base.cropped.\filename@ext}
\makeatother
\immediate\write18{pdfcrop #1 \croppedfilename}%
\fbox{\includegraphics[width=\linewidth]{\croppedfilename}}
}
\begin{document}
\includecroppedgraphics{mypath/myimage.pdf}
\the\pdfshellescape
\end{document}
This does not produce the cropped image. From the log I get
runsystem(pdfcrop mypath/myimage.pdf mypath/myimage.pdf@areamypath/myimage.pdf@ base.cropped.mypath/myimage.pdf@ext)...executed.
Obviously the parsing I got from https://tex.stackexchange.com/a/39636/49283 did not work even though it did work in Get write18 to accept / expand command
How do I get the parsing right here?