Mathematical Annotations in PDF Documents

I’m often in the situation that while working with an interesting pdf, I want to add small notes to the document. Those annotations, for the sake of being short and precise, then almost always include math symbols. The problem is, that I rarely own the LaTeX source-code to the file; all I have is the pdf.

How to add mathematical annotations to a pdf, of which you don’t own the LaTex source-code?

While this is a question that does get asked from time to time (here and here), I had yet to find a comprehensive solution to the problem.

Here is mine:

I first create an otherwise empty pdf document, which only consists of my annotations, and then stamp this mask onto the target pdf, using the multi-stamp function of the pdf-tool pdf-tk.

A step-by-step guide to making mathematical annotations:

(1)  Download pdftk

Go to pdflabs.com and download pdftk. Of course you will want to download the correct version for your operating system, but for this guide I will only reference Windows.

Unzip the downloaded file and I recommend following Sid Stewart’s advice and copy the contents (pdftk.exe and libiconv2.dll) of the bin-folder to

C:\windows\system32

Another possible choice is to set up a working folder, where you will have your mask- and target pdf and copy the files there.

(2) Creating the mask

Next we will create an empty pdf file of at least as many pages as your target document and will put the annotations in the right places using LaTex.

Tex.stackexchange user egreg , had a wonderful suggestion of how to do this. Here is his sample code:

\documentclass[a4paper]{article}

\newcommand{\multistamp}[1]{%
 \loop\unless\ifnum\value{page}>#1
 \dowhatsonthispage
 \repeat}
\newcommand{\dowhatsonthispage}{%
 \null\csname onthispage\thepage\endcsname\newpage}
\newcommand{\putonpage}[2]{%
 \expandafter\def\csname onthispage#1\endcsname{#2}}
\begin{document}
\putonpage{1}{Hello world}
 \putonpage{3}{\vspace*{\fill}Hello world\par\vspace{\fill}}
\multistamp{4}
\end{document}

As he explains, “this creates a four page document, with something on the first and third pages as decided by the commands \putonpage".

If you are not too sure of how to create your custom stamp mask from here, you can download this sample mask. (Sadly, I am not allowed to upload .tex files and had to settle for the awkward .doc file. Please open with notepad (or better notepad++) and copy&paste into the TeX Editor of your liking.)

Now create the pdf file from the source and for the sake of the tutorial name it

mask.pdf

(Don’t worry,  if you couldn’t create a mask for whatever reason, here are a mask and a target you can use.)

(3) Stamping

Copy your mask.pdf and your target pdf to a folder of your choice. Please rename your target pdf to

target.pdf

for this tutorial.

Note: If you didn’t copy pdftk files to System32, they must be copied to this folder for the procedure to work!

Now all we need to do is stamping the mask onto the target using pdftk.

For this run a terminal (by clicking on the windows start button and entering cmd in the search field).

Next change to the directory where your mask.pdf and target.pdf are.

(You can do this by entering

cd  %path-to-your-directory

for example

cd C:\Windows\stampingfolder

If you need to change drives, enter the name of the drive with a colon, for example

D:

if D is the name of your drive. Then locate your folder like above.)

Finally we enter the command that will tell pdftk to stamp the mask.pdf onto the target.pdf. Enter

pdftk target.pdf multistamp mask.pdf output stamped.pdf

This will create a pdf called stamped.pdf and it should contain everything of your target pdf with the annotations of your mask stamped upon it!

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s