diff options
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 5 | ||||
-rw-r--r-- | scripts/context/stubs/mswin/mtxrun.lua | 5 | ||||
-rw-r--r-- | scripts/context/stubs/unix/mtxrun | 5 | ||||
-rw-r--r-- | tex/context/base/buff-ini.mkiv | 4 | ||||
-rw-r--r-- | tex/context/base/buff-par.lua | 179 | ||||
-rw-r--r-- | tex/context/base/buff-par.mkiv | 151 | ||||
-rw-r--r-- | tex/context/base/buff-ver.lua | 19 | ||||
-rw-r--r-- | tex/context/base/cont-new.tex | 2 | ||||
-rw-r--r-- | tex/context/base/context.mkiv | 1 | ||||
-rw-r--r-- | tex/context/base/context.tex | 2 | ||||
-rw-r--r-- | tex/context/base/lpdf-wid.lua | 2 | ||||
-rw-r--r-- | tex/context/base/lxml-lpt.lua | 4 | ||||
-rw-r--r-- | tex/context/base/lxml-tab.lua | 1 | ||||
-rw-r--r-- | tex/context/base/mult-sys.mkiv | 1 | ||||
-rw-r--r-- | tex/context/base/node-ref.lua | 13 | ||||
-rw-r--r-- | tex/context/base/strc-ren.mkiv | 45 | ||||
-rw-r--r-- | tex/context/base/util-str.lua | 88 | ||||
-rw-r--r-- | tex/generic/context/luatex-fonts-merged.lua | 2 |
18 files changed, 469 insertions, 60 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index a80e4c730..ae9355601 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -6081,6 +6081,7 @@ local function attribute_value_error(str) end return str end + local function attribute_specification_error(str) if not reported_attribute_errors[str] then report_xml("invalid attribute specification: %q",str) @@ -7502,7 +7503,9 @@ local lp_builtin = P ( P("ns") / "ll.ns" ) * ((spaces * P("(") * spaces * P(")"))/"") -local lp_attribute = (P("@") + P("attribute::")) / "" * Cc("(ll.at and ll.at['") * R("az","AZ","--","__")^1 * Cc("'])") +-- for the moment we keep namespaces with attributes + +local lp_attribute = (P("@") + P("attribute::")) / "" * Cc("(ll.at and ll.at['") * ((R("az","AZ") + S("-_:"))^1) * Cc("'])") local lp_fastpos_p = ((P("+")^0 * R("09")^1 * P(-1)) / function(s) return "l==" .. s end) local lp_fastpos_n = ((P("-") * R("09")^1 * P(-1)) / function(s) return "(" .. s .. "<0 and (#list+".. s .. "==l))" end) local lp_fastpos = lp_fastpos_n + lp_fastpos_p diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index a80e4c730..ae9355601 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -6081,6 +6081,7 @@ local function attribute_value_error(str) end return str end + local function attribute_specification_error(str) if not reported_attribute_errors[str] then report_xml("invalid attribute specification: %q",str) @@ -7502,7 +7503,9 @@ local lp_builtin = P ( P("ns") / "ll.ns" ) * ((spaces * P("(") * spaces * P(")"))/"") -local lp_attribute = (P("@") + P("attribute::")) / "" * Cc("(ll.at and ll.at['") * R("az","AZ","--","__")^1 * Cc("'])") +-- for the moment we keep namespaces with attributes + +local lp_attribute = (P("@") + P("attribute::")) / "" * Cc("(ll.at and ll.at['") * ((R("az","AZ") + S("-_:"))^1) * Cc("'])") local lp_fastpos_p = ((P("+")^0 * R("09")^1 * P(-1)) / function(s) return "l==" .. s end) local lp_fastpos_n = ((P("-") * R("09")^1 * P(-1)) / function(s) return "(" .. s .. "<0 and (#list+".. s .. "==l))" end) local lp_fastpos = lp_fastpos_n + lp_fastpos_p diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index a80e4c730..ae9355601 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -6081,6 +6081,7 @@ local function attribute_value_error(str) end return str end + local function attribute_specification_error(str) if not reported_attribute_errors[str] then report_xml("invalid attribute specification: %q",str) @@ -7502,7 +7503,9 @@ local lp_builtin = P ( P("ns") / "ll.ns" ) * ((spaces * P("(") * spaces * P(")"))/"") -local lp_attribute = (P("@") + P("attribute::")) / "" * Cc("(ll.at and ll.at['") * R("az","AZ","--","__")^1 * Cc("'])") +-- for the moment we keep namespaces with attributes + +local lp_attribute = (P("@") + P("attribute::")) / "" * Cc("(ll.at and ll.at['") * ((R("az","AZ") + S("-_:"))^1) * Cc("'])") local lp_fastpos_p = ((P("+")^0 * R("09")^1 * P(-1)) / function(s) return "l==" .. s end) local lp_fastpos_n = ((P("-") * R("09")^1 * P(-1)) / function(s) return "(" .. s .. "<0 and (#list+".. s .. "==l))" end) local lp_fastpos = lp_fastpos_n + lp_fastpos_p diff --git a/tex/context/base/buff-ini.mkiv b/tex/context/base/buff-ini.mkiv index 221d9e4b1..c90e08e7f 100644 --- a/tex/context/base/buff-ini.mkiv +++ b/tex/context/base/buff-ini.mkiv @@ -1,6 +1,6 @@ %D \module -%D [ file=buff-ini, % was core-buf, % blocks are moved to core-blk -%D version=2000.01.05, +%D [ file=buff-ini, +%D version=2011.11.22, % previous big effort 2000.01.05, %D title=\CONTEXT\ Buffer Macros, %D subtitle=Buffers, %D author=Hans Hagen, diff --git a/tex/context/base/buff-par.lua b/tex/context/base/buff-par.lua new file mode 100644 index 000000000..763d3481d --- /dev/null +++ b/tex/context/base/buff-par.lua @@ -0,0 +1,179 @@ +if not modules then modules = { } end modules ['buff-ini'] = { + version = 1.001, + comment = "companion to buff-ini.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local trace_parallel = false trackers.register("buffers.parallel", function(v) trace_parallel = v end) + +local report_parallel = logs.new("parallel") + +local insert, remove, find, gmatch = table.insert, table.remove, string.find, string.gmatch +local strip, format = string.strip, string.format + +local variables = interfaces.variables + +buffers.parallel = { } local parallel = buffers.parallel + +local data = { } + +function parallel.define(category,tags) + local tags = utilities.parsers.settings_to_array(tags) + local entries = { } + data[category] = { + tags = tags, + entries = entries, + } + for i=1,#tags do + entries[tags[i]] = { + lines = { }, + number = 0, + } + end +end + +function parallel.reset(category,tags) + if not tags or tags == "" or tags == variables.all then + tags = table.keys(entries) + else + tags = utilities.parsers.settings_to_array(tags) + end + for i=1,#tags do + entries[tags[i]] = { + lines = { }, + number = 0, + } + end +end + +function parallel.next(category) + local dc = data[category] + local tags = dc.tags + local entries = dc.entries + for i=1,#tags do + insert(entries[tags[i]].lines, { }) + end +end + +function parallel.save(category,tag,content) + local dc = data[category] + if not dc then + return + end + local entries = dc.entries[tag] + if not entries then + return + end + local lines = entries.lines + if not lines then + return + end + local line = lines[#lines] + if not line then + return + end + -- maybe no strip + -- use lpeg + if find(content,"^%s*%[") then + local done = false + for label, content in gmatch(content,"%s*%[(.-)%]%s*([^%[]+)") do + if done then + line = { } + insert(lines,line) + else + done = true + end + if trace_parallel and label ~= "" then + report_parallel("reference found: category '%s', tag '%s', label '%s'",category,tag,label) + end + line.label = label + line.content = strip(content) + end + else + line.content = strip(content) + line.label = "" + end +end + +function parallel.hassomecontent(category,tags) + local dc = data[category] + if not dc then + return false + end + local entries = dc.entries + if not tags or tags == "" or tags == variables.all then + tags = table.keys(entries) + else + tags = utilities.parsers.settings_to_array(tags) + end + for t=1,#tags do + local tag = tags[t] + local lines = entries[tag].lines + for i=1,#lines do + local content = lines[i].content + if content and content ~= "" then + return true + end + end + end + return false +end + +local save = resolvers.savers.byscheme + +function parallel.place(category,tags,options) + local dc = data[category] + if not dc then + return + end + local entries = dc.entries + local tags = utilities.parsers.settings_to_array(tags) + local options = utilities.parsers.settings_to_hash(options) + local start, n, criterium = options.start, options.n, options.criterium + start, n = start and tonumber(start), n and tonumber(n) + local max = 1 + if n then + max = n + elseif criterium == variables.all then + max = 0 + for t=1,#tags do + local tag = tags[t] + local lines = entries[tag].lines + if #lines > max then + max = #lines + end + end + end + for i=1,max do + for t=1,#tags do + local tag = tags[t] + local entry = entries[tag] + if entry then + local lines = entry.lines + local number = entry.number + 1 + entry.number = number + local line = remove(lines,1) + if line and line.content then + local content = format("\\input{%s}",save("virtual","parallel",line.content)) + context.doflushparallel(tag,1,number,line.label,content) + else + context.doflushparallel(tag,0,number,"","") + end + end + end + end +end + +-- interface + +commands.defineparallel = parallel.define +commands.nextparallel = parallel.next +commands.saveparallel = parallel.save +commands.placeparallel = parallel.place +commands.resetparallel = parallel.reset + +function commands.doifelseparallel(category,tags) + commands.testcase(parallel.hassomecontent(category,tags)) +end diff --git a/tex/context/base/buff-par.mkiv b/tex/context/base/buff-par.mkiv new file mode 100644 index 000000000..ad7d298e0 --- /dev/null +++ b/tex/context/base/buff-par.mkiv @@ -0,0 +1,151 @@ +%D \module +%D [ file=buff-par, +%D version=2010.12.05, +%D title=\CONTEXT\ Buffer Macros, +%D subtitle=Parallel, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] +%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 Buffer Macros / Parallel} + +\registerctxluafile{buff-par}{1.001} + +%D This module is developped for Thomas Schmitz as part of +%D a project. + +\unprotect + +\letvalue{\??px:}\empty + +\def\parallelparameter#1% + {\csname\??px:% + \ifcsname\??px:\currentparallel:\currentparallelinstance:#1\endcsname + \currentparallel:\currentparallelinstance:#1% + \else\ifcsname\??px:\currentparallel:#1\endcsname + \currentparallel:#1% + \else\ifcsname\??px:#1\endcsname + #1% + \fi\fi\fi + \endcsname} + +\unexpanded\def\defineparallel + {\dodoubleargument\dodefineparallel} + +\def\dodefineparallel[#1][#2]% + {\ctxlua{commands.defineparallel("#1","#2")}% + \processcommalist[#2]\dododefineparallel + \setuvalue{\e!start#1}{\dostartparallelset{#1}}% + \setuvalue{\e!stop #1}{\dostopparallelset}} + +\def\dododefineparallel#1% + {\definebuffer[#1]%% + \setuvalue{\e!stop#1}{\dowithparallel{#1}}} + +\def\dostartparallelset#1% + {\def\currentparallel{#1}% + \ctxlua{commands.nextparallel("\currentparallel")}} + +\def\dostopparallelset#1% + {} + +\def\dowithparallel#1% defined moet ook aan de lua kant kunnen + {\ctxlua{commands.saveparallel("\currentparallel","#1",buffers.raw("\thedefinedbuffer{#1}"))}} + +\unexpanded\def\placeparallel + {\dotripleempty\doplaceparallel} + +\def\doplaceparallel[#1][#2][#3]% + {\begingroup + \def\currentparallel{#1}% + \ctxlua{commands.placeparallel("\currentparallel","#2","#3")}% + \endgroup} + +% was: \parallelparameter\c!command} + +\def\doflushparallel#1#2#3#4#5% {instance}{status}{line}{label}{content} + {\begingroup + \def\currentparallelinstance{#1}% + \def\currentparallelnumber {#2}% + \def\currentparallelline {#3}% + \def\currentparallellabel {#4}% + \def\currentparallelcontent {#5}% + \ifcase#2\relax + \expandafter\noflushparalleldefault + \or + \expandafter\doflushparalleldefault + \fi + \endgroup} + +\def\noflushparalleldefault{} +\def\doflushparalleldefault{\directsetup{\parallelparameter\c!setups}} + +\startsetups parallel:place:default + \hangafter1 + \hangindent4em + \dontleavehmode + \hbox to 3em \bgroup + \hss + \bf + \doifsomething \currentparallellabel { + \textreference[\currentparallellabel]{\currentparallelline} + } + \currentparallelline + \quad + \egroup + \currentparallelcontent + \par +\stopsetups + +\unexpanded\def\setupparallel + {\dotripleempty\dosetupparallel} + +\def\dosetupparallel[#1][#2][#3]% + {\ifthirdargument + \getparameters[\??px:#1:#2:][#3]% + \else\ifsecondargument + \getparameters[\??px:#1:][#2]% + \else + \getparameters[\??px:][#1]% maybe no : here + \fi\fi} + +\setupparallel +% [\c!command=\doflushparalleldefault] + [\c!setups=parallel:place:default] + +\def\doifelseparallel#1#2% + {\cldcontext{commands.doifelseparallel("#1","#2")}} + +\def\resetparallel + {\dodoubleempty\doresetparallel} + +\def\resetparallel[#1][#2]% + {\ctxlua{commands.resetparallel("#1","#2"))}} + +% default + +% \def\doflushparalleldefault#1#2#3#4% todo: setups instead +% {\ifcase#1\or +% \begingroup +% \hangafter1 +% \hangindent4em +% \dontleavehmode +% \hbox to 3em{\hss\bf\doifsomething{#3}{\textreference[#3]{#2}}#2\quad}#4\par +% \endgroup +% \fi} + +\protect \endinput + +% \def\dododefineparallel#1% +% {\setuvalue{\e!stop #1}{}% +% \setuvalue{\e!start#1}{\dostartparallel{#1}}} +% +% \def\dostartparallel#1% +% {\grabuntil{\e!stop#1}{\dododostartparallel{#1}}} +% +% \def\dododostartparallel#1#2% +% {\ctxlua{commands.saveparallel("\currentparallel","#1",\!!bs\detokenize{#2}\!!es)}} diff --git a/tex/context/base/buff-ver.lua b/tex/context/base/buff-ver.lua index c8f24c813..2cc8d6df9 100644 --- a/tex/context/base/buff-ver.lua +++ b/tex/context/base/buff-ver.lua @@ -491,13 +491,14 @@ end local tablength = 7 -local function flush(content,settings) +local function dotabs(content,settings) local tab = settings.tab tab = tab and (tab == v_yes and tablength or tonumber(tab)) if tab then - content = tabtospace(content,tab) + return tabtospace(content,tab) + else + return content end - visualize(content,settings) end local function filter(lines,settings) -- todo: inline or display in settings @@ -524,7 +525,8 @@ function commands.typebuffer(settings) if lines then local content, m = filter(lines,settings) if content and content ~= "" then - flush(content,checkedsettings(settings,"display")) + content = dotabs(content,settings) + visualize(content,checkedsettings(settings,"display")) end end end @@ -534,7 +536,8 @@ function commands.processbuffer(settings) if lines then local content, m = filter(lines,settings) if content and content ~= "" then - flush(content,checkedsettings(settings,"direct")) + content = dotabs(content,settings) + visualize(content,checkedsettings(settings,"direct")) end end end @@ -544,7 +547,8 @@ end function commands.typestring(settings) local content = settings.data if content and content ~= "" then - flush(content,checkedsettings(settings,"inline")) + -- content = dotabs(content,settings) + visualize(content,checkedsettings(settings,"inline")) end end @@ -563,7 +567,8 @@ function commands.typefile(settings) local lines = splitlines(str) local content, m = filter(lines,settings) if content and content ~= "" then - flush(content,checkedsettings(settings,"display")) + content = dotabs(content,settings) + visualize(content,checkedsettings(settings,"display")) end end end diff --git a/tex/context/base/cont-new.tex b/tex/context/base/cont-new.tex index 3f0f7f318..c37350f86 100644 --- a/tex/context/base/cont-new.tex +++ b/tex/context/base/cont-new.tex @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2010.12.02 18:37} +\newcontextversion{2010.12.04 09:44} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 1f9ea2200..7e15413c5 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -232,6 +232,7 @@ \loadmarkfile{buff-ini} \loadmarkfile{buff-ver} +\loadmarkfile{buff-par} \loadmarkfile{v-default} % preloaded as otherwise spurious spaces inline due to loading \loadmarkfile{v-nested} % preloaded as otherwise spurious spaces inline due to loading diff --git a/tex/context/base/context.tex b/tex/context/base/context.tex index bdcc50f61..1a1d0f38a 100644 --- a/tex/context/base/context.tex +++ b/tex/context/base/context.tex @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2010.12.02 18:37} +\edef\contextversion{2010.12.04 09:44} %D For those who want to use this: diff --git a/tex/context/base/lpdf-wid.lua b/tex/context/base/lpdf-wid.lua index 1dd0a60d5..6caf2f6c4 100644 --- a/tex/context/base/lpdf-wid.lua +++ b/tex/context/base/lpdf-wid.lua @@ -121,7 +121,7 @@ end function codeinjections.registercomment(specification) nofcomments = nofcomments + 1 - local text = buffers.collect(specification.buffer) + local text = buffers.collectcontent(specification.buffer) if stripleading then text = gsub(text,"[\n\r] *","\n") end diff --git a/tex/context/base/lxml-lpt.lua b/tex/context/base/lxml-lpt.lua index 274601d83..357535d41 100644 --- a/tex/context/base/lxml-lpt.lua +++ b/tex/context/base/lxml-lpt.lua @@ -530,7 +530,9 @@ local lp_builtin = P ( P("ns") / "ll.ns" ) * ((spaces * P("(") * spaces * P(")"))/"") -local lp_attribute = (P("@") + P("attribute::")) / "" * Cc("(ll.at and ll.at['") * R("az","AZ","--","__")^1 * Cc("'])") +-- for the moment we keep namespaces with attributes + +local lp_attribute = (P("@") + P("attribute::")) / "" * Cc("(ll.at and ll.at['") * ((R("az","AZ") + S("-_:"))^1) * Cc("'])") local lp_fastpos_p = ((P("+")^0 * R("09")^1 * P(-1)) / function(s) return "l==" .. s end) local lp_fastpos_n = ((P("-") * R("09")^1 * P(-1)) / function(s) return "(" .. s .. "<0 and (#list+".. s .. "==l))" end) local lp_fastpos = lp_fastpos_n + lp_fastpos_p diff --git a/tex/context/base/lxml-tab.lua b/tex/context/base/lxml-tab.lua index 6a85a4853..0e95fe358 100644 --- a/tex/context/base/lxml-tab.lua +++ b/tex/context/base/lxml-tab.lua @@ -263,6 +263,7 @@ local function attribute_value_error(str) end return str end + local function attribute_specification_error(str) if not reported_attribute_errors[str] then report_xml("invalid attribute specification: %q",str) diff --git a/tex/context/base/mult-sys.mkiv b/tex/context/base/mult-sys.mkiv index affbee64c..143d70485 100644 --- a/tex/context/base/mult-sys.mkiv +++ b/tex/context/base/mult-sys.mkiv @@ -623,6 +623,7 @@ \definesystemvariable {pr} % PRogrammas \definesystemvariable {ps} % PoSitioneren \definesystemvariable {pt} % PageshifT +\definesystemvariable {px} % Parallel \definesystemvariable {py} % PropertYs \definesystemvariable {pv} % PublicationVariable \definesystemvariable {ra} % RAise diff --git a/tex/context/base/node-ref.lua b/tex/context/base/node-ref.lua index 082f1c8b0..e82065ee7 100644 --- a/tex/context/base/node-ref.lua +++ b/tex/context/base/node-ref.lua @@ -321,6 +321,15 @@ local function colorize(width,height,depth,n) end u_colors[n] = u_color end + if width == 0 then + report_backends("reference %s has no horizontal dimensions: width=%s, height=%s, depth=%s",reference,width,height,depth) + width = 65536 + end + if height + depth <= 0 then + report_backends("reference %s has no vertical dimensions: width=%s, height=%s, depth=%s",reference,width,height,depth) + height = 65536/2 + depth = height + end local rule = new_rule(width,height,depth) set_attribute(rule,a_colormodel,1) -- gray color model set_attribute(rule,a_color,u_color) @@ -391,7 +400,7 @@ local function makereference(width,height,depth,reference) local result, current if trace_references then local step = 65536 - result = hpack_list(colorize(width,height-step,depth-step,2)) -- step subtracted so that we can see seperate links + result = hpack_list(colorize(width,height-step,depth-step,2,reference)) -- step subtracted so that we can see seperate links result.width = 0 current = result end @@ -460,7 +469,7 @@ local function makedestination(width,height,depth,reference) width, height, depth = 5*step, 5*step, 0 end for n=1,#name do - local rule = hpack_list(colorize(width,height,depth,3)) + local rule = hpack_list(colorize(width,height,depth,3,reference)) rule.width = 0 if not result then result, current = rule, rule diff --git a/tex/context/base/strc-ren.mkiv b/tex/context/base/strc-ren.mkiv index 1639a5a49..7f65bd8e3 100644 --- a/tex/context/base/strc-ren.mkiv +++ b/tex/context/base/strc-ren.mkiv @@ -116,18 +116,17 @@ \let\currentstructurereferenceattribute\attributeunsetvalue -\def\structureheadattribute +\def\structureheadreferenceattributes {\iflocation attr \destinationattribute \currentstructureattribute attr \referenceattribute \currentstructurereferenceattribute \fi} -% \def\docheckstructureheadreference -% {\edef\currentstructureheadinteraction{\structureheadparameter\c!interaction}% -% \ifx\currentstructureheadinteraction\v!list -% \dogetsimplepagereference{bck:\nextinternalreference}% -% \let\currentstructurereferenceattribute\currentreferenceattribute -% \fi} +\def\setinlinestructureheadreferenceattributes + {\ifconditional\structureheadisdisplay \else \iflocation + \attribute\destinationattribute\currentstructureattribute + \attribute\referenceattribute \currentstructurereferenceattribute + \fi \fi} \def\docheckstructureheadreference {\edef\currentstructureheadinteraction{\structureheadparameter\c!interaction}% @@ -151,14 +150,15 @@ \setstructureheadmarking \doresettructureheadnumbercontent \ifconditional\structureheadleaveempty - \setbox\sectionheadbox\ifvertical\vbox\else\hbox\fi \structureheadattribute to \zeropoint{}% + \setbox\sectionheadbox\ifvertical\vbox\else\hbox\fi \structureheadreferenceattributes to \zeropoint{}% \makestrutofbox\sectionheadbox \else \docheckstructureheadreference - \setbox\sectionheadbox\ifvertical\vbox\else\hbox\fi \structureheadattribute + \setbox\sectionheadbox\ifvertical\vbox\else\hbox\fi \structureheadreferenceattributes {\dosetlocalgridsnapping{\structureheadparameter\c!internalgrid}% \doresettructureheadnumbercontent \dosetfontattribute{\??nh\currentstructurehead}\c!style % but we don't want color to influence user command, todo: get the if-else out of it + \setinlinestructureheadreferenceattributes \structureheadparameter\c!command{}{\doplaceheadtextcomponent\getstructureheadtitle}}% \fi \endheadplacement{\getstructureheadsyncs}} @@ -168,19 +168,20 @@ \setstructureheadmarking \doiftextelse{\getstructureheadnumber}\dosettructureheadnumbercontent\doresettructureheadnumbercontent \ifconditional\structureheadleaveempty - \setbox\sectionheadbox\ifvertical\vbox\else\hbox\fi \structureheadattribute to \zeropoint{}% + \setbox\sectionheadbox\ifvertical\vbox\else\hbox\fi \structureheadreferenceattributes to \zeropoint{}% \makestrutofbox\sectionheadbox \else % = needed \docheckstructureheadreference - \setbox\sectionheadbox\ifvertical\vbox\else\hbox\fi \structureheadattribute + \setbox\sectionheadbox\ifvertical\vbox\else\hbox\fi \structureheadreferenceattributes {\dosetlocalgridsnapping{\structureheadparameter\c!internalgrid}% \dosetfontattribute{\??nh\currentstructurehead}\c!style + \setinlinestructureheadreferenceattributes \structureheadparameter\c!command{\doplaceheadnumbercomponent\getstructureheadnumber}{\doplaceheadtextcomponent\getstructureheadtitle}}% \fi \endheadplacement{\getstructureheadsyncs}} \unexpanded\def\placestructureheadempty - {\hbox \structureheadattribute {\getstructureheadsyncs}} + {\hbox \structureheadreferenceattributes {\getstructureheadsyncs}} %D \starttyping %D \def\StretchedBox#1% @@ -486,4 +487,24 @@ \defineheadplacement[\v!bottom][\v!vertical]#1#2{\placeheadlohi\vbox{#1}{#2}} \defineheadplacement[\v!top] [\v!vertical]#1#2{\placeheadlohi\vtop{#1}{#2}} +% helpers + +% \defineinmargin [ChapterInMargin] [outer] [normal] [distance=0.3em] +% +% \defineheadplacement[MyTest][horizontal]#1#2% +% {\startlocalheadsetup +% %\ChapterInMargin{\structureheadhbox{\strut#2}}% proper destination, ref okay +% \ChapterInMargin{\strut#2}% zero destination, ref okay +% \stoplocalheadsetup} +% +% \setuphead +% [chapter] +% [alternative=MyTest] + +\unexpanded\def\structureheadhbox{\hbox\structureheadreferenceattributes} +\unexpanded\def\structureheadvbox{\vbox\structureheadreferenceattributes} + +\unexpanded\def\startlocalheadsetup{\bgroup\localheadsetup} +\unexpanded\def\stoplocalheadsetup {\egroup} + \protect \endinput diff --git a/tex/context/base/util-str.lua b/tex/context/base/util-str.lua index 18caa27bd..adcbf1654 100644 --- a/tex/context/base/util-str.lua +++ b/tex/context/base/util-str.lua @@ -10,8 +10,9 @@ utilities = utilities or {} utilities.strings = utilities.strings or { } local strings = utilities.strings -local find, gsub = string.find, string.gsub -local patterns, Cs, lpegmatch = lpeg.patterns, lpeg.Cs, lpeg.match +local find, gsub, rep = string.find, string.gsub, string.rep +local Cs, C, Cp, P, Carg = lpeg.Cs, lpeg.C, lpeg.Cp, lpeg.P, lpeg.Carg +local patterns, lpegmatch = lpeg.patterns, lpeg.match -- str = " \n \ntest \n test\ntest " -- print("["..string.gsub(string.collapsecrlf(str),"\n","+").."]") @@ -30,37 +31,72 @@ function strings.collapsecrlf(str) return lpegmatch(pattern,str) end +-- The following functions might end up in another namespace. + +--~ function strings.tabtospace(str,tab) +--~ -- we don't handle embedded newlines +--~ while true do +--~ local s = find(str,"\t") +--~ if s then +--~ if not tab then tab = 7 end -- only when found +--~ local d = tab-(s-1) % tab +--~ if d > 0 then +--~ str = gsub(str,"\t",rep(" ",d),1) +--~ else +--~ str = gsub(str,"\t","",1) +--~ end +--~ else +--~ break +--~ end +--~ end +--~ return str +--~ end + +local extra, tab, start = 0, 0, 4, 0 + +local pattern = + Carg(1) / function(t) + extra, tab, start = 0, t or 7, 1 + end + * Cs(( + Cp() * patterns.tab / function(position) + local current = (position - start + 1) + extra + local spaces = tab-(current-1) % tab + if spaces > 0 then + extra = extra + spaces - 1 + return rep(" ",spaces) + else + return "" + end + end + + patterns.newline * Cp() / function(position) + extra, start = 0, position + end + + patterns.anything + )^1) + +function strings.tabtospace(str,tab) + return lpegmatch(pattern,str,1,tab or 7) +end + --~ local t = { --~ "1234567123456712345671234567", +--~ "\tb\tc", --~ "a\tb\tc", --~ "aa\tbb\tcc", --~ "aaa\tbbb\tccc", --~ "aaaa\tbbbb\tcccc", --~ "aaaaa\tbbbbb\tccccc", ---~ "aaaaaa\tbbbbbb\tcccccc", +--~ "aaaaaa\tbbbbbb\tcccccc\n aaaaaa\tbbbbbb\tcccccc", +--~ "one\n two\nxxx three\nxx four\nx five\nsix", --~ } ---~ for k,v do ---~ print(string.tabtospace(t[k])) +--~ for k=1,#t do +--~ print(strings.tabtospace(t[k])) --~ end --- The following functions might end up in another namespace. - -function strings.tabtospace(str,tab) - -- we don't handle embedded newlines - while true do - local s = find(str,"\t") - if s then - if not tab then tab = 7 end -- only when found - local d = tab-(s-1) % tab - if d > 0 then - str = gsub(str,"\t",rep(" ",d),1) - else - str = gsub(str,"\t","",1) - end - else - break - end - end +function strings.striplong(str) -- strips all leading spaces + str = gsub(str,"^%s*","") + str = gsub(str,"[\n\r]+ *","\n") return str end @@ -69,9 +105,3 @@ end --~ bb --~ cccccc --~ ]]) - -function strings.striplong(str) -- strips all leading spaces - str = gsub(str,"^%s*","") - str = gsub(str,"[\n\r]+ *","\n") - return str -end diff --git a/tex/generic/context/luatex-fonts-merged.lua b/tex/generic/context/luatex-fonts-merged.lua index 06ef44251..19b110416 100644 --- a/tex/generic/context/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 12/02/10 18:37:42 +-- merge date : 12/04/10 09:44:58 do -- begin closure to overcome local limits and interference |