From cf10a29d938a8fd2ad81f8034b53ee7409990169 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Tue, 18 May 2010 10:57:00 +0200 Subject: beta 2010.05.18 10:57 --- tex/context/base/bibl-bib.lua | 127 +++++++++++--- tex/context/base/bibl-bib.mkiv | 262 +++++++++++++++++++++++++++- tex/context/base/bibl-tra.lua | 166 ++---------------- tex/context/base/char-tex.lua | 22 ++- tex/context/base/cont-new.tex | 2 +- tex/context/base/context.tex | 2 +- tex/context/base/font-ctx.lua | 41 ++++- tex/context/base/font-dum.lua | 20 +++ tex/context/base/font-ini.mkiv | 62 ++----- tex/context/base/font-otc.lua | 29 --- tex/context/base/mult-sys.tex | 1 + tex/context/base/node-tsk.lua | 10 +- tex/context/base/sort-ini.lua | 32 +++- tex/context/base/sort-lan.lua | 113 ++++-------- tex/context/base/sort-lan.mkii | 10 +- tex/context/base/spac-hor.mkiv | 5 + tex/context/base/strc-lst.mkiv | 14 +- tex/context/base/strc-mat.mkiv | 8 +- tex/context/base/strc-reg.lua | 131 +++++++------- tex/context/base/type-one.mkii | 42 +++++ tex/context/base/type-otf.mkiv | 82 ++++----- tex/generic/context/luatex-fonts-merged.lua | 51 +++--- 22 files changed, 725 insertions(+), 507 deletions(-) (limited to 'tex') diff --git a/tex/context/base/bibl-bib.lua b/tex/context/base/bibl-bib.lua index 8c76465c2..c6ccdd9ba 100644 --- a/tex/context/base/bibl-bib.lua +++ b/tex/context/base/bibl-bib.lua @@ -12,11 +12,11 @@ bibtex files and converts them to xml so that the we access the content in a convenient way. Actually handling the data takes place elsewhere.

