diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/page-brk.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/page-brk.mkiv | 410 |
1 files changed, 410 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/context/base/page-brk.mkiv b/Master/texmf-dist/tex/context/base/page-brk.mkiv new file mode 100644 index 00000000000..72255676097 --- /dev/null +++ b/Master/texmf-dist/tex/context/base/page-brk.mkiv @@ -0,0 +1,410 @@ +%D \module +%D [ file=page-brk, % moved from page-ini +%D version=2011.12.07, % 2000.10.20, +%D title=\CONTEXT\ Page Macros, +%D subtitle=Breaks, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +\writestatus{loading}{ConTeXt Page Macros / Breaks} + +\unprotect + +\ifdefined\resetcurrentstructuremarkswithpage \else \let\resetcurrentstructuremarkswithpage\relax \fi +\ifdefined\noheaderandfooterlines \else \let\noheaderandfooterlines \relax \fi + +%D Page breaks. + +% \definepagebreak +% [chapter] +% [yes,header,right] +% +% \setuphead +% [chapter] +% [page=chapter, +% header=empty, +% footer=chapter] +% +% \definepagebreak % untested +% [lastpage] +% [left,{empty,right},{empty,left}] + +% public page handler, beware: definepage already in use (core-ref) +% +% \definepagebreak[instance][forsure] +% \definepagebreak[forsure][yes,+4] + +\newconditional\c_page_breaks_enabled \settrue\c_page_breaks_enabled +\newcount \c_page_breaks_prevpage + +\newtoks\everybeforepagebreak +\newtoks\everyafterpagebreak + +\let\page_breaks_current_option \empty +\let\page_breaks_current_options\empty + +\installcorenamespace{pagebreakmethod} +\installcorenamespace{pagebreaks} + +\def\page_breaks_handle#1% + {\edef\page_breaks_current_options{#1}% handy for tracing + \processcommacommand[\page_breaks_current_options]\page_breaks_handle_indeed} + +\def\page_breaks_handle_indeed#1% + {\edef\page_breaks_current_option{#1}% can be used in handler + \ifcsname\??pagebreakmethod\page_breaks_current_option\endcsname + \csname\??pagebreakmethod\page_breaks_current_option\endcsname + \else\ifcsname\??pagebreaks\page_breaks_current_option\endcsname + \expandafter\page_breaks_handle\csname\??pagebreaks\page_breaks_current_option\endcsname + \else + \csname\??pagebreakmethod\s!unknown\endcsname + \fi\fi} + +\def\page_breaks_handle_direct#1% + {\csname\??pagebreakmethod#1\endcsname} + +\unexpanded\def\installpagebreakmethod#1#2% low level definer + {\setvalue{\??pagebreakmethod#1}{#2}} + +\let\installpagebreakhandler\installpagebreakmethod % will go + +\unexpanded\def\definepagebreak + {\dodoubleargument\page_breaks_define} + +\def\page_breaks_define[#1][#2]% + {\setvalue{\??pagebreaks#1}{#2}} + +\unexpanded\def\pagebreak + {\dosingleempty\page_breaks_process} + +\let\page\pagebreak + +\appendtoks + \flushnotes +\to \everybeforepagebreak + +\def\page_breaks_process[#1]% so, page ornaments are reset after a pagebreak command, unless set + {\par % always before group so that we clear hangs etc (as in side floats) + \ifvmode % extra check + \begingroup + \the\everybeforepagebreak + \c_page_breaks_prevpage\realpageno + \ifcase\pageornamentstate \or + % disable reset after shipout + \global\pageornamentstate\plustwo + \fi + \iffirstargument % or if empty i.e. [] + \page_breaks_handle{#1}% + \else % so, no pagebreak when \pagebreak[] ! ! ! + \page_breaks_handle_direct\v!yes + \fi + \relax + \ifnum\c_page_breaks_prevpage<\realpageno + \global\pageornamentstate\zerocount + \fi + \the\everyafterpagebreak + \endgroup + \fi} + +\def\resetpagebreak % used elsewhere too + {\global\settrue\c_page_breaks_enabled} + +\def\simplifypagebreak % to be used grouped ! + {\def\page_breaks_process[##1]{\goodbreak}} + +\def\disablepagebreaks % to be used grouped ! + {\def\page_breaks_process[##1]{}} + +\installpagebreakmethod \s!dummy + {\page_otr_flush_all_floats + \page_otr_command_next_page + \page_otr_insert_dummy_page} + +\installpagebreakmethod \v!frame + {\page + \begingroup + \showframe + \page[\v!empty] + \endgroup} + +\installpagebreakmethod \s!unknown + {\doifinstringelse{+}\page_breaks_current_option + {\page_otr_flush_all_floats + \page_otr_command_next_page + \dorecurse\page_breaks_current_option\page_otr_insert_dummy_page} + {\doifnumberelse\page_breaks_current_option + {\page_otr_flush_all_floats + \page_otr_command_next_page + \doloop + {\ifnum\userpageno<\page_breaks_current_option\relax + \page_otr_insert_dummy_page + \else + \exitloop + \fi}} + {}}} + +\installpagebreakmethod \s!default + {} % do nothing if empty + +\installpagebreakmethod \v!reset + {% better not: \global\pageornamentstate\zerocount + \resetpagebreak} + +\installpagebreakmethod \v!disable + {\global\setfalse\c_page_breaks_enabled} + +\installpagebreakmethod \v!yes + {\ifconditional\c_page_breaks_enabled + \page_otr_flush_all_floats + \page_otr_command_next_page + \ifinsidecolumns % this will move to MUL + \page_otr_eject_page % otherwise sometimes no change + \fi + \fi} + +\installpagebreakmethod \v!makeup + {\ifconditional\c_page_breaks_enabled + \page_otr_fill_and_eject_page + \fi} + +\installpagebreakmethod \v!blank + {\ifcase\pageornamentstate + \global\pageornamentstate\plusone + \fi} + +\installpagebreakmethod \v!no + {\ifconditional\c_page_breaks_enabled + \dosomebreak\nobreak + \fi} + +\installpagebreakmethod \v!preference + {\ifconditional\c_page_breaks_enabled + \ifinsidecolumns % this will move to MUL + \dosomebreak\goodbreak + \else + \testpage[3][\zeropoint]% + \fi + \fi} + +\installpagebreakmethod \v!bigpreference + {\ifconditional\c_page_breaks_enabled + \ifinsidecolumns % this will move to MUL + \dosomebreak\goodbreak + \else + \testpage[5][\zeropoint]% + \fi + \fi} + +% \installpagebreakmethod \v!empty {} % defined in page-txt.mkiv +% \installpagebreakmethod \v!header{} % defined in page-txt.mkiv +% \installpagebreakmethod \v!footer{} % defined in page-txt.mkiv + +\def\page_reset_marks_and_insert_dummy + {\resetcurrentstructuremarkswithpage\page_otr_insert_dummy_page} + +\installpagebreakmethod \v!left + {\page_otr_flush_all_floats + \page_otr_command_next_page_and_inserts + \doifbothsidesoverruled\donothing\page_reset_marks_and_insert_dummy\donothing} + +\installpagebreakmethod \v!right + {\page_otr_flush_all_floats + \page_otr_command_next_page_and_inserts + \doifbothsidesoverruled\donothing\donothing\page_reset_marks_and_insert_dummy} + +\installpagebreakmethod \v!even + {\page + \doifoddpageelse\page_reset_marks_and_insert_dummy\donothing} + +\installpagebreakmethod \v!odd + {\page + \doifoddpageelse\donothing\page_reset_marks_and_insert_dummy} + +\installpagebreakmethod \v!quadruple % not yet ok inside columnsets + {\ifdoublesided + \ifnum\numexpr\realpageno/4\relax=\numexpr\realpageno/2\relax\else + \page_breaks_handle_direct\v!yes + \page_breaks_handle_direct\v!empty + \page_breaks_handle_direct\v!empty + \fi + \fi} + +\installpagebreakmethod \v!last + {\page_otr_flush_all_floats + \page_otr_command_next_page_and_inserts + \relax + \doifbothsidesoverruled + \page_facings_flush % hm + \donothing + {\noheaderandfooterlines + \page_otr_insert_dummy_page}% + \filluparrangedpages} + +\installpagebreakmethod \v!lastpage % handy for backpage preceded by empty pages + {\page_breaks_handle_direct\v!yes + \ifdoublesided + \page_breaks_handle_direct\v!left + \page_breaks_handle_direct\v!empty + \page_breaks_handle_direct\v!empty + \fi} + +\installpagebreakmethod \v!start {\global\settrue \c_otr_shipout_enabled} +\installpagebreakmethod \v!stop {\global\setfalse\c_otr_shipout_enabled} + +% Column breaks. + +\installcorenamespace{columnbreakmethod} +\installcorenamespace{columnbreaks} + +\newtoks\everybeforecolumnbreak +\newtoks\everyaftercolumnbreak + +\let\page_breaks_columns_current_option \empty +\let\page_breaks_columns_current_options\empty + +\def\page_breaks_columns_handle#1% + {\edef\page_breaks_columns_current_options{#1}% + \processcommacommand[#1]\page_breaks_columns_handle_indeed} + +\def\page_breaks_columns_handle_indeed#1% + {\edef\page_breaks_columns_current_option{#1}% + \ifcsname\??columnbreakmethod\currentoutputroutine:\page_breaks_columns_current_option\endcsname + \csname\??columnbreakmethod\currentoutputroutine:\page_breaks_columns_current_option\endcsname + \else\ifcsname\??columnbreaks\page_breaks_columns_current_option\endcsname + \expandafter\csname\page_breaks_columns_handle\??columnbreaks\page_breaks_columns_current_option\endcsname + \else + \csname\??columnbreakmethod\currentoutputroutine:\s!unknown\endcsname + \fi\fi} + +\def\page_breaks_columns_handle_direct#1% + {\csname\??columnbreakmethod\currentoutputroutine:#1\endcsname} + +\unexpanded\def\installcolumnbreakmethod#1#2#3% #1=otr-id #2=tag #3=action + {\setvalue{\??columnbreakmethod#1:#2}{#3}} + +\let\installcolumnbreakhandler\installcolumnbreakmethod % will go + +\unexpanded\def\definecolumnbreak + {\dodoubleargument\page_break_columns_define} + +\def\page_break_columns_define[#1][#2]% + {\setvalue{\??columnbreaks#1}{#2}} + +\unexpanded\def\columnbreak + {\dosingleempty\page_breaks_columns_process} + +\let\column\columnbreak + +\def\page_breaks_columns_process[#1]% so, page ornaments are reset after a pagebreak command, unless set + {\begingroup + \the\everybeforecolumnbreak + \iffirstargument + \page_breaks_columns_handle{#1}% + \else + \page_breaks_columns_handle_direct\v!yes + \fi + \relax + \the\everyaftercolumnbreak + \endgroup} + +%D Test page breaks. + +\newdimen \d_page_tests_test +\newconstant\c_page_tests_mode + +\newconstant\testpagemethod % todo: \testnewpage[method=,lines=,voffset=] +\newconstant\testpagetrigger + +\unexpanded\def\testpage {\c_page_tests_mode\plusone \dodoubleempty\page_tests_test} % +\unexpanded\def\testpageonly{\c_page_tests_mode\plustwo \dodoubleempty\page_tests_test} % no penalties added to the mvl +\unexpanded\def\testpagesync{\c_page_tests_mode\plusthree\dodoubleempty\page_tests_test} % force sync + +\def\page_tests_test[#1][#2]% don't change, only add more methods + {\relax % needed before \if + \ifconditional\c_page_breaks_enabled + % new from here + \ifcase\testpagetrigger + \endgraf + \or\ifvmode + \dosomebreak\allowbreak + \else % indeed? + \vadjust{\allowbreak}% + \endgraf + \fi\fi + % till here + \ifdim\pagegoal<\maxdimen \relax + \ifdim\pagetotal<\pagegoal \relax + \d_page_tests_test\dimexpr + #1\lineheight + +\pagetotal + \ifdim\lastskip<\parskip+\parskip\fi + \ifsecondargument+#2\fi + \relax + \ifcase\testpagemethod + \ifdim\d_page_tests_test>.99\pagegoal + \penalty-\plustenthousand + \fi + \or + \ifdim\dimexpr\d_page_tests_test-\pagegoal\relax>-\lineheight + \penalty-\plustenthousand + \fi + \or + \getnoflines\pagegoal + \ifdim\dimexpr\d_page_tests_test-\noflines\lineheight\relax>-\lineheight + \penalty-\plustenthousand + \fi + \or % same as 0 but more accurate + \ifdim\dimexpr\d_page_tests_test-10\scaledpoint\relax>\pagegoal + \penalty-\plustenthousand + \fi + \fi + \else\ifnum\c_page_tests_mode=\plusthree + \page_tests_flush_so_far + \fi\fi + \else\ifnum\c_page_tests_mode=\plusone + \goodbreak + \fi\fi + \else + \endgraf + \fi} + +\def\page_tests_flush_so_far + {\endgraf + \ifdim\pagetotal>\pagegoal + \ifdim\dimexpr\pagetotal-\pageshrink\relax>\pagegoal + \goodbreak + \else + \page + \fi + \fi} + +%D Test column breaks. + +\def\testcolumn + {\dodoubleempty\page_tests_columns_test} + +\def\page_tests_columns_test[#1][#2]% + {\endgraf + \ifdim\pagegoal<\maxdimen + \ifdim\pagetotal<\pagegoal + \d_page_tests_test\dimexpr + \pagegoal + -\pagetotal + \ifdim\lastskip<\parskip+\parskip\fi + \ifsecondargument+#2\fi + \relax + \getrawnoflines\d_page_tests_test % (raw) + \ifnum#1>\noflines + \column + \fi + \else + \penalty-\plustenthousand % (untested) + \fi + \fi} + +\protect \endinput |