0

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).

\documentclass{article}
\usepackage{hyperref}
\hypersetup{colorlinks=true}

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

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.

7
  • 1
    use the geometry package to specify the margins you want, you should not have to generate the wrong size then crop it – David Carlisle Dec 7 '20 at 19:02
  • pdfcrop works by reinserting the pdf as picture. This looses links. – Ulrike Fischer Dec 7 '20 at 19:19
  • @UlrikeFischer Ah, I see, so there is no way how to make it work with pdfcrop then. – OnDragi Dec 7 '20 at 19:20
  • well one can reinsert links later, but this is not trivial. – Ulrike Fischer Dec 7 '20 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? – OnDragi Dec 7 '20 at 19:23
0

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):

\usepackage{geometry}

\addtolength{\oddsidemargin}{-2.5cm}
\addtolength{\evensidemargin}{-2.5cm}
\addtolength{\paperwidth}{-5cm}

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.