4

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.

6

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.