Advertisement
Guest User

Henrik Skov Midtiby

a guest
Jul 28th, 2008
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 8.14 KB | None | 0 0
  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. \else%
  185. %
  186. % Remember where we are
  187. \begin{tikzpicture}[remember picture, baseline=-0.75ex]%
  188.     \node [coordinate] (inText) {};%
  189. \end{tikzpicture}%
  190. %
  191. % Make the margin par
  192. \marginpar[{% Draw note in left margin
  193. \ifdviStyle%
  194.     % Using dviStyle
  195.     \tikz[remember picture] \draw node[notestyle, fill=\fillcolor] {}; \\ %
  196.     \begin{minipage}{\@textwidth}%
  197.     \sizecommand #2%
  198.     \end{minipage} \\%
  199.    \tikz[remember picture] \draw node[notestyle, fill=\fillcolor] (inNote) {};%
  200.     \ifline%
  201.         \begin{tikzpicture}[remember picture, overlay]%
  202.             \draw[connectstyle, draw=\fillcolor]%
  203.             ([yshift=-0.2cm] inText)%
  204.             -| ([xshift=0.2cm] inNote.east)%
  205.             -| (inNote.east);%
  206.         \end{tikzpicture}%
  207.     \fi%
  208. \else%
  209.     % Using normal style (non dviStyle)
  210.     \tikz[remember picture] \draw node[notestyle, fill=\fillcolor]
  211. (inNote) {\sizecommand #2};%
  212.     \ifline%
  213.         \begin{tikzpicture}[remember picture, overlay]%
  214.             \draw[connectstyle, draw=\fillcolor]%
  215.             ([yshift=-0.2cm] inText)%
  216.             -| ([xshift=0.2cm] inNote.east)%
  217.             -| (inNote.east);%
  218.         \end{tikzpicture}%
  219.     \fi%
  220. \fi% Ending \ifdviStyle
  221. }]{% Draw note in right margin
  222. \ifdviStyle%
  223.     % Using dviStyle
  224.     \tikz[remember picture] \draw node[notestyle, fill=\fillcolor] {}; \\ %
  225.     \begin{minipage}{\@textwidth}%
  226.     \sizecommand #2%
  227.     \end{minipage} \\%
  228.    \tikz[remember picture] \draw node[notestyle, fill=\fillcolor] (inNote) {};%
  229.     \ifline%
  230.         \begin{tikzpicture}[remember picture, overlay]%
  231.             \draw[connectstyle, draw=\fillcolor]%
  232.             ([yshift=-0.2cm] inText)%
  233.             -| ([xshift=-0.2cm] inNote.west)%
  234.             -| (inNote.west);%
  235.         \end{tikzpicture}%
  236.     \fi%
  237.     \else%
  238.     % Using normal style (non dviStyle)
  239.     \tikz[remember picture] \draw node[notestyle, fill=\fillcolor]
  240. (inNote) {\sizecommand #2};%
  241.     \ifline%
  242.         \begin{tikzpicture}[remember picture, overlay]%
  243.             \draw[connectstyle, draw=\fillcolor]%
  244.             ([yshift=-0.2cm] inText)%
  245.             -| ([xshift=-0.2cm] inNote.west)%
  246.             -| (inNote.west);%
  247.         \end{tikzpicture}%
  248.     \fi%
  249. \fi% Ending \ifdviStyle
  250. }%
  251. \fi%
  252. }%
  253.  
  254. \newcommand{\missingfigure}[2]{
  255. \addcontentsline{tdo}{todo}{Figure: \protect{#1}}%
  256. \begin{tikzpicture}
  257. \draw[fill=black!40, draw = white, line width=0pt]
  258.     (-3, -2.5) rectangle +(\textwidth, 4cm);
  259. \draw (3, 0) node[right, text width=4cm] {#1};
  260. \draw[red, fill=white, rounded corners = 5pt, line width=10pt]
  261.     (30:2cm) -- (150:2cm) -- (270:2cm) -- cycle;
  262. \draw (0, 0.3) node {Missing};
  263. \draw (0, -0.3) node {figure};
  264. \end{tikzpicture}
  265. }% Ending \missingfigure command
  266. \fi % Ending \ifdisabled
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement