daily pastebin goal
6%
SHARE
TWEET

Henrik Skov Midtiby

a guest Jul 28th, 2008 321 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. % todonotes.sty
  2. % Author: Henrik Skov Midtiby
  3. % Source: Midtiby notes:
  4. %    http://midtiby.blogspot.com/2008/05/updated-todonotes-package.html
  5. % 2007-09-17: Initial release of the code
  6. % 2008-04-17: The first version of the package
  7. % 2008-05-15: Updated the option handling of the package
  8. % 2008-05-16: Slightly modified by Kjell Magne Fauske to support notes
  9. %             in the left margin (for documentstyle book).
  10. % 2008-05-28: Added a missingfigure command
  11. % 2008-06-10: Made a dependency on the calc package
  12. % 2008-07-11: Delayed the requirements for the hyperref package
  13. %             untill \begin{document} and added an optional argument
  14. %             to the todo command for adding inline todonotes (Idea
  15. %             from Patrick Toche)
  16. % 2008-07-15: Added some options to the todo macro (Idea: Patrick
  17. %             Toche) and made the \listoftodos point at the inserted
  18. %             todos and not only the current / previous section,
  19. %             subsection or figure using the \phantomsection macro.
  20. % 2008-07-28: Modified the behaviour of the inline todonotes, to
  21. %             avoid empty lines around the inline todonotes.
  22. %             Added the option colorinlistoftodos which inserts a
  23. %             small box with the used fillcolor of the todonotes in
  24. %             the list of todos.
  25. % ====================
  26. % Part: Identification
  27. % ====================
  28. \ProvidesPackage{todonotes}[2008/07/28]
  29.  
  30.  
  31. % ==============================
  32. % Part: The package loading part
  33. % ==============================
  34. % Loads the packages that todonotes depends on.
  35. \RequirePackage{ifthen}
  36. \RequirePackage{xkeyval}
  37. \RequirePackage{hyperref}
  38. \RequirePackage{xcolor}
  39. %\AtBeginDocument{\RequirePackage{hyperref}}
  40. \RequirePackage{tikz}
  41. \RequirePackage{calc}
  42.  
  43.  
  44.  
  45. % ==================
  46. % Part: Initial code
  47. % ==================
  48. % Here the default values are set
  49. \newcommand{\@backgroundcolor}{orange}
  50. \newcommand{\@bordercolor}{black}
  51. \newcommand{\@textwidth}{\marginparwidth}
  52.  
  53.  
  54. % ================================
  55. % Part: The declaration of options
  56. % ================================
  57. % In this part the various options for
  58. % the package are defined.
  59.  
  60. % Make it possible to disable the functionality
  61. % of the package. If this option is given, the
  62. % commands \todo{} and \listoftodos are defined
  63. % as commands with no effect. (But you can still
  64. % compile you document with these commands).
  65. \newif{\ifdisabled}
  66. \DeclareOptionX{disable}{\disabledtrue}
  67.  
  68. % Show small boxes in the list of todos with the color of the
  69. % inserted todonotes.
  70. \newif{\ifcolorinlistoftodos}
  71. \DeclareOptionX{colorinlistoftodos}{\colorinlistoftodostrue}
  72.  
  73. % The default style behaves bad when compiled
  74. % with latex (some text placement problems).
  75. % The dvistyle option, changes the visual behavior
  76. % to avoid this text placement problem.
  77. \newif{\ifdviStyle}
  78. \DeclareOptionX{dvistyle}{\dviStyletrue}
  79.  
  80. % Make the background color of the notes as
  81. % an option.
  82. \define@key{todonotes.sty}%
  83.         {color}{\renewcommand{\@backgroundcolor}{#1}}
  84.  
  85. % Make the color of the notes box color as
  86. % an option.
  87. \define@key{todonotes.sty}%
  88.         {bordercolor}{\renewcommand{\@bordercolor}{#1}}
  89.  
  90. % Make the text width as an option.
  91. \define@key{todonotes.sty}%
  92.         {textwidth}{\renewcommand{\@textwidth}{#1}}
  93.  
  94. % Finally process the given options.
  95. \ProcessOptionsX
  96.  
  97.  
  98. % ========================
  99. % Part: The main code part
  100. % ========================
  101. \ifdisabled
  102.         % If the option "disable" was passed to the package
  103.         % define two empty commands.
  104.         \newcommand{\listoftodos}{}
  105.         \newcommand{\todo}[2][]{}
  106.         \newcommand{\missingfigure}[1]{}
  107.  
  108. \else % \ifdisabled
  109.  
  110. % Define the list of todos command
  111. \newcommand{\listoftodos}
  112.         {\section*{Todo list} \@starttoc{tdo}}
  113. % Set the appearance of the list of todos
  114. \newcommand{\l@todo}
  115.         {\@dottedtocline{1}{0em}{2.3em}}
  116.  
  117.  
  118. % Define styles used by the todo command
  119. \tikzstyle{notestyle} = [
  120.         draw=\@bordercolor,
  121.         line width=0.5pt,
  122.         text width = \@textwidth - 1.6 ex - 1pt,
  123.         inner sep = 0.8 ex]
  124. \tikzstyle{notestyleleft} = [
  125.         notestyle,
  126.         left]
  127. \tikzstyle{connectstyle} = [
  128.         thick]
  129. \tikzstyle{inlinenotestyle} = [
  130.         notestyle,
  131.         text width=\textwidth - 1.6 ex - 1 pt]
  132.  
  133.  
  134. % Code for handling options to the todo macro
  135. % Set an arbitrarily fill color
  136. \newcommand{\fillcolor}{}%
  137. \define@key{todonotes}{color}{\renewcommand{\fillcolor}{#1}}%
  138.  
  139. % Set a relative font size
  140. \newcommand{\sizecommand}{}%
  141. \define@key{todonotes}{size}{\renewcommand{\sizecommand}{#1}}%
  142.  
  143. % Should the todo item be included in the list of todos?
  144. \newif\ifappendtolistoftodos%
  145. \define@key{todonotes}{list}[]{\appendtolistoftodostrue}%
  146. \define@key{todonotes}{nolist}[]{\appendtolistoftodosfalse}%
  147.  
  148. % Should the todo item be displayed inline?
  149. \newif\ifinlinenote%
  150. \define@key{todonotes}{inline}[]{\inlinenotetrue}%
  151. \define@key{todonotes}{noinline}[]{\inlinenotefalse}%
  152.  
  153. % Should the note in the margin be connected to the insertion point
  154. % in the text??
  155. \newif\ifline%
  156. \define@key{todonotes}{line}[]{\linetrue}%
  157. \define@key{todonotes}{noline}[]{\linefalse}%
  158.  
  159. % Preset values of the options
  160. \presetkeys
  161.         {todonotes}
  162.         {color=\@backgroundcolor, noinline,
  163.         line, list, size=\normalsize}{}%
  164.  
  165.  
  166. % Define the todo command
  167. \newcommand{\todo}[2][]{%
  168. \setkeys{todonotes}{#1}%
  169. % Add to todo list
  170. \ifappendtolistoftodos%
  171.         \phantomsection%
  172.         \ifcolorinlistoftodos%
  173.                 \addcontentsline{tdo}{todo}{\protect{%
  174.                         \colorbox{\fillcolor}{\textcolor{\fillcolor}{\tiny i}} %
  175.                         #2}}%
  176.         \else%
  177.                 \addcontentsline{tdo}{todo}{\protect{#2}}%
  178.         \fi%
  179. \fi%
  180. %
  181. \ifinlinenote%
  182.     {\par\noindent\tikz[remember picture] \draw node[inlinenotestyle, %
  183. fill=\fillcolor] {\sizecommand #2};\par}%
  184. %
  185. % Remember where we are
  186. \begin{tikzpicture}[remember picture, baseline=-0.75ex]%
  187.     \node [coordinate] (inText) {};%
  188. \end{tikzpicture}%
  189. %
  190. % Make the margin par
  191. \marginpar[{% Draw note in left margin
  192. \ifdviStyle%
  193.     % Using dviStyle
  194.     \tikz[remember picture] \draw node[notestyle, fill=\fillcolor] {}; \\ %
  195.     \begin{minipage}{\@textwidth}%
  196.     \sizecommand #2%
  197.     \end{minipage} \\%
  198.     \tikz[remember picture] \draw node[notestyle, fill=\fillcolor] (inNote) {};%
  199.         \ifline%
  200.                 \begin{tikzpicture}[remember picture, overlay]%
  201.                         \draw[connectstyle, draw=\fillcolor]%
  202.                         ([yshift=-0.2cm] inText)%
  203.                         -| ([xshift=0.2cm] inNote.east)%
  204.                         -| (inNote.east);%
  205.                 \end{tikzpicture}%
  206.         \fi%
  207.     % Using normal style (non dviStyle)
  208.     \tikz[remember picture] \draw node[notestyle, fill=\fillcolor]
  209. (inNote) {\sizecommand #2};%
  210.         \ifline%
  211.                 \begin{tikzpicture}[remember picture, overlay]%
  212.                         \draw[connectstyle, draw=\fillcolor]%
  213.                         ([yshift=-0.2cm] inText)%
  214.                         -| ([xshift=0.2cm] inNote.east)%
  215.                         -| (inNote.east);%
  216.                 \end{tikzpicture}%
  217.         \fi%
  218. \fi% Ending \ifdviStyle
  219. }]{% Draw note in right margin
  220. \ifdviStyle%
  221.     % Using dviStyle
  222.     \tikz[remember picture] \draw node[notestyle, fill=\fillcolor] {}; \\ %
  223.     \begin{minipage}{\@textwidth}%
  224.     \sizecommand #2%
  225.     \end{minipage} \\%
  226.     \tikz[remember picture] \draw node[notestyle, fill=\fillcolor] (inNote) {};%
  227.         \ifline%
  228.                 \begin{tikzpicture}[remember picture, overlay]%
  229.                         \draw[connectstyle, draw=\fillcolor]%
  230.                         ([yshift=-0.2cm] inText)%
  231.                         -| ([xshift=-0.2cm] inNote.west)%
  232.                         -| (inNote.west);%
  233.                 \end{tikzpicture}%
  234.         \fi%
  235.     \else%
  236.     % Using normal style (non dviStyle)
  237.     \tikz[remember picture] \draw node[notestyle, fill=\fillcolor]
  238. (inNote) {\sizecommand #2};%
  239.         \ifline%
  240.                 \begin{tikzpicture}[remember picture, overlay]%
  241.                         \draw[connectstyle, draw=\fillcolor]%
  242.                         ([yshift=-0.2cm] inText)%
  243.                         -| ([xshift=-0.2cm] inNote.west)%
  244.                         -| (inNote.west);%
  245.                 \end{tikzpicture}%
  246.         \fi%
  247. \fi% Ending \ifdviStyle
  248. }%
  249. \fi%
  250. }%
  251.  
  252. \newcommand{\missingfigure}[2]{
  253. \addcontentsline{tdo}{todo}{Figure: \protect{#1}}%
  254. \begin{tikzpicture}
  255. \draw[fill=black!40, draw = white, line width=0pt]
  256.         (-3, -2.5) rectangle +(\textwidth, 4cm);
  257. \draw (3, 0) node[right, text width=4cm] {#1};
  258. \draw[red, fill=white, rounded corners = 5pt, line width=10pt]
  259.         (30:2cm) -- (150:2cm) -- (270:2cm) -- cycle;
  260. \draw (0, 0.3) node {Missing};
  261. \draw (0, -0.3) node {figure};
  262. \end{tikzpicture}
  263. }% Ending \missingfigure command
  264. \fi % Ending \ifdisabled
RAW Paste Data
Top