0

I'm trying to put a background image on all pages across a Context document, but adding repeat=yes to \definelayer and state=repeat to \setupbackgrounds doesn't seem to work.

I'd also like to know whether I can turn on/off the defined background in the middle of the text.

\setupcolors[state=start]

\setuppagenumbering[state=stop]

\definelayer[mybg]  % name of the layer
    [repeat=yes % all pages of the document
    x=0mm, y=0mm,  % from upper left corner of paper
     width=\paperwidth, height=\paperheight, % let the layer cover the full paper
     repeat=yes
     ] 

\setlayer[mybg] % name of the layer
    %[hoffset=1cm, voffset=1cm]  % placement (from upper left corner of the layer)
    {\externalfigure[cow][width=\paperwidth,height=\paperheight]}  % the actual contents of the layer

\setupbackgrounds[page][background=mybg,state=repeat % repeat each page
]

\setupindenting[yes,small]


\starttext

asdf
\page
asdf
\page
asdf

\stoptext
6
  • You've missed a comma after repeat=yes. You could use \setupbackgrounds[page][background=<newbackground>] and \setupbackgrounds[page][background=<oldbackground>] when needed.
    – user226564
    Commented Dec 3, 2020 at 16:01
  • Just that? I guess I'd never haver figured that out. But do I need a comma after all last arguments (there's no comma after state=repeat) or just in this particular case? Anyways, if you turn your comment into an answer I'll accept it, thanks a lot.
    – user9424
    Commented Dec 3, 2020 at 16:53
  • I meant, you wrote repeat=yes twice in \definelayer and the first instance lacks a comma so it's possibly the reason your example didn't work.
    – user226564
    Commented Dec 3, 2020 at 17:02
  • Now I see. It's weird because I put a comma in the last and one it worked, too.
    – user9424
    Commented Dec 3, 2020 at 17:09
  • @JairoA.delRio: Could you please post your comment as an answer
    – Aditya
    Commented Dec 10, 2020 at 16:07

1 Answer 1

3

This answer is mainly for eventual ConTeXt users with the same question in case a comment answer isn't clear enough.

You missed a comma in your layer definition. To answer your actual question, it's as easy as applying your background after \page. Even better, using \setupses makes the task less cumbersome. Below an example:

%For testing only
\usecolors[svg]
\setuppapersize[A7]
\setupexternalfigure[location=default]
%
\definelayer[firsttest][repeat=yes,width=\paperwidth,height=\paperheight]
\setlayer[firsttest]{\externalfigure[spider][width=\paperwidth,height=\paperheight]}
\definelayer[secondtest][repeat=yes,width=\paperwidth,height=\paperheight]
\setlayer[secondtest]{\externalfigure[hacker][width=\paperwidth,height=\paperheight]}
%Setups for abbreviating
\startsetups Background:firsttest
\setupbackgrounds[page][background=firsttest]
\stopsetups
%
\startsetups Background:secondtest
\setupbackgrounds[page][background=secondtest]
\stopsetups
%Let's see if color backgrounds work
\startsetups Background:thirdtest
\setupbackgrounds[page][background=color,backgroundcolor=gold]
\stopsetups
%
\starttext
%Spider
\setups[Background:firsttest]
\dorecurse{2}{\input bryson}
\page
%Color
%It works fine without a "repeat" specification
\setups[Background:thirdtest]
\input knuth
\page
%Hacker
%You're able to reuse backgrounds ad libitum
%\setups[Background:firsttest]
\setups[Background:secondtest]
\dorecurse{2}{\input tufte}
\page
\stoptext

enter image description here

You must log in to answer this question.