I am trying to use write18 to crop a pdf. The code is
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\newcommand{\filename}{}
\newcommand{\croppedfilename}{}
\begin{document}
\makeatletter
\renewcommand{\filename}{mypath/myimage.pdf}
\filename@parse{mypath/myimage.pdf}
\renewcommand{\croppedfilename}{\filename@area\filename@base.cropped.\filename@ext}
\makeatother
filename: \filename
croppedfilename: \croppedfilename
\immediate\write18{pdfcrop mypath/myimage.pdf \croppedfilename}%
\immediate\write18{pdfcrop \filename \croppedfilename}%
\the\pdfshellescape
\end{document}
Here \the\pdfshellescape is 1.
The line \immediate\write18{pdfcrop mypath/myimage.pdf \croppedfilename} does produce my cropped pdf, but \immediate\write18{pdfcrop \filename \croppedfilename} does not. Of course I need the second version in order to put it into a command.