I am trying to use write18 to crop a pdf. The code is






    filename: \filename

    croppedfilename: \croppedfilename

    \immediate\write18{pdfcrop mypath/myimage.pdf \croppedfilename}%

    \immediate\write18{pdfcrop \filename \croppedfilename}%



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.


If you check the log, you'll see

runsystem(pdfcrop mypath/myimage.pdf mypath/myimage.cropped.pdf)...executed.

runsystem(pdfcrop mypath/myimage.pdfmypath/myimage.cropped.pdf)...executed.

Notice the lack of a space in the second line. What's happening is the usual TeX behaviour of skipping spaces after macro names: in your case \filename. Thus you need to make sure a space is 'seen' there:

\immediate\write18{pdfcrop \filename\space\croppedfilename}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.