{"id":16,"date":"2010-01-23T14:40:36","date_gmt":"2010-01-23T22:40:36","guid":{"rendered":"http:\/\/patternweaver.com\/blog\/?p=16"},"modified":"2011-12-19T18:32:15","modified_gmt":"2011-12-19T18:32:15","slug":"xelatex-watermarking-environment-macro","status":"publish","type":"post","link":"http:\/\/patternweaver.com\/blog\/2010\/01\/xelatex-watermarking-environment-macro\/","title":{"rendered":"XeLaTeX watermarking environment macro"},"content":{"rendered":"<p>I&#8217;m totally enjoying my switch from LaTeX to XeLaTeX, with all of the added benefits that entails. Over the years I&#8217;ve cobbled together and built a number of helpful macros so this will be my first of many posts to share them. Some may not be XeLaTeX specific, but as that&#8217;s the environment I use, many of them will not be fully LaTeX compatible.<\/p>\n<p>The first entry is a simple watermarking system, it&#8217;s a slight modification of a script from <a href=\"http:\/\/www.blogger.com\/profile\/07052058313681392060\">Filox<\/a>, an environment throughout which each page receives a watermark. just create a file named &#8216;watermark .png&#8217;, and put the macro in a file named &#8216;watermark.sty&#8217;.<\/p>\n<script src=\"https:\/\/gist.github.com\/1498296.js?file=watermark.tex\"><\/script><noscript><pre><code class=\"language-tex tex\">\\usepackage{everypage}\n\n\\newenvironment{water}{\\AddEverypageHook{\\waterb}}{\n    \\AddThispageHook{\\waterb}\\AddEverypageHook{\\watere}\n}\n\n\\makeatletter\n\\newcommand{\\waterb}{\n\\AddToShipoutPicture*{%\n            \\setlength{\\@tempdimb}{.3\\paperwidth}%\n            \\setlength{\\@tempdimc}{.4\\paperheight}%\n            \\setlength{\\unitlength}{1pt}%\n            \\put(\\strip@pt\\@tempdimb,\\strip@pt\\@tempdimc){%\n        \\includegraphics[height=100mm]{watermark.png}\n            }%\n}}\n\\makeatother\n\n\\makeatletter\n\\newcommand{\\watere}{\n\\AddToShipoutPicture*{%\n            \\setlength{\\@tempdimb}{.3\\paperwidth}%\n            \\setlength{\\@tempdimc}{.4\\paperheight}%\n            \\setlength{\\unitlength}{1pt}%\n            \\put(\\strip@pt\\@tempdimb,\\strip@pt\\@tempdimc){%\n        \\includegraphics[height=100mm]{watermark.png}\n            }%\n}}\n\\makeatother\n<\/code><\/pre><\/noscript>\n<p>Now I want another type of draft watermark I can use when circulating incomplete documents, so I alter that to put &#8216;DRAFT&#8217; diagonally across the background. I put this into a file called &#8216;draft_watermark.sty&#8217;.<\/p>\n<script src=\"https:\/\/gist.github.com\/1498296.js?file=draft_watermark.tex\"><\/script><noscript><pre><code class=\"language-tex tex\">\\usepackage{everypage}\n\n\\newenvironment{water}{\\AddEverypageHook{\\waterb}}{\n    \\AddThispageHook{\\waterb}\\AddEverypageHook{\\watere}\n}\n\n\\makeatletter\n\\newcommand{\\waterb}{\n\\AddToShipoutPicture*{%\n            \\setlength{\\@tempdimb}{.5\\paperwidth}%\n            \\setlength{\\@tempdimc}{.5\\paperheight}%\n            \\setlength{\\unitlength}{1pt}%\n            \\put(\\strip@pt\\@tempdimb,\\strip@pt\\@tempdimc){%\n        \\makebox(0,0){\\rotatebox{45}{\\textcolor[gray]{0.75}%\n        {\\fontsize{6cm}{6cm}\\selectfont{DRAFT}}}}%\n            }%\n}}\n\\makeatother\n\n\\makeatletter\n\\newcommand{\\watere}{\n\\AddToShipoutPicture*{%\n            \\setlength{\\@tempdimb}{.5\\paperwidth}%\n            \\setlength{\\@tempdimc}{.5\\paperheight}%\n            \\setlength{\\unitlength}{1pt}%\n            \\put(\\strip@pt\\@tempdimb,\\strip@pt\\@tempdimc){%\n        \\makebox(0,0){\\rotatebox{45}{\\textcolor[gray]{1}%\n        {\\fontsize{6cm}{6cm}\\selectfont{DRAFT}}}}%\n            }%\n}}\n\\makeatother<\/code><\/pre><\/noscript>\n<p>and now I can switch between the two identical environments by simply switching which style file is included, and I open and close the environment simple using the following syntax:<\/p>\n<script src=\"https:\/\/gist.github.com\/1498296.js?file=watermark_usage.tex\"><\/script><noscript><pre><code class=\"language-tex tex\">\\begin{water}\n    % watermarked pages here\n\\end{water}<\/code><\/pre><\/noscript>\n<p>It&#8217;s a little hacky in the way it works, but I&#8217;ve used it without issue for quite a while. Enjoy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m totally enjoying my switch from LaTeX to XeLaTeX, with all of the added benefits that entails. Over the years I&#8217;ve cobbled together and built a number of helpful macros so this will be my first of many posts to share them. Some may not be XeLaTeX specific, but as that&#8217;s the environment I use, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-16","post","type-post","status-publish","format-standard","hentry","category-xelatex"],"_links":{"self":[{"href":"http:\/\/patternweaver.com\/blog\/wp-json\/wp\/v2\/posts\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/patternweaver.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/patternweaver.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/patternweaver.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/patternweaver.com\/blog\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":0,"href":"http:\/\/patternweaver.com\/blog\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"wp:attachment":[{"href":"http:\/\/patternweaver.com\/blog\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/patternweaver.com\/blog\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/patternweaver.com\/blog\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}