0

I'm having some problem creating a new function.

I found in another topic a method to create a watermark on pages, and to make my work easier, I created a function when called, inserts the watermark on my sheets. So far I have this code.

\usepackage{eso-pic}
\usepackage{rotating}
\usepackage{transparent}


\newcommand{\watermark}[1]{
    \AddToShipoutPicture{
    
        \put(0,0){
        
            \parbox[b][\paperheight]{\paperwidth}{
                \vfill
                \centering
            
                {\transparent{0.15}\fontsize{150pt}{1.5pt}\fontfamily{lmtt}\selectfont \begin{turn}{45} \textbf{#1}\end{turn}}
                \vfill}}}
        
    }

However, I want to optimize this command even more, passing through the mandatory command the text to be displayed, and optional parameters the following data: "rotation, transparency and font size". But I don't know how to create a command with all these optional and mandatory parameters.

Thank you in advance.

5
  • 1
    Why not using a specialized package such as draftwatermark?
    – egreg
    Feb 6, 2022 at 10:28
  • 1
    (a) Different ways of defining a macro with parameters: tex.stackexchange.com/questions/266811/… (b) A key=value method is more powerful and flexible; the \newcommand method can have 9 parameters, only the first parameter can be optional (although nesting of \newcommands is possible) (c) In expl3, multiple optional parameters are allowed, but are positional, not named (although named parameters can be coded up in and out of expl3 (there was a TeX.se question about naming parameters so they could be typed in any order)).
    – Cicada
    Feb 7, 2022 at 14:18
  • @egreg I created a new command with draftwatermark package too, but I have this same need. I tried with xwatermark package too, but this one didn't work. Feb 7, 2022 at 14:58
  • @Cicada Its exactly what I need. I found this post, wich explain how to create key=value method. tex.stackexchange.com/questions/34312/…. Feb 7, 2022 at 16:30
  • I suggest using CTAN eso-pic.
    – FHZ
    Mar 9, 2022 at 18:10

1 Answer 1

1

Reading the answer of @Cicada and the link for me sent, I found what I really need. In this link I found a method to create the command with all the parameters. I got this:

\documentclass[a4paper]{article}
\usepackage{keyval}
\usepackage{eso-pic}
\usepackage{rotating}
\usepackage{transparent}

\makeatletter
\define@key{watermark}{fontsize}{\def\wm@fontsize{#1}}
\define@key{watermark}{transparency}{\def\wm@transparency{#1}}
\define@key{watermark}{align}{\def\wm@align{#1}}

\setkeys{watermark}{fontsize=100pt,transparency=0.15,align=45}%
\newcommand{\watermark}[2][]{
    \setkeys{watermark}{#1}
    \AddToShipoutPicture{
        \put(0,0){  
            \parbox[b][\paperheight]{\paperwidth}{
                \vfill
                \centering      
                {\transparent{\wm@transparency}\fontsize{\wm@fontsize}{1.5pt}\fontfamily{lmtt}\selectfont \begin{turn}{\wm@align} \textbf{#2}\end{turn}}
                \vfill}}}
}

\makeatother

\begin{document}
    \watermark{DRAFT}
\end{document}

Thank you very much for the attention.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .