# In ConTeXt, how to make leftpage/rightpage arguments of setupbackgrounds work properly?

My goal is to set a background to my document containing both a tiled image and a watermark. The watermark must be different on odd and even pages.

When I use `page` as `setupbackgrounds` first argument, I do have both the background image and the watermark on all pages (but of course the same watermark on all pages), i.e. everything work as I expect, but this is not the result I try to achieve.

However, if I instead use `leftpage` or `rightpage` (as a first step toward my goal to differentiate between odd and even pages), I loose both the image and the watermark on ALL pages : in other words, the layer is not applied anywhere anymore.

Here is a minimal (non)working example:

``````% Document main configuration
\setuppapersize[A4]                             % document page size
\setupbodyfont[10pt]                            % document default font size

% --- Font families definitions ---
\definefontfamily[myfont][serif][myfontname]

% --- Document Background ---
\define\mybgimg                                 % macro for background image code
{\backgroundimage{1}                        % - 1 = tiled along x & y
{\paperwidth}{\paperheight}             % - set width and height of the addition
{\externalfigure[bg.jpg]}}              % - addition of a bg image

\define[1]\mywatermarkformat{{                  % macro to format the watermark
\switchtobodyfont[myfont]                   % - set font family
\switchtobodyfont[105pt]                    % - set font size
\color[red]{#1}                             % - set color to text argument
}}

\definelayer[mybglayer]                         % define and name new layer for the bg
[x=0mm, y=0mm,                              % - from upper left corner of paper
width=\paperwidth, height=\paperheight,     % - let the layer cover the full paper
repeat=yes%                                 % - layer on all pages
]
\setlayer[mybglayer]{\mybgimg}                  % fill layer with bg image
\setlayer[mybglayer]                            % fill layer with watermark
[hoffset=0cm, voffset=23cm]                 % - placement from layer upper left corner
{\mywatermarkformat{foobar}}                % - watermark text

\setupbackgrounds[page][background=mybglayer]  % <--- OK : place the layer on all pages
% OR
\setupbackgrounds[leftpage][background=mybglayer]% <---- NOT OK : place nothing at all

% --- Document Content ---
\starttext
\input knuth
\page
\input knuth
\page
\input knuth
\page
\input knuth
\stoptext
``````

I'm a beginner with ConTeXt, so please do not hesitate to tell me if, independantly of the main question, you can see some dubious constructs in the code.

• The background for a left page is only placed in a double sided document (`\setuppapegnumbering[alternative=doublesided]`) but your document is single sided with right pages only. – Wolfgang Schuster Dec 8 '17 at 11:57
• Ok, adding the correct page numbering alternative indeed solves the issue. – Silverspur Dec 8 '17 at 13:43

You have to set the document to doublesided. You should also take better care of spurious spaces.

``````\setuppapersize[A4]
\setuppagenumbering[alternative=doublesided]

\definefontfamily[myfont][serif][TeX Gyre Pagella]
\setupbodyfont[modern,10pt]

\define\mybgimg
{\backgroundimage{1}%
{\paperwidth}{\paperheight}%
{\externalfigure[cow]}}

\define[1]\mywatermarkformat
{{\switchtobodyfont[myfont,105pt]\color[red]{#1}}}

\definelayer
[page]
[width=\paperwidth,
height=\paperheight,
repeat=yes]

\definelayer[rightlayer][page]
\definelayer[leftlayer][page]

\setlayer
[rightlayer]
{\mybgimg}

\setlayer
[rightlayer]
[hoffset=0cm,voffset=23cm]
{\mywatermarkformat{right page}}

\setlayer
[leftlayer]
{\mybgimg}

\setlayer
[leftlayer]
[hoffset=0cm,voffset=23cm]
{\mywatermarkformat{left page}}

\setupbackgrounds[rightpage][background=rightlayer]
\setupbackgrounds[leftpage][background=leftlayer]

\starttext
\input knuth
\page
\input knuth
\page
\input knuth
\page
\input knuth
\stoptext
``````