1

Two watermark prints need to be put at different places of the same page. One at lower left corner, the other at page center. To do this, macros \AtPageLowerLeft and \AtAtPageCenter from package eso-pic are used. I want to set the origin of coordinate in accordance with conditions. So another macro \position is introduced by \let. But this causes the former watermark print at a wrong place, please see the code for details:

\documentclass[12pt,a4paper]{article}
\usepackage{eso-pic}

\begin{document}
\null
\let\position\AtPageCenter
    \AddToShipoutPictureBG{%
        \position{%
            \put(0,0){paper center waterprint}
        }
    }
%
\let\position\AtPageLowerLeft
    \AddToShipoutPictureBG{%
        \position{%
            \put(20,20){lower left waterprint}
        }
    }   
\end{document}

You can see that both watermark prints are located at lower left corner of the page.

enter image description here

Can anyone tell me the reason?

  • The text is inserted at shipout, when the page is written, at this time \position has the second meaning. Btw: Edit your question and correct some of the errors, "Marcos" instead of "macros" looks quite odd. – Ulrike Fischer Aug 19 '17 at 12:36
  • So, is there a solution to block \position from changing until the former waterprint is finished? – lyl Aug 19 '17 at 14:08
  • 1
    I don't know as I don't understand what you are trying to achieve and why you can't simply write \AtPageCenter and \AtPageLowerLeft instead of \position. – Ulrike Fischer Aug 19 '17 at 14:14
  • I need to construct a marco in which the position of origin of coordinate is a argument,for example, \mywaterpint{ll} will typeset a waterprint based on the lower left corner of the page, and \mywaterpint{pc} will typeset a waterprint based on the pape center. If I call \mywaterprint{pc}, then \mywaterprint{ll} at the same page, both waterprints are located on the lower left corner of the page. So, could you help me with this problem? Thank you. – lyl Aug 19 '17 at 14:25
  • With your last comment, this seems to be a xy-problem. Please edit your question to ask what you want (and what have been answered by Ulrike). – Schweinebacke Aug 19 '17 at 14:50
3

To answer the question in the comment. You can can e.g. do something like this:

\documentclass[12pt,a4paper]{article}
\usepackage{eso-pic}

\makeatletter
\let\mypackage@esopicposition@pc\AtPageCenter
\newcommand\mypackage@waterprint@pc{\put(0,0){paper center waterprint}}

\let\mypackage@esopicposition@ll\AtPageLowerLeft
\newcommand\mypackage@waterprint@ll{\put(20,20){paper left waterprint}}


\newcommand\mywaterprint[1]{%
  \AddToShipoutPictureBG{%
        \csname mypackage@esopicposition@#1\endcsname {%
            \csname mypackage@waterprint@#1\endcsname 
        }
    }}

\makeatother
\begin{document}
\null
\mywaterprint{pc}

\mywaterprint{ll}
\end{document}

As you are so allergic against an @ in a command name here a version without them:

\documentclass[12pt,a4paper]{article}
\usepackage{eso-pic}


\let\mypackageXesopicpositionXpc\AtPageCenter
\newcommand\mypackageXwaterprintXpc{\put(0,0){paper center waterprint}}

\let\mypackageXesopicpositionXll\AtPageLowerLeft
\newcommand\mypackageXwaterprintXll{\put(20,20){paper left waterprint}}


\newcommand\mywaterprint[1]{%
  \AddToShipoutPictureBG{%
        \csname mypackageXesopicpositionX#1\endcsname {%
            \csname mypackageXwaterprintX#1\endcsname
        }
    }}


\begin{document}
\null
\mywaterprint{pc}

\mywaterprint{ll}
\end{document}
  • Many thanks for your solution. And, is the mechanism "makeatletter...\makeatother" mandatory, I mean, can I have a version of Latex without this mechanism? – lyl Aug 19 '17 at 14:50
  • Sure you can. But that you can't use a @ in the internal command names. – Ulrike Fischer Aug 19 '17 at 14:54
  • Can I understand your soluntion like this: changing my marco name "\positon" with a internal command(use @, like \@position) will prevent from being set to the second meaning while the second call of it occurs? If no internal commands are used, how to achieve the function I want by pure Latex? Thank you – lyl Aug 19 '17 at 15:12
  • If you don't like the @ then replace the mypackage@esopicposition@pc by mypackageXesopicpositionXpc. It doesn't matter. The @ is nothing special, only a very mild protection against overwriting. – Ulrike Fischer Aug 19 '17 at 15:23
  • Thank you. But if I "replace the mypackage@esopicposition@pc by mypackageXesopicpositionXpc", what's the difference between "\let\mypackageXesopicpositionXpc\AtPageCenter" and my "\let\position\AtPageCenter"? – lyl Aug 19 '17 at 15:46
1
\documentclass[12pt,a4paper]{article}
\usepackage{eso-pic}
\newcommand\myWaterprint[1][C]{%
    \AddToShipoutPictureBG{%
      \ifx#1C
        \AtPageCenter{\put(0,0){paper center waterprint}}%
      \else
        \AtPageLowerLeft{\put(20,20){lower left waterprint}}%   
      \fi}}    
\begin{document}
\null
\myWaterprint% default is [C]

\myWaterprint[L]

\end{document}
  • This is a good cue to my question. Thank you!! – lyl Aug 19 '17 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.