--ldx]]-- -local lower, format, gsub = string.lower, string.format, string.gsub +local lower, format, gsub, concat = string.lower, string.format, string.gsub, table.concat local next = next local lpegmatch = lpeg.match -local textoutf = characters.tex.toutf -local variables = interfaces.variables +local textoutf = characters and characters.tex.toutf +local variables = interfaces and interfaces.variables local trace_bibxml = false trackers.register("publications.bibxml", function(v) trace_bibtex = v end) @@ -26,12 +26,27 @@ bibtex.size = 0 bibtex.definitions = 0 bibtex.shortcuts = 0 +local defaultshortcuts = { + jan = "1", + feb = "2", + mar = "3", + apr = "4", + may = "5", + jun = "6", + jul = "7", + aug = "8", + sep = "9", + oct = "10", + nov = "11", + dec = "12", +} + local shortcuts = { } -local data = { } +local data = { } local entries -- Currently we expand shortcuts and for large ones (like the acknowledgements --- in tugboat.bib this is not that efficient. However, eventually stings get +-- in tugboat.bib this is not that efficient. However, eventually strings get -- hashed again. local function do_shortcut(tag,key,value) @@ -58,28 +73,30 @@ local function do_definition(tag,key,tab) -- maybe check entries here (saves mem end local function resolve(s) - return shortcuts[s] or "" + return shortcuts[s] or defaultshortcuts[s] or s -- can be number end -local percent = lpeg.P("%") -local start = lpeg.P("@") -local comma = lpeg.P(",") -local hash = lpeg.P("#") -local escape = lpeg.P("\\") -local single = lpeg.P("'") -local double = lpeg.P('"') -local left = lpeg.P('{') -local right = lpeg.P('}') +local P, R, S, C, Cc, Cs, Ct = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct + +local percent = P("%") +local start = P("@") +local comma = P(",") +local hash = P("#") +local escape = P("\\") +local single = P("'") +local double = P('"') +local left = P('{') +local right = P('}') local both = left + right -local lineending = lpeg.S("\n\r") -local space = lpeg.S(" \t\n\r\f") +local lineending = S("\n\r") +local space = S(" \t\n\r\f") local spacing = space^0 -local equal = lpeg.P("=") +local equal = P("=") local collapsed = (space^1)/ " " local function add(a,b) if b then return a..b else return a end end -local keyword = lpeg.C((lpeg.R("az","AZ","09") + lpeg.S("@_:-"))^1) -- lpeg.C((1-space)^1) +local keyword = C((lpeg.R("az","AZ","09") + S("@_:-"))^1) -- lpeg.C((1-space)^1) local s_quoted = ((escape*single) + collapsed + (1-single))^0 local d_quoted = ((escape*double) + collapsed + (1-double))^0 local balanced = lpeg.patterns.balanced @@ -90,7 +107,7 @@ local b_value = (left /"") * balanced * (right /"") local r_value = keyword/resolve local somevalue = s_value + d_value + b_value + r_value -local value = lpeg.Cs((somevalue * ((spacing * hash * spacing)/"" * somevalue)^0)) +local value = Cs((somevalue * ((spacing * hash * spacing)/"" * somevalue)^0)) local assignment = spacing * keyword * spacing * equal * spacing * value * spacing local shortcut = keyword * spacing * left * spacing * (assignment * comma^0)^0 * spacing * right @@ -146,13 +163,28 @@ local ihatethis = { z = "\\z", } +local command = P("\\")/"" * Cc("\\bibtexcommand{") * (R("az","AZ")^1) * Cc("}") +local any = P(1) +local done = P(-1) +local one_l = P("{") / "" +local one_r = P("}") / "" +local two_l = P("{{") / "" +local two_r = P("}}") / "" + +local filter = Cs( + two_l * (command + any - two_r - done)^0 * two_r * done + + one_l * (command + any - one_r - done)^0 * one_r * done + + (command + any )^0 +) + function bibtex.toxml(session,options) -- we can always speed this up if needed -- format slows down things a bit but who cares statistics.starttiming(bibtex) local result = { } - local options = aux.settings_to_array(options) + local options = aux.settings_to_hash(options) local convert = options.convert -- todo: interface + local strip = options.strip -- todo: interface local entries = session.entries result[#result+1] = format("") result[#result+1] = format("") @@ -164,19 +196,31 @@ function bibtex.toxml(session,options) for key, value in next, entry do value = gsub(value,"\\(.)",ihatethis) value = lpegmatch(escaped_pattern,value) + if value ~= "" then if convert then - value = textoutf(value) + value = textoutf(value,true) + end + if strip then + -- as there is no proper namespace in bibtex we need this + -- kind of hackery ... bibtex databases are quite unportable + value = lpegmatch(filter,value) or value end result[#result+1] = format(" %s",key,value) end end - result[#result+1] = format("") + result[#result+1] = format("") end end end result[#result+1] = format("") - session.xml = xml.convert(table.concat(result,"\n")) + -- alternatively we could use lxml.convert + session.xml = xml.convert(concat(result,"\n"), { + resolve_entities = true, + resolve_predefined_entities = true, -- in case we have escaped entities + -- unify_predefined_entities = true, -- & -> & + utfize_entities = true, + } ) statistics.stoptiming(bibtex) end @@ -240,13 +284,16 @@ if commands then function commands.definebibtexsession(name) sessions[name] = bibtex.new() end + function commands.preparebibtexsession(name,options) bibtex.toxml(sessions[name],options) lxml.register("bibtex:"..name,sessions[name].xml) end + function commands.registerbibtexfile(name,filename) bibtex.load(sessions[name],filename) end + function commands.registerbibtexentry(name,entry) local session = sessions[name] local entries = session.entries @@ -257,4 +304,36 @@ if commands then end end + local splitter = Ct(lpeg.splitat(" and ")) + + local function bibtexconcat(str,between,betweenlast,betweentwo) + between = between or ", " + betweenlast = betweenlast or between + betweentwo = betweentwo or betweenlast + local s = lpegmatch(splitter,str) + local n = #s + if n > 2 then + for i=1,n-2 do + s[i] = s[i] .. between + end + s[n-1] = s[n-1] .. betweenlast + str = concat(s) + elseif n > 1 then + str = concat(s,betweentwo) + end + return str + end + + -- commands.bibtexconcat = bibtexconcat + + local finalizers = xml.finalizers.tex + + function finalizers.bibtexconcat(collected,...) + if collected then -- rather dumb, just text, no embedded xml + tex.sprint(tex.ctxcatcodes,bibtexconcat(collected[1].dt[1] or "",...)) + end + end + + -- print(commands.bibtextconcat("hans and taco and hartmut",", "," en ")) + end diff --git a/tex/context/base/bibl-bib.mkiv b/tex/context/base/bibl-bib.mkiv index 94737b03a..7d7cd279f 100644 --- a/tex/context/base/bibl-bib.mkiv +++ b/tex/context/base/bibl-bib.mkiv @@ -17,11 +17,122 @@ \unprotect +% todo: et al limiters +% todo: split: citationvariant and publicationvariant + +%D This interface is under development. As I don't use \BIBTEX\ myself I need +%D some motivation to spend time on it, and an occasional question on the +%D list can be a reason. A few examples. As \BIBTEX\ databases can be poluted +%D by local commands, we need to catch: +%D +%D \startbuffer +%D \defbibtexcommand\MF {MF} +%D \defbibtexcommand\MP {MP} +%D \defbibtexcommand\TUB {TUGboat} +%D \defbibtexcommand\Mc {Mac} +%D \defbibtexcommand\sltt{\tt} +%D \defbibtexcommand\<#1>{\type{#1}} +%D \defbibtexcommand\acro#1{#1} +%D \stopbuffer +%D +%D \typebuffer +%D +%D Let's define a session and load a few databases. We convert to \UTF\ and +%D strip commands. +%D +%D \startbuffer +%D \definebibtexsession [somebibtex] +%D \registerbibtexfile [somebibtex] [tugboat.bib] +%D \registerbibtexfile [somebibtex] [komoedie.bib] +%D \preparebibtexsession [somebibtex] [convert,strip] +%D \stopbuffer +%D +%D \typebuffer +%D +%D This loads an mapping (work in progress): +%D +%D \startbuffer +%D \def\currentbibtexformat{apa} \input bxml-\currentbibtexformat.mkiv +%D \stopbuffer +%D +%D \typebuffer +%D +%D There are several ways to handle the \XML. It helps if you're a bit +%D familiar with \XML\ processing in \MKIV. +%D +%D Here we regular setups. Three elements are mapped but only one +%D is actually used and applied to root element \type {/bibtex}. +%D +%D \startbuffer +%D \startxmlsetups bibtex +%D \xmlregistereddocumentsetups{#1}{} +%D \xmlsetsetup{#1}{bibtex|entry|field}{bibtex:*} +%D \xmlmain{#1} +%D \stopxmlsetups +%D +%D \startxmlsetups bibtex:bibtex +%D \xmlfilter{#1}{ +%D /entry[@category='article'] +%D /field[@name='author' and (find(text(),'Hagen') or find(text(),'Hoekwater'))] +%D /../command(bibtex:format) +%D } +%D \stopxmlsetups +%D +%D \applytobibtexsession[somebibtex][bibtex] +%D \stopbuffer +%D +%D \typebuffer +%D +%D A simpler setup is given next. Here we just apply a setup to the root +%D element directly: +%D +%D \startbuffer +%D \startxmlsetups bibtex:list +%D \xmlfilter{#1}{/bibtex/entry/command(bibtex:format)} +%D \stopxmlsetups +%D +%D \applytobibtexsession[somebibtex][bibtex:list] +%D \stopbuffer +%D +%D \typebuffer +%D +%D A slightly more complex expression: +%D +%D \startbuffer +%D \startxmlsetups bibtex:filter +%D \xmlfilter{#1}{ +%D /bibtex +%D /entry[@category='article'] +%D /field[@name='author' and (find(text(),'Hagen') or find(text(),'Hoekwater'))] +%D /../command(bibtex:format) +%D } +%D \stopxmlsetups +%D +%D \applytobibtexsession[somebibtex][bibtex:filter] +%D \stopbuffer +%D +%D \typebuffer + +\newtoks \everydefinebibtexsession +\newtoks \everypreparebibtexsession +\newtoks \everysetupbibtexsession +\setfalse \tracebibtexformat + \def\definebibtexsession {\dosingleargument\dodefinebibtexsession} \def\preparebibtexsession {\dodoubleempty \dopreparebibtexsession} +\def\setupbibtexsession {\dodoubleargument\dosetupbibtexsession} + +\def\dodefinebibtexsession [#1]{\edef\currentbibtexsession{#1}% + \ctxlua{commands.definebibtexsession("#1")}% + \the\everydefinebibtexsession} + +\def\dopreparebibtexsession[#1][#2]{\edef\currentbibtexsession{#1}% + \ctxlua{commands.preparebibtexsession("#1","#2")}% + \the\everypreparebibtexsession} -\def\dodefinebibtexsession [#1]{\ctxlua{commands.definebibtexsession("#1")}} -\def\dopreparebibtexsession[#1][#2]{\ctxlua{commands.preparebibtexsession("#1","#2")}} +\def\dosetupbibtexsession [#1][#2]{\edef\currentbibtexsession{#1}% + \getparameters[\??pb#1][#2]% + \the\everysetupbibtexsession} \def\registerbibtexfile {\dodoubleargument\doregisterbibtexfile} \def\registerbibtexentry {\dodoubleargument\doregisterbibtexentry} @@ -31,19 +142,154 @@ \def\doregisterbibtexentry [#1][#2]{\ctxlua{commands.registerbibtexentry("#1","#2")}} \def\doapplytobibtexsession[#1][#2]{\xmlprocessregistered{bibtex:#1}{#2}{#2}} +\unexpanded\def\bibtexcommand#1% + {\ifcsname\??pb:c:#1\endcsname \else + \fakebibtexcommand{#1}% + \fi + \csname\??pb:c:#1\endcsname} + +\def\fakebibtexcommand#1% + {\ifcsname#1\endcsname + \writestatus{bibtex}{unknown command: #1, using built-in context variant}% + \setugvalue{\??pb:c:#1}{\dosomebibtexcommand{#1}}% + \else + \writestatus{bibtex}{unknown command: #1}% + \setugvalue{\??pb:c:#1}{\dofakebibtexcommand{#1}}% + \fi} + +\let\dosomebibtexcommand \getvalue +\def\dofakebibtexcommand#1{{\tttf#1}} + +\def\defbibtexcommand#1% + {\setuvalue{\strippedcsname#1}} + +\def\bibxmldoifelse#1{\xmldoifelse\currentbibxmlnode{/field[@name='#1']}} +\def\bibxmldoif #1{\xmldoif \currentbibxmlnode{/field[@name='#1']}} +\def\bibxmldoifnot #1{\xmldoifnot \currentbibxmlnode{/field[@name='#1']}} +\def\bibxmlflush #1{\xmlcontext \currentbibxmlnode{/field[@name='#1']}} +\def\bibxmlsetup {\xmlsetup \currentbibxmlnode} % {#1} + +\def\currentbibtexformat{apa} % ho wto interface this, maybe split loading and key +\def\currentbibxmlnode {unset} +\def\currentbibxmltag {unset} + \startxmlsetups bibtex \xmlregistereddocumentsetups{#1}{} \xmlsetsetup{#1}{bibtex|entry|field}{bibtex:*} \xmlmain{#1} \stopxmlsetups -\def\bibxmldoifelse#1#2#3#4#5% entry field before after else - {\xmldoifelse{#1}{/field[@name='#2']}{#3\xmlfilter{#1}{/field[@name='#2']/context()}#4}{#5}} +\startxmlsetups bibtex:format + \bibtexpublicationsparameter\c!before\relax % prevents lookahead + \edef\currentbibxmlnode {#1} + \edef\currentbibxmltag {\xmlatt{#1}{tag}} + \edef\currentbibxmlcategory{\xmlatt{#1}{category}} + \ifconditional\tracebibtexformat + \tracedbibxmlintro\currentbibxmltag + \tracedbibxmlintro\currentbibxmlcategory + \fi + \ignorespaces + \xmlcommand{#1}{.}{bibtex:\currentbibtexformat:\currentbibxmlcategory} + \removeunwantedspaces + \bibtexpublicationsparameter\c!after\relax % prevents lookahead +\stopxmlsetups + +\startxmlsetups bibtex:list + \xmlfilter{#1}{/bibtex/entry/command(bibtex:format)} +\stopxmlsetups + +\startxmlsetups bibtex:bibtex + \xmlfilter{#1}{/entry/command(bibtex:format)} +\stopxmlsetups + +% formatters + +\let\normalbibxmlflush\bibxmlflush + +\definecolor[bibtextracecolor][darkred] -\def\bibxmldoif#1#2#3#4% entry field before after - {\xmldoif{#1}{/field[@name='#2']}{#3\xmlfilter{#1}{/field[@name='#2']/context()}#4}} +\def\tracedbibxmlintro#1{{\tttf#1 -> }} +\def\tracedbibxmlflush#1{\color[bibtextracecolor]{\tttf[#1]}} +\def\tracedbibxmltexts#1{\color[bibtextracecolor]{\tttf<#1>}} -\def\bibxmldoifnot#1#2#3#4% entry field before after - {\xmldoifnot{#1}{/field[@name='#2']}{#3\xmlfilter{#1}{/field[@name='#2']/context()}#4}} +\def\tracedbibxmltext + {\ifconditional\tracebibtexformat + \expandafter\tracedbibxmltexts % plural + \else + \expandafter\firstofoneargument + \fi} + +\def\bibxmlflush + {\ifconditional\tracebibtexformat + \expandafter\tracedbibxmlflush + \else + \expandafter\normalbibxmlflush + \fi} + +\startxmlsetups bibtex:format:common:author + \ifconditional\tracebibtexformat + \bibxmlflush\currentbibtexvariant + \else + \xmlfilter{#1}{/field[@name='\currentbibtexvariant']/bibtexconcat( + '\bibtexpublicationsparameter\c!namesep', + '\bibtexpublicationsparameter\c!lastnamesep', + '\bibtexpublicationsparameter\c!finalnamesep' + )} + \fi +\stopxmlsetups + +\startxmlsetups bibtex:format:author + \begingroup + \def\currentbibtexvariant{author} + \xmlsetup{#1}{bibtex:format:common:author} + \endgroup +\stopxmlsetups + +\startxmlsetups bibtex:format:artauthor + \begingroup + \def\currentbibtexvariant{artauthor} + \xmlsetup{#1}{bibtex:format:common:author} + \endgroup +\stopxmlsetups + +\startxmlsetups bibtex:format:editor + \begingroup + \def\currentbibtexvariant{editor} + \xmlsetup{#1}{bibtex:format:common:author} + \endgroup +\stopxmlsetups + +% lists + +\def\bibtexlistprocessor + {\ctxlua{bibtex.hacks.add(structure.lists.uservalue("\currentlist",\currentlistindex,"bibref"),\currentlistindex)}} + +\appendtoks + \definelist[\currentbibtexsession]% + \setuplist[\currentbibtexsession][\c!state=\v!start,\c!width=]% + \installstructurelistprocessor{\currentbibtexsession:userdata}{\bibtexlistprocessor}% +\to \everydefinebibtexsession + +% \def\installbibtexsorter#1#2% +% {\setvalue{\??pb:\c!sort:#1}{#2}} + +% \installbibtexsorter\v!no {no} +% \installbibtexsorter\v!author {au} +% \installbibtexsorter\v!title {ti} +% \installbibtexsorter\v!short {ab} +% \installbibtexsorter\empty {no} +% \installbibtexsorter\s!default{no} + +% \setupbibtex +% [\c!sorttype=\v!cite, +% \c!sort=no] + +% \long\def\startpublication#1\stoppublication +% {\blank +% todo +% \blank} + +% \let\stoppublication\relax \protect \endinput + diff --git a/tex/context/base/bibl-tra.lua b/tex/context/base/bibl-tra.lua index 6cf0544ec..baf99f28f 100644 --- a/tex/context/base/bibl-tra.lua +++ b/tex/context/base/bibl-tra.lua @@ -73,10 +73,6 @@ function hacks.add(str,listindex) end end -local function compare(a,b) - return ordered[a[1]] < ordered[b[1]] -end - local function compare(a,b) local aa, bb = a[1], b[1] if aa and bb then @@ -93,7 +89,7 @@ function hacks.flush(sortvariant) sort(list,compare) end for i=1,#list do - texsprint(ctxcatcodes,format("\\doprocessbibtexentry{%s}",list[i][1])) + context.doprocessbibtexentry(list[i][1]) end end @@ -180,155 +176,19 @@ function hacks.resolve(prefix,block,reference) -- maybe already feed it split end end end - for i=1,#collected do - local c = collected[i] - if c[3] then - texsprint(ctxcatcodes,format("\\dowithbibtexnumrefrange{%s}{%s}{%s}{%s}{%s}{%s}{%s}",#collected,i,prefix,c[1],c[2],c[3],c[4])) - else - texsprint(ctxcatcodes,format("\\dowithbibtexnumref{%s}{%s}{%s}{%s}{%s}",#collected,i,prefix,c[1],c[2])) + if #collected > 0 then + for i=1,#collected do + local c = collected[i] + if c[3] then + context.dowithbibtexnumrefrange(#collected,i,prefix,c[1],c[2],c[3],c[4]) + else + context.dowithbibtexnumref(#collected,i,prefix,c[1],c[2]) + end end + else + context.nobibtexnumref("error 1") end + else + context.nobibtexnumref("error 2") end end - --- we've decided that external references make no sense --- --- local function compare(a,b) --- return a[3] < b[3] --- end --- --- local function resolve(subset,block,rest) --- local blk, tag, found = block, nil, nil --- if rest then --- if block then --- tag = blk .. ":" .. rest --- found = subset[tag] --- if not found then --- for i=block-1,1,-1 do --- tag = i .. ":" .. rest --- found = subset[tag] --- if found then --- blk = i --- break --- end --- end --- end --- end --- if not found then --- blk = "*" --- tag = blk .. ":" .. rest --- found = subset[tag] --- end --- end --- return blk, rest, found --- end - --- local function set_error(results,...) --- local re = results[false] --- if not re then re = { } results[false] = re end --- re[#re+1] = { format(...) } --- end --- --- local function resolve_outer(results,outer,inner) --- if inner then --- if outer then --- local re = results[outer] --- if not re then re = { } results[outer] = re end --- -- todo: external refs --- re[#re+1] = { format("%s: %s",outer,inner) } --- else --- set_error(results,"no outer for inner: %s",inner) --- end --- else --- set_error(results,"no inner for outer: %s",outer) --- end --- end --- --- function hacks.resolve(prefix,block,reference) -- maybe already feed it split --- local set, bug = jobreferences.identify(prefix,reference) --- local subset = jobreferences.collected[prefix or ""] or jobreferences.collected[""] --- if subset then --- local jobname = tex.jobname --- local results, done = { [jobname] = { } }, { } --- local rj = results[jobname] --- block = tonumber(block) --- for i=1,#set do --- local s = set[i] --- local inner, outer, special = s.inner, s.outer, s.special --- if special == "file" then --- resolve_outer(results,outer,s.operation) --- elseif outer then --- resolve_outer(results,outer,inner) --- elseif inner then --- local blk, inner, found = resolve(subset,block,inner) --- local current = found and found.entries and found.entries.text --- if current and not done[current] then --- rj[#rj+1] = { blk, inner, current } --- done[current] = true --- end --- end --- end --- for where, result in next, results do --- if where then -- else errors --- sort(result,compare) --- end --- end --- local first, last, firsti, lasti, firstr, lastr --- local function finish(cw) --- if first then --- if last > first + 1 then --- cw[#cw+1] = { firstr[1], firstr[2], lastr[1], lastr[2] } --- else --- cw[#cw+1] = { firstr[1], firstr[2] } --- if last > first then --- cw[#cw+1] = { lastr[1], lastr[2] } --- end --- end --- end --- end --- local collections = { } --- for where, result in next, results do --- if where == jobname then --- local cw = { } --- for i=1,#result do --- local r = result[i] --- local current = r[3] --- if not first then --- first, last, firsti, lasti, firstr, lastr = current, current, i, i, r, r --- elseif current == last + 1 then --- last, lasti, lastr = current, i, r --- else --- finish(cw) --- first, last, firsti, lasti, firstr, lastr = current, current, i, i, r, r --- end --- end --- finish(cw) --- if next(cw) then collections[where] = cw end --- elseif where == false then --- collections[where] = result -- temp hack --- else --- collections[where] = result -- temp hack --- end --- end --- for where, collection in next, collections do --- local n = #collection --- for i=1,n do --- local c = collection[i] --- if where == jobname then --- -- internals --- if c[4] then --- texsprint(ctxcatcodes,format("\\dowithbibtexnumrefrange{%s}{%s}{%s}{%s}{%s}{%s}{%s}",n,i,prefix,c[1],c[2],c[3],c[4])) --- else --- texsprint(ctxcatcodes,format("\\dowithbibtexnumref{%s}{%s}{%s}{%s}{%s}",n,i,prefix,c[1],c[2])) --- end --- elseif where == false then --- -- errors --- texsprint(ctxcatcodes,c[1]) --- else --- -- externals --- texsprint(ctxcatcodes,c[1]) --- end --- end --- end --- end --- end diff --git a/tex/context/base/char-tex.lua b/tex/context/base/char-tex.lua index 3e726703a..ed9a244d7 100644 --- a/tex/context/base/char-tex.lua +++ b/tex/context/base/char-tex.lua @@ -66,10 +66,24 @@ local commands = (P('\\') * C(R("az","AZ")^1)) / remap_commands local convert_accents = Cs((accents + P(1))^0) local convert_commands = Cs((commands + P(1))^0) -function characters.tex.toutf(str) - if find(str,"\\") then - str = lpegmatch(convert_commands,str) - str = lpegmatch(convert_accents,str) +local no_l = P("{") / "" +local no_r = P("}") / "" + +local convert_accents_strip = Cs((no_l * accents * no_r + accents + P(1))^0) +local convert_commands_strip = Cs((no_l * commands * no_r + commands + P(1))^0) + +function characters.tex.toutf(str,strip) + if find(str,"\\") then -- we can start at teh found position + if strip then + str = lpegmatch(convert_commands_strip,str) + str = lpegmatch(convert_accents_strip,str) + else + str = lpegmatch(convert_commands,str) + str = lpegmatch(convert_accents,str) + end end return str end + +--~ print(characters.tex.toutf([[\"{e}]]),true) +--~ print(characters.tex.toutf([[{\"{e}}]],true)) diff --git a/tex/context/base/cont-new.tex b/tex/context/base/cont-new.tex index 62cfaab81..f66f17b65 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.05.14 15:26} +\newcontextversion{2010.05.18 10:57} %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.tex b/tex/context/base/context.tex index 20abc1967..2ec316a15 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.05.14 15:26} +\edef\contextversion{2010.05.18 10:57} %D For those who want to use this: diff --git a/tex/context/base/font-ctx.lua b/tex/context/base/font-ctx.lua index f634e5806..50283fccb 100644 --- a/tex/context/base/font-ctx.lua +++ b/tex/context/base/font-ctx.lua @@ -9,7 +9,8 @@ if not modules then modules = { } end modules ['font-ctx'] = { -- needs a cleanup: merge of replace, lang/script etc local texsprint, count, texsetcount = tex.sprint, tex.count, tex.setcount -local format, concat, gmatch, match, find, lower, gsub = string.format, table.concat, string.gmatch, string.match, string.find, string.lower, string.gsub +local format, concat, gmatch, match, find, lower, gsub, byte = string.format, table.concat, string.gmatch, string.match, string.find, string.lower, string.gsub, string.byte + local tostring, next, type = tostring, next, type local lpegmatch = lpeg.match local round = math.round @@ -528,3 +529,41 @@ fonts.map.reset() -- resets the default file -- we need an 'do after the banner hook' -- pdf.mapfile("mkiv-base.map") -- loads the default file + +local nounicode = byte("?") + +local function name_to_slot(name) -- maybe some day rawdata + local tfmdata = fonts.ids[font.current()] + local shared = tfmdata and tfmdata.shared + local fntdata = shared and shared.otfdata or shared.afmdata + if fntdata then + local unicode = fntdata.luatex.unicodes[name] + if not unicode then + return nounicode + elseif type(unicode) == "number" then + return unicode + else -- multiple unicodes + return unicode[1] + end + end + return nounicode +end + +fonts.name_to_slot = name_to_slot + +function fonts.char(n) -- todo: afm en tfm + if type(n) == "string" then + n = name_to_slot(n) + end + if type(n) == "number" then + texsprint(ctxcatcodes,format("\\char%s ",n)) + end +end + +-- thsi will become obsolete: + +fonts.otf.name_to_slot = name_to_slot +fonts.afm.name_to_slot = name_to_slot + +fonts.otf.char = fonts.char +fonts.afm.char = fonts.char diff --git a/tex/context/base/font-dum.lua b/tex/context/base/font-dum.lua index 5ba8e6015..8b35c3278 100644 --- a/tex/context/base/font-dum.lua +++ b/tex/context/base/font-dum.lua @@ -257,3 +257,23 @@ fonts.otf.meanings.normalize = fonts.otf.meanings.normalize or function(t) t.rand = "random" end end + +-- bonus + +function fonts.otf.name_to_slot(name) + local tfmdata = fonts.ids[font.current()] + if tfmdata and tfmdata.shared then + local otfdata = tfmdata.shared.otfdata + local unicode = otfdata.luatex.unicodes[name] + return unicode and (type(unicode) == "number" and unicode or unicode[1]) + end +end + +function fonts.otf.char(n) + if type(n) == "string" then + n = fonts.otf.name_to_slot(n) + end + if type(n) == "number" then + tex.sprint("\\char" .. n) + end +end diff --git a/tex/context/base/font-ini.mkiv b/tex/context/base/font-ini.mkiv index 61e5b8cc8..1628b6810 100644 --- a/tex/context/base/font-ini.mkiv +++ b/tex/context/base/font-ini.mkiv @@ -2662,11 +2662,12 @@ % \definefontfeature[mathscript] [math-script] % \definefontfeature[mathscriptscript] [math-scriptscript] -%D Also new: +%D Also new, handy for manuals: -% handy for manuals +\unexpanded\def\fontchar#1{\ctxlua{fonts.char("#1")}} -\def\otfchar#1{\ctxlua{fonts.otf.char("#1")}} +\let\otfchar\fontchar % will disappear, for compatibility only +\let\afmchar\fontchar % will disappear, for compatibility only %D: We cannot yet inherit because no colors are predefined. @@ -3732,56 +3733,23 @@ %D \macros %D {definefontvariant,fontvariant,variant} %D -%D A slightly adapted version of Adam Lindsays variant patches: -%D -%D \starttyping -%D \usetypescriptfile[type-psc] \loadmapfile[texnansi-public-fpl] -%D \usetypescript[palatino][texnansi] \setupbodyfont[palatino] -%D -%D \definefontvariant [Serif][osf] [OsF] -%D -%D \startlines -%D {\sc abcdefgHIJKlmnop} -%D 123{\Var[osf]456}789 -%D {\Var[osf] 123{\Var[reset]456}789} -%D {\it 123{\Var[osf]456}789 -%D {\Var[osf]123{\Var[reset]456}789}} -%D {\tfb\bf 123{\Var[osf]456}789 -%D {\Var[osf] 123{\Var[reset]456}789}} -%D {\sc 123{\Var[osf]456}789 -%D {\Var[osf] 123{\Var[reset]456}789}} -%D \stoplines -%D \stoptyping +%D This command is obsolete in \MKIV\ as we have features. It might +%D come back using the local features handlers. -\def\definefontvariant - {\dotripleargument\dodefinefontvariant} +\def\definefontvariant{\dotripleargument\dodefinefontvariant} -\def\dodefinefontvariant[#1][#2][#3]% - {\setvalue{\??fv#1#2}{#3}} +\def\dodefinefontvariant[#1][#2][#3]{} +\def\variant [#1]{} -\def\fontvariant#1#2{\executeifdefined{\??fv#1#2}\empty} - -\def\dosetscaledfont - {\checkrelativefontsize\fontstyle - \scaledfontsize\currentfontscale\bodyfontsize - \scaledfontsize\relativefontsize\scaledfontsize} - -\unexpanded\def\variant[#1]% slow - {\dosetscaledfont - \normalexpanded{\noexpand\definedfont[\fontstringA\fontstylesuffix\fontvariant\fontstringA{#1} at \the\dimexpr\scaledfontsize\relax]}% - \ignoreimplicitspaces} - -\ifx\Var\undefined \let\Var\variant \fi +\ifdefined\Var\else \let\Var\variant \fi %D By default we load the Computer Modern Roman fonts (but %D not yet at this moment) and activate the 12pt roman %D bodyfont. Sans serif and teletype are also available and -%D can be called for by \type{\ss} and \type{\tt}. - -% \setupbodyfont [unk, rm] -% \setupbodyfont [rm] - -%D Also needed is: +%D can be called for by \type{\ss} and \type{\tt}. Loading +%D takes place elsewhere. +%D +%D For tracing purposes we define: \definefont[tinyfont][Mono at 1ex] @@ -3818,8 +3786,6 @@ % {\bf test \mine test \sl test \mine test \bs oeps \mine oeps {\tt test \mine \bf test}} -\definesystemvariable{sx} - \def\definestylecollection {\dosingleargument\dodefinestylecollection} diff --git a/tex/context/base/font-otc.lua b/tex/context/base/font-otc.lua index 198b790b5..357d347b1 100644 --- a/tex/context/base/font-otc.lua +++ b/tex/context/base/font-otc.lua @@ -9,8 +9,6 @@ if not modules then modules = { } end modules ['font-otc'] = { local format, insert = string.format, table.insert local type, next = type, next -local ctxcatcodes = tex.ctxcatcodes - -- we assume that the other otf stuff is loaded already local trace_loading = false trackers.register("otf.loading", function(v) trace_loading = v end) @@ -213,30 +211,3 @@ fonts.initializers.node.otf.lineheight = fonts.initializers.common.lineheight fonts.initializers.base.otf.compose = fonts.initializers.common.compose fonts.initializers.node.otf.compose = fonts.initializers.common.compose - --- bonus function - -function otf.name_to_slot(name) -- todo: afm en tfm - local tfmdata = fonts.ids[font.current()] - if tfmdata and tfmdata.shared then - local otfdata = tfmdata.shared.otfdata - local unicode = otfdata.luatex.unicodes[name] - if not unicode then - return string.byte("?") -- nil - elseif type(unicode) == "number" then - return unicode - else - return unicode[1] - end - end - return nil -end - -function otf.char(n) -- todo: afm en tfm - if type(n) == "string" then - n = otf.name_to_slot(n) - end - if n then - tex.sprint(ctxcatcodes,format("\\char%s ",n)) - end -end diff --git a/tex/context/base/mult-sys.tex b/tex/context/base/mult-sys.tex index 2a7cde0e2..676c8d5c9 100644 --- a/tex/context/base/mult-sys.tex +++ b/tex/context/base/mult-sys.tex @@ -96,6 +96,7 @@ \definesystemconstant {SerifBoldItalic} \definesystemconstant {SansBoldItalic} \definesystemconstant {MonoBoldItalic} \definesystemconstant {SerifSlanted} \definesystemconstant {SansSlanted} \definesystemconstant {MonoSlanted} \definesystemconstant {SerifBoldSlanted} \definesystemconstant {SansBoldSlanted} \definesystemconstant {MonoBoldSlanted} +\definesystemconstant {SerifCaps} \definesystemconstant {SansCaps} \definesystemconstant {MonoCaps} \definesystemconstant {Normal} \definesystemconstant {Caps} diff --git a/tex/context/base/node-tsk.lua b/tex/context/base/node-tsk.lua index 4b1c133d7..a40158978 100644 --- a/tex/context/base/node-tsk.lua +++ b/tex/context/base/node-tsk.lua @@ -6,6 +6,8 @@ if not modules then modules = { } end modules ['node-tsk'] = { license = "see context related readme files" } +-- this might move to task-* + local trace_tasks = false trackers.register("tasks.creation", function(v) trace_tasks = v end) tasks = tasks or { } @@ -33,6 +35,7 @@ function tasks.enableaction(name,action) data.runner = false end end + function tasks.disableaction(name,action) local data = tasks.data[name] if data then @@ -40,6 +43,7 @@ function tasks.disableaction(name,action) data.runner = false end end + function tasks.enablegroup(name,group) local data = tasks.data[name] if data then @@ -47,6 +51,7 @@ function tasks.enablegroup(name,group) data.runner = false end end + function tasks.disablegroup(name,group) local data = tasks.data[name] if data then @@ -224,10 +229,11 @@ function tasks.table(name) --maybe move this to task-deb.lua local o = order[i] local l = list[o] if #l == 0 then - NC() type(o) NC() NC() NR() + NC() type(o) NC() context("unset") NC() NR() else + local done = false for k, v in table.sortedpairs(l) do - NC() type(o) NC() type(v) NC() NR() + NC() if not done then type(o) done = true end NC() type(v) NC() NR() end end end diff --git a/tex/context/base/sort-ini.lua b/tex/context/base/sort-ini.lua index 0348e0132..00a3be061 100644 --- a/tex/context/base/sort-ini.lua +++ b/tex/context/base/sort-ini.lua @@ -181,6 +181,18 @@ function sorters.sort(entries,cmp) end return r == -1 end) + local s + for i=1,#entries do + local split = entries[i].split + local entry, first = sorters.firstofsplit(split) + if first == s then + first = " " + else + s = first + logs.report("sorter",">> %s 0x%05X (%s 0x%05X)",first,utfbyte(first),entry,utfbyte(entry)) + end + logs.report("sorter"," %s",pack(split)) + end else sort(entries, function(a,b) return cmp(a,b,map) == -1 @@ -188,21 +200,31 @@ function sorters.sort(entries,cmp) end end +-- some day we can have a characters.upper and characters.lower + function sorters.add_uppercase_entries(entries) - for k, v in pairs(entries) do + local new = { } + for k, v in next, entries do local u = chardata[utfbyte(k)].uccode if u then - entries[utfchar(u)] = v + new[utfchar(u)] = v end end + for k, v in next, new do + entries[k] = v + end end function sorters.add_uppercase_mappings(mappings,offset) - offset = offset or 0 - for k, v in pairs(mappings) do + local new = { } + for k, v in next, mappings do local u = chardata[utfbyte(k)].uccode if u then - mappings[utfchar(u)] = v + offset + new[utfchar(u)] = v + offset end end + offset = offset or 0 + for k, v in next, new do + mappings[k] = v + end end diff --git a/tex/context/base/sort-lan.lua b/tex/context/base/sort-lan.lua index 8f5d95708..e6466043a 100644 --- a/tex/context/base/sort-lan.lua +++ b/tex/context/base/sort-lan.lua @@ -75,94 +75,49 @@ sorters.replacements['cz'] = { } sorters.entries['cz'] = { - ['a'] = "a", - [uc(0x00E1)] = "a", - ['b'] = "b", - ['c'] = "c", + ['a'] = "a", -- a + [uc(0x00E1)] = "a", -- aacute + ['b'] = "b", -- b + ['c'] = "c", -- c [uc(0x010D)] = uc(0x010D), -- ccaron - ['d'] = "d", + ['d'] = "d", -- d [uc(0x010F)] = uc(0x010F), -- dcaron - ['e'] = "e", - [uc(0x00E9)] = "e", - [uc(0x011B)] = "e", - ['f'] = "f", - ['g'] = "g", - ['h'] = "h", - [uc(0xFF01)] = "ch", - ['i'] = "i", - [uc(0x00ED)] = "i", - ['j'] = "j", - ['k'] = "k", - ['l'] = "l", - ['m'] = "m", - ['n'] = "n", + ['e'] = "e", -- e + [uc(0x00E9)] = "e", -- eacute + [uc(0x011B)] = "e", -- ecaron + ['f'] = "f", -- f + ['g'] = "g", -- g + ['h'] = "h", -- h + [uc(0xFF01)] = "ch", -- ch + ['i'] = "i", -- i + [uc(0x00ED)] = "i", -- iacute + ['j'] = "j", -- j + ['k'] = "k", -- k + ['l'] = "l", -- l + ['m'] = "m", -- m + ['n'] = "n", -- n [uc(0x0147)] = uc(0x0147), -- ncaron - ['o'] = "o", - ['p'] = "p", - ['q'] = "q", - ['r'] = "r", - [uc(0x00F3)] = uc(0x00F3), -- oacute + ['o'] = "o", -- o + ['p'] = "p", -- p + ['q'] = "q", -- q + ['r'] = "r", -- r [uc(0x0147)] = uc(0x0147), -- rcaron - ['s'] = "s", + ['s'] = "s", -- s [uc(0x0161)] = uc(0x0161), -- scaron - ['t'] = "t", + ['t'] = "t", -- t [uc(0x0165)] = uc(0x0165), -- tcaron - ['u'] = "u", - [uc(0x00FA)] = "u", - [uc(0x016F)] = "u", - ['v'] = "v", - ['w'] = "w", - ['x'] = "x", - ['y'] = "y", + ['u'] = "u", -- u + [uc(0x00FA)] = "u", -- uacute + [uc(0x016F)] = "u", -- uring + ['v'] = "v", -- v + ['w'] = "w", -- w + ['x'] = "x", -- x + ['y'] = "y", -- y [uc(0x00FD)] = uc(0x00FD), -- yacute - ['z'] = "z", + ['z'] = "z", -- z [uc(0x017E)] = uc(0x017E), -- zcaron } -sorters.mappings['cz'] = { - ['a'] = 1, -- a - [uc(0x00E1)] = 2, -- aacute - ['b'] = 3, -- b - ['c'] = 4, -- c - [uc(0x010D)] = 5, -- ccaron - ['d'] = 6, -- d - [uc(0x010F)] = 7, -- dcaron - ['e'] = 8, -- e - [uc(0x00E9)] = 9, -- eacute - [uc(0x011B)] = 10, -- ecaron - ['f'] = 11, -- f - ['g'] = 12, -- g - ['h'] = 13, -- h - [uc(0xFF01)] = 14, -- ch - ['i'] = 15, -- i - [uc(0x00ED)] = 16, -- iacute - ['j'] = 17, -- j - ['k'] = 18, -- k - ['l'] = 19, -- l - ['m'] = 20, -- m - ['n'] = 21, -- n - [uc(0x0147)] = 22, -- ncaron - [uc(0x00F3)] = 24, -- oacute - ['p'] = 25, -- p - ['q'] = 26, -- q - ['r'] = 27, -- r - [uc(0x0147)] = 28, -- rcaron - ['s'] = 29, -- s - [uc(0x0161)] = 20, -- scaron - ['t'] = 31, -- t - [uc(0x0165)] = 32, -- tcaron - ['u'] = 33, -- u - [uc(0x00FA)] = 34, -- uacute - [uc(0x016F)] = 35, -- uring - ['v'] = 36, -- v - ['w'] = 37, -- w - ['x'] = 38, -- x - ['y'] = 39, -- y - [uc(0x00FD)] = 40, -- yacute - ['z'] = 41, -- z - [uc(0x017E)] = 42, -- zcaron -} - sorters.mappings['cz'] = { ['a'] = 1, -- a [uc(0x00E1)] = 3, -- aacute @@ -186,7 +141,7 @@ sorters.mappings['cz'] = { ['m'] = 39, -- m ['n'] = 41, -- n [uc(0x0147)] = 43, -- ncaron - [uc(0x00F3)] = 45, -- oacute + ['o'] = 45, -- o ['p'] = 47, -- p ['q'] = 49, -- q ['r'] = 51, -- r diff --git a/tex/context/base/sort-lan.mkii b/tex/context/base/sort-lan.mkii index 26ee80405..97df559bf 100644 --- a/tex/context/base/sort-lan.mkii +++ b/tex/context/base/sort-lan.mkii @@ -45,13 +45,13 @@ % \exportsortexpansion {cacute} {czz} % \exportsortexpansion {dstroke} {dz} % \exportsortexpansion {scaron} {sz} -% \exportsortexpansion {zacron} {zz} +% \exportsortexpansion {zcaron} {zz} % \exportsortdivision {cz} {ccaron} % \exportsortdivision {czz} {cacute} % \exportsortdivision {dz} {dstroke} % \exportsortdivision {sz} {scaron} -% \exportsortdivision {zz} {zacron} +% \exportsortdivision {zz} {zcaron} % \stopmode % % \startmode[sortorder-sl] @@ -59,13 +59,13 @@ % \exportsortexpansion {cacute} {c+2} % \exportsortexpansion {dstroke} {d+1} % \exportsortexpansion {scaron} {s+1} -% \exportsortexpansion {zacron} {z+1} +% \exportsortexpansion {zcaron} {z+1} % % \exportsortdivision {c+1} {ccaron} % \exportsortdivision {c+2} {cacute} % \exportsortdivision {d+1} {dstroke} % \exportsortdivision {s+1} {scaron} -% \exportsortdivision {z+1} {zacron} +% \exportsortdivision {z+1} {zcaron} % \stopmode \startmode[sortorder-sl] @@ -73,7 +73,7 @@ \exportsortrule {cacute} {c+2} \exportsortrule {dstroke} {d+1} \exportsortrule {scaron} {s+1} - \exportsortrule {zacron} {z+1} + \exportsortrule {zcaron} {z+1} \stopmode % finnish diff --git a/tex/context/base/spac-hor.mkiv b/tex/context/base/spac-hor.mkiv index a8d71705a..0db85fafa 100644 --- a/tex/context/base/spac-hor.mkiv +++ b/tex/context/base/spac-hor.mkiv @@ -929,4 +929,9 @@ \def\doautoinsertnextspace {\ctxlua{commands.autonextspace("\meaning\nexttoken")}} % todo, just consult nexttoken at the lua end +%D Moved from bib module: + +\def\outdented#1% + {\hskip-\hangindent#1\relax} + \protect \endinput diff --git a/tex/context/base/strc-lst.mkiv b/tex/context/base/strc-lst.mkiv index b800aa6a8..41bfb7822 100644 --- a/tex/context/base/strc-lst.mkiv +++ b/tex/context/base/strc-lst.mkiv @@ -127,7 +127,7 @@ % \appendtoks % \to \everystructurelist -\def\placestructurelist#1#2#3% +\def\placestructurelist#1#2#3% hm ... [][][] {\ctxlua{structure.lists.process("#1","#2","#3")}} \def\analysestructurelist#1#2#3% @@ -189,7 +189,11 @@ % so far (todo: also recursive) \def\listalternativeparameter#1% - {\csname\??li\??li\listparameter\c!alternative#1\endcsname} + {\ifcsname\??li\??li\listparameter\c!alternative#1\endcsname + \csname\??li\??li\listparameter\c!alternative#1\endcsname + \else + \listparameter{#1}% + \fi} \def\setuplistalternative[#1]% {\dodoubleargument\getparameters[\??li\??li#1]} @@ -209,8 +213,8 @@ \def\listdots{\leaders\hbox to .5em{\hss.\hss}\hfill} -\setvalue{\??li\c!alternative}{\getvalue{\??li\c!alternative b}} -\getvalue{\??li\c!alternative} +% \setvalue{\??li\c!alternative}{\getvalue{\??li\c!alternative b}} % ? +% \getvalue{\??li\c!alternative} % ? \def\checklistexistence#1% {\ifcsname\??li#1\s!parent\endcsname \else @@ -615,7 +619,7 @@ \!!widthc\zeropoint} {\!!widtha\listparameter\c!width}} {\!!widtha\listparameter\c!width}}% - \getvalue{\??li\c!alternative\listparameter\c!alternative}% +% \getvalue{\??li\c!alternative\listparameter\c!alternative}% ? \endgraf \noindent \domakelistelement\v!all{#2}\hbox diff --git a/tex/context/base/strc-mat.mkiv b/tex/context/base/strc-mat.mkiv index 57f898118..18e0fc0e8 100644 --- a/tex/context/base/strc-mat.mkiv +++ b/tex/context/base/strc-mat.mkiv @@ -244,8 +244,8 @@ \appendtoks \global\setfalse\insideplaceformula \global\setfalse\insideplacesubformula - \global\setfalse\insideformulas - \global\setfalse\insidesubformulas +% \global\setfalse\insideformulas +% \global\setfalse\insidesubformulas \to \everyresetformulas \newif\ifinformula @@ -541,7 +541,8 @@ \def\stopsubformulas {\nonoindentation \checknextindentation[\formulaparameter\c!indentnext]% - \the\everyresetformulas + \the\everyresetformulas % to be checked + \global\setfalse\insidesubformulas \dorechecknextindentation} % here ? %D Named subformulas (to be redone) @@ -595,6 +596,7 @@ #2% \egroup \stopdisplaymath + \global\setfalse\insideformulas \egroup \the\everyresetformulas \hangafter\minusone % added for side floats diff --git a/tex/context/base/strc-reg.lua b/tex/context/base/strc-reg.lua index c4adbfca4..e35e4a79c 100644 --- a/tex/context/base/strc-reg.lua +++ b/tex/context/base/strc-reg.lua @@ -399,17 +399,21 @@ end function jobregisters.finalize(data,options) local result = data.result data.metadata.nofsorted = #result - local split = { } + local split, lasttag, s, d = { }, nil, nil, nil -- maps character to index (order) for k=1,#result do local v = result[k] local entry, tag = sorters.firstofsplit(v.split) - local s = split[tag] -- keeps track of change - if not s then - s = { tag = tag, data = { } } - split[tag] = s + if tag ~= lasttag then + if trace_registers then + logs.report("registers","splitting at %s",tag) + end + d = { } + s = { tag = tag, data = d } + split[#split+1] = s + lasttag = tag end - s.data[#s.data+1] = v + d[#d+1] = v end data.result = split end @@ -441,6 +445,8 @@ function jobregisters.userdata(index,name) end end +-- proc can be wrapped + function jobregisters.flush(data,options,prefixspec,pagespec) local equal = table.are_equal texsprint(ctxcatcodes,"\\startregisteroutput") @@ -451,51 +457,52 @@ function jobregisters.flush(data,options,prefixspec,pagespec) local function pagenumber(entry) local er = entry.references texsprint(ctxcatcodes,format("\\registeronepage{%s}{%s}{",er.internal or 0,er.realpage or 0)) -- internal realpage content -local proc = entry.processors and entry.processors[2] -if proc then - texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") - helpers.prefixpage(entry,prefixspec,pagespec) - texsprint(ctxcatcodes,"}") -else - helpers.prefixpage(entry,prefixspec,pagespec) -end + local proc = entry.processors and entry.processors[2] + if proc then + texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") + helpers.prefixpage(entry,prefixspec,pagespec) + texsprint(ctxcatcodes,"}") + else + helpers.prefixpage(entry,prefixspec,pagespec) + end texsprint(ctxcatcodes,"}") end local function pagerange(f_entry,t_entry,is_last) local er = f_entry.references texsprint(ctxcatcodes,format("\\registerpagerange{%s}{%s}{",er.internal or 0,er.realpage or 0)) -local proc = entry.processors and entry.processors[2] -if proc then - texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") - helpers.prefixpage(f_entry,prefixspec,pagespec) - texsprint(ctxcatcodes,"}") -else - helpers.prefixpage(f_entry,prefixspec,pagespec) -end + local proc = entry.processors and entry.processors[2] + if proc then + texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") + helpers.prefixpage(f_entry,prefixspec,pagespec) + texsprint(ctxcatcodes,"}") + else + helpers.prefixpage(f_entry,prefixspec,pagespec) + end local er = t_entry.references texsprint(ctxcatcodes,format("}{%s}{%s}{",er.internal or 0,er.lastrealpage or er.realpage or 0)) if is_last then -if proc then - texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") - helpers.prefixlastpage(t_entry,prefixspec,pagespec) -- swaps page and realpage keys - texsprint(ctxcatcodes,"}") -else - helpers.prefixlastpage(t_entry,prefixspec,pagespec) -- swaps page and realpage keys -end + if proc then + texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") + helpers.prefixlastpage(t_entry,prefixspec,pagespec) -- swaps page and realpage keys + texsprint(ctxcatcodes,"}") + else + helpers.prefixlastpage(t_entry,prefixspec,pagespec) -- swaps page and realpage keys + end else -if proc then - texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") - helpers.prefixpage(t_entry,prefixspec,pagespec) - texsprint(ctxcatcodes,"}") -else - helpers.prefixpage(t_entry,prefixspec,pagespec) -end + if proc then + texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") + helpers.prefixpage(t_entry,prefixspec,pagespec) + texsprint(ctxcatcodes,"}") + else + helpers.prefixpage(t_entry,prefixspec,pagespec) + end end texsprint(ctxcatcodes,"}") end -- ranges need checking ! - for k, letter in ipairs(table.sortedkeys(result)) do - local sublist = result[letter] +--~ for k, letter in ipairs(table.sortedkeys(result)) do + for i=1,#result do + local sublist = result[i] local done = { false, false, false, false } local data = sublist.data local d, n = 0, 0 @@ -526,24 +533,24 @@ end end if metadata then texsprint(ctxcatcodes,"\\registerentry{") -local proc = entry.processors and entry.processors[1] -if proc then - texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") - helpers.title(e[i],metadata) - texsprint(ctxcatcodes,"}") -else - helpers.title(e[i],metadata) -end + local proc = entry.processors and entry.processors[1] + if proc then + texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") + helpers.title(e[i],metadata) + texsprint(ctxcatcodes,"}") + else + helpers.title(e[i],metadata) + end texsprint(ctxcatcodes,"}") else -local proc = entry.processors and entry.processors[1] -if proc then - texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") - texsprint(ctxcatcodes,format("\\registerentry{%s}",e[i])) - texsprint(ctxcatcodes,"}") -else - texsprint(ctxcatcodes,format("\\registerentry{%s}",e[i])) -end + local proc = entry.processors and entry.processors[1] + if proc then + texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") + texsprint(ctxcatcodes,format("\\registerentry{%s}",e[i])) + texsprint(ctxcatcodes,"}") + else + texsprint(ctxcatcodes,format("\\registerentry{%s}",e[i])) + end end else done[i] = false @@ -704,14 +711,14 @@ end elseif kind == 'see' then -- maybe some day more words texsprint(ctxcatcodes,"\\startregisterseewords") -local proc = entry.processors and entry.processors[1] -if proc then - texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") - texsprint(ctxcatcodes,format("\\registeroneword{0}{0}{%s}",entry.seeword.text)) -- todo: internal - texsprint(ctxcatcodes,"}") -else - texsprint(ctxcatcodes,format("\\registeroneword{0}{0}{%s}",entry.seeword.text)) -- todo: internal -end + local proc = entry.processors and entry.processors[1] + if proc then + texsprint(ctxcatcodes,"\\applyprocessor{",proc,"}{") + texsprint(ctxcatcodes,format("\\registeroneword{0}{0}{%s}",entry.seeword.text)) -- todo: internal + texsprint(ctxcatcodes,"}") + else + texsprint(ctxcatcodes,format("\\registeroneword{0}{0}{%s}",entry.seeword.text)) -- todo: internal + end texsprint(ctxcatcodes,"\\stopregisterseewords") end end diff --git a/tex/context/base/type-one.mkii b/tex/context/base/type-one.mkii index 17ba108cb..d7fa839f6 100644 --- a/tex/context/base/type-one.mkii +++ b/tex/context/base/type-one.mkii @@ -2596,4 +2596,46 @@ \stoptypescriptcollection +\starttypescriptcollection[libertine] + + \starttypescript [serif] [libertine] [ec] + \definefontsynonym [Libertine-Regular] [fxlr-t1] [encoding=ec] + \definefontsynonym [Libertine-Italic] [fxlri-t1] [encoding=ec] + \definefontsynonym [Libertine-Bold] [fxlb-t1] [encoding=ec] + \definefontsynonym [Libertine-BoldItalic] [fxlbi-t1] [encoding=ec] + \definefontsynonym [Libertine-SmallCaps] [fxlrc-t1] %[encoding=ec] + \loadmapfile [libertine.map] + \stoptypescript + + \starttypescript [serif] [libertine] [name] + \definefontsynonym [Serif] [Libertine-Regular] + \definefontsynonym [SerifItalic] [Libertine-Italic] + \definefontsynonym [SerifSlanted] [Libertine-Italic] + \definefontsynonym [SerifBold] [Libertine-Bold] + \definefontsynonym [SerifBoldItalic] [Libertine-BoldItalic] + \definefontsynonym [SerifBoldSlanted][Libertine-BoldItalic] + \definefontsynonym [SerifCaps] [Libertine-SmallCaps] + \stoptypescript + + \starttypescript [libertine] [ec] + \definetypeface [libertine] [tt] [mono] [default] [default] [encoding=ec] + \definetypeface [libertine] [ss] [sans] [default] [default] [encoding=ec] + \definetypeface [libertine] [rm] [serif] [libertine] [default] [encoding=ec] + \stoptypescript + +\stoptypescriptcollection + +\starttypescriptcollection[inconsolata] + + \starttypescript [mono] [inconsolata] [ec] + \definefontsynonym [Inconsolata] [ec-inconsolata] [encoding=ec] + \pdfmapline{ec-inconsolata Inconsolata "fi4ECEncoding ReEncodeFont" <[fi4-ec.enc