Definitions.tex 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. \usepackage{tikz}
  2. \usetikzlibrary{calc}
  3. \usepackage{xcolor}
  4. \makeatletter
  5. % to change colors
  6. \newcommand{\fillcol}{green!20}
  7. \newcommand{\bordercol}{black}
  8. % code from Andrew Stacey (with small adjustment to the border color)
  9. % http://tex.stackexchange.com/questions/51582/background-coloring-with-overlay-specification-in-algorithm2e-beamer-package
  10. \newcounter{jumping}
  11. \resetcounteronoverlays{jumping}
  12. \def\jump@setbb#1#2#3{%
  13. \@ifundefined{jump@#1@maxbb}{%
  14. \expandafter\gdef\csname jump@#1@maxbb\endcsname{#3}%
  15. }{%
  16. \csname jump@#1@maxbb\endcsname
  17. \pgf@xa=\pgf@x
  18. \pgf@ya=\pgf@y
  19. #3
  20. \pgfmathsetlength\pgf@x{max(\pgf@x,\pgf@xa)}%
  21. \pgfmathsetlength\pgf@y{max(\pgf@y,\pgf@ya)}%
  22. \expandafter\xdef\csname jump@#1@maxbb\endcsname{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
  23. }
  24. \@ifundefined{jump@#1@minbb}{%
  25. \expandafter\gdef\csname jump@#1@minbb\endcsname{#2}%
  26. }{%
  27. \csname jump@#1@minbb\endcsname
  28. \pgf@xa=\pgf@x
  29. \pgf@ya=\pgf@y
  30. #2
  31. \pgfmathsetlength\pgf@x{min(\pgf@x,\pgf@xa)}%
  32. \pgfmathsetlength\pgf@y{min(\pgf@y,\pgf@ya)}%
  33. \expandafter\xdef\csname jump@#1@minbb\endcsname{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
  34. }
  35. }
  36. \tikzset{%
  37. remember picture with id/.style={%
  38. remember picture,
  39. overlay,
  40. draw=\bordercol,
  41. save picture id=#1,
  42. },
  43. save picture id/.code={%
  44. \edef\pgf@temp{#1}%
  45. \immediate\write\pgfutil@auxout{%
  46. \noexpand\savepointas{\pgf@temp}{\pgfpictureid}}%
  47. },
  48. if picture id/.code args={#1#2#3}{%
  49. \@ifundefined{save@pt@#1}{%
  50. \pgfkeysalso{#3}%
  51. }{
  52. \pgfkeysalso{#2}%
  53. }
  54. },
  55. onslide/.code args={<#1>#2}{%
  56. \only<#1>{\pgfkeysalso{#2}}%
  57. },
  58. alt/.code args={<#1>#2#3}{%
  59. \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}%
  60. },
  61. stop jumping/.style={
  62. execute at end picture={%
  63. \stepcounter{jumping}%
  64. \immediate\write\pgfutil@auxout{%
  65. \noexpand\jump@setbb{\the\value{jumping}}{\noexpand\pgfpoint{\the\pgf@picminx}{\the\pgf@picminy}}{\noexpand\pgfpoint{\the\pgf@picmaxx}{\the\pgf@picmaxy}}
  66. },
  67. \csname jump@\the\value{jumping}@maxbb\endcsname
  68. \path (\the\pgf@x,\the\pgf@y);
  69. \csname jump@\the\value{jumping}@minbb\endcsname
  70. \path (\the\pgf@x,\the\pgf@y);
  71. },
  72. }
  73. }
  74. \def\savepointas#1#2{%
  75. \expandafter\gdef\csname save@pt@#1\endcsname{#2}%
  76. }
  77. \def\tmk@labeldef#1,#2\@nil{%
  78. \def\tmk@label{#1}%
  79. \def\tmk@def{#2}%
  80. }
  81. \tikzdeclarecoordinatesystem{pic}{%
  82. \pgfutil@in@,{#1}%
  83. \ifpgfutil@in@%
  84. \tmk@labeldef#1\@nil
  85. \else
  86. \tmk@labeldef#1,\pgfpointorigin\@nil
  87. \fi
  88. \@ifundefined{save@pt@\tmk@label}{%
  89. \tikz@scan@one@point\pgfutil@firstofone\tmk@def
  90. }{%
  91. \pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
  92. \pgfsys@getposition{\pgfpictureid}\save@this@pic%
  93. \pgf@process{\pgfpointorigin\save@this@pic}%
  94. \pgf@xa=\pgf@x
  95. \pgf@ya=\pgf@y
  96. \pgf@process{\pgfpointorigin\save@orig@pic}%
  97. \advance\pgf@x by -\pgf@xa
  98. \advance\pgf@y by -\pgf@ya
  99. }%
  100. }
  101. \newcommand\tikzmark[2][]{%
  102. \tikz[remember picture with id=#2] #1;}
  103. \makeatother
  104. \resetcounteronoverlays{algocf}
  105. \newcommand<>{\boxto}[1]{%
  106. \only#2{\tikz[remember picture with id=#1]
  107. \draw[line width=1pt,fill=\fillcol,rectangle,rounded corners]
  108. (pic cs:#1) ++(5.2,-.1) rectangle (-0.4,0)
  109. ;\tikz\node [anchor=base] (#1){};}% <= insertion to store the anchor to be used as based for the annotation
  110. }