diff options
Diffstat (limited to 'Master/texmf-dist/tex/plain/pitex')
-rw-r--r-- | Master/texmf-dist/tex/plain/pitex/pitex.tex | 112 | ||||
-rw-r--r-- | Master/texmf-dist/tex/plain/pitex/sections.ptx | 169 |
2 files changed, 253 insertions, 28 deletions
diff --git a/Master/texmf-dist/tex/plain/pitex/pitex.tex b/Master/texmf-dist/tex/plain/pitex/pitex.tex index e66c674f8bb..5b62b8b5529 100644 --- a/Master/texmf-dist/tex/plain/pitex/pitex.tex +++ b/Master/texmf-dist/tex/plain/pitex/pitex.tex @@ -30,6 +30,11 @@ % This to write in latin1. \directlua{% + lualog = function (message) + texio.write_nl("") texio.write_nl("") + texio.write_nl(message) + texio.write_nl("") texio.write_nl("") + end function convert(buf) return string.gsub(buf,"(.)", function (ch) return unicode.utf8.char(string.byte(ch)) @@ -38,6 +43,15 @@ callback.register('process_input_buffer',convert) } +\newcount\ptx@attribute_count +\def\newattribute#1{% + \advance\ptx@attribute_count1 + \edefcs{ptx@attribute_#1}{10\the\ptx@attribute_count}% + } +\def\ptx@attribute_number#1{\usecs{ptx@attribute_#1}} +\def\ptx@attribute_set#1{\passcs\attribute{ptx@attribute_#1}=1\relax} +\def\ptx@attribute_unset#1{\passcs\attribute{ptx@attribute_#1}=-"7FFFFFFF\relax} + \newdimen\urvsize \urvsize\vsize @@ -150,7 +164,89 @@ \pdfstartlink attr {/Border [0 0 0]} goto name {#1}#2\pdfendlink } +% Margin notes à la Bringhurst: aligned with the line they refer +% to, unless they bleed into the bottom margin, in which case they +% are shifted up so that their bottom line is aligned with the +% page's bottom line. Totally experimental. It'd be nice if I could +% do that with sections too (so that a note doesn't bleed into the +% next section). +\newattribute{note} +\def\note{\ifnext[{\ptx@note}{\ptx@note[0pt]}} +\def\ptx@note[#1]#2{% + \ptx@attribute_set{note}% + \setbox0=\hbox{\vtop{% We need the box's height minus its first line, hence the vtop. + \notefont \baselineskip=9pt + \hsize\dimexpr\pdfpagewidth-(\pdfhorigin+\hsize+4em)\relax + \rightskip=0pt plus 1fil + \it\noindent #2}}% + \ptx@attribute_unset{note}% + \ht0=0pt \dp0=0pt + \vadjust{% + \kern-\dimexpr(2pt+#1)\relax + \moveright\dimexpr\hsize+1em + \box0 + \kern\dimexpr2pt+#1}% + \vrule height 0pt width 0pt depth 2pt +% Problem: if the line where the note appears is last of its +% box, the box has no depth and vfilling doesn't work properly. + }% +\directlua{% + % + % Box255 is traversed from the last node upward. + % Each node with dimension adds to the "remaining height", + % which is used when a note is encountered: if the note's depth + % (minus its last box's depth) is larger than the remaining height, + % then it is shifted upward, so that it doesn't bleed in the bottom + % margin. When computing the remaining height, kerns and glues aren't + % taken into account until a box has been seen (and the depth of + % that first box isn't added either), so the note doesn't even + % bleed into available page space that isn't filled with text. + % + process_marginalia = function (head) + local remainingheight, first, item = 0, true, node.slide(head) + while item do + if node.has_attribute(item,\ptx@attribute_number{note}) then + local depth = item.list.depth - node.tail(item.list.list).depth + if depth > remainingheight then + lualog("A note has been shifted on page " .. tex.count[0] .. + " by an amount of " .. (depth-remainingheight)/65536 .. "pt.") + item.list.shift = remainingheight-depth + end + elseif node.has_field(item, "height") then + remainingheight = remainingheight+item.height + if first then + first = false + else + remainingheight = remainingheight + item.depth + end + elseif node.has_field(item,"kern") then + if not first then + remainingheight = remainingheight+item.kern + end + elseif node.has_field(item, "spec") then + if not first then + remainingheight = remainingheight+item.spec.width + end + end + item = item.prev + end + end + } +\def\processmarginalia{% + \directlua{process_marginalia(tex.box[255].list)}% + } + +\def\stoppage{\penalty-10000\relax} +\def\clearpage{\vfil\stoppage\relax} +\def\needspace#1{% + \penalty0 + \ifdim\dimexpr\pagegoal-\pagetotal<\dimexpr#1\relax + \clearpage + \fi + } + % Verbatim facilities. +\newbox\ptx@box_temp \def\tcode#1{{\codefont#1}} \long\def\com#1{% @@ -174,6 +270,7 @@ \codefont \readexample }% +\let\ptx@example_original\example \bgroup \setcatcodes{\\=12,\|=0,\^^M=13}% |gdef|readexample#1^^M#2\example/{#2|egroup|exampleskip}% @@ -223,8 +320,11 @@ {\setcatcodes{\\=12,\|=0}|gdef|examplestring{\Example/}}% \egroup -\def\typesetexample{{\input\jobname.pex }} -\def\doexample{{\let\example\ptx@Example\input\jobname.pex }} +\def\typesetexample{% + {\input\jobname.pex }% + } +\def\doexamplenogroup{\let\example\ptx@Example\input\jobname.pex \let\example\ptx@example_original} +\def\doexample{{\doexamplenogroup}} \def\ptx@Example{% \iffnext/{\gobbleoneand\endinput}% } @@ -278,14 +378,14 @@ \gdef\noPT#1pt{#1 }} \def\ptx@colorbox_do#1#2{% \bgroup - \setbox0=\hbox{#2}% + \setbox\ptx@box_temp=\hbox{#2}% \hbox{% \pdfliteral{ q #1 rg #1 RG -\expandafter\noPT\the\ptx@extraboxspace_left - \expandafter\noPT\the\dimexpr(\ht0+\ptx@extraboxspace_top)\relax - \expandafter\noPT\the\dimexpr(\wd0+\ptx@extraboxspace_left+\ptx@extraboxspace_right)\relax - -\expandafter\noPT\the\dimexpr(\ht0+\ptx@extraboxspace_top+\dp0+\ptx@extraboxspace_bottom)\relax + \expandafter\noPT\the\dimexpr(\ht\ptx@box_temp+\ptx@extraboxspace_top)\relax + \expandafter\noPT\the\dimexpr(\wd\ptx@box_temp+\ptx@extraboxspace_left+\ptx@extraboxspace_right)\relax + -\expandafter\noPT\the\dimexpr(\ht\ptx@box_temp+\ptx@extraboxspace_top+\dp0+\ptx@extraboxspace_bottom)\relax re f Q}% #2}% \egroup diff --git a/Master/texmf-dist/tex/plain/pitex/sections.ptx b/Master/texmf-dist/tex/plain/pitex/sections.ptx index 0a8280f0d43..1c56112bdac 100644 --- a/Master/texmf-dist/tex/plain/pitex/sections.ptx +++ b/Master/texmf-dist/tex/plain/pitex/sections.ptx @@ -1,12 +1,76 @@ -\newcount\ptx@section_skip % A count, since vertical skips are expressed in number of lines. +\def\ptx@bookmark_list{} +\def\ptx@bookmark_stack{} +\def\createbookmark{% + \ifnextnospace[{\ptx@createbookmark}{\ptx@createbookmark[]}% + } +\def\ptx@createbookmark[#1]#2#3#4{% + \passexpanded{\ptx@bookmark_add{#2}{{#3}{#4}{#1}}}\ptx@bookmark_stack + } +\bgroup +\setcatcodes{\{\}=12,<=1,>=2} +\gdef\ptx@leftbrace<{> +\gdef\ptx@rightbrace<}> +\egroup +\newfor\ptx@bookmark_add{2}#3,{% + \straightenif{ifdim}{#1pt>#3pt } + {\eaddright\ptx@bookmark_list{#2\ptx@leftbrace} + \retrieverest{\ptx@bookmark_addtostack{#1,#3,}}} + {\eaddright\ptx@bookmark_list{\ptx@rightbrace,}} + }[\eaddright\ptx@bookmark_list{#2\ptx@leftbrace} + \ptx@bookmark_addtostack{#1,}{}] +\def\ptx@bookmark_addtostack#1#2{\def\ptx@bookmark_stack{#1#2}} +\newfor\ptx@bookmark_endlist#1,{% + \eaddright\ptx@bookmark_list{\ptx@rightbrace,}% + } +\newfor\ptx@bookmark_process#1#2#3#4,{% + \ptx@bookmark_subcount{0}{#1}{#2}{#3}{#4}% + \reverse\iffemptystring{#4}{\ptx@bookmark_process{#4}}% + } +\newfor\ptx@bookmark_subcount{4}#5,{% + \passarguments{#1+1}{#2}{#3}{#4} + }[\def\ptx@bookmark_sign{-}% +% \def\ptx@bookmark_options{}% +% \ptx@option_launchloop{bookmark}{#4}% + \pdfoutline attr {#4} goto name {#3} count \ptx@bookmark_sign\the\numexpr(#1) {#2}% + ] +\def\processbookmarks{% + \reverse\iffemptycommand\ltr@bookmark_list{% + \expandafter\ptx@bookmark_endlist\expandafter{\ptx@bookmark_stack} + \bgroup + \setcatcodes{_@=11} + \scantokens\expandafter{\expandafter\gdef\expandafter\ptx@bookmark_list\expandafter{\ptx@bookmark_list}}% + \egroup + \expandafter\ptx@bookmark_process\expandafter{\ptx@bookmark_list}} + } +%\let\ptx@end\end +%\def\end{\processbookmarks\ptx@end} +% \newcount\ptx@section_link +\let\sectionaction\unbrace +\def\tosection#1#2{% + \reverse\iffcs{ptx@section_dest:#1} + {\global\advance\ptx@section_link1 + \xdefcs{ptx@section_dest:#1}{\the\ptx@section_link}}% + \sectionaction{\pdfstartlink attr {/Border [0 0 0]} goto name {ptx@section_link:\usecs{ptx@section_dest:#1}}#2\pdfendlink}% + } + +\newcount\ptx@section_skip % A count, since vertical skips are expressed in number of lines. \def\sectioncommand#1#2#3{% - \par\penalty0 + \ifnext[ + {\ptx@sectioncommand{#1}{#2}{#3}} + {\ptx@sectioncommand{#1}{#2}{#3}[ptx@noop]}% + } + +\def\ptx@sectioncommand#1#2#3[#4]{% + \par\removelastskip\penalty0 \ifvalue #1 : clear = true {\vfil\penalty-10000}% Clear the page... - {% Or skip some lines. The "beforeskip" attribute is the number of blank lines one wants before a section - % title and "minimum" is the minimum number of lines it must be possible to have after the section title. - \ifdim\dimexpr(\pagegoal-\pagetotal) < \numexpr(\usevalueor #1 : beforeskip 0+\usevalueor #1 : minimum 0) \baselineskip + {% Or skip some lines. The "beforeskip" attribute is + % the number of blank lines one wants before a section + % title, afterskip is the same thing after, + % and "minimum" is the minimum number of lines + % one wants after the section title. + \ifdim\dimexpr(\pagegoal-\pagetotal) < \numexpr(\usevalueor #1 : beforeskip 0+\usevalueor #1 : afterskip 0+\usevalueor #1 : minimum 0) \baselineskip \vfil\penalty-10000 % Not enough room. \else \vskip\usevalueor #1 : beforeskip 0 \baselineskip @@ -18,10 +82,16 @@ \resetbelow{#1}% Resets all internal counts of sections which depend on the current one (i.e. "section" depends on "chapter", etc.). % % + \ptx@attribute_set{section}% \ifvalue #1 : link = true {% - \global\advance\ptx@section_link 1 - \pdfdest num \ptx@section_link xyz - \pdfoutline attr {/Border [0 0 0]} goto num \ptx@section_link {\detokenize{#2}}}{}% + \ifcs{ptx@section_dest:#4} + {\edef\ptx@temp{ptx@section_link:\usecs{ptx@section_dest:#4}}} + {\global\advance\ptx@section_link1 + \edef\ptx@temp{ptx@section_link:\the\ptx@section_link}% + \reverse\iffstring{#4}{ptx@noop}{\xdefcs{ptx@section_dest:#4}{\the\ptx@section_link}}}% + \pdfdest name {\ptx@temp} xyz + \passexpanded{\createbookmark[\usevalue #1 : bookmarkstyle ]{\usevalueor #1 : bookmarklevel 0}{\detokenize{#2}}}{\ptx@temp}% + }{}% \noindent \hskip\usevalueor #1 : indent {0pt}% \bgroup @@ -41,6 +111,7 @@ \ifvalue #1 : inline = true {} {\vskip\usevalueor #1:afterskip 0\baselineskip}% + \ptx@attribute_unset{section}% } \newwhile\resetbelow1{}{% \ifattribute #1 : below @@ -65,23 +136,26 @@ meta = metasection \setparameter chapter : - clear = true - number = arabic - below = section - afterskip = 3 - indent = "0pt plus 1fill" - beforenumber = "chapitre " - afternumber = {\par\hfill} + clear = true + number = arabic + below = section + afterskip = 3 + indent = "0pt plus 1fill" + beforenumber = "chapitre " + afternumber = {\par\hfill} + bookmarklevel = 1 \setparameter section : - beforeskip = 2 - below = subsection + beforeskip = 2 + below = subsection + bookmarklevel = 2 \setparameter subsection : - font = \it - beforeskip = 1 - beforenumber = "\usevalue section:internalcount ." - minimum = 3 + font = \it + beforeskip = 1 + beforenumber = "\usevalue section:internalcount ." + minimum = 3 + bookmarklevel = 3 \def\chaptertitle{}% \def\chapter#1{% @@ -89,4 +163,55 @@ \sectioncommand{chapter}{#1}{#1}% } \def\section#1{\sectioncommand{section}{#1}{#1}} -\def\subsection#1{\sectioncommand{subsection}{#1}{#1}}
\ No newline at end of file +\def\subsection#1{\sectioncommand{subsection}{#1}{#1}} + +\newattribute{section} +% +% Move pending titles if they happen. They shouldn't by themselves, +% but the next paragraph might want more room than available +% and clear the page. Hence this. +% It reads box 255 backwards and move everything with set +% section attribute to the next page. If the first such material +% is a line, a (totally arbitrary) one-line skip is added, unless +% there's already a skip on top of the next page that isn't +% TeX-inserted (e.g. \baselineskip). +% This is probably totally insufficient. +% +\directlua{% + onelineskip = node.new(11) + onelineskip.kern = tex.baselineskip.width + move_pendingtitles = function (head) + local item, first = node.slide(head), true + while item do + if node.has_attribute(item,\ptx@attribute_number{section}) then + local nextitem = item.prev + node.remove(head,item) + if not ((item.id == 10 or item.id == 11) and first) then + node.insert_before(tex.lists.contrib_head, tex.lists.contrib_head, item) + tex.lists.contrib_head = item + end + if item.id == 0 then + if first then + first = false + if not (tex.lists.contrib_head.next.id == 10 and tex.lists.contrib_head.next.subtype == 0) then + node.insert_after(tex.lists.contrib_head, item, node.copy(onelineskip)) + lualog("A title has been moved from page " .. tex.count[0] .. + " to page " .. tex.count[0]+1 .. ".") + end + end + else + end + item = nextitem + else + if item.id == 0 or item.id == 1 then + item = nil + else + item = item.prev + end + end + end + end + } +\def\removependingtitles{% + \directlua{move_pendingtitles(tex.box[255].list)}% + }
\ No newline at end of file |