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 ==

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to