6

I know this is probably one of the weirdest requests on this forum, but I am just not getting anywhere on my own. I use latex to write my worksheets for my students. I often use the margins for tips and hints or small graphics. Unfortunately, the problem arises that the students obviously often want to print the sheets and then the hole punch holes hit those little graphics. I would like to get around that. Is there any chance to define a tikz picture or something else, which depicts the two hole punch holes on all pages while I write on the worksheets to place the margins entries appropriately?

I literally have no idea on how to even get started.

4
4

You can avoid atbegshi using the \AddToHook command. Here is a MWE, taking the tikz code by Dr. Manuel Kuehner. The output is the same:

\documentclass{article}
\usepackage{tikz}
\usepackage{blindtext}

\AddToHook{shipout/background}{%
 \begin{tikzpicture}[overlay,remember picture,every node/.style={circle, minimum height=5mm,minimum width=5mm,draw, xshift = 6mm}]
 \draw (current page.west) node[yshift = 30mm]{};
 \draw (current page.west) node[yshift = -30mm]{};
 \end{tikzpicture}%
}

\begin{document}
 
 \blindtext[6]
 
\end{document}

EDIT

SebGlav's observation is quite right. In a two-sided document, holes cannot be placed on the left on every page, but left on odd pages and right on even pages. There are two solutions: 1) leave the even pages blank; 2) draw the holes on the right in the even pages

Solution 1) Holes only on odd pages:

\AddToHook{shipout/background}{%
 \ifodd\value{page}
 \begin{tikzpicture}[overlay,remember picture,every node/.style={circle, minimum height=5mm,minimum width=5mm,draw, xshift = 6mm}]
 \draw (current page.west) node[yshift = 30mm]{};
 \draw (current page.west) node[yshift = -30mm]{};
 \end{tikzpicture}%
 \fi
}

Solution 2) Holes on the left and right, respectively, in the odd and even pages:

\AddToHook{shipout/background}{%
 \ifodd\value{page}
 \begin{tikzpicture}[overlay,remember picture,every node/.style={circle, minimum height=5mm,minimum width=5mm,draw, xshift = 6mm}]
 \draw (current page.west) node[yshift = 30mm]{};
 \draw (current page.west) node[yshift = -30mm]{};
 \end{tikzpicture}%
 \else
 \begin{tikzpicture}[overlay,remember picture,every node/.style={circle, minimum height=5mm,minimum width=5mm,draw, xshift = -6mm}]
 \draw (current page.east) node[yshift = 30mm]{};
 \draw (current page.east) node[yshift = -30mm]{};
 \end{tikzpicture}%
 \fi
}

Solution 2bis) Like above, but saving a few lines of code:

\newcommand{\printholes}[2]{%
 \begin{tikzpicture}[overlay,remember picture,every node/.style={circle, minimum height=5mm,minimum width=5mm,draw, xshift = #1}]
 \draw (current page.#2) node[yshift = 30mm]{};
 \draw (current page.#2) node[yshift = -30mm]{};
 \end{tikzpicture}%
}
\AddToHook{shipout/background}{%
 \ifodd\value{page}
   \printholes{6mm}{west}
    \else
   \printholes{-6mm}{east}
 \fi
}
7
  • 1
    Very nice and customizable. And if one has to print 2-sided documents? – SebGlav Mar 21 at 20:25
  • 2
    @SebGlav Maybe one can use this texfaq.org/FAQ-oddpage within the \AddToHook. Or see tex.stackexchange.com/questions/154256 (\ifodd\value{page}). – Dr. Manuel Kuehner Mar 21 at 22:23
  • 1
    @SebGlav Thanks for the suggestion. You are right. I did not think about it, I edited the answer. – Ivan Mar 21 at 23:12
  • I am unable to have this compile. ... Undefined control sequence \AddToHook{...}. TexLive 2020 with pdfTeX. – Jeffrey J Weimer Mar 21 at 23:24
  • Is your TeX Live distribution updated? – Ivan Mar 21 at 23:52
10

\documentclass[]{article}
\usepackage{tikz}
\usepackage{blindtext}
\usepackage{atbegshi} % https://www.ctan.org/pkg/atbegshi

\newcommand\myPunchHole{%
    \begin{tikzpicture}[remember picture,overlay]
        \draw (current page.west) node[circle, minimum size=5mm, draw, xshift = 6mm, yshift = 30mm]{};
        \draw (current page.west) node[circle, minimum size=5mm, draw, xshift = 6mm, yshift = -30mm]{};
    \end{tikzpicture}%
}

\AtBeginShipout{\myPunchHole}
\AtBeginShipoutFirst{\myPunchHole}

\begin{document}

\blindtext[6]

\end{document}

enter image description here


Related

4
  • Just to be clear, this requires two cycles of compilation to print the holes, right? – Jeffrey J Weimer Mar 21 at 23:27
  • @Jeffrey J Weimer Yes. – Dr. Manuel Kuehner Mar 21 at 23:39
  • @JeffreyJWeimer Yes (my last comment was done on my smartphone where the autocomplete for "@" does not work) – Dr. Manuel Kuehner Mar 22 at 18:17
  • Thank you for the response. – Jeffrey J Weimer Mar 22 at 20:06

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.