Advertisement
Guest User

Henrik Skov Midtiby

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