diff options
author | Karl Berry <karl@freefriends.org> | 2016-05-08 22:44:34 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-05-08 22:44:34 +0000 |
commit | fa5d18c2f98ae3bca364f3c19804bd42f8305512 (patch) | |
tree | 46de646df6b2cff7ab3793e4806f0e5b5a5aa741 /Master/texmf-dist/tex/context/modules/mkiv | |
parent | 43354cc71f70a0e237312e593234b6a4efab3eb2 (diff) |
context
git-svn-id: svn://tug.org/texlive/trunk@40962 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/modules/mkiv')
6 files changed, 279 insertions, 96 deletions
diff --git a/Master/texmf-dist/tex/context/modules/mkiv/m-scite.mkiv b/Master/texmf-dist/tex/context/modules/mkiv/m-scite.mkiv index 71f31becef3..e033235c313 100644 --- a/Master/texmf-dist/tex/context/modules/mkiv/m-scite.mkiv +++ b/Master/texmf-dist/tex/context/modules/mkiv/m-scite.mkiv @@ -165,8 +165,29 @@ function scite.installcommands() context(exportcolors()) end +local p = lpeg.P("\\slxS ")^1 + +local function indent(str) + local l = string.split(str,"\n") + for i=1,#l do + local s = l[i] + if #s > 0 then + local n = lpegmatch(p,s) + if n then + n = (n-1)/6 + else + n = 0 + end + l[i] = formatters["\\slxb{%s}%s\\slxe"](n,s) + end + end + return concat(l,"\n") +end + local function lexdata(data,lexname) - buffers.assign("lex",exportstyled(scite.loadedlexers[lexname],data or "")) + local styled = exportstyled(scite.loadedlexers[lexname],data or "") + styled = indent(styled) + buffers.assign("lex",styled) end scite.lexdata = lexdata @@ -187,9 +208,21 @@ end \unprotect +\unexpanded\def\buff_scite_slxb#1% + {%\begingroup + \hangindent\dimexpr\numexpr#1+1\relax\emwidth\relax + \hangafter \numexpr\numexpr#1+1\relax} + +\unexpanded\def\buff_scite_slxe + {\par + }%\endgroup} + \unexpanded\def\installscitecommands {\ctxlua{buffers.scite.installcommands()}% - \let\installscitecommands\relax} + \let\installscitecommands\relax + \def\slxS{\fixedspace\allowbreak}% + \let\slxb\buff_scite_slxb + \let\slxe\buff_scite_slxe} \unexpanded\def\startscite {\begingroup @@ -212,6 +245,7 @@ end \installscitecommands \tt \dontcomplain + \raggedright \startcontextcode \startlines \getbuffer[lex]% @@ -232,6 +266,7 @@ end \installscitecommands \tt \dontcomplain + \raggedright \setcatcodetable\ctxcatcodes % needed in xml \startlines \getbuffer[lex]% diff --git a/Master/texmf-dist/tex/context/modules/mkiv/s-languages-hyphenation.lua b/Master/texmf-dist/tex/context/modules/mkiv/s-languages-hyphenation.lua index c5a4f91f1e9..971ca3d8f3c 100644 --- a/Master/texmf-dist/tex/context/modules/mkiv/s-languages-hyphenation.lua +++ b/Master/texmf-dist/tex/context/modules/mkiv/s-languages-hyphenation.lua @@ -11,111 +11,194 @@ moduledata.languages.hyphenation = moduledata.languages.hyphenation or { } local a_colormodel = attributes.private('colormodel') +local tex = tex +local context = context + local nodecodes = nodes.nodecodes -local nodepool = nodes.pool +local nuts = nodes.nuts +local nodepool = nuts.pool + local disc_code = nodecodes.disc local glyph_code = nodecodes.glyph + local emwidths = fonts.hashes.emwidths local exheights = fonts.hashes.exheights + local newkern = nodepool.kern local newrule = nodepool.rule local newglue = nodepool.glue -local insert_node_after = node.insert_after -local traverse_by_id = node.traverse_id -local hyphenate = languages.hyphenators.handler -- lang.hyphenate -local find_tail = node.tail -local remove_node = nodes.remove +local insert_node_after = nuts.insert_after +local traverse_by_id = nuts.traverse_id + +local tonut = nodes.tonut +local tonode = nodes.tonode +local getid = nuts.getid +local getnext = nuts.getnext +local getdisc = nuts.getdisc +local getattr = nuts.getattr +local getfont = nuts.getfont +local getfield = nuts.getfield +local setlink = nuts.setlink +local setdisc = nuts.setdisc +local setfield = nuts.setfield +local free_node = nuts.free local tracers = nodes.tracers local colortracers = tracers and tracers.colors local setnodecolor = colortracers.set +-- maybe this will become code code + +local states = table.setmetatableindex(function(t,k) + return { + lefthyphenmin = tex.lefthyphenmin, + righthyphenmin = tex.righthyphenmin, + hyphenationmin = tex.hyphenationmin, + prehyphenchar = tex.prehyphenchar, + posthyphenchar = tex.posthyphenchar, + } +end) + +interfaces.implement { + name = "storelanguagestate", + actions = function() + states[tex.language] = { + lefthyphenmin = tex.lefthyphenmin, + righthyphenmin = tex.righthyphenmin, + hyphenationmin = tex.hyphenationmin, + prehyphenchar = tex.prehyphenchar, + posthyphenchar = tex.posthyphenchar, + } + end +} + +function moduledata.languages.getstate(l) + return states[l] -- code +end + +-- end + local function identify(head,marked) - local current, prev = head, nil + local current = tonut(head) + local prev = nil while current do - local id = current.id - local next = current.next + local id = getid(current) + local next = getnext(current) if id == disc_code then - if prev and next then -- and next.id == glyph_code then -- catch other usage of disc + if prev and next then -- asume glyphs marked[#marked+1] = prev + local pre, post, replace, pre_tail, post_tail, replace_tail = getdisc(current,true) + if replace then + setlink(prev,replace) + setlink(replace_tail,next) + setdisc(pre,post,nil) + prev = tail + else + setlink(prev,next) + end + free_node(current) end elseif id == glyph_code then prev = current + else + prev = nil end current = next end end -local function strip(head,marked) +local function mark(head,marked,w,h,d,how) + head = tonut(head) for i=1,#marked do - local prev = marked[i] - remove_node(head,prev.next,true) + local current = marked[i] + local font = getfont(current) + local em = emwidths[font] + local ex = exheights[font] + local width = w*em + local rule = newrule(width,h*ex,d*ex) + head, current = insert_node_after(head,current,newkern(-width/2)) + head, current = insert_node_after(head,current,rule) + head, current = insert_node_after(head,current,newkern(-width/2)) + head, current = insert_node_after(head,current,newglue(0)) + setnodecolor(rule,how) -- ,getattr(current,a_colormodel)) end end -local function mark(head,marked,w,h,d,how) - for i=1,#marked do - local prev = marked[i] - local font = prev.font - local em = emwidths[font] - local ex = exheights[font] - local width = w*em - local rule = newrule(width,h*ex,d*ex) - head, prev = insert_node_after(head,prev,newkern(-width/2)) - head, prev = insert_node_after(head,prev,rule) - head, prev = insert_node_after(head,prev,newkern(-width/2)) - head, prev = insert_node_after(head,prev,newglue(0)) - setnodecolor(rule,how,prev[a_colormodel]) +local function getlanguage(head,l,left,right) + local t = { } + for n in traverse_by_id(glyph_code,tonut(head)) do + t[n] = { + getfield(n,"lang"), + getfield(n,"left"), + getfield(n,"right"), + } end end -local langs, tags, noflanguages = { }, { }, 0 - -local colorbytag = false +local langs = { } +local tags = { } +local noflanguages = 0 +local colorbytag = false function moduledata.languages.hyphenation.showhyphens(head) if noflanguages > 0 then local marked = { } + local cached = { } + -- somehow assigning -1 fails + for n in traverse_by_id(glyph_code,tonut(head)) do + cached[n] = { + getfield(n,"lang"), + getfield(n,"left"), + getfield(n,"right") + } + end for i=1,noflanguages do local m = { } local l = langs[i] + local s = states[l] marked[i] = m - for n in traverse_by_id(glyph_code,head) do - n.lang = l + local lmin = s.lefthyphenmin + local rmin = s.righthyphenmin + for n in next, cached do + setfield(n,"lang",l) + setfield(n,"left",lmin) + setfield(n,"right",rmin) end languages.hyphenators.methods.original(head) identify(head,m) - strip(head,m) end for i=noflanguages,1,-1 do local l = noflanguages - i + 1 mark(head,marked[i],1/16,l/2,l/4,"hyphenation:"..(colorbytag and tags[i] or i)) end + for n, d in next, cached do + setfield(n,"lang",d[1]) + setfield(n,"left",d[2]) + setfield(n,"right",d[3]) + end return head, true else return head, false end end -local savedlanguage - function moduledata.languages.hyphenation.startcomparepatterns(list) if list and list ~= "" then tags = utilities.parsers.settings_to_array(list) end - savedlanguage = tex.language - tex.language = 0 noflanguages = #tags + context.begingroup() for i=1,noflanguages do langs[i] = tags[i] and languages.getnumber(tags[i]) + context.language{tags[i]} end + context.endgroup() nodes.tasks.enableaction("processors","moduledata.languages.hyphenation.showhyphens") end function moduledata.languages.hyphenation.stopcomparepatterns() noflanguages = 0 - tex.language = savedlanguage or tex.language nodes.tasks.disableaction("processors","moduledata.languages.hyphenation.showhyphens") end diff --git a/Master/texmf-dist/tex/context/modules/mkiv/s-languages-hyphenation.mkiv b/Master/texmf-dist/tex/context/modules/mkiv/s-languages-hyphenation.mkiv index 6662dbf2f32..9ff5720a04f 100644 --- a/Master/texmf-dist/tex/context/modules/mkiv/s-languages-hyphenation.mkiv +++ b/Master/texmf-dist/tex/context/modules/mkiv/s-languages-hyphenation.mkiv @@ -34,6 +34,12 @@ \ctxlua{moduledata.languages.hyphenation.stopcomparepatterns()}% \endgroup} +\appendtoks + \clf_storelanguagestate % global +\to \everylanguage + +\clf_storelanguagestate % initialize + \installmodulecommandluasingle \showcomparepatternslegend {moduledata.languages.hyphenation.showcomparelegend} \protect @@ -42,11 +48,13 @@ \definecolor[hyphenation:2] [g=.8] \definecolor[hyphenation:3] [b=.8] \definecolor[hyphenation:4] [r=.4,g=.4] +\definecolor[hyphenation:5] [r=.4,b=.4] \definecolor[hyphenation:en] [hyphenation:1] \definecolor[hyphenation:de] [hyphenation:2] \definecolor[hyphenation:nl] [hyphenation:3] \definecolor[hyphenation:fr] [hyphenation:4] +\definecolor[hyphenation:sl] [hyphenation:5] \stopmodule @@ -56,10 +64,33 @@ \starttext -\def|#1|{-} + \startcomparepatterns[en,sl] + {For Mojca Miklavec} + {For Mojca Miklavec} + \stopcomparepatterns + + \startcomparepatterns[en] + {For Mojca Miklavec} + {For Mojca Miklavec} + \stopcomparepatterns + + \startcomparepatterns[sl] + {For Mojca Miklavec} + {For Mojca Miklavec} + \stopcomparepatterns + + \startcomparepatterns[en,sl] + {For Mojca Miklavec}\crlf + {For Mojca Miklavec}\crlf + {\de For Mojca Miklavec}\crlf + {For Mojca Miklavec}\crlf + {\fr For Mojca Miklavec} + \stopcomparepatterns + + \page \startsubject{Normal text} - \input tufte + \input tufte \stopsubject \startsubject{Compare hyphenation points of \showcomparepatternslegend[en,de]} diff --git a/Master/texmf-dist/tex/context/modules/mkiv/s-mod-01.mkiv b/Master/texmf-dist/tex/context/modules/mkiv/s-mod-01.mkiv index 6946bef691c..f1c8d425806 100644 --- a/Master/texmf-dist/tex/context/modules/mkiv/s-mod-01.mkiv +++ b/Master/texmf-dist/tex/context/modules/mkiv/s-mod-01.mkiv @@ -278,13 +278,14 @@ \setuplayout [\c!backspace=3.5cm, + \c!cutspace=2cm, \c!leftmargin=1.75cm, \c!rightmargin=0cm, \c!margindistance=.5cm, \c!leftedgedistance=.25cm, \c!rightedgedistance=.5cm, \c!edge=1.5cm, - \c!width=15.55333cm, % 13.998cm at 9pt => 15.55333 at 10pt + \c!width=middle, \c!topspace=2cm, \c!header=1.25cm, \c!footer=1.25cm, diff --git a/Master/texmf-dist/tex/context/modules/mkiv/x-ldx.lua b/Master/texmf-dist/tex/context/modules/mkiv/x-ldx.lua index 31cbebf1392..e88c4c79772 100644 --- a/Master/texmf-dist/tex/context/modules/mkiv/x-ldx.lua +++ b/Master/texmf-dist/tex/context/modules/mkiv/x-ldx.lua @@ -19,13 +19,13 @@ with <logo label='tex'/>. I will rewrite this using lpeg. On the other hand, we cannot expect proper <logo label='tex'/> and for educational purposed the syntax might be wrong. + +Todo: use the scite parser. --ldx]]-- --- there is a nice parser on from http://lua-users.org/wiki/LpegRecipes (by --- Patrick Donnelly) but lua crashes when I apply functions to some of the --- matches +local banner = "version 1.0.1 - 2007+ - PRAGMA ADE / CONTEXT" -banner = "version 1.0.1 - 2007+ - PRAGMA ADE / CONTEXT" +local report = logs.reporter("x-ldx") --[[ This script needs a few libraries. Instead of merging the code here @@ -226,6 +226,8 @@ and by calculating the indentation we also avoid space troubles. It also makes it possible to change the indentation afterwards. --ldx]]-- +local newmethod = true + function ldx.as_xml(data) -- ldx: not needed local t, cmode = { }, false t[#t+1] = "<?xml version='1.0' standalone='yes'?>\n" @@ -233,38 +235,44 @@ function ldx.as_xml(data) -- ldx: not needed for k=1,#data do local v = data[k] if v.code and not emptystring(v.code) then - t[#t+1] = "\n<code>\n" - local split = splitstring(v.code,"\n") - for k=1,#split do -- make this faster - local v = split[k] - local a, b = find(v,"^(%s+)") - if v then v = gsub(v,"[\n\r ]+$","") end - if a and b then - v = sub(v,b+1,#v) - if cmode then - t[#t+1] = "<line comment='yes' n='" .. b .. "'>" .. v .. "</line>\n" - else - t[#t+1] = "<line n='" .. b .. "'>" .. v .. "</line>\n" - end - elseif emptystring(v) then - if cmode then - t[#t+1] = "<line comment='yes'/>\n" + if newmethod then + t[#t+1] = "\n<luacode><![CDATA[\n" + t[#t+1] = v.code + t[#t+1] = "]]></luacode>\n" + else + t[#t+1] = "\n<code>\n" + local split = splitstring(v.code,"\n") + for k=1,#split do -- make this faster + local v = split[k] + local a, b = find(v,"^(%s+)") + if v then v = gsub(v,"[\n\r ]+$","") end + if a and b then + v = sub(v,b+1,#v) + if cmode then + t[#t+1] = "<line comment='yes' n='" .. b .. "'>" .. v .. "</line>\n" + else + t[#t+1] = "<line n='" .. b .. "'>" .. v .. "</line>\n" + end + elseif emptystring(v) then + if cmode then + t[#t+1] = "<line comment='yes'/>\n" + else + t[#t+1] = "<line/>\n" + end + elseif find(v,"^%-%-%[%[") then + t[#t+1] = "<line comment='yes'>" .. v .. "</line>\n" + cmode= true + elseif find(v,"^%]%]%-%-") then + t[#t+1] = "<line comment='yes'>" .. v .. "</line>\n" + cmode= false + elseif cmode then + t[#t+1] = "<line comment='yes'>" .. v .. "</line>\n" else - t[#t+1] = "<line/>\n" + t[#t+1] = "<line>" .. v .. "</line>\n" end - elseif find(v,"^%-%-%[%[") then - t[#t+1] = "<line comment='yes'>" .. v .. "</line>\n" - cmode= true - elseif find(v,"^%]%]%-%-") then - t[#t+1] = "<line comment='yes'>" .. v .. "</line>\n" - cmode= false - elseif cmode then - t[#t+1] = "<line comment='yes'>" .. v .. "</line>\n" - else - t[#t+1] = "<line>" .. v .. "</line>\n" end + t[#t+1] = "</code>\n" end - t[#t+1] = "</code>\n" elseif v.comment then t[#t+1] = "\n<comment>\n" .. v.comment .. "\n</comment>\n" else @@ -288,20 +296,25 @@ The next function wraps it all in one call: --ldx]]-- function ldx.convert(luaname,ldxname) - if not file.is_readable(luaname) then - luaname = luaname .. ".lua" + if not lfs.isfile(luaname) then + file.addsuffix(luaname,"lua") end - if file.is_readable(luaname) then + if lfs.isfile(luaname) then if not ldxname then ldxname = file.replacesuffix(luaname,"ldx") end + report("converting file %a to %a",luaname,ldxname) local data = ldx.load(luaname) if data then - ldx.enhance(data) +-- ldx.enhance(data) if ldxname ~= luaname then ldx.save(ldxname,data) end + else + report("invalid file %a",luaname) end + else + report("unknown file %a",luaname) end end @@ -336,6 +349,6 @@ The main conversion call is: if environment.files and environment.files[1] then ldx.convert(environment.files[1],environment.files[2]) +else + report("no file given") end - ---~ exit(1) diff --git a/Master/texmf-dist/tex/context/modules/mkiv/x-ldx.mkiv b/Master/texmf-dist/tex/context/modules/mkiv/x-ldx.mkiv index 0156f2c5569..06163a594bb 100644 --- a/Master/texmf-dist/tex/context/modules/mkiv/x-ldx.mkiv +++ b/Master/texmf-dist/tex/context/modules/mkiv/x-ldx.mkiv @@ -93,7 +93,23 @@ \startxmlsetups ldx:code \startpacked \xmlflush{#1}\relax - \stoppacked + \scitepacked +\stopxmlsetups + +\startluacode + function xml.finalizers.tex.cdatatobuffer(c,name) + buffers.assign(name,xml.cdata(c[1])) + end +\stopluacode + +\startxmlsetups ldx:luacode + \blank + \begingroup + \switchtobodyfont[dejavu-condensed] + \xmlfilter{#1}{./cdatatobuffer('name')} + \scitebuffer[lua][name] + \endgroup + \blank \stopxmlsetups \startxmlsetups ldx:lines @@ -150,26 +166,22 @@ % code -> cd % comment -> tx (text) -\definetypeface[mainfacenormal] [ss][sans] [iwona] [default] -\definetypeface[mainfacenormal] [rm][serif][palatino] [default] -\definetypeface[mainfacenormal] [tt][mono] [modern] [default][rscale=1] % 1.1 -\definetypeface[mainfacenormal] [mm][math] [iwona] [default][encoding=default] - -\definetypeface[mainfacemedium] [ss][sans] [iwona-medium][default] -\definetypeface[mainfacenormal] [rm][serif][palatino] [default] -\definetypeface[mainfacemedium] [tt][mono] [modern] [default][rscale=1] % 1.1 -\definetypeface[mainfacemedium] [mm][math] [iwona-medium][default][encoding=default] +\usemodule[scite] -\definetypeface[mainfacenarrowtt][tt][mono] [modern-cond] [default][rscale=1] % 1.1 +\switchtobodyfont + [dejavu-condensed,10pt] % preload \setupbodyfont - [mainfacenormal,11pt] + [dejavu,10pt] % main font + +\mainlanguage + [en] \setupwhitespace [big] -\defineregister[function][functions] -\defineregister[variable][variables] +\defineregister[function] +\defineregister[variable] \definehead[source][subject] \definehead[extra] [subsubject] @@ -190,7 +202,15 @@ \setuplayout [width=middle, height=middle, - backspace=2cm, - topspace=2cm] + footer=0pt, + header=1.5cm, + backspace=1.5cm, + topspace=1.5cm] + +\doifmode {nocolor} { + + \setupcolors + [conversion=always] +} \endinput |