I like to crop white margins to save screen space while working in Overleaf. I use latexmkrc file with the following code: $pdflatex = 'pdflatex %O %S; pdfcrop --margins "20" %B.pdf %B-c.pdf; mv %B-c.pdf %B.pdf';

However, pdfcrop seems to disable hyperref links. Without the pdfcrop command, the hyperlinks work. With pdfcrop, the hyperlinks are not clickable anymore (even though the links are still colored by hyperref).


\section{Section one}\label{sec:one}
This is Section~\ref{sec:one}.

Am I doing something wrong? Is there a way to make both hyperref and pdfcrop work? Alternatively, is there another way to crop the white margins away while being able to use hyperref links?

Remark: To rule out other issues with the latexmkrc code, I tried with $pdflatex = 'pdflatex %O %S; mv %B.pdf %B-c.pdf; mv %B-c.pdf %B.pdf';, which works fine.

  • 1
    use the geometry package to specify the margins you want, you should not have to generate the wrong size then crop it Commented Dec 7, 2020 at 19:02
  • pdfcrop works by reinserting the pdf as picture. This looses links. Commented Dec 7, 2020 at 19:19
  • @UlrikeFischer Ah, I see, so there is no way how to make it work with pdfcrop then. Commented Dec 7, 2020 at 19:20
  • well one can reinsert links later, but this is not trivial. Commented Dec 7, 2020 at 19:21
  • @DavidCarlisle Changing just the margins would make a wide textwidth which is undesirable — I want things to be typeset as in the document with the margins. But I guess geometry allows to change all sizes, right? So if I just make margins 0 or very small, and textwidth as it should be in the final a4, everything should be the same when I then change it to the actual a4 layout — or do I need to redefine some other widths too? Commented Dec 7, 2020 at 19:23

1 Answer 1


pdfcrop reinserts the pdf as a picture, so the hyperlinks are lost, as pointed out by @UlrikeFischer.

An alternative way to crop out the white margins is to make use of the geometry package, as pointed by @DavidCarlisle. Instead of making latex generate the full page and then cropping it, we generate already smaller page by latex. We can use, e.g., the following (values for a4paper):



You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .