Guest User

Untitled

a guest
Mar 5th, 2023
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.83 KB | None | 0 0
  1. \documentclass{beamer}
  2. \usepackage{soulutf8}
  3. \usepackage{atbegshi}
  4. \usepackage{etoolbox}
  5. \usepackage{tikz}
  6. \usetikzlibrary{tikzmark,calc,decorations.pathmorphing}
  7.  
  8.  
  9. \colorlet{tdcolor}{gray!50}
  10.  
  11. \newlength{\LineWidth}
  12. \setlength{\LineWidth}{0.7pt}
  13.  
  14. \newlength{\CornerRadius}
  15. \setlength{\CornerRadius}{5pt}
  16.  
  17. \newlength{\BorderDispl}
  18. \setlength{\BorderDispl}{2pt}
  19.  
  20. \makeatletter
  21.  
  22. \newlength{\txtdec@depth}
  23. \setlength{\txtdec@depth}{.45ex}
  24. \newlength{\txtdec@height}
  25. \setlength{\txtdec@height}{\f@size pt} % sensible default
  26.  
  27. \newcounter{txtdec@hyphmark}
  28. \newcounter{txtdec@decormark}
  29. \newcounter{txtdec@hyphdraw}
  30. \setcounter{txtdec@hyphdraw}{1}
  31. \newcounter{txtdec@decordraw}
  32. \setcounter{txtdec@decordraw}{1}
  33.  
  34. \newcounter{txtdec@thenextpage}
  35.  
  36. \newtoggle{txtdec@unfinisheddecor}
  37. \newtoggle{txtdec@stayonpage}
  38. \newtoggle{txtdec@stayondecor}
  39. \newtoggle{txtdec@stayonline}
  40.  
  41. % from https://tex.stackexchange.com/a/33765/105447
  42. \newcommand{\gettikzxy}[3]{%
  43. \tikz@scan@one@point\pgfutil@firstofone#1\relax
  44. \edef#2{\the\pgf@x}%
  45. \edef#3{\the\pgf@y}%
  46. }
  47.  
  48. % the drawing macros
  49.  
  50. \newcommand{\txtdec@draw@all}{%
  51. \draw[tdcolor, line width=\LineWidth, rounded corners=\CornerRadius] ($(\Xbegin,\Ybegin)+(-\BorderDispl,-\txtdec@depth)$) rectangle ($(\Xend,\Yend)+(\BorderDispl,\txtdec@height-\txtdec@depth)$) ;
  52. }
  53.  
  54. \newcommand{\txtdec@draw@begin}{%
  55. \draw[tdcolor, line width=\LineWidth, rounded corners=\CornerRadius]
  56. ($(\Xlineend,\Ylineend)+(0,\txtdec@height-\txtdec@depth)$) --
  57. ($(\Xbegin,\Ybegin)+(-\BorderDispl,\txtdec@height-\txtdec@depth)$) --
  58. ($(\Xbegin,\Ybegin)+(-\BorderDispl,-\txtdec@depth)$) --
  59. ($(\Xlineend,\Ylineend)+(0,-\txtdec@depth)$) ;
  60. }
  61.  
  62. \newcommand{\txtdec@draw@middle}{%
  63. \draw[tdcolor, line width=\LineWidth] ($(\Xlinebegin,\Ylinebegin)+(0,-\txtdec@depth)$) -- ($(\Xlineend,\Ylineend)+(0,-\txtdec@depth)$) ;
  64. \draw[tdcolor, line width=\LineWidth] ($(\Xlinebegin,\Ylinebegin)+(0,\txtdec@height-\txtdec@depth)$) -- ($(\Xlineend,\Ylineend)+(0,\txtdec@height-\txtdec@depth)$) ;
  65. }
  66.  
  67. \newcommand{\txtdec@draw@end}{%
  68. \draw[tdcolor, line width=\LineWidth, rounded corners=\CornerRadius]
  69. ($(\Xlinebegin,\Ylinebegin)+(0,\txtdec@height-\txtdec@depth)$) --
  70. ($(\Xend,\Yend)+(\BorderDispl,\txtdec@height-\txtdec@depth)$) --
  71. ($(\Xend,\Yend)+(\BorderDispl,-\txtdec@depth)$) --
  72. ($(\Xlinebegin,\Ylinebegin)+(0,-\txtdec@depth)$) ;
  73. }
  74.  
  75. % using soul to set tikzmarks
  76.  
  77. \def\SOUL@tdleaders{%
  78. \stepcounter{txtdec@hyphmark}%
  79. \tikzmark{p\thepage.d\arabic{txtdec@decormark}.\arabic{txtdec@hyphmark}}%
  80. \leaders\hrule\@depth\z@\@height\z@\relax
  81. }
  82.  
  83. \def\SOUL@tdunderline#1{{%
  84. \setbox\z@\hbox{#1}%
  85. \dimen@=\wd\z@
  86. \dimen@i=\SOUL@uloverlap
  87. \advance\dimen@2\dimen@i
  88. \rlap{%
  89. \null
  90. \kern-\dimen@i
  91. \SOUL@ulcolor{\SOUL@tdleaders\hskip\dimen@}%
  92. \hskip\dimen@
  93. }%
  94. \unhcopy\z@
  95. }}
  96.  
  97. \def\SOUL@tdpreamble{%
  98. \spaceskip\SOUL@spaceskip
  99. \stepcounter{txtdec@decormark}%
  100. \setcounter{txtdec@hyphmark}{0}%
  101. \tikzmark{p\thepage.d\arabic{txtdec@decormark}.begin}%
  102. }
  103. \def\SOUL@tdeverysyllable{%
  104. \SOUL@tdunderline{%
  105. \the\SOUL@syllable
  106. \SOUL@setkern\SOUL@charkern
  107. }%
  108. \stepcounter{txtdec@hyphmark}%
  109. \tikzmark{p\thepage.d\arabic{txtdec@decormark}.\arabic{txtdec@hyphmark}}%
  110. }
  111. \def\SOUL@tdeveryhyphen{%
  112. \discretionary{%
  113. \unkern
  114. \SOUL@tdunderline{%
  115. \SOUL@setkern\SOUL@hyphkern
  116. \SOUL@sethyphenchar
  117. }%
  118. \stepcounter{txtdec@hyphmark}%
  119. \tikzmark{p\thepage.d\arabic{txtdec@decormark}.\arabic{txtdec@hyphmark}}%
  120. }{}{}%
  121. }
  122. \def\SOUL@tdeveryexhyphen#1{%
  123. \SOUL@setkern\SOUL@hyphkern
  124. \SOUL@tdunderline{#1}%
  125. \stepcounter{txtdec@hyphmark}%
  126. \tikzmark{p\thepage.d\arabic{txtdec@decormark}.\arabic{txtdec@hyphmark}}%
  127. \discretionary{}{}{%
  128. \SOUL@setkern\SOUL@charkern
  129. }%
  130. }
  131. \def\SOUL@tdpostamble{%
  132. % create an extra mark, vertically displaced, to create an exit condition for the last line
  133. \stepcounter{txtdec@hyphmark}%
  134. \raisebox{-5pt}{\tikzmark{p\thepage.d\arabic{txtdec@decormark}.\arabic{txtdec@hyphmark}}}%
  135. \tikzmark{p\thepage.d\arabic{txtdec@decormark}.end}%
  136. }
  137. \def\SOUL@tdsetup{%
  138. \SOUL@setup
  139. \let\SOUL@preamble\SOUL@tdpreamble
  140. \let\SOUL@everysyllable\SOUL@tdeverysyllable
  141. \let\SOUL@everyhyphen\SOUL@tdeveryhyphen
  142. \let\SOUL@everyexhyphen\SOUL@tdeveryexhyphen
  143. \let\SOUL@postamble\SOUL@tdpostamble
  144. }
  145. \DeclareRobustCommand*\textdecor{\SOUL@tdsetup\SOUL@}
  146.  
  147. % get the drawing done AtBeginShipout
  148.  
  149. \AtBeginShipout{%
  150. \AtBeginShipoutUpperLeft{%
  151. % getting the number of the next page
  152. \setcounter{txtdec@thenextpage}{\thepage}%
  153. \stepcounter{txtdec@thenextpage}%
  154. % if the current decoration occurs on this page, stay on it
  155. \iftikzmark{p\thepage.d\arabic{txtdec@decordraw}.\arabic{txtdec@hyphdraw}}{%
  156. \toggletrue{txtdec@stayonpage}}{}%
  157. \whileboolexpr{togl {txtdec@stayonpage}}{%
  158. \begin{tikzpicture}[remember picture, overlay]
  159. \setlength{\txtdec@height}{\f@size pt}%
  160. \iftikzmark{p\thepage.d\arabic{txtdec@decordraw}.begin}{%
  161. % if current decor begins in current page, get coordinates
  162. \gettikzxy{(pic cs:p\thepage.d\arabic{txtdec@decordraw}.begin)}{\Xbegin}{\Ybegin}}{%
  163. % if current decor begins in previous page, set to top left of the page
  164. \gettikzxy{(current page.north west)}{\Xbegin}{\Ybegin}}%
  165. \iftikzmark{p\thepage.d\arabic{txtdec@decordraw}.end}{%
  166. % if current decor ends in current page, get coordinates
  167. \gettikzxy{(pic cs:p\thepage.d\arabic{txtdec@decordraw}.end)}{\Xend}{\Yend}}{%
  168. % if current decor ends in future page, set to bottom right of the page
  169. \gettikzxy{(current page.south east)}{\Xend}{\Yend}}%
  170. \ifdim\Ybegin=\Yend % the simplest case, a single line
  171. \txtdec@draw@all
  172. \stepcounter{txtdec@decordraw}%
  173. \else % current textdecor has a line break
  174. \toggletrue{txtdec@stayondecor}%
  175. \whileboolexpr{togl {txtdec@stayondecor}}{%
  176. \gettikzxy{(pic cs:p\thepage.d\arabic{txtdec@decordraw}.\arabic{txtdec@hyphdraw})}{\Xlinebegin}{\Ylinebegin}%
  177. \edef\Xcurrent{\Xlinebegin}%
  178. \edef\Ycurrent{\Ylinebegin}%
  179. \edef\Xnext{\Xcurrent}%
  180. \edef\Ynext{\Ycurrent}%
  181. \toggletrue{txtdec@stayonline}%
  182. \whileboolexpr{togl {txtdec@stayonline}}{%
  183. \ifdim\Ycurrent=\Ynext
  184. \stepcounter{txtdec@hyphdraw}%
  185. % if the following tikzmark exists, we are at a page break
  186. \iftikzmark{p\arabic{txtdec@thenextpage}.d\arabic{txtdec@decordraw}.\arabic{txtdec@hyphdraw}}{%
  187. \edef\Xcurrent{\Xnext}%
  188. \edef\Ycurrent{\Ynext}%
  189. \gettikzxy{(current page.south east)}{\Xnext}{\Ynext}
  190. \togglefalse{txtdec@stayondecor}%
  191. }{% else, we remain on the same page
  192. \iftikzmark{p\thepage.d\arabic{txtdec@decordraw}.\arabic{txtdec@hyphdraw}}{%
  193. \edef\Xcurrent{\Xnext}%
  194. \edef\Ycurrent{\Ynext}%
  195. \gettikzxy{(pic cs:p\thepage.d\arabic{txtdec@decordraw}.\arabic{txtdec@hyphdraw})}{\Xnext}{\Ynext}}{}%
  196. }%
  197. \else
  198. \edef\Xlineend{\Xcurrent}%
  199. \edef\Ylineend{\Ycurrent}%
  200. % if we are on the first line of the current decoration
  201. \ifdim\Ylinebegin=\Ybegin
  202. \txtdec@draw@begin
  203. \else
  204. % if we are on the last line of the current decoration
  205. \ifdim\Ycurrent=\Yend
  206. \txtdec@draw@end
  207. \stepcounter{txtdec@decordraw}%
  208. \setcounter{txtdec@hyphdraw}{1}%
  209. \togglefalse{txtdec@stayondecor}%
  210. % if we are in a middle line of the decoration
  211. \else
  212. \txtdec@draw@middle
  213. \fi
  214. \fi
  215. \togglefalse{txtdec@stayonline}%
  216. \fi
  217. }%
  218. }%
  219. \fi
  220. \end{tikzpicture}%
  221. % if the beginning of the next decor does not exist in this page, leave this page
  222. \iftikzmark{p\thepage.d\arabic{txtdec@decordraw}.begin}{}{%
  223. \togglefalse{txtdec@stayonpage}}%
  224. % if the continuation of the current decor exists in the next page, leave this page
  225. \iftikzmark{p\arabic{txtdec@thenextpage}.d\arabic{txtdec@decordraw}.\arabic{txtdec@hyphdraw}}{%
  226. \togglefalse{txtdec@stayonpage}}{}%
  227. }%
  228. }%
  229. }
  230.  
  231. \makeatother
  232.  
  233. \begin{document}
  234.  
  235. \begin{frame}[fragile]{x}
  236. Lorem ipsum \textdecor{dolor sit amet, consectetuer adipiscing}
  237. elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae.\newline
  238. Beamer version: 3.69, Ti\textit{k}Z version 3.1.10
  239. \end{frame}
  240. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment