[***SPAM***] Resetting Page Backgrounds
I have written Python classes to automate reading a Tumblr blog and writing a file for processing by ConTeXt. No manual editing of the ConTeXt input file is allowed. Photos are incorporated in a graphic created using METAPOST commands embedded in the ConTeXt input file. Then the graphic is used as a background. I need this background to appear only on one page. My current solution is to use TeX conditionals to test if the page number has incremented, then reset the background to empty. This approach fails in many cases. The code below provides a minimum working example of a failure. Photos are shown as squares to reduce the size of this post. Is there a better way to reset the background? ConTeXt ver: 2011.05.18 18:04 MKIV fmt: 2011.7.13 int: english/english this is luatex, version beta-0.70.1-2011051908 (rev 4277) % == Start Minimum Working Example == \pdfminorversion=5 \definepapersize[LG1][width=8.5in,height=8.5in] \definepapersize[LP1][width=8.5in,height=8.5in] \setuppapersize[LG1][LP1] \definelayout[contents_1] [backspace=3.25in, leftmargin=2.25in, leftmargindistance=0.25in, width=4.75in, rightmargindistance=0.25in, rightmargin=0.25in, topspace=0.5in, header=0.25in, headerdistance=4.75in, height=7.75in, footerdistance=0.25in, footer=0.25in] \definelayout[contents_2] [backspace=3.25in, leftmargin=2.25in, leftmargindistance=0.25in, width=4.75in, rightmargindistance=0.25in, rightmargin=0.25in, topspace=0.5in, header=0.25in, headerdistance=3.5in, height=7.75in, footerdistance=0.25in, footer=0.25in] \definelayout[contents_4] [backspace=3.25in, leftmargin=2.25in, leftmargindistance=0.25in, width=4.75in, rightmargindistance=0.25in, rightmargin=0.25in, topspace=0.5in, header=0.25in, headerdistance=1.0in, height=7.75in, footerdistance=0.25in, footer=0.25in] \setupwhitespace[small] \setupfloats[spacebefore=none] \setuppagenumbering[location=footer,style=\white] \starttext \setupheader[state=start] \setupheadertexts[\hbox to 2.5in{MARCH}THESOUNDARABBITMAKES][][][] \setuppagenumber[state=start] \setupfooter[state=start] \setupfootertexts[\pagenumber][] \page \setupbackgrounds[page][background={{}}] \setuplayout[contents_4] \hskip1em \page \startuniqueMPgraphic{2e31ddc5-43da-4879-a223-61674e0df438} page_width := 8.5in; page_height := 8.5in; draw (0, 0)--(page_width, 0) withpen pencircle scaled 1bp withcolor white; draw (0, 0)--(0, page_height) withpen pencircle scaled 1bp withcolor white; photo_grp_x_shift := 3.25in; photo_grp_y_shift := 3.25in; photo_grp_width := 4.75in; photo_grp_height := 4.75in; draw (photo_grp_x_shift, photo_grp_y_shift) --(photo_grp_x_shift, photo_grp_y_shift + photo_grp_height) --(photo_grp_x_shift + photo_grp_width, photo_grp_y_shift + photo_grp_height) --(photo_grp_x_shift + photo_grp_width, photo_grp_y_shift) --(photo_grp_x_shift, photo_grp_y_shift) withpen pencircle scaled 1bp withcolor black; photo_grp_x_shift := 0.75in; photo_grp_y_shift := 5.75in; photo_grp_width := 2.25in; photo_grp_height := 2.25in; draw (photo_grp_x_shift, photo_grp_y_shift) --(photo_grp_x_shift, photo_grp_y_shift + photo_grp_height) --(photo_grp_x_shift + photo_grp_width, photo_grp_y_shift + photo_grp_height) --(photo_grp_x_shift + photo_grp_width, photo_grp_y_shift) --(photo_grp_x_shift, photo_grp_y_shift) withpen pencircle scaled 1bp withcolor black; photo_grp_x_shift := 0.75in; photo_grp_y_shift := 3.25in; photo_grp_width := 2.25in; photo_grp_height := 2.25in; draw (photo_grp_x_shift, photo_grp_y_shift) --(photo_grp_x_shift, photo_grp_y_shift + photo_grp_height) --(photo_grp_x_shift + photo_grp_width, photo_grp_y_shift + photo_grp_height) --(photo_grp_x_shift + photo_grp_width, photo_grp_y_shift) --(photo_grp_x_shift, photo_grp_y_shift) withpen pencircle scaled 1bp withcolor black; \stopuniqueMPgraphic \defineoverlay[2e31ddc5-43da-4879-a223-61674e0df438][\uniqueMPgraphic{2e31ddc5-43da-4879-a223-61674e0df438}] \setupbackgrounds[page][background={{2e31ddc5-43da-4879-a223-61674e0df438}}] \setuplayout[contents_1] \edef\lastpagenumber{\pagenumber} {\bf November 08, 2010} ({\bf Enryakuji}) \ifnum\pagenumber>\lastpagenumber \setupbackgrounds[page][background={{}}]\setuplayout[contents_4] \fi\pagenumber\par My labmates, professor, and I visited this temple in Shiga prefecture last weekend to see the 紅葉 ({\bf kouyou} , autumn colors). Amazingly even though it is November, many of the trees had not changed yet. But the trees whose foliage had changed were beautiful! \ifnum\pagenumber>\lastpagenumber \setupbackgrounds[page][background={{}}]\setuplayout[contents_4] \fi\pagenumber\par When we saw the trees, we all exclaimed in our native languages: \ifnum\pagenumber>\lastpagenumber \setupbackgrounds[page][background={{}}]\setuplayout[contents_4] \fi\pagenumber\par Tres jolie! \ifnum\pagenumber>\lastpagenumber \setupbackgrounds[page][background={{}}]\setuplayout[contents_4] \fi\pagenumber\par Tres jolie! \ifnum\pagenumber>\lastpagenumber \setupbackgrounds[page][background={{}}]\setuplayout[contents_4] \fi\pagenumber\par Tres jolie! \ifnum\pagenumber>\lastpagenumber \setupbackgrounds[page][background={{}}]\setuplayout[contents_4] \fi\pagenumber\par Tres jolie! \ifnum\pagenumber>\lastpagenumber \setupbackgrounds[page][background={{}}]\setuplayout[contents_4] \fi\pagenumber\par Wow. So pretty! \ifnum\pagenumber>\lastpagenumber \setupbackgrounds[page][background={{}}]\setuplayout[contents_4] \fi\pagenumber\par \page \setupbackgrounds[page][background={{}}] \setuplayout[contents_4] \hskip1em \stoptext % == Stop Minimum Working Example ==
On 18-4-2012 14:18, Raymond LeClair wrote:
\setupbackgrounds[page][background={{}}]
just \setupbackgrounds[page][background=] ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Wed, 18 Apr 2012, Raymond LeClair wrote:
I have written Python classes to automate reading a Tumblr blog and writing a file for processing by ConTeXt. No manual editing of the ConTeXt input file is allowed.
Photos are incorporated in a graphic created using METAPOST commands embedded in the ConTeXt input file. Then the graphic is used as a background. I need this background to appear only on one page.
My current solution is to use TeX conditionals to test if the page number has incremented, then reset the background to empty. This approach fails in many cases. The code below provides a minimum working example of a failure. Photos are shown as squares to reduce the size of this post.
Is there a better way to reset the background?
Use can use layers with state=reset, which automatically reset after each page. \startuseMPgraphic{test-metapost-1} StartPage; fill Page withcolor 0.25[blue,white]; StopPage; \stopuseMPgraphic \startuseMPgraphic{test-metapost-2} StartPage; fill Page withcolor 0.25[green,white]; StopPage; \stopuseMPgraphic \definelayer [test-layer] [ width=\paperwidth, height=\paperheight, state=reset, frame=on, ] \setMPlayer[test-layer]{\useMPgraphic{test-metapost-1}} \setupbackgrounds[page][background={test-layer}] \starttext \dorecurse{10}{\input knuth} \setMPlayer[test-layer]{\useMPgraphic{test-metapost-2}} \dorecurse{10}{\input knuth} \stoptext Aditya
On Thu, 19 Apr 2012, Aditya Mahajan wrote:
On Wed, 18 Apr 2012, Raymond LeClair wrote:
I have written Python classes to automate reading a Tumblr blog and writing a file for processing by ConTeXt. No manual editing of the ConTeXt input file is allowed.
Photos are incorporated in a graphic created using METAPOST commands embedded in the ConTeXt input file. Then the graphic is used as a background. I need this background to appear only on one page.
My current solution is to use TeX conditionals to test if the page number has incremented, then reset the background to empty. This approach fails in many cases. The code below provides a minimum working example of a failure. Photos are shown as squares to reduce the size of this post.
Is there a better way to reset the background?
If you know the page numbers in advance, you can also set the layer content in the preamble. \startuseMPgraphic{test-metapost-1} StartPage; fill Page withcolor 0.25[blue,white]; StopPage; \stopuseMPgraphic \startuseMPgraphic{test-metapost-2} StartPage; fill Page withcolor 0.25[green,white]; StopPage; \stopuseMPgraphic \definelayer [test-layer] [ width=\paperwidth, height=\paperheight, state=repeat, frame=on, ] \definelayer[test-layer:2][test-layer] \definelayer[test-layer:3][test-layer] \setMPlayer[test-layer:2]{\useMPgraphic{test-metapost-1}} \setMPlayer[test-layer:3]{\useMPgraphic{test-metapost-2}} \setupbackgrounds[page][background={test-layer}] \starttext \dorecurse{20}{\input knuth} \stoptext Aditya
participants (3)
-
Aditya Mahajan
-
Hans Hagen
-
Raymond LeClair