Tuesday, May 28, 2013

Using LaTeX todonotes on a document with small margins

 I'm currently writing my Master's thesis (in LaTeX of course) and have found a nice tool called todonotes. It allows you to insert some snippets inside documents that will remind you of work that is yet to be done. I think they are better than in-document notes (like prepending your notes with a bunch of special characters **!!**) because they really jump in your face, you just cannot ignore them. The author of the todonotes, Henrik Skov Midtiby, has also done a pretty good job in adding interesting features like printing a list of the current todos in your document. Go check it out on CTAN.

 However, if you are working on a custom document like me, your margins may be too small to display the notes correctly. Here is the todonotesexample file set with my margins and todonotes enabled :



 Now that's not very readable. The problem is that I set very small margins for my document. I need to be able to enlarge them without modifying the overall aspect of my document. What we will do is specify a custom document size using the geometry package. This is the code at the head of my document taking care of the formatting :
\setlength{\oddsidemargin}{35mm}
\setlength{\evensidemargin}{35mm}
\setlength{\voffset}{-1in}
\setlength{\hoffset}{-1in}
\setlength{\textwidth}{156mm}
\setlength{\topmargin}{4mm}
\setlength{\headheight}{10mm}
\setlength{\headsep}{12mm}
\setlength{\topskip}{0mm}
\setlength{\textheight}{228mm}
 The margins are too small to display the notes properly, so what we're going to do is define a temporary page size using geometry to artificially enlarge our page since we don't really care what size the page is - it's not going to be printed yet. Add this block before the block of \setlength commands, it will make the page 60 mm wider :
\usepackage[paperwidth=275.9mm, paperheight=279.4mm]{geometry} %regular letter size is 215.9 wide by 279.44 long
 We will also adjust the size of the margin, the even one in this case - adjust the odd margin if that's where you want your todos to be placed! Change the \setlength{\evensidemargin} to become :
\setlength{\evensidemargin}{95mm}
 So we made our right margin eat up all the new space.

 Finally, you also want to adjust the width of your todos to make them a bit larger (especially if your font is big like me - 12 pts), you can do this by modifying or adding the textwidth parameter in your todonotes package import :
\usepackage[colorinlistoftodos, textwidth=65mm, shadow]{todonotes}
 There we go :


Hope this is useful to someone out there! Of course, once your document reaches it's final state you will have to remove the geometry changes and put back your old margin value. I could have written some code that checked the draft mode to set it automatically for you, but I'm not personally a fan of the draft mode since it hides all images in your document.