daily pastebin goal
6%
SHARE
TWEET

Henrik Skov Midtiby

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