diff options
111 files changed, 3243 insertions, 2150 deletions
| diff --git a/tex/context/base/anch-pgr.mkiv b/tex/context/base/anch-pgr.mkiv index 9b0151a81..50574e3ab 100644 --- a/tex/context/base/anch-pgr.mkiv +++ b/tex/context/base/anch-pgr.mkiv @@ -127,23 +127,26 @@  %D the head and tail anchors from this one. We set these  %D anchors before and after each page. +\newdimen\c_anch_page_width +\newdimen\c_anch_page_height +  \unexpanded\def\anch_positions_register_page#1% this one is flushed first ! ... can't we avoid this one    {\ifpositioning\ifcase\realpageno\or -     \ifdim\printpaperheight=\paperheight -       \ifdim\printpaperwidth=\paperwidth -         % not needed, +     \ifdim\c_anch_page_height=\paperheight +       \ifdim\c_anch_page_width=\paperwidth +         % no change         \else -         \anch_positions_register_page_indeed{#1}% +         \c_anch_page_width \paperwidth +         \c_anch_page_height\paperheight +         \anch_make_page_box{#1}% \ifvbox#1\setbox#1\hbox{\box#1}\fi         \fi       \else -       \anch_positions_register_page_indeed{#1}% +       \c_anch_page_width \paperwidth +       \c_anch_page_height\paperheight +       \anch_make_page_box{#1}% \ifvbox#1\setbox#1\hbox{\box#1}\fi       \fi     \fi\fi} -\def\anch_positions_register_page_indeed#1% maybe like text -  {\ifvbox#1\setbox#1\hbox{\box#1}\fi -   \anch_make_page_box{#1}} -  \unexpanded\def\anch_positions_place_anchors    {\ifpositioning       \anch_positions_place_anchors_yes diff --git a/tex/context/base/anch-pos.lua b/tex/context/base/anch-pos.lua index f9c061e92..059da81e2 100644 --- a/tex/context/base/anch-pos.lua +++ b/tex/context/base/anch-pos.lua @@ -135,6 +135,21 @@ jobpositions.used       = false  local function initializer()      tobesaved = jobpositions.tobesaved      collected = jobpositions.collected +    -- add sparse regions +    local pages = structures.pages.collected +    if pages  then +        local last = nil +        for p=1,#pages do +            local region = "page:" .. p +            local data   = collected[region] +            if data then +                last   = data +                last.p = nil -- no need for a page +            elseif last then +                collected[region] = last +            end +        end +    end      -- enhance regions with paragraphs      for tag, data in next, collected do          local region = data.r @@ -401,7 +416,7 @@ function jobpositions.e_region(correct)      region = regions[#regions]  end -local function markregionbox(n,tag,correct) +local function setregionbox(n,tag)      if not tag or tag == "" then          nofregions = nofregions + 1          tag = f_region(nofregions) @@ -418,6 +433,11 @@ local function markregionbox(n,tag,correct)          h = h ~= 0 and h or nil,          d = d ~= 0 and d or nil,      } +    return tag, box +end + +local function markregionbox(n,tag,correct) +    local tag, box = setregionbox(n,tag)      local push = new_latelua(f_b_region(tag))      local pop  = new_latelua(f_e_region(tostring(correct))) -- todo: check if tostring is needed with formatter      -- maybe we should construct a hbox first (needs experimenting) so that we can avoid some at the tex end @@ -436,6 +456,7 @@ local function markregionbox(n,tag,correct)  end  jobpositions.markregionbox = markregionbox +jobpositions.setregionbox  = setregionbox  function jobpositions.enhance(name)      enhance(tobesaved[name]) @@ -602,7 +623,17 @@ end  function jobpositions.region(id)      local jpi = collected[id] -    return jpi and jpi.r or false +    if jpi then +        local r = jpi.r +        if r then +            return r +        end +        local p = jpi.p +        if p then +            return "page:" .. p +        end +    end +    return false  end  function jobpositions.column(id) @@ -994,21 +1025,24 @@ scanners.MPc = function() -- name      local jpi = collected[scanstring()]      if jpi then          local c = jpi.c -        if c and p ~= true  then +        if c and c ~= true  then              context(c)              return          end      end -    context(c) -- number +    context('0') -- okay ?  end  scanners.MPr = function() -- name      local jpi = collected[scanstring()]      if jpi then          local r = jpi.r -        if r and p ~= true  then +        if r and r ~= true  then              context(r) -            return +        end +        local p = jpi.p +        if p then +            context("page:" .. p)          end      end  end @@ -1143,10 +1177,18 @@ scanners.markregionbox = function() -- box      markregionbox(scaninteger())  end +scanners.setregionbox = function() -- box +    setregionbox(scaninteger()) +end +  scanners.markregionboxtagged = function() -- box tag      markregionbox(scaninteger(),scanstring())  end +scanners.setregionboxtagged = function() -- box tag +    setregionbox(scaninteger(),scanstring()) +end +  scanners.markregionboxcorrected = function() -- box tag      markregionbox(scaninteger(),scanstring(),true)  end diff --git a/tex/context/base/anch-pos.mkiv b/tex/context/base/anch-pos.mkiv index ef47da594..f35261742 100644 --- a/tex/context/base/anch-pos.mkiv +++ b/tex/context/base/anch-pos.mkiv @@ -288,7 +288,7 @@     \clf_markregionboxcorrected#1{textarea:\the\c_anch_text}}  \unexpanded\def\anch_make_page_box#1% maybe like text -  {\clf_markregionboxtagged#1{page:\the\realpageno}} % needs an hbox +  {\clf_setregionboxtagged#1{page:\the\realpageno}}  \unexpanded\def\anch_mark_text_box#1%    {\clf_markregionboxtagged#1{text:\the\realpageno}} % needs an hbox diff --git a/tex/context/base/attr-col.lua b/tex/context/base/attr-col.lua index 9dcc991ac..1b9a65520 100644 --- a/tex/context/base/attr-col.lua +++ b/tex/context/base/attr-col.lua @@ -17,9 +17,14 @@ local format = string.format  local concat = table.concat  local min, max, floor = math.min, math.max, math.floor -local attributes, nodes, utilities, logs, backends, storage = attributes, nodes, utilities, logs, backends, storage -local commands, context, interfaces = commands, context, interfaces -local tex = tex +local attributes            = attributes +local nodes                 = nodes +local utilities             = utilities +local logs                  = logs +local backends              = backends +local storage               = storage +local context               = context +local tex                   = tex  local allocate              = utilities.storage.allocate  local setmetatableindex     = table.setmetatableindex @@ -43,6 +48,9 @@ local unsetvalue      = attributes.unsetvalue  local registerstorage = storage.register  local formatters      = string.formatters +local interfaces      = interfaces +local implement       = interfaces.implement +  -- We can distinguish between rules and glyphs but it's not worth the trouble. A  -- first implementation did that and while it saves a bit for glyphs and rules, it  -- costs more resourses for transparencies. So why bother. @@ -560,10 +568,10 @@ end  -- interface -commands.enablecolor        = colors.enable -commands.enabletransparency = transparencies.enable -commands.enablecolorintents = colorintents.enable +implement { name = "enablecolor",         actions = colors.enable } +implement { name = "enabletransparency",  actions = transparencies.enable } +implement { name = "enablecolorintents",  actions = colorintents.enable } -function commands.registercolor       (...) context(colors        .register(...)) end -function commands.registertransparency(...) context(transparencies.register(...)) end -function commands.registercolorintent (...) context(colorintents  .register(...)) end +--------- { name = "registercolor",        actions = { colors        .register, context }, arguments = "string" } +--------- { name = "registertransparency", actions = { transparencies.register, context }, arguments = { ... } } +implement { name = "registercolorintent",  actions = { colorintents  .register, context }, arguments = { ... } } diff --git a/tex/context/base/attr-eff.lua b/tex/context/base/attr-eff.lua index b187b64c7..ff41e12de 100644 --- a/tex/context/base/attr-eff.lua +++ b/tex/context/base/attr-eff.lua @@ -6,7 +6,6 @@ if not modules then modules = { } end modules ['attr-eff'] = {      license   = "see context related readme files"  } -local commands, interfaces = commands, interfaces  local attributes, nodes, backends, utilities = attributes, nodes, backends, utilities  local tex = tex @@ -18,6 +17,9 @@ local allocate          = utilities.storage.allocate  local setmetatableindex = table.setmetatableindex  local formatters        = string.formatters +local interfaces        = interfaces +local implement         = interfaces.implement +  local variables         = interfaces.variables  local v_normal          = variables.normal @@ -91,8 +93,13 @@ local function register(specification)      return n  end +local enabled = false +  local function enable() -    tasks.enableaction("shipouts","attributes.effects.handler") +    if not enabled then +        tasks.enableaction("shipouts","attributes.effects.handler") +        enabled = true +    end  end  effects.register = register @@ -100,12 +107,28 @@ effects.enable   = enable  -- interface -local enabled = false +implement { +    name      = "seteffect", +    actions   = function(specification) +        if not enabled then +            enable() +        end +        texsetattribute(a_effect,register(specification)) +    end, +    arguments = { +        { +            { "alternative",   "string"  }, +            { "stretch",       "integer" }, +            { "rulethickness", "dimen"   } +        } +    } +} -function commands.triggereffect(specification) -    if not enabled then -        enable() -        enabled = true +implement { +    name      = "reseteffect", +    actions   = function() +        if enabled then +            texsetattribute(a_effect,register()) +        end      end -    texsetattribute(a_effect,register(specification)) -end +} diff --git a/tex/context/base/attr-eff.mkiv b/tex/context/base/attr-eff.mkiv index 43f575a7a..bec8687ea 100644 --- a/tex/context/base/attr-eff.mkiv +++ b/tex/context/base/attr-eff.mkiv @@ -36,14 +36,14 @@  \to \everydefineeffect  \unexpanded\def\starteffect[#1]% -  {\ctxcommand{triggereffect{ -     alternative   = "\namedeffectparameter{#1}\c!alternative", -     stretch       = \number\namedeffectparameter{#1}\c!stretch, -     rulethickness = \number\dimexpr\namedeffectparameter{#1}\c!rulethickness\relax -    }}} +  {\clf_seteffect +     alternative   {\namedeffectparameter{#1}\c!alternative} +     stretch       \numexpr\namedeffectparameter{#1}\c!stretch\relax +     rulethickness \dimexpr\namedeffectparameter{#1}\c!rulethickness\relax +   \relax}  \unexpanded\def\stopeffect % can be special -  {\ctxcommand{triggereffect()}} % v!normal 0 0 +  {\clf_reseteffect} % v!normal 0 0  \unexpanded\def\effect[#1]%    {\groupedcommand{\starteffect[#1]}{\stopeffect}} diff --git a/tex/context/base/attr-ini.lua b/tex/context/base/attr-ini.lua index 177eb30eb..df7404d11 100644 --- a/tex/context/base/attr-ini.lua +++ b/tex/context/base/attr-ini.lua @@ -6,8 +6,6 @@ if not modules then modules = { } end modules ['attr-ini'] = {      license   = "see context related readme files"  } -local commands, context, nodes, storage = commands, context, nodes, storage -  local next, type = next, type  --[[ldx-- @@ -15,6 +13,13 @@ local next, type = next, type  symbolic names later on.</p>  --ldx]]-- +local nodes           = nodes +local context         = context +local storage         = storage +local commands        = commands + +local implement       = interfaces.implement +  attributes            = attributes or { }  local attributes      = attributes @@ -126,19 +131,11 @@ function attributes.ofnode(n)      showlist(n,n.attr)  end --- interface - -commands.showattributes = attributes.showcurrent - -function commands.defineattribute(name,category) -    context(attributes.define(name,category)) -end -  -- rather special  local store = { } -function commands.savecurrentattributes(name) +function attributes.save(name)      name = name or ""      local n = node.current_attr()      n = n and n.next @@ -153,7 +150,7 @@ function commands.savecurrentattributes(name)      }  end -function commands.restorecurrentattributes(name) +function attributes.restore(name)      name = name or ""      local t = store[name]      if t then @@ -171,3 +168,28 @@ function commands.restorecurrentattributes(name)      end   -- store[name] = nil  end + +implement { +    name      = "defineattribute", +    arguments = { "string", "string" }, +    actions   = { attributes.define, context } +} + +-- interface + +implement { +    name      = "showattributes", +    actions   = attributes.showcurrent +} + +implement { +    name      = "savecurrentattributes", +    arguments = "string", +    actions   = attributes.save +} + +implement { +    name      = "restorecurrentattributes", +    arguments = "string", +    actions   = attributes.restore +} diff --git a/tex/context/base/attr-ini.mkiv b/tex/context/base/attr-ini.mkiv index d4912ed65..f351a6800 100644 --- a/tex/context/base/attr-ini.mkiv +++ b/tex/context/base/attr-ini.mkiv @@ -44,31 +44,6 @@  \ifdefined \s!public    \else \def\s!public   {public}    \fi % for metatex % or hard check later  \ifdefined \s!attribute \else \def\s!attribute{attribute} \fi % for metatex % or hard check later -% \unexpanded\def\defineattribute -%   {\dodoubleempty\attr_basics_define} -% -% \unexpanded\def\definesystemattribute -%   {\dodoubleempty\attr_basics_define_system} -% -% \def\attr_basics_define[#1]% -%   {\expandafter\newattribute\csname\??attributecount#1\endcsname -%    \expandafter\newconstant \csname\??attributeid#1\endcsname -%    \csname\??attributeid#1\endcsname\c_syst_last_allocated_attribute -%    \ctxcommand{defineattribute("#1",\number\csname\??attributeid#1\endcsname)}% -%    \attr_basics_define_properties[#1]} -% -% \def\attr_basics_define_system[#1]% -%   {\scratchcounter\ctxcommand{getprivateattribute("#1")}\relax -%    \expandafter\attributedef\csname\??attributecount#1\endcsname\scratchcounter -%    \expandafter\newconstant \csname\??attributeid#1\endcsname -%    \csname\??attributeid#1\endcsname\scratchcounter -%   %\writestatus\m!system{defining system attribute #1 with number \number\scratchcounter}% -%    \attr_basics_define_properties[#1]} -% -% \def\attr_basics_define_properties[#1][#2]% -%   {\doifnotinset\s!global{#2}{\appendetoks\csname\??attributecount#1\endcsname\attributeunsetvalue\to\attributesresetlist}% -%    \doifinset   \s!public{#2}{\expandafter\let\csname#1\s!attribute\expandafter\endcsname\csname\??attributeid#1\endcsname}} -  \unexpanded\def\defineattribute      {\dodoubleempty\attr_basics_define}  \unexpanded\def\definesystemattribute{\dodoubleempty\attr_basics_define_system} @@ -76,7 +51,7 @@  \def\attr_basics_define_system{\attr_basics_define_indeed{private}}  \def\attr_basics_define_indeed#1[#2][#3]% -  {\scratchcounter\ctxcommand{defineattribute("#2","#1")}\relax +  {\scratchcounter\clf_defineattribute{#2}{#1}\relax    %\writestatus\m!system{defining #1 attribute #2 with number \number\scratchcounter}%     \expandafter\attributedef\csname\??attributecount#2\endcsname\scratchcounter     \expandafter\newconstant \csname\??attributeid#2\endcsname @@ -101,8 +76,8 @@  %D Rather special. -\unexpanded\def\savecurrentattributes   #1{\ctxcommand{savecurrentattributes   ("#1")}} -\unexpanded\def\restorecurrentattributes#1{\ctxcommand{restorecurrentattributes("#1")}} +\unexpanded\def\savecurrentattributes   #1{\clf_savecurrentattributes   {#1}} +\unexpanded\def\restorecurrentattributes#1{\clf_restorecurrentattributes{#1}}  %D For the moment we put this here (later it will move to where it's used): @@ -127,6 +102,6 @@  \definesystemattribute [checkedbreak]        [public]  \definesystemattribute [vboxtohboxseparator] [public] -\unexpanded\def\showattributes{\ctxcommand{showattributes()}} +\unexpanded\def\showattributes{\clf_showattributes}  \protect \endinput diff --git a/tex/context/base/attr-lay.lua b/tex/context/base/attr-lay.lua index e7d532237..0d43979c8 100644 --- a/tex/context/base/attr-lay.lua +++ b/tex/context/base/attr-lay.lua @@ -15,9 +15,17 @@ if not modules then modules = { } end modules ['attr-lay'] = {  local type = type  local insert, remove = table.insert, table.remove -local attributes, nodes, utilities, logs, backends = attributes, nodes, utilities, logs, backends -local commands, context, interfaces = commands, context, interfaces -local tex = tex +local attributes          = attributes +local nodes               = nodes +local utilities           = utilities +local logs                = logs +local backends            = backends + +local context             = context +local interfaces          = interfaces +local tex                 = tex + +local implement           = interfaces.implement  local allocate            = utilities.storage.allocate  local setmetatableindex   = table.setmetatableindex @@ -38,6 +46,8 @@ local viewerlayers      = attributes.viewerlayers  local variables         = interfaces.variables  local v_local           = variables["local"]  local v_global          = variables["global"] +local v_start           = variables["start"] +local v_yes             = variables["yes"]  local a_viewerlayer     = attributes.private("viewerlayer") @@ -85,11 +95,6 @@ viewerlayers.resolve_begin = layerstacker.resolve_begin  viewerlayers.resolve_step  = layerstacker.resolve_step  viewerlayers.resolve_end   = layerstacker.resolve_end -function commands.cleanuplayers() -    layerstacker.clean() -    -- todo -end -  -- stacked  local function startlayer(...) startlayer = nodeinjections.startlayer return startlayer(...) end @@ -240,15 +245,63 @@ function viewerlayers.define(settings)      end  end -commands.defineviewerlayer = viewerlayers.define -commands.startviewerlayer  = viewerlayers.start -commands.stopviewerlayer   = viewerlayers.stop - -function commands.definedviewerlayer(settings) -    viewerlayers.define(settings) -    context(register(settings.tag,true)) -- true forces a use +function viewerlayers.definedlayoutcomponent(tag) +    viewerlayers.define { +        tag       = tag, +        title     = utilities.strings.nice(tag), +        visible   = v_start, +        editable  = v_yes, +        printable = v_yes, +    } +    return register(tag,true) -- true forces a use  end -function commands.registeredviewerlayer(name) -    context(register(name,true)) -- true forces a use +function viewerlayers.cleanup() +    layerstacker.clean() +    -- todo  end + +implement { +    name      = "cleanuplayers", +    actions   = viewerlayers.cleanup +} + +implement { +    name      = "defineviewerlayer", +    actions   = viewerlayers.define, +    arguments = { +        { +            { "tag" }, +            { "title" }, +            { "visible" }, +            { "editable" }, +            { "export" }, +            { "printable" }, +            { "scope" }, +        }, +        true +    } +} + +implement { +    name      = "definedlayoutcomponent", +    actions   = { viewerlayers.definedlayoutcomponent, context }, +    arguments = "string" +} + +implement { +    name      = "startviewerlayer", +    actions   = viewerlayers.start, +    arguments = "string", +} + +implement { +    name      = "stopviewerlayer", +    actions   = viewerlayers.stop +} + +implement { +    name      = "registeredviewerlayer", +    actions   = { register, context }, +    arguments = { "string", true } -- true forces a use +} diff --git a/tex/context/base/attr-lay.mkiv b/tex/context/base/attr-lay.mkiv index 8181417ab..14ef4a6d4 100644 --- a/tex/context/base/attr-lay.mkiv +++ b/tex/context/base/attr-lay.mkiv @@ -39,23 +39,25 @@     \c!method=\v!none]  \appendtoks -  \ctxcommand{defineviewerlayer{ -       tag       = "\currentviewerlayer", -       title     = "\viewerlayerparameter\c!title", -       visible   = "\viewerlayerparameter\c!state", -       editable  = "\v!yes", -       export    = "\viewerlayerparameter\c!export", -       printable = "\viewerlayerparameter\c!printable", -       scope     = "\viewerlayerparameter\c!scope" -  }}% +  \clf_defineviewerlayer +       tag       {\currentviewerlayer}% +       title     {\viewerlayerparameter\c!title}% +       visible   {\viewerlayerparameter\c!state}% +       editable  {\v!yes}% +       export    {\viewerlayerparameter\c!export}% +       printable {\viewerlayerparameter\c!printable}% +       scope     {\viewerlayerparameter\c!scope}% +  \relax    \doif{\viewerlayerparameter\c!method}\v!command      {\setuxvalue{\e!start#1}{\startviewerlayer[\currentviewerlayer]}%       \setuxvalue{\e!stop #1}{\stopviewerlayer}}%  \to \everydefineviewerlayer -\unexpanded\def\startviewerlayer[#1]{\ctxcommand{startviewerlayer("#1")}}                      % not grouped -\unexpanded\def\stopviewerlayer     {\ctxcommand{stopviewerlayer()}}                           % not grouped -\unexpanded\def\viewerlayer     [#1]{\groupedcommand{\startviewerlayer[#1]}{\stopviewerlayer}} % grouped +\unexpanded\def\startviewerlayer[#1]{\clf_startviewerlayer{#1}}% not grouped +\unexpanded\def\stopviewerlayer     {\clf_stopviewerlayer}     % not grouped +\unexpanded\def\viewerlayer     [#1]{\groupedcommand +                                    {\clf_startviewerlayer{#1}}% grouped +                                    {\clf_stopviewerlayer}}    % grouped  % some day we will keep this at the lua end as the info is only needed there @@ -72,13 +74,7 @@  \installcorenamespace{layoutcomponentattribute}  \def\attr_layoutcomponent_initialize#1% -  {\edef\layoutcomponentboxattribute{\ctxcommand{definedviewerlayer{% -     tag       = "#1", -     title     = utilities.strings.nice("#1"), % only here as in steps we have step:<number> -     visible   = "\v!start", -     editable  = "\v!yes", -     printable = "\v!yes" -   }}}% +  {\edef\layoutcomponentboxattribute{\clf_definedlayoutcomponent{#1}}%     \edef\layoutcomponentboxattribute{attr \viewerlayerattribute \layoutcomponentboxattribute\relax}%     \expandafter\glet\csname\??layoutcomponentattribute#1\endcsname\layoutcomponentboxattribute} @@ -100,7 +96,7 @@     \let\resetlayoutcomponentattribute\attr_layoutcomponent_reset}  \unexpanded\def\attr_layoutcomponent_cleanup -  {\ctxcommand{cleanuplayers()}} +  {\clf_cleanuplayers}  \appendtoks      \attr_layoutcomponent_cleanup diff --git a/tex/context/base/back-exp.lua b/tex/context/base/back-exp.lua index 70ed78282..c37a725ac 100644 --- a/tex/context/base/back-exp.lua +++ b/tex/context/base/back-exp.lua @@ -73,6 +73,8 @@ local v_flushright      = variables.flushright  local v_middle          = variables.middle  local v_flushleft       = variables.flushleft +local implement         = interfaces.implement +  local settings_to_array = utilities.parsers.settings_to_array  local setmetatableindex = table.setmetatableindex @@ -612,6 +614,12 @@ do          }      end +    function structurestags.setitem(head) +        itemgroups[locatedtag("item")] = { +            head = head, +        } +    end +      function extras.itemgroup(di,element,n,fulltag)          local hash = itemgroups[fulltag]          if hash then @@ -621,6 +629,13 @@ do          end      end +    function extras.item(di,element,n,fulltag) +        local hash = itemgroups[fulltag] +        if hash then +            setattribute(di,"head",hash.head and "yes" or nil) +        end +    end +  end  do @@ -3381,7 +3396,7 @@ local htmltemplate = [[      local appendaction = nodes.tasks.appendaction      local enableaction = nodes.tasks.enableaction -    function commands.setupexport(t) +    function structurestags.setupexport(t)          table.merge(finetuning,t)          keephyphens      = finetuning.hyphen == v_yes          exportproperties = finetuning.properties @@ -3390,6 +3405,8 @@ local htmltemplate = [[          end      end + +      local function startexport(v)          if v and not exporting then              report_export("enabling export to xml") @@ -3417,16 +3434,101 @@ end  -- These are called at the tex end: -commands.settagsectionlevel      = structurestags.setsectionlevel -commands.settagitemgroup         = structurestags.setitemgroup -commands.settagsynonym           = structurestags.setsynonym -commands.settagsorting           = structurestags.setsorting -commands.settagdescription       = structurestags.setdescription -commands.settagdescriptionsymbol = structurestags.setdescriptionsymbol -commands.settaghighlight         = structurestags.sethighlight -commands.settagfigure            = structurestags.setfigure -commands.settagcombination       = structurestags.setcombination -commands.settagtablecell         = structurestags.settablecell -commands.settagtabulatecell      = structurestags.settabulatecell -commands.settagregister          = structurestags.setregister -commands.settaglist              = structurestags.setlist +implement { +    name      = "setupexport", +    actions   = structurestags.setupexport, +    arguments = { +        { +            { "align" }, +            { "bodyfont", "dimen" }, +            { "width", "dimen" }, +            { "properties" }, +            { "hyphen" }, +            { "title" }, +            { "subtitle" }, +            { "author" }, +            { "firstpage" }, +            { "lastpage" }, +            { "svgstyle" }, +            { "cssfile" }, +        } +    } +} + +implement { +    name      = "settagitemgroup", +    actions   = structurestags.setitemgroup, +    arguments = { "boolean", "integer", "string" } +} + +implement { +    name      = "settagitem", +    actions   = structurestags.setitem, +    arguments = "boolean" +} + +implement { +    name      = "settagsynonym", +    actions   = structurestags.setsynonym, +    arguments = "string" +} + +implement { +    name      = "settagsorting", +    actions   = structurestags.setsorting, +    arguments = "string" +} + +implement { +    name      = "settagdescription", +    actions   = structurestags.setdescription, +    arguments = { "string", "integer" } +} + +implement { +    name      = "settagdescriptionsymbol", +    actions   = structurestags.setdescriptionsymbol, +    arguments = { "string", "integer" } +} + +implement { +    name      = "settaghighlight", +    actions   = structurestags.sethighlight, +    arguments = { "string", "integer" } +} + +implement { +    name      = "settagfigure", +    actions    = structurestags.setfigure, +    arguments = { "string", "string", "string", "dimen", "dimen" } +} + +implement { +    name      = "settagcombination", +    actions   = structurestags.setcombination, +    arguments = { "integer", "integer" } +} + +implement { +    name      = "settagtablecell", +    actions   = structurestags.settablecell, +    arguments = { "integer", "integer", "integer" } +} + +implement { +    name      = "settagtabulatecell", +    actions   = structurestags.settabulatecell, +    arguments = "integer" +} + +implement { +    name      = "settagregister", +    actions   = structurestags.setregister, +    arguments = { "string", "integer" } +} + +implement { +    name      = "settaglist", +    actions   = structurestags.setlist, +    arguments = "string" +} diff --git a/tex/context/base/back-exp.mkiv b/tex/context/base/back-exp.mkiv index c056547b9..3b26e5ace 100644 --- a/tex/context/base/back-exp.mkiv +++ b/tex/context/base/back-exp.mkiv @@ -80,63 +80,110 @@  \to \everytabulatepar % tricky, maybe this should be neverypar  \appendtoks -    \unexpanded\def\dotagTABLEcell  {\taggedctxcommand{settagtablecell(\number\tablecellrows,\number\tablecellcolumns,\number\raggedstatus)}}% -    \unexpanded\def\dotagTABLEsignal{\char\zerocount}% brrr, we need to tag empty cells (unless we start numbering) +    \unexpanded\def\dotagTABLEcell +      {\iftrialtypesetting\else +         \clf_settagtablecell +           \numexpr\tablecellrows\relax +           \numexpr\tablecellcolumns\relax +           \numexpr\raggedstatus\relax +       \fi}% +    % brrr, we need to tag empty cells (unless we start numbering) +    \unexpanded\def\dotagTABLEsignal +      {\char\zerocount}%  \to \everyenableelements  \appendtoks -    \unexpanded\def\dotagtabulatecell  {\taggedctxcommand{settagtabulatecell(\number\c_tabl_tabulate_align)}}% -    \unexpanded\def\dotagtabulatesignal{\dontleavehmode\char\zerocount\ignorespaces}% +    \unexpanded\def\dotagtabulatecell +      {\iftrialtypesetting\else\clf_settagtabulatecell\c_tabl_tabulate_align\fi}% +    \unexpanded\def\dotagtabulatesignal +      {\dontleavehmode\char\zerocount\ignorespaces}%  \to \everyenableelements -% \appendtoks -%     \unexpanded\def\dotagsectionlevel{\taggedctxcommand{settagsectionlevel("\currentheadlevel")}}% -% \to \everyenableelements -  \appendtoks -    \unexpanded\def\dotagsynonym{\taggedctxcommand{settagsynonym("\currentsynonymtag")}}% +    \unexpanded\def\dotagsynonym +      {\iftrialtypesetting\else\clf_settagsynonym{\currentsynonymtag}\fi}%  \to \everyenableelements  \appendtoks -    \unexpanded\def\dotagsorting{\taggedctxcommand{settagsorting("\currentsortingtag")}}% +    \unexpanded\def\dotagsorting +      {\iftrialtypesetting\else\clf_settagsorting{\currentsortingtag}\fi}%  \to \everyenableelements  \appendtoks % frozen and assumed global per highlight class -    \unexpanded\def\dotaghighlight{\taggedctxcommand{settaghighlight(\!!bs\highlightparameter\c!style\!!es,\number\attribute\colorattribute)}}% +    \unexpanded\def\dotaghighlight +      {\iftrialtypesetting\else +         \clf_settaghighlight{\highlightparameter\c!style}\attribute\colorattribute\relax +       \fi}%  \to \everyenableelements  \appendtoks % we can have differently scaled images -    \unexpanded\def\dotagfigure{\taggedctxcommand{settagfigure("\figurefileoriginal","\figurefullname","\figurefilepage",\number\dimexpr\figurewidth,\number\dimexpr\figureheight)}}% +    \unexpanded\def\dotagfigure +      {\iftrialtypesetting\else +         \clf_settagfigure +           {\figurefileoriginal}% +           {\figurefullname}% +           {\figurefilepage}% +           \dimexpr\figurewidth\relax +           \dimexpr\figureheight\relax +       \fi}%  \to \everyenableelements  \appendtoks -    \unexpanded\def\dotagcombination{\taggedctxcommand{settagcombination(\combinationparameter\c!nx,\combinationparameter\c!ny)}}% -   %\unexpanded\def\dotagcombination{\taggedctxcommand{settagcombination(\number\horcombination,\number\totcombination)}}% +    \unexpanded\def\dotagcombination +      {\iftrialtypesetting\else +         \clf_settagcombination +            \numexpr\combinationparameter\c!nx\relax +            \numexpr\combinationparameter\c!ny\relax +       \fi}%  \to \everyenableelements  \appendtoks -    \unexpanded\def\dotagsetparcounter{\global\advance\tagparcounter\plusone\attribute\taggedparattribute\tagparcounter}% -    \unexpanded\def\doresetparcounter {\attribute\taggedparattribute\attributeunsetvalue}% +    \unexpanded\def\dotagsetparcounter +      {\global\advance\tagparcounter\plusone\attribute\taggedparattribute\tagparcounter}% +    \unexpanded\def\doresetparcounter +      {\attribute\taggedparattribute\attributeunsetvalue}%  \to \everyenableelements  \appendtoks -    \unexpanded\def\dotagsetitemgroup{\taggedctxcommand{settagitemgroup(\ifconditional\c_strc_itemgroups_pack true\else false\fi,\number\currentitemlevel,"\currentitemgroupsymbol")}}% +    \unexpanded\def\dotagsetitemgroup +      {\iftrialtypesetting\else +         \clf_settagitemgroup +           \ifconditional\c_strc_itemgroups_pack true\else false\fi\space +           \numexpr\currentitemlevel\relax +           {\currentitemgroupsymbol}% +       \fi}% +    \unexpanded\def\dotagsetitem +      {\iftrialtypesetting\else +         \clf_settagitem\ifconditional\c_strc_itemgroups_head true\else false\fi\relax +       \fi}%  \to \everyenableelements  \appendtoks -    \unexpanded\def\dotagsetdescription{\taggedctxcommand{settagdescription("\currentdescription",\currentdescriptionnumberentry)}}% +    \unexpanded\def\dotagsetdescription +      {\iftrialtypesetting\else +         \clf_settagdescription{\currentdescription}\currentdescriptionnumberentry\relax +       \fi}%  \to \everyenableelements  \appendtoks -    \unexpanded\def\dotagsetnotesymbol{\taggedctxcommand{settagdescriptionsymbol("\currentnote",\currentnotenumber)}}% +    \unexpanded\def\dotagsetnotesymbol +      {\iftrialtypesetting\else +         \clf_settagdescriptionsymbol{\currentnote}\currentnotenumber\relax +       \fi}%  \to \everyenableelements  \appendtoks -    \unexpanded\def\dotagregisterlocation{\taggedctxcommand{settagregister("\currentregister",\currentregisternumber)}}% +    \unexpanded\def\dotagregisterlocation +      {\iftrialtypesetting\else +         \clf_settagregister{\currentregister}\currentregisternumber\relax +       \fi}%  \to \everyenableelements  \appendtoks -    \unexpanded\def\dotaglistlocation{\taggedctxcommand{settaglist(\currentlistindex)}}% +    \unexpanded\def\dotaglistlocation +      {\iftrialtypesetting\else +         \clf_settaglist{\currentlistindex}% +       \fi}%  \to \everyenableelements  \appendtoks @@ -174,20 +221,20 @@  \def\dosynchronizeexport    {\let\currentexport\empty -   \ctxcommand{setupexport{ -       align      = "\exportparameter\c!align", -       bodyfont   = \number\dimexpr\exportparameter\c!bodyfont, -       width      = \number\dimexpr\exportparameter\c!width, -       properties = "\exportparameter\c!properties", -       hyphen     = "\exportparameter\c!hyphen", -       title      = \!!bs\exportparameter\c!title\!!es, -       subtitle   = \!!bs\exportparameter\c!subtitle\!!es, -       author     = \!!bs\exportparameter\c!author\!!es, -       firstpage  = "\exportparameter\c!firstpage", -       lastpage   = "\exportparameter\c!lastpage", -       svgstyle   = "\exportparameter\c!svgstyle", -       cssfile    = "\exportparameter\c!cssfile", -   }}} +   \clf_setupexport +       align      {\exportparameter\c!align}% +       bodyfont   \dimexpr\exportparameter\c!bodyfont\relax +       width      \dimexpr\exportparameter\c!width\relax +       properties {\exportparameter\c!properties}% +       hyphen     {\exportparameter\c!hyphen}% +       title      {\exportparameter\c!title}% +       subtitle   {\exportparameter\c!subtitle}% +       author     {\exportparameter\c!author}% +       firstpage  {\exportparameter\c!firstpage}% +       lastpage   {\exportparameter\c!lastpage}% +       svgstyle   {\exportparameter\c!svgstyle}% +       cssfile    {\exportparameter\c!cssfile}% +   \relax}  \appendtoks      \doifsomething{\backendparameter\c!export}\dosynchronizeexport diff --git a/tex/context/base/blob-ini.lua b/tex/context/base/blob-ini.lua index 7c30131bc..b837250ce 100644 --- a/tex/context/base/blob-ini.lua +++ b/tex/context/base/blob-ini.lua @@ -45,6 +45,8 @@ local tohpackfast     = typesetters.tohpackfast  local tovpack         = typesetters.tovpack  local tovpackfast     = typesetters.tovpackfast +local implement       = interfaces.implement +  blobs = blobs or  { }  -- provide copies here (nicer for manuals) @@ -195,7 +197,7 @@ blobs.strht = strht  blobs.strdp = strdp  blobs.strhd = strhd -function commands.strwd(str) context(strwd(str)) end -function commands.strht(str) context(strht(str)) end -function commands.strdp(str) context(strdp(str)) end -function commands.strhd(str) context(strhd(str)) end +implement { name = "strwd", arguments = "string", actions = { strwd, context } } +implement { name = "strht", arguments = "string", actions = { strht, context } } +implement { name = "strdp", arguments = "string", actions = { strdp, context } } +implement { name = "strhd", arguments = "string", actions = { strhd, context } } diff --git a/tex/context/base/blob-ini.mkiv b/tex/context/base/blob-ini.mkiv index 1dfb766f4..64582c0db 100644 --- a/tex/context/base/blob-ini.mkiv +++ b/tex/context/base/blob-ini.mkiv @@ -27,10 +27,10 @@  % this one takes simple (utf) strings -\def\wdofstring#1{\dimexpr\ctxcommand{strwd(\!!bs#1\!!es)}\scaledpoint\relax} -\def\htofstring#1{\dimexpr\ctxcommand{strht(\!!bs#1\!!es)}\scaledpoint\relax} -\def\dpofstring#1{\dimexpr\ctxcommand{strdp(\!!bs#1\!!es)}\scaledpoint\relax} -\def\hdofstring#1{\dimexpr\ctxcommand{strhd(\!!bs#1\!!es)}\scaledpoint\relax} +\def\wdofstring#1{\dimexpr\clf_strwd{#1}\scaledpoint\relax} +\def\htofstring#1{\dimexpr\clf_strht{#1}\scaledpoint\relax} +\def\dpofstring#1{\dimexpr\clf_strdp{#1}\scaledpoint\relax} +\def\hdofstring#1{\dimexpr\clf_strhd{#1}\scaledpoint\relax}  \def\widthofstring         {\the\wdofstring}  \def\heightofstring        {\the\htofstring} diff --git a/tex/context/base/buff-ver.mkiv b/tex/context/base/buff-ver.mkiv index c756c57c4..9a1c769d2 100644 --- a/tex/context/base/buff-ver.mkiv +++ b/tex/context/base/buff-ver.mkiv @@ -861,7 +861,7 @@       name   {#2}%       strip  {\typingparameter\c!strip}%       tab    {\typingparameter\c!tab}% -     method {\p_buff_option}% +   % method {\p_buff_option}%       nature {direct}%     \relax} diff --git a/tex/context/base/chem-ini.lua b/tex/context/base/chem-ini.lua index 10db1a1e4..f7d10ffa2 100644 --- a/tex/context/base/chem-ini.lua +++ b/tex/context/base/chem-ini.lua @@ -32,12 +32,31 @@ function chemistry.molecule(str)      return lpegmatch(moleculeparser,str)  end -function commands.molecule(str) -    if trace_molecules then -        local rep = lpegmatch(moleculeparser,str) -        report_chemistry("molecule %a becomes %a",str,rep) -        context(rep) -    else -        context(lpegmatch(moleculeparser,str)) -    end -end +interfaces.implement { +    name      = "molecule", +    arguments = "string", +    actions   = function(str) +        if trace_molecules then +            local rep = lpegmatch(moleculeparser,str) +            report_chemistry("molecule %a becomes %a",str,rep) +            context(rep) +        else +            context(lpegmatch(moleculeparser,str)) +        end +    end, +} + +-- interfaces.implement { +--     name      = "molecule", +--     scope     = "private", +--     action    = function() +--         local str = scanstring() +--         if trace_molecules then +--             local rep = lpegmatch(moleculeparser,str) +--             report_chemistry("molecule %a becomes %a",str,rep) +--             context(rep) +--         else +--             context(lpegmatch(moleculeparser,str)) +--         end +--     end, +-- } diff --git a/tex/context/base/chem-ini.mkiv b/tex/context/base/chem-ini.mkiv index 357bceefa..9a44b4f1a 100644 --- a/tex/context/base/chem-ini.mkiv +++ b/tex/context/base/chem-ini.mkiv @@ -37,7 +37,7 @@  %D \typebuffer \getbuffer  \unexpanded\def\molecule#1% -  {\ctxcommand{molecule(\!!bs#1\!!es)}} +  {\clf_molecule{#1}}  %D For old times sake: diff --git a/tex/context/base/chem-str.lua b/tex/context/base/chem-str.lua index 6c1d3b837..d724394bb 100644 --- a/tex/context/base/chem-str.lua +++ b/tex/context/base/chem-str.lua @@ -44,6 +44,8 @@ local P, R, S, C, Cs, Ct, Cc, Cmt = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cs, lpe  local variables    = interfaces and interfaces.variables  local commands     = commands  local context      = context +local implement    = interfaces.implement +  local formatters   = string.formatters  local texgetcount  = tex.getcount @@ -67,6 +69,7 @@ local chemistry = chemistry  chemistry.instance   = "chemistry"  chemistry.format     = "metafun" +chemistry.method     = "double"  chemistry.structures = 0  local common_keys = { @@ -768,6 +771,7 @@ function chemistry.stop()          metapost.graphic {              instance    = chemistry.instance,              format      = chemistry.format, +            method      = chemistry.method,              data        = mpcode,              definitions = f_initialize,          } @@ -776,14 +780,12 @@ function chemistry.stop()      end  end -function chemistry.component(spec,text,settings) +function chemistry.component(spec,text,rulethickness,rulecolor)      if metacode then -        rulethickness, rulecolor, offset = settings.rulethickness, settings.rulecolor          local spec = settings_to_array_with_repeat(spec,true) -- no lower?          local text = settings_to_array_with_repeat(text,true) -    -- inspect(spec)          metacode[#metacode+1] = f_start_component -        process(1,spec,text,1,rulethickness,rulecolor) -- offset? +        process(1,spec,text,1,rulethickness,rulecolor)          metacode[#metacode+1] = f_stop_component      end  end @@ -796,11 +798,52 @@ end)  -- interfaces -commands.undefinechemical  = chemistry.undefine -commands.definechemical    = chemistry.define -commands.startchemical     = chemistry.start -commands.stopchemical      = chemistry.stop -commands.chemicalcomponent = chemistry.component +implement { +    name      = "undefinechemical", +    actions   = chemistry.undefine, +    arguments = "string" +} + +implement { +    name      = "definechemical", +    actions   = chemistry.define, +    arguments = { "string", "string", "string" } +} + +implement { +    name      = "startchemical", +    actions   = chemistry.start, +    arguments = { +        { +            { "width" }, +            { "height" }, +            { "left" }, +            { "right" }, +            { "top" }, +            { "bottom" }, +            { "scale" }, +            { "rotation" }, +            { "symalign" }, +            { "axis" }, +            { "framecolor" }, +            { "rulethickness" }, +            { "offset" }, +            { "unit" }, +            { "factor" } +        } +    } +} + +implement { +    name      = "stopchemical", +    actions   = chemistry.stop, +} + +implement { +    name      = "chemicalcomponent", +    actions   = chemistry.component, +    arguments = { "string", "string", "string", "string" } +}  -- todo: top / bottom  -- maybe add "=" for double and "≡" for triple? @@ -817,7 +860,9 @@ local inline = {      ["space"]       = "\\chemicalspace",  } -function commands.inlinechemical(spec) +local ctx_chemicalinline = context.chemicalinline + +function chemistry.inlinechemical(spec)      local spec = settings_to_array_with_repeat(spec,true)      for i=1,#spec do          local s = spec[i] @@ -825,7 +870,13 @@ function commands.inlinechemical(spec)          if inl then              context(inl) -- could be a fast context.sprint          else -            context.chemicalinline(molecule(s)) +            ctx_chemicalinline(molecule(s))          end      end  end + +implement { +    name      = "inlinechemical", +    actions   = chemistry.inlinechemical, +    arguments = "string" +} diff --git a/tex/context/base/chem-str.mkiv b/tex/context/base/chem-str.mkiv index 801683cfd..e810977ab 100644 --- a/tex/context/base/chem-str.mkiv +++ b/tex/context/base/chem-str.mkiv @@ -62,7 +62,7 @@  %D a historical and practical reason (like shared keys with different meaning  %D that could clash, e.g.\ align). -\defineMPinstance +\defineMPinstance % not really needed as we set in lua    [chemistry]    [\s!format=metafun,    %\s!extensions=\v!yes,      % Should we add extensions and initializations? @@ -88,7 +88,7 @@    {\startnointerference     \edef\currentdefinedchemical{#1}%     \let\chemical\chem_chemical_nested -   \ctxcommand{undefinechemical("#1")}% +   \clf_undefinechemical{#1}%     #2% flush     \stopnointerference} @@ -96,7 +96,7 @@    {\dodoubleempty\chem_chemical_nested_indeed}  \def\chem_chemical_nested_indeed[#1][#2]% -  {\ctxcommand{definechemical("\currentdefinedchemical",\!!bs#1\!!es,\!!bs\detokenize{#2}\!!es)}} +  {\clf_definechemical{\currentdefinedchemical}{#1}{\detokenize{#2}}}  % chemical symbols @@ -160,28 +160,28 @@     \fi\fi     \the\everystructurechemical     \setbox\b_chem_result\hbox\bgroup -   \ctxcommand{startchemical { -     width         = "\chemicalparameter\c!width", -     height        = "\chemicalparameter\c!height", -     left          = "\chemicalparameter\c!left", -     right         = "\chemicalparameter\c!right", -     top           = "\chemicalparameter\c!top", -     bottom        = "\chemicalparameter\c!bottom", -     scale         = "\chemicalparameter\c!scale", -     rotation      = "\chemicalparameter\c!rotation", -     symalign      = "\chemicalparameter\c!symalign", -     axis          = "\chemicalparameter\c!axis", -     framecolor    = "\MPcolor{\chemicalparameter\c!framecolor}", -     rulethickness = \number\dimexpr\chemicalparameter\c!rulethickness\relax, -     offset        = \number\dimexpr\chemicalparameter\c!offset\relax, -     unit          = \number\dimexpr\chemicalparameter\c!unit\relax, -     factor        = \number\chemicalparameter\c!factor, -   } }% +   \clf_startchemical +     width         {\chemicalparameter\c!width}% +     height        {\chemicalparameter\c!height}% +     left          {\chemicalparameter\c!left}% +     right         {\chemicalparameter\c!right}% +     top           {\chemicalparameter\c!top}% +     bottom        {\chemicalparameter\c!bottom}% +     scale         {\chemicalparameter\c!scale}% +     rotation      {\chemicalparameter\c!rotation}% +     symalign      {\chemicalparameter\c!symalign}% +     axis          {\chemicalparameter\c!axis}% +     framecolor    {\MPcolor{\chemicalparameter\c!framecolor}}% +     rulethickness {\number\dimexpr\chemicalparameter\c!rulethickness}% +     offset        {\number\dimexpr\chemicalparameter\c!offset}% +     unit          {\number\dimexpr\chemicalparameter\c!unit}% +     factor        {\number\chemicalparameter\c!factor}% +   \relax     \startnointerference}  \unexpanded\def\stopchemical    {\stopnointerference -   \ctxcommand{stopchemical()}% +   \clf_stopchemical     \egroup     \d_chem_width \wd\b_chem_result     \d_chem_height\ht\b_chem_result @@ -222,17 +222,21 @@  \def\strc_chem_indeed_three[#1][#2][#3]%    {\writestatus\m!chemicals{hyperlinked chemicals not yet supported}% todo reference, for the moment ignored -   \ctxcommand{chemicalcomponent(\!!bs#2\!!es, \!!bs\detokenize{#3}\!!es, { % maybe also pass first two args this way -     rulethickness = "\the\dimexpr\chemicalparameter\c!rulethickness\relax", % todo: scaled points -     rulecolor     = "\MPcolor{\chemicalparameter\c!rulecolor}" % we can precalculate this for speedup -    } ) }% +   \clf_chemicalcomponent +      {#2}% +      {\detokenize{#3}}% +      {\the\dimexpr\chemicalparameter\c!rulethickness}% todo: scaled points +      {\MPcolor{\chemicalparameter\c!rulecolor}}%     % we can precalculate this for speedup +   \relax     \ignorespaces}  \def\strc_chem_indeed_two[#1][#2]% -  {\ctxcommand{chemicalcomponent(\!!bs#1\!!es,\!!bs\detokenize{#2}\!!es, { % maybe also pass first two args this way -     rulethickness = "\the\dimexpr\chemicalparameter\c!rulethickness\relax", % todo: scaled points -     rulecolor     = "\MPcolor{\chemicalparameter\c!rulecolor}" % we can precalculate this for speedup -    } ) }% +  {\clf_chemicalcomponent +      {#1}% +      {\detokenize{#2}}% +      {\the\dimexpr\chemicalparameter\c!rulethickness}% todo: scaled points +      {\MPcolor{\chemicalparameter\c!rulecolor}}%     % we can precalculate this for speedup +   \relax     \ignorespaces}  \appendtoks @@ -311,8 +315,8 @@  \def\chem_arrow_construct#1#2#3%    {\enspace     \mathematics{#1% -     {\strut\hbox \s!spread 2\emwidth{\hss\ctxcommand{inlinechemical(\!!bs#3\!!es)}\hss}}%   {\strut\hbox \s!spread 2em{\hss#3\hss}}}% -     {\strut\hbox \s!spread 2\emwidth{\hss\ctxcommand{inlinechemical(\!!bs#2\!!es)}\hss}}}%  {\strut\hbox \s!spread 2em{\hss#2\hss}}% +     {\strut\hbox \s!spread 2\emwidth{\hss\clf_inlinechemical{#3}\hss}}%   {\strut\hbox \s!spread 2em{\hss#3\hss}}}% +     {\strut\hbox \s!spread 2\emwidth{\hss\clf_inlinechemical{#2}\hss}}}%  {\strut\hbox \s!spread 2em{\hss#2\hss}}%     \enspace}  % special macros (probably needs some more work) @@ -505,7 +509,7 @@     \begingroup     \scratchcounter\normalmathstyle     \usechemicalstyleandcolor\c!style\c!color -   \hbox{\mathematics{\tf\triggermathstyle\scratchcounter\ctxcommand{inlinechemical(\!!bs#1\!!es)}}}% +   \hbox{\mathematics{\tf\triggermathstyle\scratchcounter\clf_inlinechemical{#1}}}%     \endgroup}  \unexpanded\def\displaychemical @@ -531,7 +535,7 @@  \unexpanded\def\inlinechemical#1%    {\dontleavehmode -   \hbox{\usechemicalstyleandcolor\c!style\c!color\ctxcommand{inlinechemical(\!!bs#1\!!es)}}} +   \hbox{\usechemicalstyleandcolor\c!style\c!color\clf_inlinechemical{#1}}}  \unexpanded\def\chemicalbondrule    {\hbox{\vrule\s!height.75\exheight\s!depth-\dimexpr.75\exheight-\linewidth\relax\s!width\emwidth\relax}} diff --git a/tex/context/base/cldf-scn.lua b/tex/context/base/cldf-scn.lua index 13339c362..5948fdeaf 100644 --- a/tex/context/base/cldf-scn.lua +++ b/tex/context/base/cldf-scn.lua @@ -6,14 +6,15 @@ if not modules then modules = { } end modules ['cldf-scn'] = {      license   = "see context related readme files"  } -if not tokens.setters then return end -  local load, type = load, type  local formatters = string.formatters  local char       = string.char  local concat     = table.concat +local lpegmatch  = lpeg.match +local p_unquoted = lpeg.Cs(lpeg.patterns.unquoted) +  local f_action_f = formatters["action%s(%s)"]  local f_action_s = formatters["local action%s = action[%s]"]  local f_command  = formatters["local action = tokens._action\n%\nt\nreturn function(%s) return %s end"] @@ -51,21 +52,36 @@ function interfaces.implement(specification)      elseif #actions == 1 then          command = actions[1]      else +        -- this one is not yet complete .. compare tokens          tokens._action = actions          local f = { } -        local a = { } -        local args = "" -        if arguments then +        local args +        if not arguments then +            args = "" +        elseif type(arguments) == "table" then +            local a = { }              for i=1,#arguments do                  local v = arguments[i]                  local t = type(v)                  if t == "boolean" then                      a[i] = tostring(v) +                elseif t == "number" then +                    a[i] = tostring(v) +                elseif t == "string" then +                    local s = lpegmatch(p_unquoted,v) +                    if s and v ~= s then +                        a[i] = v -- a string, given as "'foo'" or '"foo"' +                    else +                        a[i] = char(96+i) +                    end                  else +                    -- nothing special for tables                      a[i] = char(96+i)                  end              end              args = concat(a,",") +        else +            args = "a"          end          command = args          for i=1,#actions do @@ -79,7 +95,7 @@ function interfaces.implement(specification)          end          tokens._action = nil      end -    if scanners[name] then +    if scanners[name] and not specification.overload then          report("warning: 'scanners.%s' is redefined",name)      end      scanners[name] = scanner diff --git a/tex/context/base/colo-ext.mkiv b/tex/context/base/colo-ext.mkiv index 41d60cb0b..c076fda9e 100644 --- a/tex/context/base/colo-ext.mkiv +++ b/tex/context/base/colo-ext.mkiv @@ -47,10 +47,10 @@  \installcorenamespace{colorintent}  \unexpanded\def\registercolorintent#1#2% -  {\setevalue{\??colorintent#1}{\attribute\colorintentattribute\ctxcommand{registercolorintent('#2')} }} +  {\setevalue{\??colorintent#1}{\attribute\colorintentattribute\clf_registercolorintent{#2}}}  \unexpanded\def\colo_intents_set -  {\ctxcommand{enablecolorintents()}% +  {\clf_enablecolorintents     \unexpanded\gdef\colo_intents_set##1{\csname\??colorintent##1\endcsname}%     \colo_intents_set} diff --git a/tex/context/base/colo-ini.lua b/tex/context/base/colo-ini.lua index 19d0703cf..35c72ef47 100644 --- a/tex/context/base/colo-ini.lua +++ b/tex/context/base/colo-ini.lua @@ -17,16 +17,13 @@ local trace_define = false  trackers.register("colors.define",function(v) trace_  local report_colors = logs.reporter("colors","defining") -local attributes, backends, storage = attributes, backends, storage -local context, commands = context, commands +local attributes          = attributes +local backends            = backends +local storage             = storage +local context             = context +local commands            = commands -local scanners            = tokens.scanners -local scanstring          = scanners.string -local scanboolean         = scanners.boolean -local scaninteger         = scanners.integer - -local compilescanner      = tokens.compile -local scanners            = interfaces.scanners +local implement           = interfaces.implement  local settings_to_hash_strict = utilities.parsers.settings_to_hash_strict @@ -65,7 +62,7 @@ local function pushset(name)      end  end -local function popset(name) +local function popset()      colorset = remove(stack)  end @@ -814,7 +811,13 @@ colors.defineintermediatecolor = defineintermediatecolor  -- for the moment downward compatible -local patterns = { "colo-imp-%s.mkiv", "colo-imp-%s.tex", "colo-%s.mkiv", "colo-%s.tex" } +local patterns = { +    "colo-imp-%s.mkiv", +    "colo-imp-%s.tex", +    -- obsolete: +    "colo-%s.mkiv", +    "colo-%s.tex" +}  local function action(name,foundname)      -- could be one command @@ -844,130 +847,120 @@ end  colors.usecolors = usecolors --- interface (todo: use locals) +-- backend magic -local setcolormodel = colors.setmodel +local currentpagecolormodel -function commands.setcolormodel(model,weight) -    texsetattribute(a_colorspace,setcolormodel(model,weight)) +function colors.setpagecolormodel(model) +    currentpagecolormodel = model  end -scanners.setcolormodel = function() -    texsetattribute(a_colorspace,setcolormodel(scanstring(),scanboolean())) +function colors.getpagecolormodel() +    return currentpagecolormodel  end --- function commands.setrastercolor(name,s) ---     texsetattribute(a_color,colors.definesimplegray(name,s)) --- end +-- interface -function commands.registermaintextcolor(a) -    colors.main = a -end +local setcolormodel = colors.setmodel + +implement { +    name      = "setcolormodel", +    arguments = { "string", "boolean" }, +    actions   = function(model,weight) +        texsetattribute(a_colorspace,setcolormodel(model,weight)) +    end +} -commands.defineprocesscolor      = defineprocesscolor -commands.definespotcolor         = definespotcolor -commands.definemultitonecolor    = definemultitonecolor -commands.definetransparency      = definetransparency -commands.defineintermediatecolor = defineintermediatecolor +implement { +    name      = "setpagecolormodel", +    actions   = colors.setpagecolormodel, +    arguments = { "string" }, +} -scanners.defineprocesscolorlocal = compilescanner { +implement { +    name      = "defineprocesscolorlocal",      actions   = defineprocesscolor,      arguments = { "string", "string", false, "boolean" }  } -scanners.defineprocesscolorglobal = compilescanner { +implement { +    name      = "defineprocesscolorglobal",      actions   = defineprocesscolor,      arguments = { "string", "string", true, "boolean" }  } -scanners.defineprocesscolordummy = compilescanner { +implement { +    name      = "defineprocesscolordummy",      actions   = defineprocesscolor,      arguments = { "'d_u_m_m_y'", "string", false, false }  } -scanners.definespotcolorglobal = compilescanner { +implement { +    name      = "definespotcolorglobal",      actions   = definespotcolor,      arguments = { "string", "string", "string", true }  } -scanners.definemultitonecolorglobal = compilescanner { -    actions   = definespotcolor, +implement { +    name      = "definemultitonecolorglobal", +    actions   = definemultitonecolor,      arguments = { "string", "string", "string", "string", true }  } -scanners.registermaintextcolor = function() -    colors.main = scaninteger() -end +implement { +    name      = "registermaintextcolor", +    actions   = function(main) +        colors.main = main +    end, +    arguments = { "integer" } +} -scanners.definetransparency = compilescanner { +implement { +    name      = "definetransparency",      actions   = definetransparency, -    arguments = { "string", "integer" }, +    arguments = { "string", "integer" }  } -scanners.defineintermediatecolor = compilescanner { +implement { +    name      = "defineintermediatecolor",      actions   = defineintermediatecolor,      arguments = { "string", "string", "integer", "integer", "integer", "integer", "string", false, "boolean" }  } -function commands.spotcolorname         (a)   context(spotcolorname         (a))   end -function commands.spotcolorparent       (a)   context(spotcolorparent       (a))   end -function commands.spotcolorvalue        (a)   context(spotcolorvalue        (a))   end -function commands.colorcomponents       (a,s) context(colorcomponents       (a,s)) end -function commands.transparencycomponents(a,s) context(transparencycomponents(a,s)) end -function commands.processcolorcomponents(a,s) context(processcolorcomponents(a,s)) end -function commands.formatcolor           (...) context(formatcolor           (...)) end -function commands.formatgray            (...) context(formatgray            (...)) end - -scanners.spotcolorname          = compilescanner {  actions = spotcolorname,   arguments = "integer" } -scanners.spotcolorparent        = compilescanner {  actions = spotcolorparent, arguments = "integer" } -scanners.spotcolorvalue         = compilescanner {  actions = spotcolorvalue,  arguments = "integer" } - -scanners.colorcomponents        = compilescanner {  actions = colorcomponents,        arguments =   "integer" } -scanners.transparencycomponents = compilescanner {  actions = transparencycomponents, arguments =   "integer" } -scanners.processcolorcomponents = compilescanner {  actions = processcolorcomponents, arguments = { "integer", "','" } } - -scanners.formatcolor            = compilescanner {  actions = formatcolor, arguments = { "integer", "string" } } -scanners.formatgray             = compilescanner {  actions = formatgray,  arguments = { "integer", "string" } } - -function commands.mpcolor(model,ca,ta,default) -    context(mpcolor(model,ca,ta,default)) -end - --- scanners.mpcolor = function() ---     context(mpcolor(scaninteger(),scaninteger(),scaninteger())) --- end - -scanners.mpcolor = compilescanner { +implement { name = "spotcolorname",          actions = { spotcolorname,          context }, arguments = "integer" } +implement { name = "spotcolorparent",        actions = { spotcolorparent,        context }, arguments = "integer" } +implement { name = "spotcolorvalue",         actions = { spotcolorvalue,         context }, arguments = "integer" } +implement { name = "colorcomponents",        actions = { colorcomponents,        context }, arguments = "integer" } +implement { name = "transparencycomponents", actions = { transparencycomponents, context }, arguments = "integer" } +implement { name = "processcolorcomponents", actions = { processcolorcomponents, context }, arguments = "integer" } +implement { name = "formatcolor",            actions = { formatcolor,            context }, arguments = { "integer", "string" } } +implement { name = "formatgray",             actions = { formatgray,             context }, arguments = { "integer", "string" } } + +implement { +    name      = "mpcolor",      actions   = { mpcolor, context },      arguments = { "integer", "integer", "integer" }  } -function commands.mpoptions(model,ca,ta,default) -    context(mpoptions(model,ca,ta,default)) -end - -scanners.mpoptions = compilescanner { +implement { +    name      = "mpoptions",      actions   = { mpoptions, context },      arguments = { "integer", "integer", "integer" }  }  local ctx_doifelse = commands.doifelse -function commands.doifblackelse(a) -    ctx_doifelse(isblack(a)) -end - -function commands.doifdrawingblackelse() -    ctx_doifelse(isblack(texgetattribute(a_color))) -end +implement { +    name      = "doifdrawingblackelse", +    actions   = function() ctx_doifelse(isblack(texgetattribute(a_color))) end +} -scanners.doifblackelse = compilescanner { +implement { +    name      = "doifblackelse",      actions   = { isblack, ctx_doifelse },      arguments = "integer"  } -scanners.doifdrawingblackelse = commands.doifdrawingblackelse -  -- function commands.withcolorsinset(name,command)  --     local set  --     if name and name ~= "" then @@ -986,38 +979,36 @@ scanners.doifdrawingblackelse = commands.doifdrawingblackelse  --     end  -- end -commands.startcolorset = pushset -commands.stopcolorset  = popset -commands.usecolors     = usecolors - -scanners.startcolorset = compilescanner { actions = pushset, arguments = "string" } -scanners.stopcolorset  = popset -scanners.usecolors     = compilescanner { actions = usecolors, arguments = "string" } +implement { name = "startcolorset", actions = pushset,   arguments = "string" } +implement { name = "stopcolorset",  actions = popset } +implement { name = "usecolors",     actions = usecolors, arguments = "string" }  -- bonus -local function pgfxcolorspec(ca) -- {}{}{colorspace}{list} +function colors.pgfxcolorspec(ca) -- {}{}{colorspace}{list}   -- local cv = attributes.colors.values[ca]      local cv = colorvalues[ca]      if cv then          local model = cv[1]          if model == 2 then -            context("{gray}{%1.3f}",cv[2]) +            return formatters["{gray}{%1.3f}"](cv[2])          elseif model == 3 then -            context("{rgb}{%1.3f,%1.3f,%1.3f}",cv[3],cv[4],cv[5]) +            return formatters["{rgb}{%1.3f,%1.3f,%1.3f}"](cv[3],cv[4],cv[5])          elseif model == 4 then -            context("{cmyk}{%1.3f,%1.3f,%1.3f,%1.3f}",cv[6],cv[7],cv[8],cv[9]) +            return formatters["{cmyk}{%1.3f,%1.3f,%1.3f,%1.3f}"](cv[6],cv[7],cv[8],cv[9])          else -            context("{gray}{%1.3f}",cv[2]) +            return formatters["{gray}{%1.3f}"](cv[2])          end      else -        context("{gray}{0}") +        return "{gray}{0}"      end  end -commands.pgfxcolorspec = pgfxcolorspec - -scanners.pgfxcolorspec = compilescanner { actions = pgfxcolorspec, arguments = "integer" } +implement { +    name      = "pgfxcolorspec", +    actions   = { colors.pgfxcolorspec, context }, +    arguments = "integer" +}  -- function commands.pgfregistercolor(name,attribute)  --     local cv = colorvalues[ca] diff --git a/tex/context/base/colo-ini.mkiv b/tex/context/base/colo-ini.mkiv index 217330afc..621b7a303 100644 --- a/tex/context/base/colo-ini.mkiv +++ b/tex/context/base/colo-ini.mkiv @@ -255,14 +255,14 @@     \colo_helpers_set_current_model     \ifproductionrun       \edef\p_pagecolormodel{\directcolorsparameter\c!pagecolormodel}% -     \ctxcommand{synchronizecolormodel("\ifx\p_pagecolormodel\v!auto \currentcolormodel \else \p_pagecolormodel \fi")}% +     \clf_setpagecolormodel{\ifx\p_pagecolormodel\v!auto\currentcolormodel\else\p_pagecolormodel\fi}%     \fi  \to \everysetupcolors  \appendtoks      \setupcolors[\c!state=\v!start]% -    \ctxcommand{enablecolor()}%           % this can as well happen when -    \ctxcommand{enabletransparency()}%    % the handler is defined in lua +    \clf_enablecolor           % this can as well happen when +    \clf_enabletransparency    % the handler is defined in lua      \let\colo_helpers_show_message\showmessage  \to \everyjob @@ -1068,7 +1068,7 @@  \def\MPoptions#1% -  {\clfmpoptions +  {\clf_mpoptions       \attribute\colormodelattribute       \colo_helpers_inherited_current_ca{#1} %       \colo_helpers_inherited_current_ta{#1} } @@ -1076,16 +1076,15 @@  \def\thecolorattribute       #1{\number\csname\??colorattribute       \ifcsname\??colorattribute       \currentcolorprefix#1\endcsname\currentcolorprefix#1\else\ifcsname\??colorattribute       #1\endcsname#1\fi\fi\endcsname}  \def\thetransparencyattribute#1{\number\csname\??transparencyattribute\ifcsname\??transparencyattribute\currentcolorprefix#1\endcsname\currentcolorprefix#1\else\ifcsname\??transparencyattribute#1\endcsname#1\fi\fi\endcsname} -  \def\thecolormodelattribute    {\the\attribute\colormodelattribute}  \def\internalspotcolorname   #1{\clf_spotcolorname  \thecolorattribute{#1} }  \def\internalspotcolorparent #1{\clf_spotcolorparent\thecolorattribute{#1} }  \def\internalspotcolorsize   #1{\clf_spotcolorvalue \thecolorattribute{#1} } -\def\colorcomponents         #1{\clf_colorcomponents       \thecolorattribute{#1} } +\def\colorcomponents         #1{\clf_colorcomponents       \thecolorattribute       {#1} }  \def\transparencycomponents  #1{\clf_transparencycomponents\thetransparencyattribute{#1} } -\def\processcolorcomponents  #1{\clf_processcolorcomponents\thecolorattribute{#1} } +\def\processcolorcomponents  #1{\clf_processcolorcomponents\thecolorattribute       {#1} }  \def\colorvalue              #1{\clf_formatcolor\thecolorattribute{#1}{\colorformatseparator}}  \def\grayvalue               #1{\clf_formatgray \thecolorattribute{#1}{\colorformatseparator}} diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index de6e6c573..bb8f9e38c 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,7 +11,7 @@  %C therefore copyrighted by \PRAGMA. See mreadme.pdf for  %C details. -\newcontextversion{2015.03.28 22:37} +\newcontextversion{2015.03.30 23:33}  %D This file is loaded at runtime, thereby providing an excellent place for  %D hacks, patches, extensions and new features. diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdfBinary files differ index b66529ce9..d1915c91d 100644 --- a/tex/context/base/context-version.pdf +++ b/tex/context/base/context-version.pdf diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 06723d6c2..50fa0da05 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -28,7 +28,7 @@  %D up and the dependencies are more consistent.  \edef\contextformat {\jobname} -\edef\contextversion{2015.03.28 22:37} +\edef\contextversion{2015.03.30 23:33}  \edef\contextkind   {beta}  %D For those who want to use this: diff --git a/tex/context/base/core-con.lua b/tex/context/base/core-con.lua index 9a48255bd..93cf0400e 100644 --- a/tex/context/base/core-con.lua +++ b/tex/context/base/core-con.lua @@ -24,6 +24,7 @@ local P, C, Cs, lpegmatch = lpeg.P, lpeg.C, lpeg.Cs, lpeg.match  local context            = context  local commands           = commands +local implement          = interfaces.implement  local settings_to_array  = utilities.parsers.settings_to_array  local allocate           = utilities.storage.allocate @@ -39,10 +40,8 @@ local languages          = languages  converters.number  = tonumber  converters.numbers = tonumber -commands.number  = context -commands.numbers = context - -ctx_doifelse     = commands.doifelse +implement { name = "number",  actions = context } +implement { name = "numbers", actions = context }  -- to be reconsidered ... languages namespace here, might become local plus a register command @@ -223,8 +222,13 @@ local function do_alphabetic(n,mapping,mapper,t) -- todo: make zero based varian      end  end -local function alphabetic(n,code) return do_alphabetic(n,code and counters[code] or defaultcounter,lowercharacter) end -local function Alphabetic(n,code) return do_alphabetic(n,code and counters[code] or defaultcounter,uppercharacter) end +local function alphabetic(n,code) +    return do_alphabetic(n,code and code ~= "" and counters[code] or defaultcounter,lowercharacter) +end + +local function Alphabetic(n,code) +    return do_alphabetic(n,code and code ~= "" and counters[code] or defaultcounter,uppercharacter) +end  converters.alphabetic = alphabetic  converters.Alphabetic = Alphabetic @@ -242,12 +246,13 @@ converters['A']  = converters.Characters  converters['AK'] = converters.Characters  converters['KA'] = converters.Characters -function commands.alphabetic(n,c) context(do_alphabetic(n,c and counters[c] or defaultcounter,lowercharacter)) end -function commands.Alphabetic(n,c) context(do_alphabetic(n,c and counters[c] or defaultcounter,uppercharacter)) end -function commands.character (n)   context(chr (n,lower_offset)) end -function commands.Character (n)   context(chr (n,upper_offset)) end -function commands.characters(n)   context(chrs(n,lower_offset)) end -function commands.Characters(n)   context(chrs(n,upper_offset)) end +implement { name = "alphabetic", actions = { alphabetic, context }, arguments = { "integer", "string" } } +implement { name = "Alphabetic", actions = { Alphabetic, context }, arguments = { "integer", "string" } } + +implement { name = "character",  actions = { chr,  context }, arguments = { "integer", lower_offset } } +implement { name = "Character",  actions = { chr,  context }, arguments = { "integer", upper_offset } } +implement { name = "characters", actions = { chrs, context }, arguments = { "integer", lower_offset } } +implement { name = "Characters", actions = { chrs, context }, arguments = { "integer", upper_offset } }  local weekday    = os.weekday    -- moved to l-os  local isleapyear = os.isleapyear -- moved to l-os @@ -273,20 +278,22 @@ converters.leapyear   = leapyear  converters.nofdays    = nofdays  converters.textime    = textime -function commands.weekday (day,month,year) context(weekday (day,month,year)) end -function commands.leapyear(year)           context(leapyear(year))           end -- rather useless, only for ifcase -function commands.nofdays (year,month)     context(nofdays (year,month))     end - -function commands.year   () context(date("%Y")) end -function commands.month  () context(date("%m")) end -function commands.hour   () context(date("%H")) end -function commands.minute () context(date("%M")) end -function commands.second () context(date("%S")) end -function commands.textime() context(textime()) end - -function commands.doifleapyearelse(year) -    ctx_doifelse(isleapyear(year)) -end +implement { name = "weekday",  actions = { weekday,  context }, arguments = { "integer", "integer", "integer" } } +implement { name = "leapyear", actions = { leapyear, context }, arguments = { "integer" } } +implement { name = "nofdays",  actions = { nofdays,  context }, arguments = { "integer", "integer" } } + +implement { name = "year",     actions = { date,     context }, arguments = "'%Y'" } +implement { name = "month",    actions = { date,     context }, arguments = "'%m'" } +implement { name = "hour",     actions = { date,     context }, arguments = "'%H'" } +implement { name = "minute",   actions = { date,     context }, arguments = "'%M'" } +implement { name = "second",   actions = { date,     context }, arguments = "'%S'" } +implement { name = "textime",  actions = { textime,  context } } + +implement { +    name      = "doifleapyearelse", +    actions   = { isleapyear, commands.doifelse }, +    arguments = "integer" +}  local roman = {      { [0] = '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX' }, @@ -313,8 +320,17 @@ converters['R']  = converters.Romannumerals  converters['KR'] = converters.Romannumerals  converters['RK'] = converters.Romannumerals -function commands.romannumerals(n) context(lower(toroman(n))) end -function commands.Romannumerals(n) context(      toroman(n))  end +implement { +    name      = "romannumerals", +    actions   = { toroman, lower, context }, +    arguments = "integer", +} + +implement { +    name      = "Romannumerals", +    actions   = { toroman, context }, +    arguments = "integer", +}  --~ local small = {  --~     0x0627, 0x066E, 0x062D, 0x062F, 0x0647, 0x0648, 0x0631 @@ -367,8 +383,17 @@ converters.toabjad = toabjad  function converters.abjadnumerals     (n) return toabjad(n,false) end  function converters.abjadnodotnumerals(n) return toabjad(n,true ) end -function commands.abjadnumerals     (n) context(toabjad(n,false)) end -function commands.abjadnodotnumerals(n) context(toabjad(n,true )) end +implement { +    name      = "abjadnumerals", +    actions   = { toabjad, context }, +    arguments = { "integer", false } +} + +implement { +    name      = "abjadnodotnumerals", +    actions   = { toabjad, context }, +    arguments = { "integer", true } +}  local vector = {      normal = { @@ -510,14 +535,20 @@ end  converters.tochinese = tochinese -function converters.chinesenumerals   (n) return tochinese(n,"normal") end -function converters.chinesecapnumerals(n) return tochinese(n,"cap"   ) end -function converters.chineseallnumerals(n) return tochinese(n,"all"   ) end +function converters.chinesenumerals   (n,how) return tochinese(n,how or "normal") end +function converters.chinesecapnumerals(n)     return tochinese(n,"cap") end +function converters.chineseallnumerals(n)     return tochinese(n,"all") end  converters['cn']   = converters.chinesenumerals  converters['cn-c'] = converters.chinesecapnumerals  converters['cn-a'] = converters.chineseallnumerals +implement { +    name      = "chinesenumerals", +    actions   = { tochinese, context }, +    arguments = { "integer", "string" } +} +  -- this is a temporary solution: we need a better solution when we have  -- more languages @@ -532,10 +563,6 @@ converters['characters:sl'] = converters.sloveniannumerals  converters['Characters:es'] = converters.Spanishnumerals  converters['Characters:sl'] = converters.Sloveniannumerals -function commands.chinesenumerals   (n) context(tochinese(n,"normal")) end -function commands.chinesecapnumerals(n) context(tochinese(n,"cap"   )) end -function commands.chineseallnumerals(n) context(tochinese(n,"all"   )) end -  converters.sequences = converters.sequences or { }  local sequences      = converters.sequences @@ -548,7 +575,11 @@ function converters.define(name,set) -- ,language)      sequences[name] = settings_to_array(set)  end -commands.defineconversion = converters.define +implement { +    name      = "defineconversion", +    actions   = converters.define, +    arguments = { "string", "string" } +}  local function convert(method,n,language)      local converter = language and converters[method..":"..language] or converters[method] @@ -575,13 +606,21 @@ end  converters.convert = convert -function commands.doifelseconverter(method,language) -    ctx_doifelse(converters[method..":"..language] or converters[method] or sequences[method]) +local function valid(method,language) +    return converters[method..":"..language] or converters[method] or sequences[method]  end -function commands.checkedconversion(method,n,language) -    context(convert(method,n,language)) -end +implement { +    name      = "doifelseconverter", +    actions   = { valid, commands.doifelse }, +    arguments = { "string", "string" } +} + +implement { +    name      = "checkedconversion", +    actions   = { convert, context }, +    arguments = { "string", "integer" } +}  -- Well, since the one asking for this didn't test it the following code is not  -- enabled. @@ -756,7 +795,7 @@ function converters.ordinal(n,language)      return t and t(n)  end -function commands.ordinal(n,language) +local function ctxordinal(n,language)      local t = language and ordinals[language]      local o = t and t(n)      context(n) @@ -765,6 +804,12 @@ function commands.ordinal(n,language)      end  end +implement { +    name      = "ordinal", +    actions   = ctxordinal, +    arguments = { "string", "string" } +} +  -- verbose numbers  local data         = allocate() @@ -1007,11 +1052,17 @@ function converters.verbose.translate(n,language)      return t and t.translate(n) or n  end -function commands.verbose(n,language) +local function verbose(n,language)      local t = language and data[language]      context(t and t.translate(n) or n)  end +implement { +    name      = "verbose", +    actions   = verbose, +    arguments = { "integer", "string" } +} +  -- These are just helpers but not really for the tex end. Do we have to  -- use translate here? @@ -1074,33 +1125,60 @@ local months = { -- not variables.january      "december",  } -function commands.dayname(n) -    context.labeltext(days[n] or "unknown") +local function dayname(n) +    return days[n] or "unknown"  end -function commands.weekdayname(day,month,year) -    context.labeltext(days[weekday(day,month,year)] or "unknown") +local function weekdayname(day,month,year) +    return days[weekday(day,month,year)] or "unknown"  end -function commands.monthname(n) -    context.labeltext(months[n] or "unknown") +local function monthname(n) +    return months[n] or "unknown"  end -function commands.monthmnem(n) +local function monthmnem(n)      local m = months[n] -    context.labeltext(m and (m ..":mnem") or "unknown") +    return m and (m ..":mnem") or "unknown"  end +implement { +    name      = "dayname", +    actions   = { dayname,  context.labeltext }, +    arguments = "integer", +} + +implement { +    name      = "weekdayname", +    actions   = { weekdayname,  context.labeltext }, +    arguments = { "integer", "integer", "integer" } +} + +implement { +    name      = "monthname", +    actions   = { monthname,  context.labeltext }, +    arguments = { "integer" } +} + +implement { +    name      = "monthmnem", +    actions   = { monthmnem,  context.labeltext }, +    arguments = { "integer" } +} +  -- a prelude to a function that we can use at the lua end  -- day:ord month:mmem  -- j and jj obsolete -function commands.currentdate(str,currentlanguage) -- second argument false : no label +local function currentdate(str,currentlanguage) -- second argument false : no label      local list = utilities.parsers.settings_to_array(str)      local splitlabel = languages.labels.split or string.itself -- we need to get the loading order right      local year, month, day = tex.year, tex.month, tex.day      local auto = true +    if currentlanguage == "" then +        currentlanguage = false +    end      for i=1,#list do          local entry = list[i]          local tag, plus = splitlabel(entry) @@ -1126,9 +1204,9 @@ function commands.currentdate(str,currentlanguage) -- second argument false : no              if currentlanguage == false then                  context(months[month] or "unknown")              elseif mnemonic then -                commands.monthmnem(month) +                context.labeltext(monthmnem(month))              else -                commands.monthname(month) +                context.labeltext(monthmnem(month))              end          elseif tag == "mm" then              context("%02i",month) @@ -1138,7 +1216,7 @@ function commands.currentdate(str,currentlanguage) -- second argument false : no              if currentlanguage == false then                  context(days[day] or "unknown")              else -                context.convertnumber(v_day,day) +                context.convertnumber(v_day,day) -- why not direct              end              whatordinal = day          elseif tag == "dd" then @@ -1152,7 +1230,7 @@ function commands.currentdate(str,currentlanguage) -- second argument false : no              if currentlanguage == false then                  context(days[wd] or "unknown")              else -                commands.dayname(wd) +                context.labeltext(days[wd] or "unknown")              end          elseif tag == "W" then              context(weekday(day,month,year)) @@ -1175,6 +1253,14 @@ function commands.currentdate(str,currentlanguage) -- second argument false : no      end  end -function commands.rawdate(str) -    commands.currentdate(str,false) -end +implement { +    name      = "currentdate", +    actions   = currentdate, +    arguments = { "string",  "string" } +} + +implement { +    name      = "rawdate", +    actions   = currentdate, +    arguments = { "string", false } +} diff --git a/tex/context/base/core-con.mkiv b/tex/context/base/core-con.mkiv index fcc16ef12..19a81685e 100644 --- a/tex/context/base/core-con.mkiv +++ b/tex/context/base/core-con.mkiv @@ -67,47 +67,43 @@  %D \showsetup{romannumerals}  %D \showsetup{Romannumerals} -\def\romannumerals#1{\ctxcommand{romannumerals(\number#1)}} -\def\Romannumerals#1{\ctxcommand{Romannumerals(\number#1)}} +\def\romannumerals#1{\clf_romannumerals\numexpr#1\relax} +\def\Romannumerals#1{\clf_Romannumerals\numexpr#1\relax}  %D Arabic  etc: -\def\abjadnumerals     #1{\ctxcommand{abjadnumerals     (\number#1)}} -\def\abjadnodotnumerals#1{\ctxcommand{abjadnodotnumerals(\number#1)}} -\def\abjadnaivenumerals#1{\ctxcommand{arabicnumerals    (\number#1)}} +\def\abjadnumerals     #1{\clf_abjadnumerals     \numexpr#1\relax} +\def\abjadnodotnumerals#1{\clf_abjadnodotnumerals\numexpr#1\relax} +\def\abjadnaivenumerals#1{\clf_alphabetic        \numexpr#1\relax{arabic}} % okay? -\def\languagecharacters#1{\ctxcommand{alphabetic(\number#1,"\currentlanguage")}} % new -\def\languageCharacters#1{\ctxcommand{Alphabetic(\number#1,"\currentlanguage")}} % new +\def\languagecharacters#1{\clf_alphabetic\numexpr#1\relax{\currentlanguage}} % new +\def\languageCharacters#1{\clf_Alphabetic\numexpr#1\relax{\currentlanguage}} % new -\def\alphabeticnumerals#1{\ctxcommand{alphabetic(\number#1)}} -\def\Alphabeticnumerals#1{\ctxcommand{Alphabetic(\number#1)}} +\def\alphabeticnumerals#1{\clf_alphabetic\numexpr#1\relax{}} +\def\Alphabeticnumerals#1{\clf_Alphabetic\numexpr#1\relax{}} -% we could use an auxiliary macro to save some bytes in the format -% -% \def\dolanguagecharacters#1#2{\ctxcommand{alphabetic(\number#2,"#1")}} - -\def\thainumerals      #1{\ctxcommand{alphabetic(\number#1,"thai")}} -\def\devanagarinumerals#1{\ctxcommand{alphabetic(\number#1,"devanagari")}} -\def\gurmurkhinumerals #1{\ctxcommand{alphabetic(\number#1,"gurmurkhi")}} -\def\gujaratinumerals  #1{\ctxcommand{alphabetic(\number#1,"gujarati")}} -\def\tibetannumerals   #1{\ctxcommand{alphabetic(\number#1,"tibetan")}} -\def\greeknumerals     #1{\ctxcommand{alphabetic(\number#1,"greek")}} -\def\Greeknumerals     #1{\ctxcommand{Alphabetic(\number#1,"greek")}} -\def\arabicnumerals    #1{\ctxcommand{alphabetic(\number#1,"arabic")}} -\def\persiannumerals   #1{\ctxcommand{alphabetic(\number#1,"persian")}} +\def\thainumerals      #1{\clf_alphabetic\numexpr#1\relax{thai}} +\def\devanagarinumerals#1{\clf_alphabetic\numexpr#1\relax{devanagari}} +\def\gurmurkhinumerals #1{\clf_alphabetic\numexpr#1\relax{gurmurkhi}} +\def\gujaratinumerals  #1{\clf_alphabetic\numexpr#1\relax{gujarati}} +\def\tibetannumerals   #1{\clf_alphabetic\numexpr#1\relax{tibetan}} +\def\greeknumerals     #1{\clf_alphabetic\numexpr#1\relax{greek}} +\def\Greeknumerals     #1{\clf_Alphabetic\numexpr#1\relax{greek}} +\def\arabicnumerals    #1{\clf_alphabetic\numexpr#1\relax{arabic}} +\def\persiannumerals   #1{\clf_alphabetic\numexpr#1\relax{persian}}  \let\arabicexnumerals     \persiannumerals -\def\koreannumerals    #1{\ctxcommand{alphabetic(\number#1,"korean")}} -\def\koreannumeralsp   #1{\ctxcommand{alphabetic(\number#1,"korean-parent")}} -\def\koreannumeralsc   #1{\ctxcommand{alphabetic(\number#1,"korean-circle")}} +\def\koreannumerals    #1{\clf_alphabetic\numexpr#1\relax{korean}} +\def\koreannumeralsp   #1{\clf_alphabetic\numexpr#1\relax{korean-parent}} +\def\koreannumeralsc   #1{\clf_alphabetic\numexpr#1\relax{korean-circle}}  \let\koreanparentnumerals\koreannumeralsp  \let\koreancirclenumerals\koreannumeralsc -\def\chinesenumerals   #1{\ctxcommand{chinesenumerals   (\number#1)}} -\def\chinesecapnumerals#1{\ctxcommand{chinesecapnumerals(\number#1,"cap")}} -\def\chineseallnumerals#1{\ctxcommand{chineseallnumerals(\number#1,"all")}} +\def\chinesenumerals   #1{\clf_chinesenumerals\numexpr#1\relax{normal}} +\def\chinesecapnumerals#1{\clf_chinesenumerals\numexpr#1\relax{cap}} +\def\chineseallnumerals#1{\clf_chinesenumerals\numexpr#1\relax{all}}  %D \macros  %D   {character,Character} @@ -127,8 +123,8 @@  \def\unknowncharacter{-} % else in lists \relax -\def\character#1{\ctxcommand{character(\number#1)}} -\def\Character#1{\ctxcommand{Character(\number#1)}} +\def\character#1{\clf_character\numexpr#1\relax} +\def\Character#1{\clf_Character\numexpr#1\relax}  %D \macros  %D   {characters,Characters} @@ -139,8 +135,8 @@  %D \showsetup{characters}  %D \showsetup{Characters} -\def\characters#1{\ctxcommand{characters(\number#1)}} -\def\Characters#1{\ctxcommand{Characters(\number#1)}} +\def\characters#1{\clf_characters\numexpr#1\relax} +\def\Characters#1{\clf_Characters\numexpr#1\relax}  %D \macros  %D   {greeknumerals,Greeknumerals} @@ -209,8 +205,8 @@  %D  %D Anyhow, the conversion looks like: -\unexpanded\def\monthlong #1{\ctxcommand{monthname(#1)}} -\unexpanded\def\monthshort#1{\ctxcommand{monthmnem(#1)}} +\unexpanded\def\monthlong #1{\clf_monthname\numexpr#1\relax} +\unexpanded\def\monthshort#1{\clf_monthmnem\numexpr#1\relax}  \let\convertmonth\monthlong % for old times sake @@ -243,16 +239,16 @@  %D \showsetup{weekday}  %D \showsetup{WEEKDAY} -\unexpanded\def\weekday#1{\ctxcommand{day(#1)}} -\unexpanded\def\WEEKDAY#1{\WORD{\weekday{#1}}} +\unexpanded\def\weekday#1{\clf_day\numexpr#1\relax} +\unexpanded\def\WEEKDAY#1{\WORD{\clf_day\numexpr#1\relax}}  %D \macros  %D   {getdayoftheweek, dayoftheweek}  \newcount\normalweekday -           \def\dayoftheweek   #1#2#3{\ctxcommand{weekdayname(\number#1,\number#2,\number#3)}}                 % name -\unexpanded\def\getdayoftheweek#1#2#3{\normalweekday\ctxcommand{weekday(\number#1,\number#2,\number#3)}\relax} % number +           \def\dayoftheweek   #1#2#3{\clf_weekdayname\numexpr#1\relax\numexpr#2\relax,\numexpr#3\relax}                 % name +\unexpanded\def\getdayoftheweek#1#2#3{\normalweekday\clf_weekday\numexpr#1\relax\numexpr#2\relax,\numexpr#3\relax\relax} % number  %D Using this macro in  %D @@ -298,13 +294,13 @@  %D The number of days is available in the macro \type {\numberofdays}.  \def\doifleapyearelse#1% -  {\ctxcommand{doifleapyearelse(\number#1)}} +  {\clf_doifleapyearelse\numexpr#1\relax}  \unexpanded\def\getdayspermonth#1#2% -  {\edef\numberofdays{\ctxcommand{nofdays(\number#1,\number#2)}}} +  {\edef\numberofdays{\clf_nofdays\numexpr#1\relax\numexpr#2\relax}}  \def\dayspermonth#1#2% -  {\ctxcommand{nofdays(\number#1,\number#2)}} +  {\clf_nofdays\numexpr#1\relax\numexpr#2\relax}  % \dayoftheweek{2006}{9}{15}  % \doifleapyearelse{2000}{OK}{NOT OK} @@ -416,7 +412,7 @@    {\begingroup     \the\everycurrentdate     \doifsomething{#1}{\edef\currentdatespecification{#1}}% -   \ctxcommand{currentdate(\!!bs\currentdatespecification\!!es,"\labellanguage")}% +   \clf_currentdate{\currentdatespecification}{\labellanguage}%     \endgroup}  \unexpanded\def\date @@ -437,7 +433,7 @@     \endgroup}  \def\rawdate[#1]% expandable and no labels -  {\ctxcommand{rawdate(\!!bs\currentdatespecification\!!es)}} +  {\clf_rawdate{\currentdatespecification}}  %D \macros  %D   {currenttime} @@ -446,9 +442,9 @@  %D to the previous date macro using the keys \type {h}, \type {m} and a separator.  \unexpanded\def\calculatecurrenttime -  {\edef\currenthour  {\ctxcommand{hour  ()}}% -   \edef\currentminute{\ctxcommand{minute()}}% -   \edef\currentsecond{\ctxcommand{second()}}} +  {\edef\currenthour  {\clf_hour  }% +   \edef\currentminute{\clf_minute}% +   \edef\currentsecond{\clf_second}}  \let\currenthour  \!!plusone  \let\currentminute\!!plusone @@ -542,12 +538,12 @@  \def\syst_converters_define_conversion_indeed#1#2#3%    {\doifinstringelse{,}{\detokenize{#3}} -     {\ctxcommand{defineconversion("#2",\!!bs\detokenize{#3}\!!es)}% a set e.g. of symbols +     {\clf_defineconversion{#2}{\detokenize{#3}}% a set e.g. of symbols        \setgvalue{\??conversion#1}{\syst_converters_checked_conversion{#2}}}       {\setgvalue{\??conversion#1}{#3}}}  \def\syst_converters_checked_conversion#1#2% -  {\ctxcommand{checkedconversion("#1",#2)}} +  {\clf_checkedconversion{#1}\numexpr#2\relax}  %D If a conversion is just a font switch then we need to make sure that the  %D number is indeed ends up as number in the input, so we need to handle the @@ -609,10 +605,10 @@  \def\highordinalstr     #1{\high{\notsmallcapped{#1}}}  \def\ordinalstr         #1{\notsmallcapped{#1}} -\def\ordinaldaynumber   #1{\ctxcommand{ordinal(#1,"\currentlanguage")}} +\def\ordinaldaynumber   #1{\clf_ordinal\numexpr#1\relax{\currentlanguage}} -\def\verbosenumber      #1{\ctxcommand{verbose(#1,"\currentlanguage")}} -\def\VerboseNumber      #1{\Words{\ctxcommand{verbose(#1,"\currentlanguage")}}} +\def\verbosenumber      #1{\clf_verbose\numexpr#1\relax{\currentlanguage}} +\def\VerboseNumber      #1{\Words{\clf_verbose\numexpr#1\relax{\currentlanguage}}}  %D As longs as symbols are linked to levels or numbers, we can also use the  %D conversion mechanism, but in for instance the itemization macros, we prefer @@ -721,11 +717,11 @@  %D feature. We do need these definitions for mechanisms like itemize that check  %D for converters. -\def\sloveniannumerals#1{\ctxcommand{alphabetic(\number#1,"sl")}} -\def\slovenianNumerals#1{\ctxcommand{Alphabetic(\number#1,"sl")}} +\def\sloveniannumerals#1{\clf_alphabetic\numexpr#1\relax{sl}} +\def\slovenianNumerals#1{\clf_Alphabetic\numexpr#1\relax{sl}} -\def\spanishnumerals  #1{\ctxcommand{alphabetic(\number#1,"es")}} -\def\spanishNumerals  #1{\ctxcommand{Alphabetic(\number#1,"es")}} +\def\spanishnumerals  #1{\clf_alphabetic\numexpr#1\relax{es}} +\def\spanishNumerals  #1{\clf_Alphabetic\numexpr#1\relax{es}}  \defineconversion [\s!sl] [character]  [\sloveniannumerals]  \defineconversion [\s!sl] [Character]  [\slovenianNumerals] diff --git a/tex/context/base/core-sys.lua b/tex/context/base/core-sys.lua index 3a3a691b0..263b4dc76 100644 --- a/tex/context/base/core-sys.lua +++ b/tex/context/base/core-sys.lua @@ -9,7 +9,8 @@ if not modules then modules = { } end modules ['core-sys'] = {  local lower, format, gsub = string.lower, string.format, string.gsub  local suffixonly, basename, removesuffix = file.suffix, file.basename, file.removesuffix -local environment = environment +local environment  = environment +local implement    = interfaces.implement  local report_files = logs.reporter("system","files") @@ -90,6 +91,11 @@ function environment.initializefilenames() -- commands.updatefilenames(jobname,f      function environment.initializefilenames() end  end +implement { +    name      = "setdocumentfilenames", +    actions   = environment.initializefilenames, +} +  statistics.register("result saved in file", function()      -- suffix will be fetched from backend      local outputfilename = environment.outputfilename or environment.jobname or tex.jobname or "<unset>" @@ -100,6 +106,10 @@ statistics.register("result saved in file", function()      end  end) -function commands.systemlog(whereto,category,text) -    logs.system(whereto,"context",tex.jobname,category,text) -end +implement { +    name      = "systemlog", +    arguments = { "string", "string", "string" }, +    actions   = function(whereto,category,text) +        logs.system(whereto,"context",tex.jobname,category,text) +    end, +} diff --git a/tex/context/base/core-two.lua b/tex/context/base/core-two.lua index 9773eaf6f..bb1afa7db 100644 --- a/tex/context/base/core-two.lua +++ b/tex/context/base/core-two.lua @@ -144,18 +144,36 @@ jobpasses.inlist = inlist  -- interface -function commands.gettwopassdata     (id)   local r = get  (id)   if r then context(r) end end -function commands.getfirsttwopassdata(id)   local r = first(id)   if r then context(r) end end -function commands.getlasttwopassdata (id)   local r = last (id)   if r then context(r) end end -function commands.findtwopassdata    (id,n) local r = find (id,n) if r then context(r) end end -function commands.gettwopassdatalist (id)   local r = list (id)   if r then context(r) end end -function commands.counttwopassdata   (id)   local r = count(id)   if r then context(r) end end -function commands.checktwopassdata   (id)   local r = check(id)   if r then context(r) end end - -commands.definetwopasslist     = jobpasses.define -commands.savetwopassdata       = jobpasses.save -commands.savetaggedtwopassdata = jobpasses.savetagged - -function commands.doifelseintwopassdata(id,str) -    commands.doifelse(inlist(id,str)) -end +local implement = interfaces.implement + +implement { name = "gettwopassdata",     actions = { get  , context }, arguments = "string" } +implement { name = "getfirsttwopassdata",actions = { first, context }, arguments = "string" } +implement { name = "getlasttwopassdata", actions = { last , context }, arguments = "string" } +implement { name = "findtwopassdata",    actions = { find , context }, arguments = { "string", "string" } } +implement { name = "gettwopassdatalist", actions = { list , context }, arguments = "string" } +implement { name = "counttwopassdata",   actions = { count, context }, arguments = "string" } +implement { name = "checktwopassdata",   actions = { check, context }, arguments = "string" } + +implement { +    name      = "definetwopasslist", +    actions   = jobpasses.define, +    arguments = "string" +} + +implement { +    name      = "savetwopassdata", +    actions   = jobpasses.save, +    arguments = { "string", "string" } +} + +implement { +    name      = "savetaggedtwopassdata", +    actions   = jobpasses.savetagged, +    arguments = { "string", "string", "string" } +} + +implement { +    name      = "doifelseintwopassdata", +    actions   = { inlist, commands.doifelse }, +    arguments = { "string", "string" } +} diff --git a/tex/context/base/core-two.mkiv b/tex/context/base/core-two.mkiv index b08914ef4..30fd27f3d 100644 --- a/tex/context/base/core-two.mkiv +++ b/tex/context/base/core-two.mkiv @@ -73,10 +73,10 @@  \registerctxluafile{core-two}{1.001} -\def\immediatesavetwopassdata   #1#2#3{\normalexpanded{\noexpand\ctxcommand    {savetwopassdata('#1',"#3")}}} +\def\immediatesavetwopassdata   #1#2#3{\normalexpanded{\noexpand\clf_savetwopassdata{#1}{#3}}}  \def\savetwopassdata            #1#2#3{\normalexpanded{\noexpand\ctxlatecommand{savetwopassdata('#1',"#3")}}}  \def\lazysavetwopassdata        #1#2#3{\normalexpanded{\noexpand\ctxlatecommand{savetwopassdata('#1',"#3")}}} -\def\savetaggedtwopassdata    #1#2#3#4{\normalexpanded{\noexpand\ctxcommand    {savetaggedtwopassdata('#1','#3',"#4")}}} +\def\savetaggedtwopassdata    #1#2#3#4{\normalexpanded{\noexpand\clf_savetaggedtwopassdata{#1}{#3}{#4}}}  \def\lazysavetaggedtwopassdata#1#2#3#4{\normalexpanded{\noexpand\ctxlatecommand{savetaggedtwopassdata('#1','#3',"#4")}}}  % temp hack: needs a proper \starteverytimeluacode @@ -87,7 +87,7 @@  \newif   \iftwopassdatafound  % obsolete, will go -\def\syst_twopass_check +\def\syst_twopass_check % can be delegated to lua once obsolete is gone    {\ifx\twopassdata\empty       \twopassdatafoundfalse % obsolete       \setfalse\twopassdatafound @@ -104,17 +104,17 @@    {\twopassdatafoundtrue % obsolete     \settrue\twopassdatafound} -\unexpanded\def\definetwopasslist        #1{\ctxcommand{definetwopasslist('#1')}} -\unexpanded\def\gettwopassdata           #1{\edef\twopassdata    {\ctxcommand{gettwopassdata      ("#1")}}\syst_twopass_check} -\unexpanded\def\checktwopassdata         #1{\edef\twopassdata    {\ctxcommand{checktwopassdata    ("#1")}}\syst_twopass_check} -\unexpanded\def\findtwopassdata        #1#2{\edef\twopassdata    {\ctxcommand{findtwopassdata("#1","#2")}}\syst_twopass_check} -\unexpanded\def\getfirsttwopassdata      #1{\edef\twopassdata    {\ctxcommand{getfirsttwopassdata ("#1")}}\syst_twopass_check} -\unexpanded\def\getlasttwopassdata       #1{\edef\twopassdata    {\ctxcommand{getlasttwopassdata  ("#1")}}% -                                            \edef\noftwopassitems{\ctxcommand{counttwopassdata    ("#1")}}\syst_twopass_check} -\unexpanded\def\getnamedtwopassdatalist#1#2{\edef              #1{\ctxcommand{gettwopassdatalist  ("#2")}}} -\unexpanded\def\gettwopassdatalist       #1{\edef\twopassdatalist{\ctxcommand{gettwopassdatalist  ("#1")}}} +\unexpanded\def\definetwopasslist        #1{\clf_definetwopasslist{#1}} +\unexpanded\def\gettwopassdata           #1{\edef\twopassdata    {\clf_gettwopassdata      {#1}}\syst_twopass_check} +\unexpanded\def\checktwopassdata         #1{\edef\twopassdata    {\clf_checktwopassdata    {#1}}\syst_twopass_check} +\unexpanded\def\findtwopassdata        #1#2{\edef\twopassdata    {\clf_findtwopassdata {#1}{#2}}\syst_twopass_check} +\unexpanded\def\getfirsttwopassdata      #1{\edef\twopassdata    {\clf_getfirsttwopassdata {#1}}\syst_twopass_check} +\unexpanded\def\getlasttwopassdata       #1{\edef\twopassdata    {\clf_getlasttwopassdata  {#1}}% +                                            \edef\noftwopassitems{\clf_counttwopassdata    {#1}}\syst_twopass_check} +\unexpanded\def\getnamedtwopassdatalist#1#2{\edef              #1{\clf_gettwopassdatalist  {#2}}} +\unexpanded\def\gettwopassdatalist       #1{\edef\twopassdatalist{\clf_gettwopassdatalist  {#1}}} -\unexpanded\def\doifelseintwopassdata  #1#2{\ctxcommand{doifelseintwopassdata("#1","#2")}} +\unexpanded\def\doifelseintwopassdata  #1#2{\clf_doifelseintwopassdata{#1}{#2}}             \let\getfromtwopassdata          \findtwopassdata diff --git a/tex/context/base/core-uti.lua b/tex/context/base/core-uti.lua index 27ef93608..b6ddf775e 100644 --- a/tex/context/base/core-uti.lua +++ b/tex/context/base/core-uti.lua @@ -29,6 +29,8 @@ local packers       = utilities.packers  local allocate      = utilities.storage.allocate  local mark          = utilities.storage.mark +local implement     = interfaces.implement +  local texgetcount   = tex.getcount  local report_passes = logs.reporter("job","passes") @@ -378,5 +380,14 @@ function statistics.formatruntime(runtime)      end  end -commands.savevariable  = job.variables.save -commands.setjobcomment = job.comment +implement { +    name      = "savevariable", +    actions   = job.variables.save, +    arguments = { "string", "string" } +} + +implement { +    name      = "setjobcomment", +    actions   = job.comment, +    arguments = { { "*" } } +} diff --git a/tex/context/base/core-uti.mkiv b/tex/context/base/core-uti.mkiv index 5937240b9..1fb8f0b57 100644 --- a/tex/context/base/core-uti.mkiv +++ b/tex/context/base/core-uti.mkiv @@ -18,15 +18,15 @@  \registerctxluafile{core-uti}{1.001}  \def\savecurrentvalue#1#2% immediate, so not \unexpanded -  {\ctxcommand{savevariable("\strippedcsname#1","#2")}} +  {\clf_savevariable{\strippedcsname#1}{#2}}  \appendtoks -    \ctxlua{job.comment{ -        file   = tex.jobname, -        format = "\contextformat", -        stamp  = "\contextversion", -        escape = "\!!bs\space...\space\!!es" -    }}% +    \clf_setjobcomment +        file   {tex.jobname}% +        format {\contextformat}% +        stamp  {\contextversion}% +        escape {\!!bs\space...\space\!!es}% +    \relax  \to \everystarttext  \appendtoks diff --git a/tex/context/base/file-job.lua b/tex/context/base/file-job.lua index ff99aa651..d90dcc271 100644 --- a/tex/context/base/file-job.lua +++ b/tex/context/base/file-job.lua @@ -11,15 +11,20 @@ if not modules then modules = { } end modules ['file-job'] = {  local gsub, match, find = string.gsub, string.match, string.find  local insert, remove, concat = table.insert, table.remove, table.concat -local validstring = string.valid +local validstring, formatters = string.valid, string.formatters  local sortedhash = table.sortedhash -local formatters = string.formatters -local commands, resolvers, context = commands, resolvers, context +local commands          = commands +local resolvers         = resolvers +local context           = context -local trace_jobfiles  = false  trackers.register("system.jobfiles", function(v) trace_jobfiles = v end) +local ctx_doifelse      = commands.doifelse -local report_jobfiles = logs.reporter("system","jobfiles") +local implement         = interfaces.implement + +local trace_jobfiles    = false  trackers.register("system.jobfiles", function(v) trace_jobfiles = v end) + +local report_jobfiles   = logs.reporter("system","jobfiles")  local texsetcount       = tex.setcount  local elements          = interfaces.elements @@ -72,46 +77,69 @@ end  resolvers.findctxfile = findctxfile -function commands.processfile(name) -    name = findctxfile(name) -    if name ~= "" then -        context.input(name) +implement { +    name      = "processfile", +    arguments = "string", +    actions   = function(name) +        name = findctxfile(name) +        if name ~= "" then +            context.input(name) +        end      end -end - -function commands.doifinputfileelse(name) -    commands.doifelse(findctxfile(name) ~= "") -end +} -function commands.locatefilepath(name) -    context(dirname(findctxfile(name))) -end +implement { +    name      = "doifinputfileelse", +    arguments = "string", +    actions   = function(name) +        ctx_doifelse(findctxfile(name) ~= "") +    end +} -function commands.usepath(paths) -    report_jobfiles("using path: %s",paths) -    registerextrapath(paths) -end +implement { +    name      = "locatefilepath", +    arguments = "string", +    actions   = function(name) +        context(dirname(findctxfile(name))) +    end +} -function commands.usesubpath(subpaths) -    report_jobfiles("using subpath: %s",subpaths) -    registerextrapath(nil,subpaths) -end +implement { +    name      = "usepath", +    arguments = "string", +    actions   = function(paths) +        report_jobfiles("using path: %s",paths) +        registerextrapath(paths) +    end +} -function commands.allinputpaths() -    context(concat(resolvers.instance.extra_paths or { },",")) -end +implement { +    name      = "usesubpath", +    arguments = "string", +    actions   = function(subpaths) +        report_jobfiles("using subpath: %s",subpaths) +        registerextrapath(nil,subpaths) +    end +} -function commands.setdocumentfilenames() -    environment.initializefilenames() -end +implement { +    name      = "allinputpaths", +    actions   = function() +        context(concat(resolvers.instance.extra_paths or { },",")) +    end +} -function commands.usezipfile(name,tree) -    if tree and tree ~= "" then -        resolvers.usezipfile(formatters["zip:///%s?tree=%s"](name,tree)) -    else -        resolvers.usezipfile(formatters["zip:///%s"](name)) +implement { +    name      = "usezipfile", +    arguments = { "string", "string" }, +    actions   = function(name,tree) +        if tree and tree ~= "" then +            resolvers.usezipfile(formatters["zip:///%s?tree=%s"](name,tree)) +        else +            resolvers.usezipfile(formatters["zip:///%s"](name)) +        end      end -end +}  local report_system  = logs.reporter("system") @@ -122,7 +150,7 @@ local luapatterns = { "%s" .. utilities.lua.suffixes.luc, "%s.lua" }  local cldpatterns = { "%s.cld" }  local xmlpatterns = { "%s.xml" } -local uselibrary = commands.uselibrary +local uselibrary = resolvers.uselibrary  local input      = context.input  -- status @@ -133,23 +161,36 @@ local processstack   = { }  local processedfile  = ""  local processedfiles = { } -function commands.processedfile() -    context(processedfile) -end +implement { +    name    = "processedfile", +    actions = function() +        context(processedfile) +    end +} -function commands.processedfiles() -    context(concat(processedfiles,",")) -end +implement { +    name    = "processedfiles", +    actions = function() +        context(concat(processedfiles,",")) +    end +} -function commands.dostarttextfile(name) -    insert(processstack,name) -    processedfile = name -    insert(processedfiles,name) -end +implement { +    name      = "dostarttextfile", +    arguments = "string", +    actions   = function(name) +        insert(processstack,name) +        processedfile = name +        insert(processedfiles,name) +    end +} -function commands.dostoptextfile() -    processedfile = remove(processstack) or "" -end +implement { +    name      = "dostoptextfile", +    actions   = function() +        processedfile = remove(processstack) or "" +    end +}  local function startprocessing(name,notext)      if not notext then @@ -230,11 +271,6 @@ local function usexmlfile(name,onlyonce,notext)      stopprocessing(notext)  end -commands.usetexfile = usetexfile -commands.useluafile = useluafile -commands.usecldfile = usecldfile -commands.usexmlfile = usexmlfile -  local suffixes = {      mkvi = usetexfile,      mkiv = usetexfile, @@ -259,7 +295,18 @@ local function useanyfile(name,onlyonce)      context(resolvers.poppath)  end -commands.useanyfile = useanyfile +implement { name = "usetexfile",     actions = usetexfile, arguments = "string" } +implement { name = "useluafile",     actions = useluafile, arguments = "string" } +implement { name = "usecldfile",     actions = usecldfile, arguments = "string" } +implement { name = "usexmlfile",     actions = usexmlfile, arguments = "string" } + +implement { name = "usetexfileonce", actions = usetexfile, arguments = { "string", true } } +implement { name = "useluafileonce", actions = useluafile, arguments = { "string", true } } +implement { name = "usecldfileonce", actions = usecldfile, arguments = { "string", true } } +implement { name = "usexmlfileonce", actions = usexmlfile, arguments = { "string", true } } + +implement { name = "useanyfile",     actions = useanyfile, arguments = "string" } +implement { name = "useanyfileonce", actions = useanyfile, arguments = { "string", true } }  function jobresolvers.usefile(name,onlyonce,notext)      local s = suffixes[suffixonly(name)] @@ -280,6 +327,8 @@ local function startstoperror()      startstoperror = dummyfunction  end +local stopped +  local function starttext()      if textlevel == 0 then          if trace_jobfiles then @@ -293,65 +342,86 @@ local function starttext()  end  local function stoptext() -    if textlevel == 0 then -        startstoperror() -    elseif textlevel > 0 then -        textlevel = textlevel - 1 -    end -    texsetcount("global","textlevel",textlevel) -    if textlevel <= 0 then -        if trace_jobfiles then -            report_jobfiles("stopping text") +    if not stopped then +        if textlevel == 0 then +            startstoperror() +        elseif textlevel > 0 then +            textlevel = textlevel - 1 +        end +        texsetcount("global","textlevel",textlevel) +        if textlevel <= 0 then +            if trace_jobfiles then +                report_jobfiles("stopping text") +            end +            context.dostoptext() +            -- registerfileinfo[end]jobfilename +            context.finalend() +            stopped = true          end -        context.dostoptext() -        -- registerfileinfo[end]jobfilename -        context.finalend() -        commands.stoptext = dummyfunction      end  end -commands.starttext = starttext -commands.stoptext  = stoptext +implement { name = "starttext", actions = starttext } +implement { name = "stoptext",  actions = stoptext  } -function commands.forcequitjob(reason) -    if reason then -        report_system("forcing quit: %s",reason) -    else -        report_system("forcing quit") +implement { +    name      = "forcequitjob", +    arguments = "string", +    actions   = function(reason) +        if reason then +            report_system("forcing quit: %s",reason) +        else +            report_system("forcing quit") +        end +        context.batchmode() +        while textlevel >= 0 do +            context.stoptext() +        end      end -    context.batchmode() -    while textlevel >= 0 do +} + +implement { +    name    = "forceendjob", +    actions = function() +        report_system([[don't use \end to finish a document]])          context.stoptext()      end -end - -function commands.forceendjob() -    report_system([[don't use \end to finish a document]]) -    context.stoptext() -end +} -function commands.autostarttext() -    if textlevel == 0 then -        report_system([[auto \starttext ... \stoptext]]) +implement { +    name    = "autostarttext", +    actions = function() +        if textlevel == 0 then +            report_system([[auto \starttext ... \stoptext]]) +        end +        context.starttext()      end -    context.starttext() -end +} -commands.autostoptext = stoptext +implement { +    name    = "autostoptext", +    actions = stoptext +}  -- project structure -function commands.processfilemany(name) -    useanyfile(name,false) -end +implement { +    name      = "processfilemany", +    arguments = { "string", false }, +    actions   = useanyfile +} -function commands.processfileonce(name) -    useanyfile(name,true) -end +implement { +    name      = "processfileonce", +    arguments = { "string", true }, +    actions   = useanyfile +} -function commands.processfilenone(name) -    -- skip file -end +implement { +    name      = "processfilenone", +    arguments = "string", +    actions   = dummyfunction, +}  local tree               = { type = "text", name = "", branches = { } }  local treestack          = { } @@ -619,10 +689,10 @@ local function process(what,name)      end  end -function commands.useproject    (name) process(v_project,    name) end -function commands.useenvironment(name) process(v_environment,name) end -function commands.useproduct    (name) process(v_product,    name) end -function commands.usecomponent  (name) process(v_component,  name) end +implement { name = "useproject",     actions = function(name) process(v_project,    name) end, arguments = "string" } +implement { name = "useenvironment", actions = function(name) process(v_environment,name) end, arguments = "string" } +implement { name = "useproduct",     actions = function(name) process(v_product,    name) end, arguments = "string" } -- will be overloaded +implement { name = "usecomponent",   actions = function(name) process(v_component,  name) end, arguments = "string" }  -- todo: setsystemmode to currenttype  -- todo: make start/stop commands at the tex end @@ -669,20 +739,20 @@ local function autoname(name)      return name  end -function commands.startproject    (name) gotonextlevel(v_project,    autoname(name)) end -function commands.startproduct    (name) gotonextlevel(v_product,    autoname(name)) end -function commands.startcomponent  (name) gotonextlevel(v_component,  autoname(name)) end -function commands.startenvironment(name) gotonextlevel(v_environment,autoname(name)) end +implement { name = "startproject",       actions = function(name) gotonextlevel(v_project,    autoname(name)) end, arguments = "string" } +implement { name = "startproduct",       actions = function(name) gotonextlevel(v_product,    autoname(name)) end, arguments = "string" } +implement { name = "startcomponent",     actions = function(name) gotonextlevel(v_component,  autoname(name)) end, arguments = "string" } +implement { name = "startenvironment",   actions = function(name) gotonextlevel(v_environment,autoname(name)) end, arguments = "string" } -function commands.stopproject    () gotopreviouslevel(v_project    ) end -function commands.stopproduct    () gotopreviouslevel(v_product    ) end -function commands.stopcomponent  () gotopreviouslevel(v_component  ) end -function commands.stopenvironment() gotopreviouslevel(v_environment) end +implement { name = "stopproject",        actions = function() gotopreviouslevel(v_project    ) end } +implement { name = "stopproduct",        actions = function() gotopreviouslevel(v_product    ) end } +implement { name = "stopcomponent",      actions = function() gotopreviouslevel(v_component  ) end } +implement { name = "stopenvironment",    actions = function() gotopreviouslevel(v_environment) end } -function commands.currentproject    () context(topofstack(v_project    )) end -function commands.currentproduct    () context(topofstack(v_product    )) end -function commands.currentcomponent  () context(topofstack(v_component  )) end -function commands.currentenvironment() context(topofstack(v_environment)) end +implement { name = "currentproject",     actions = function() context(topofstack(v_project    )) end } +implement { name = "currentproduct",     actions = function() context(topofstack(v_product    )) end } +implement { name = "currentcomponent",   actions = function() context(topofstack(v_component  )) end } +implement { name = "currentenvironment", actions = function() context(topofstack(v_environment)) end }  -- -- -- this will move -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  -- @@ -711,7 +781,7 @@ local function convertexamodes(str)      end  end -function commands.loadexamodes(filename) +function environment.loadexamodes(filename)      if not filename or filename == "" then          filename = removesuffix(tex.jobname)      end @@ -724,6 +794,8 @@ function commands.loadexamodes(filename)      end  end +commands.loadexamodes = environment.loadexamodes +  -- changed in mtx-context  -- code moved from luat-ini @@ -766,22 +838,48 @@ function document.setfilename(i,name)      end  end -function document.getargument(key,default) -- commands +function document.getargument(key,default)      local v = document.arguments[key]      if type(v) == "boolean" then          v = (v and "yes") or "no"          document.arguments[key] = v      end -    context(v or default or "") +    return v or default or ""  end -function document.setargument(key,value) -    document.arguments[key] = value -- only strings +function document.getfilename(i) +    return document.files[tonumber(i)] or ""  end -function document.getfilename(i) -- commands -    context(document.files[tonumber(i)] or "") -end +implement { +    name      = "setdocumentargument", +    actions   = document.setargument, +    arguments = { "string", "string" } +} + +implement { +    name      = "setdocumentdefaultargument", +    actions   = document.setdefaultargument, +    arguments = { "string", "string" } +} + +implement { +    name      = "setdocumentfilename", +    actions   = document.setfilename, +    arguments = { "integer", "string" } +} + +implement { +    name      = "getdocumentargument", +    actions   = { document.getargument, context }, +    arguments = { "string", "string" } +} + +implement { +    name      = "getdocumentfilename", +    actions   = { document.getfilename, context }, +    arguments = "integer" +}  function commands.getcommandline() -- has to happen at the tex end in order to expand @@ -1048,15 +1146,20 @@ if environment.initex then  end -function commands.doifelsecontinuewithfile(inpname,basetoo) -    local inpnamefull = addsuffix(inpname,"tex") -    local inpfilefull = addsuffix(environment.inputfilename,"tex") -    local continue = inpnamefull == inpfilefull -    if basetoo and not continue then -        continue = inpnamefull == basename(inpfilefull) -    end -    if continue then -        report_system("continuing input file %a",inpname) +implement { +    name      = "doifelsecontinuewithfile", +    arguments = "string", +    actions   = function(inpname,basetoo) +        local inpnamefull = addsuffix(inpname,"tex") +        local inpfilefull = addsuffix(environment.inputfilename,"tex") +        local continue = inpnamefull == inpfilefull +     -- if basetoo and not continue then +        if not continue then +            continue = inpnamefull == basename(inpfilefull) +        end +        if continue then +            report_system("continuing input file %a",inpname) +        end +        ctx_doifelse(continue)      end -    commands.doifelse(continue) -end +} diff --git a/tex/context/base/file-job.mkvi b/tex/context/base/file-job.mkvi index 171dc1a6a..74cf8147f 100644 --- a/tex/context/base/file-job.mkvi +++ b/tex/context/base/file-job.mkvi @@ -22,28 +22,28 @@  % processing  \unexpanded\def\doifinputfileelse#name% -  {\ctxcommand{doifinputfileelse("#name")}} +  {\clf_doifinputfileelse{#name}}  \unexpanded\def\processfile#name% -  {\ctxcommand{processfile("#name")}} +  {\clf_processfile{#name}}  % path control  \unexpanded\def\usepath[#path]% -  {\ctxcommand{usepath("#path")}} +  {\clf_usepath{#path}}  \unexpanded\def\usesubpath[#path]% -  {\ctxcommand{usesubpath("#path")}} +  {\clf_usesubpath{#path}}  \def\allinputpaths -  {\ctxcommand{allinputpaths()}} +  {\clf_allinputpaths}  % helper (not really needed nowadays)  \let\locatedfilepath\empty  \unexpanded\def\locatefilepath#name% no [] ? -  {\edef\locatedfilepath{\ctxcommand{locatefilepath("#name")}}} +  {\edef\locatedfilepath{\clf_locatefilepath{#name}}}  % % maybe:  % @@ -59,7 +59,7 @@    {\dodoubleempty\syst_files_use_zip_file}  \def\syst_files_use_zip_file[#zipname][#subtree]% -  {\ctxcommand{usezipfile("#zipname","#subtree")}} +  {\clf_usezipfile{#zipname}{#subtree}}  % exa stuff might become obsolete: @@ -85,14 +85,6 @@  \def\syst_files_load_indeed#name% from now on we assume a suffix to be part of the name    {\readsysfile{#name}{\showmessage\m!system2{#name}}\donothing} -% obsolete, but we keep it as reference of what happened -% -% \unexpanded\def\loadoptionfile -%   {\readjobfile{\jobname.\f!optionextension} -%      {\writestatus\m!system{\jobname.\f!optionextension\space loaded}% -%       \ctxcommand{copyfiletolog("\jobname.\f!optionextension")}}% -%      {\writestatus\m!system{no \jobname.\f!optionextension}}} -  % document structure  \ifdefined\textlevel                         \else \newcount\textlevel                          \fi % might go away @@ -116,12 +108,12 @@     \doifsometokselse\everynotabene{\writeline\the\everynotabene\writeline}\donothing     \normalend}           % tex's \end -\unexpanded\def\starttext    {\ctxcommand{starttext()}} -\unexpanded\def\stoptext     {\ctxcommand{stoptext()}} -\unexpanded\def\forcequitjob {\ctxcommand{forcequitjob()}} -\unexpanded\def\end          {\ctxcommand{forceendjob()}} -\unexpanded\def\autostarttext{\ctxcommand{autostarttext()}} -\unexpanded\def\autostoptext {\ctxcommand{autostoptext()}} +\unexpanded\def\starttext    {\clf_starttext} +\unexpanded\def\stoptext     {\clf_stoptext} +\unexpanded\def\forcequitjob {\clf_forcequitjob} +\unexpanded\def\end          {\clf_forceendjob} +\unexpanded\def\autostarttext{\clf_autostarttext} +\unexpanded\def\autostoptext {\clf_autostoptext}  \unexpanded\def\finishjob{\stoptext} % nicer in luatex call commandline @@ -133,39 +125,39 @@  % protect structure -\unexpanded\def\processfilemany#name{\ctxcommand{processfilemany("#name")}} -\unexpanded\def\processfileonce#name{\ctxcommand{processfileonce("#name")}} -\unexpanded\def\processfilenone#name{\ctxcommand{processfilenone("#name")}} +\unexpanded\def\processfilemany#name{\clf_processfilemany{#name}} +\unexpanded\def\processfileonce#name{\clf_processfileonce{#name}} +\unexpanded\def\processfilenone#name{\clf_processfilenone{#name}}  \unexpanded\def\project    {\doifnextoptionalcselse\useproject    \syst_structure_arg_project}  \unexpanded\def\product    {\doifnextoptionalcselse\useproduct    \syst_structure_arg_product}  \unexpanded\def\component  {\doifnextoptionalcselse\usecomponent  \syst_structure_arg_component}  \unexpanded\def\environment{\doifnextoptionalcselse\useenvironment\syst_structure_arg_environment} -\def\syst_structure_arg_project    #name {\ctxcommand{useproject    ("#name")}} -\def\syst_structure_arg_product    #name {\ctxcommand{useproduct    ("#name")}} -\def\syst_structure_arg_component  #name {\ctxcommand{usecomponent  ("#name")}} -\def\syst_structure_arg_environment#name {\ctxcommand{useenvironment("#name")}} +\def\syst_structure_arg_project    #name {\clf_useproject    {#name}} +\def\syst_structure_arg_product    #name {\clf_useproduct    {#name}} +\def\syst_structure_arg_component  #name {\clf_usecomponent  {#name}} +\def\syst_structure_arg_environment#name {\clf_useenvironment{#name}}  \unexpanded\def\startproject    {\doifnextoptionalcselse\syst_structure_start_opt_project    \syst_structure_start_arg_project    }  \unexpanded\def\startproduct    {\doifnextoptionalcselse\syst_structure_start_opt_product    \syst_structure_start_arg_product    }  \unexpanded\def\startcomponent  {\doifnextoptionalcselse\syst_structure_start_opt_component  \syst_structure_start_arg_component  }  \unexpanded\def\startenvironment{\doifnextoptionalcselse\syst_structure_start_opt_environment\syst_structure_start_arg_environment} -\def\syst_structure_start_arg_project    #name {\ctxcommand{startproject    ("#name")}} -\def\syst_structure_start_arg_product    #name {\ctxcommand{startproduct    ("#name")}} -\def\syst_structure_start_arg_component  #name {\ctxcommand{startcomponent  ("#name")}} -\def\syst_structure_start_arg_environment#name {\ctxcommand{startenvironment("#name")}} +\def\syst_structure_start_arg_project    #name {\clf_startproject    {#name}} +\def\syst_structure_start_arg_product    #name {\clf_startproduct    {#name}} +\def\syst_structure_start_arg_component  #name {\clf_startcomponent  {#name}} +\def\syst_structure_start_arg_environment#name {\clf_startenvironment{#name}} -\unexpanded\def\useproject    [#name]{\ctxcommand{useproject    ("#name")}} -\unexpanded\def\useproduct    [#name]{\ctxcommand{useproduct    ("#name")}} -\unexpanded\def\usecomponent  [#name]{\ctxcommand{usecomponent  ("#name")}} -\unexpanded\def\useenvironment[#name]{\ctxcommand{useenvironment("#name")}} +\unexpanded\def\useproject    [#name]{\clf_useproject    {#name}} +\unexpanded\def\useproduct    [#name]{\clf_useproduct    {#name}} +\unexpanded\def\usecomponent  [#name]{\clf_usecomponent  {#name}} +\unexpanded\def\useenvironment[#name]{\clf_useenvironment{#name}} -\unexpanded\def\syst_structure_start_opt_project    [#name]{\ctxcommand{startproject    ("#name")}} -\unexpanded\def\syst_structure_start_opt_product    [#name]{\ctxcommand{startproduct    ("#name")}} -\unexpanded\def\syst_structure_start_opt_component  [#name]{\ctxcommand{startcomponent  ("#name")}} -\unexpanded\def\syst_structure_start_opt_environment[#name]{\ctxcommand{startenvironment("#name")}} +\unexpanded\def\syst_structure_start_opt_project    [#name]{\clf_startproject    {#name}} +\unexpanded\def\syst_structure_start_opt_product    [#name]{\clf_startproduct    {#name}} +\unexpanded\def\syst_structure_start_opt_component  [#name]{\clf_startcomponent  {#name}} +\unexpanded\def\syst_structure_start_opt_environment[#name]{\clf_startenvironment{#name}}  \newconditional\endofinput % hack, needed because \endinput happens one level down in the input when we write from lua @@ -178,34 +170,35 @@       \endinput     \fi} -\unexpanded\def\stopproject              {\ctxcommand{stopproject    ()}\honorendofinput} -\unexpanded\def\stopproduct              {\ctxcommand{stopproduct    ()}\honorendofinput} -\unexpanded\def\stopcomponent            {\ctxcommand{stopcomponent  ()}\honorendofinput} -\unexpanded\def\stopenvironment          {\ctxcommand{stopenvironment()}\honorendofinput} +\unexpanded\def\stopproject              {\clf_stopproject    \honorendofinput} +\unexpanded\def\stopproduct              {\clf_stopproduct    \honorendofinput} +\unexpanded\def\stopcomponent            {\clf_stopcomponent  \honorendofinput} +\unexpanded\def\stopenvironment          {\clf_stopenvironment\honorendofinput} -\def\currentproject                      {\ctxcommand{currentproject    ()}} -\def\currentproduct                      {\ctxcommand{currentproduct    ()}} -\def\currentcomponent                    {\ctxcommand{currentcomponent  ()}} -\def\currentenvironment                  {\ctxcommand{currentenvironment()}} -\def\processedfile                       {\ctxcommand{processedfile()}} -\def\processedfiles                      {\ctxcommand{processedfiles()}} +           \let\currentproject            \clf_currentproject +           \let\currentproduct            \clf_currentproduct +           \let\currentcomponent          \clf_currentcomponent +           \let\currentenvironment        \clf_currentenvironment +           \let\processedfile             \clf_processedfile +           \let\processedfiles            \clf_processedfiles -\unexpanded\def\dostarttextfile     #name{\ctxcommand{dostarttextfile(name)}} -\unexpanded\def\dostoptextfile           {\ctxcommand{dostoptextfile()}} +\unexpanded\def\dostarttextfile     #name{\clf_dostarttextfile{name}} +\unexpanded\def\dostoptextfile           {\clf_dostoptextfile} -\unexpanded\def\loadtexfile       [#name]{\ctxcommand{usetexfile("#name")}} -\unexpanded\def\loadluafile       [#name]{\ctxcommand{useluafile("#name")}} -\unexpanded\def\loadcldfile       [#name]{\ctxcommand{usecldfile("#name")}} -\unexpanded\def\loadanyfile       [#name]{\ctxcommand{useanyfile("#name")}} +\unexpanded\def\loadtexfile       [#name]{\clf_usetexfile{#name}} +\unexpanded\def\loadluafile       [#name]{\clf_useluafile{#name}} +\unexpanded\def\loadcldfile       [#name]{\clf_usecldfile{#name}} +\unexpanded\def\loadanyfile       [#name]{\clf_useanyfile{#name}} -\unexpanded\def\loadtexfileonce   [#name]{\ctxcommand{usetexfile("#name",true)}} -\unexpanded\def\loadluafileonce   [#name]{\ctxcommand{useluafile("#name",true)}} -\unexpanded\def\loadcldfileonce   [#name]{\ctxcommand{usecldfile("#name",true)}} -\unexpanded\def\loadanyfileonce   [#name]{\ctxcommand{useanyfile("#name",true)}} +\unexpanded\def\loadtexfileonce   [#name]{\clf_usetexfileonce{#name}} +\unexpanded\def\loadluafileonce   [#name]{\clf_useluafileonce{#name}} +\unexpanded\def\loadcldfileonce   [#name]{\clf_usecldfileonce{#name}} +\unexpanded\def\loadanyfileonce   [#name]{\clf_useanyfileonce{#name}}  %D Handy for modules that have a test/demo appended (true added). -\unexpanded\def\continueifinputfile#name{\ctxcommand{doifelsecontinuewithfile("#name",true)}\relax\endinput} % we cannot do \endinput via lua +\unexpanded\def\continueifinputfile#name% +  {\clf_doifelsecontinuewithfile{#name}\relax\endinput} % we cannot do \endinput via lua  % \startproject test  %     1: \startmode[*project] project \stopmode \endgraf diff --git a/tex/context/base/file-lib.lua b/tex/context/base/file-lib.lua index 2471cdd84..361608ea3 100644 --- a/tex/context/base/file-lib.lua +++ b/tex/context/base/file-lib.lua @@ -9,7 +9,7 @@ if not modules then modules = { } end modules ['file-lib'] = {  -- todo: check all usage of truefilename at the tex end and remove  -- files there (and replace definitions by full names) -local format = string.format +local format, gsub = string.format, string.gsub  local trace_libraries = false  trackers.register("resolvers.libraries", function(v) trace_libraries = v end)  ----- trace_files     = false  trackers.register("resolvers.readfile",  function(v) trace_files     = v end) @@ -33,7 +33,7 @@ local function defaultfailure(name)      report_files("asked name %a, not found",name)  end -function commands.uselibrary(specification) -- todo: reporter +function resolvers.uselibrary(specification) -- todo: reporter      local name = specification.name      if name and name ~= "" then          local patterns = specification.patterns or defaultpatterns @@ -86,3 +86,5 @@ function commands.uselibrary(specification) -- todo: reporter          end      end  end + +commands.uselibrary = resolvers.uselibrary -- for the moment diff --git a/tex/context/base/file-mod.lua b/tex/context/base/file-mod.lua index bf369d035..ff54dfe97 100644 --- a/tex/context/base/file-mod.lua +++ b/tex/context/base/file-mod.lua @@ -25,10 +25,9 @@ local permit_unprefixed = false  directives.register("modules.permitunprefixed",  local report_modules    = logs.reporter("resolvers","modules") -commands                = commands or { }  local commands          = commands -  local context           = context +local implement         = interfaces.implement  local findbyscheme      = resolvers.finders.byscheme -- use different one  local iterator          = utilities.parsers.iterator @@ -97,7 +96,7 @@ local function usemodule(name,hasscheme)      end  end -function commands.usemodules(prefix,askedname,truename) +function environment.usemodules(prefix,askedname,truename)      local truename = truename or environment.truefilename(askedname)      local hasprefix = prefix and prefix ~= ""      local hashname = ((hasprefix and prefix) or "*") .. "-" .. truename @@ -184,23 +183,51 @@ end)  -- moved from syst-lua.lua: -local splitter = lpeg.tsplitter(lpeg.S(". "),tonumber) +local lpegmatch = lpeg.match +local splitter  = lpeg.tsplitter(lpeg.S(". "),tonumber) -function commands.doifolderversionelse(one,two) -- one >= two -    if not two then +function environment.comparedversion(one,two) -- one >= two +    if not two or two == "" then          one, two = environment.version, one      elseif one == "" then          one = environment.version      end -    one = lpeg.match(splitter,one) -    two = lpeg.match(splitter,two) +    one = lpegmatch(splitter,one) +    two = lpegmatch(splitter,two)      one = (one[1] or 0) * 10000 + (one[2] or 0) * 100 + (one[3] or 0)      two = (two[1] or 0) * 10000 + (two[2] or 0) * 100 + (two[3] or 0) -    commands.doifelse(one>=two) +    if one < two then +        return -1 +    elseif one > two then +        return 1 +    else +        return 0 +    end  end -function commands.useluamodule(list) +environment.comparedversion = comparedversion + + +function environment.useluamodule(list)      for filename in iterator(list) do          environment.loadluafile(filename)      end  end + +implement { +    name      = "usemodules", +    actions   = environment.usemodules, +    arguments = { "string", "string" } +} + +implement { +    name      = "doifolderversionelse", +    actions   = function(one,two) commands.doifelse(comparedversion(one,two) >= 0) end, +    arguments = { "string", "string" } +} + +implement { +    name      = "useluamodule", +    actions   = environment.useluamodule, +    arguments = "string" +} diff --git a/tex/context/base/file-mod.mkvi b/tex/context/base/file-mod.mkvi index 1591a69cc..d4fd3d3bc 100644 --- a/tex/context/base/file-mod.mkvi +++ b/tex/context/base/file-mod.mkvi @@ -37,39 +37,6 @@  \let\usemodule   \usemodules  \let\usetexmodule\usemodules -% \def\strc_modules_use[#category][#name][#parameters]% -%   {\pushmacro\currentmodule -%    \pushmacro\currentmoduleparameters -%    \let\currentmoduleparameters\empty -%    \ifthirdargument -%      \singleexpandafter\strc_modules_use_a -%    \else\ifsecondargument -%      \doubleexpandafter\strc_modules_use_b -%    \else -%      \doubleexpandafter\strc_modules_use_c -%    \fi\fi -%    % here we load -%    \popmacro\currentmoduleparameters -%    \popmacro\currentmodule} -% -% \def\strc_modules_use_a[#category][#name][#parameters]% -%   {\doifsomething{#name} -%      {\def\currentmoduleparameters{#parameters}% -%       \processcommalist[#name]{\strc_modules_use_indeed{#category}}}} -% -% \def\strc_modules_use_b[#category][#name][#parameters]% -%   {\doifsomething{#name} -%      {\doifassignmentelse{#name} -%         {\def\currentmoduleparameters{#name}% -%          \processcommalist[#category]{\strc_modules_use_indeed\empty}} -%         {\processcommalist[#name]{\strc_modules_use_indeed{#category}}}}} -% -% \def\strc_modules_use_c[#category][#name][#parameters]% -%   {\processcommalist[#category]{\strc_modules_use_indeed\empty}} -% -% \def\strc_modules_use_indeed#category#name% -%   {\ctxcommand{usemodules("#category","#name","\truefilename{#name}")}} -  \def\strc_modules_use[#category][#name][#parameters]% category=t|m|x|p|...    {\pushmacro\currentmodule     \pushmacro\currentmodulecategory @@ -96,8 +63,8 @@     \popmacro\currentmodulecategory     \popmacro\currentmodule} -\def\strc_modules_use_indeed#category#name% truefilename moved to lua end -  {\ctxcommand{usemodules("#category","#name")}} % ,"\truefilename{#name}")}} +\def\strc_modules_use_indeed#category#name% +  {\clf_usemodules{#category}{#name}}  \installcorenamespace{module} @@ -238,8 +205,8 @@  %D  %D The version pattern is \type {yyyy.mm.dd} (with mm and dd being optional). -\unexpanded\def\doifolderversionelse#parent#child{\ctxcommand{doifolderversionelse("#parent","#child")}} -\unexpanded\def\doifoldercontextelse       #child{\ctxcommand{doifolderversionelse("#child")}} +\unexpanded\def\doifolderversionelse#parent#child{\clf_doifolderversionelse{#parent}{#child}} +\unexpanded\def\doifoldercontextelse       #child{\clf_doifolderversionelse{#child}{}}  %D Relatively new: @@ -299,6 +266,6 @@  % new: -\unexpanded\def\useluamodule[#1]{\ctxcommand{useluamodule("#1")}} +\unexpanded\def\useluamodule[#1]{\clf_useluamodule{#1}}  \protect \endinput diff --git a/tex/context/base/file-syn.lua b/tex/context/base/file-syn.lua index c1f9a5f48..b6ad27c83 100644 --- a/tex/context/base/file-syn.lua +++ b/tex/context/base/file-syn.lua @@ -6,13 +6,16 @@ if not modules then modules = { } end modules ['file-syn'] = {      license   = "see context related readme files"  } -local report_files = logs.reporter("files")  environment.filesynonyms = environment.filesynonyms or { }  local filesynonyms       = environment.filesynonyms -local settings_to_array = utilities.parsers.settings_to_array -local findfile          = resolvers.findfile +local settings_to_array  = utilities.parsers.settings_to_array +local findfile           = resolvers.findfile + +local implement          = interfaces.implement + +local report_files       = logs.reporter("files")  storage.register("environment/filesynonyms", filesynonyms, "environment.filesynonyms") @@ -27,11 +30,7 @@ end  environment.truefilename = truefilename -function commands.truefilename(name) -    context(truefilename(name)) -end - -function commands.definefilesynonym(name,realname) +function environment.definefilesynonym(name,realname)      local names = settings_to_array(name)      for i=1,#names do          local name = names[i] @@ -43,7 +42,7 @@ function commands.definefilesynonym(name,realname)      end  end -function commands.definefilefallback(name,alternatives) +function environment.definefilefallback(name,alternatives)      local names = settings_to_array(alternatives)      for i=1,#names do          local realname = findfile(names[i]) @@ -53,3 +52,21 @@ function commands.definefilefallback(name,alternatives)          end      end  end + +implement { +    name      = "truefilename", +    actions   = { truefilename, context }, +    arguments = "string" +} + +implement { +    name      = "definefilesynonym", +    actions   = environment.definefilesynonym, +    arguments = { "string", "string" } +} + +implement { +    name      = "definefilefallback", +    actions   = environment,definefilefallback, +    arguments = { "string", "string" } +} diff --git a/tex/context/base/file-syn.mkvi b/tex/context/base/file-syn.mkvi index b61bd8ae4..52ecd0d71 100644 --- a/tex/context/base/file-syn.mkvi +++ b/tex/context/base/file-syn.mkvi @@ -46,8 +46,8 @@  \unexpanded\def\definefilesynonym {\dodoubleempty   \syst_files_define_synonym }  \unexpanded\def\definefilefallback{\dodoubleargument\syst_files_define_fallback} % still used? -\def\syst_files_define_synonym     [#name][#realname]{\ctxcommand{definefilesynonym ("#name","#realname")}} -\def\syst_files_define_fallback[#name][#alternatives]{\ctxcommand{definefilefallback("#name","#alternatives")}} +\def\syst_files_define_synonym     [#name][#realname]{\clf_definefilesynonym {#name}{#realname}} +\def\syst_files_define_fallback[#name][#alternatives]{\clf_definefilefallback{#name}{#alternatives}}  %D \macros  %D   {truefilename} @@ -61,6 +61,6 @@  %D  %D The implementation shows that nesting is supported. -\def\truefilename#1{\ctxcommand{truefilename("#1")}} +\def\truefilename#1{\clf_truefilename{#1}}  \protect \endinput diff --git a/tex/context/base/font-col.lua b/tex/context/base/font-col.lua index 187e33311..997c57c9f 100644 --- a/tex/context/base/font-col.lua +++ b/tex/context/base/font-col.lua @@ -45,6 +45,8 @@ local currentfont        = font.current  local fontpatternhassize = fonts.helpers.fontpatternhassize +local implement          = interfaces.implement +  local list               = { }  local current            = 0  local enabled            = false @@ -275,9 +277,38 @@ end  -- interface -commands.fontcollectiondefine   = collections.define -commands.fontcollectionreset    = collections.reset -commands.fontcollectionprepare  = collections.prepare -commands.fontcollectionreport   = collections.report -commands.fontcollectionregister = collections.registermain -commands.fontcollectionclone    = collections.clonevector +implement { +    name      = "fontcollectiondefine", +    actions   = collections.define, +    arguments = { "string", "string", "string", "string" } +} + +implement { +    name      = "fontcollectionreset", +    actions   = collections.reset, +    arguments = { "string", "string" } +} + +implement { +    name      = "fontcollectionprepare", +    actions   = collections.prepare, +    arguments = "string" +} + +implement { +    name      = "fontcollectionreport", +    actions   = collections.report, +    arguments = "string" +} + +implement { +    name      = "fontcollectionregister", +    actions   = collections.registermain, +    arguments = "string" +} + +implement { +    name      = "fontcollectionclone", +    actions   = collections.clonevector, +    arguments = "string" +} diff --git a/tex/context/base/font-col.mkvi b/tex/context/base/font-col.mkvi index 34a1b04a8..bc8e8151e 100644 --- a/tex/context/base/font-col.mkvi +++ b/tex/context/base/font-col.mkvi @@ -34,13 +34,13 @@  \unexpanded\def\resetfontfallback {\dodoubleempty   \font_fallbacks_reset }  \def\font_fallbacks_define[#name][#font][#ranges][#settings]% -  {\ctxcommand{fontcollectiondefine("#name","#font",\!!bs#ranges\!!es,\!!bs#settings\!!es)}} +  {\clf_fontcollectiondefine{#name}{#font}{#ranges}{#settings}}  \def\font_fallbacks_reset[#name][#font]% -  {\ctxcommand{fontcollectionreset("#name","#font")}} +  {\clf_fontcollectionreset{#name}{#font}}  \def\font_fallbacks_prepare#name% -  {\ctxcommand{fontcollectionprepare("#name")}} % add fallbacks to last font +  {\clf_fontcollectionprepare{#name}} % add fallbacks to last font  % we might as well move the handling to lua but then we need to pass the  % fallbacks, skewchar etc. @@ -77,7 +77,7 @@    {\endgroup}  \def\font_fallbacks_clone_unique#specification#scale% kind of dododefinefont -  {\ctxcommand{fontcollectionreport("defining #specification (relative scale: #scale)")}% brrr +  {\clf_fontcollectionreport{defining #specification (relative scale: #scale)}% brrr     \setfalse\c_font_auto_size     \let\lastfontidentifier\s!dummy     \def\v_font_size_relative{#scale}% @@ -89,8 +89,8 @@  \def\font_fallbacks_clone_inherited#font% also a second argument    {\font_fallbacks_clone_unique{#font \savedfontspec}} -\def\font_fallbacks_register_main        #name{\ctxcommand{fontcollectionregister("#name")}} -\def\font_fallbacks_prepare_clone_vectors#name{\ctxcommand{fontcollectionclone("#name")}} +\def\font_fallbacks_register_main        #name{\clf_fontcollectionregister{#name}} +\def\font_fallbacks_prepare_clone_vectors#name{\clf_fontcollectionclone{#name}}  % check : only replace when present in replacement font (default: no)  % force : force replacent even when basefont has glyph  (default: yes) diff --git a/tex/context/base/font-ctx.lua b/tex/context/base/font-ctx.lua index 2d0e99653..0a0e5eab6 100644 --- a/tex/context/base/font-ctx.lua +++ b/tex/context/base/font-ctx.lua @@ -1761,10 +1761,10 @@ function fonts.definetypeface(name,t)      local boldwidth    = t.boldwidth    or t.width  or p.boldwidth    or p.width  or "normal"      Shape = Shapes[shape] or "Serif"      ctx_startfontclass { name } -        ctx_definefontsynonym( { format("%s",           Shape) }, { format("spec:%s-%s-regular-%s", fontname, normalweight, normalwidth) } ) -        ctx_definefontsynonym( { format("%sBold",       Shape) }, { format("spec:%s-%s-regular-%s", fontname, boldweight,   boldwidth  ) } ) -        ctx_definefontsynonym( { format("%sBoldItalic", Shape) }, { format("spec:%s-%s-italic-%s",  fontname, boldweight,   boldwidth  ) } ) -        ctx_definefontsynonym( { format("%sItalic",     Shape) }, { format("spec:%s-%s-italic-%s",  fontname, normalweight, normalwidth) } ) +        ctx_definefontsynonym( { formatters["%s"]          (Shape) }, { formatters["spec:%s-%s-regular-%s"] (fontname, normalweight, normalwidth) } ) +        ctx_definefontsynonym( { formatters["%sBold"]      (Shape) }, { formatters["spec:%s-%s-regular-%s"] (fontname, boldweight,   boldwidth  ) } ) +        ctx_definefontsynonym( { formatters["%sBoldItalic"](Shape) }, { formatters["spec:%s-%s-italic-%s"]  (fontname, boldweight,   boldwidth  ) } ) +        ctx_definefontsynonym( { formatters["%sItalic"]    (Shape) }, { formatters["spec:%s-%s-italic-%s"]  (fontname, normalweight, normalwidth) } )      ctx_stopfontclass()      local settings = sequenced({ features= t.features },",")      ctx_dofastdefinetypeface(name, shortcut, shape, size, settings) @@ -2138,7 +2138,7 @@ local glyph_code         = nodes.nodecodes.glyph  local states             = analyzers.states -local names = { +local colornames = {      [states.init] = "font:1",      [states.medi] = "font:2",      [states.fina] = "font:3", @@ -2159,7 +2159,7 @@ local function markstates(head)          for glyph in traverse_by_id(glyph_code,head) do              local a = getprop(glyph,a_state)              if a then -                local name = names[a] +                local name = colornames[a]                  if name then                      local color = m_color[name]                      if color then diff --git a/tex/context/base/font-fea.mkvi b/tex/context/base/font-fea.mkvi index e1a7651fe..90da7b0fc 100644 --- a/tex/context/base/font-fea.mkvi +++ b/tex/context/base/font-fea.mkvi @@ -129,7 +129,7 @@    {\dodoubleargument\font_basics_features_list}  \def\font_basics_features_list[#name][#separator]% todo: arg voor type -  {\clf_featurelist{#name}{\luaescapestring{#separator}}} +  {\clf_featurelist{#name}{\detokenize{#separator}}}  \attribute\zerocount\zerocount % first in list, so fast match diff --git a/tex/context/base/font-gds.lua b/tex/context/base/font-gds.lua index c2c506b7a..b021004fe 100644 --- a/tex/context/base/font-gds.lua +++ b/tex/context/base/font-gds.lua @@ -9,10 +9,12 @@ if not modules then modules = { } end modules ['font-gds'] = {  -- depends on ctx  local type, next, tonumber = type, next, tonumber -local gmatch, format, lower, find, splitup = string.gmatch, string.format, string.lower, string.find, string.splitup -local texsp = tex.sp +local gmatch, lower, find, splitup = string.gmatch, string.lower, string.find, string.splitup -local fonts, nodes, attributes, node = fonts, nodes, attributes, node +local fonts              = fonts +local nodes              = nodes +local attributes         = attributes +local node               = node  local trace_goodies      = false  trackers.register("fonts.goodies", function(v) trace_goodies = v end)  local report_goodies     = logs.reporter("fonts","goodies") @@ -20,6 +22,11 @@ local report_goodies     = logs.reporter("fonts","goodies")  local allocate           = utilities.storage.allocate  local setmetatableindex  = table.setmetatableindex +local implement          = interfaces.implement + +local texsp              = tex.sp +local formatters         = string.formatters +  local otf                = fonts.handlers.otf  local afm                = fonts.handlers.afm  local tfm                = fonts.handlers.tfm @@ -429,7 +436,7 @@ local function setextrafeatures(tfmdata)                      addotffeature(tfmdata.shared.rawdata,feature,specification)                      registerotffeature {                          name        = feature, -                        description = format("extra: %s",feature) +                        description = formatters["extra: %s"](feature)                      }                  end              end @@ -819,8 +826,16 @@ end  -- interface -commands.loadfontgoodies        = fontgoodies.load -commands.enablefontcolorschemes = colorschemes.enable +implement { +    name      = "loadfontgoodies", +    actions   = fontgoodies.load, +    arguments = "string" +} + +implement { +    name      = "enablefontcolorschemes", +    actions   = colorschemes.enable +}  -- weird place ... depends on math diff --git a/tex/context/base/font-gds.mkvi b/tex/context/base/font-gds.mkvi index 6d9798428..e9c34e807 100644 --- a/tex/context/base/font-gds.mkvi +++ b/tex/context/base/font-gds.mkvi @@ -46,10 +46,10 @@  \definesystemattribute[colorscheme][public]  \unexpanded\def\loadfontgoodies[#filename]% -  {\ctxcommand{loadfontgoodies("#filename")}} +  {\clf_loadfontgoodies{#filename}}  \unexpanded\def\setfontcolorscheme % will move to the lua end -  {\ctxcommand{enablefontcolorschemes()}% +  {\clf_enablefontcolorschemes     \unexpanded\xdef\setfontcolorscheme[##1]{\attribute\colorschemeattribute##1\relax}%     \setfontcolorscheme} diff --git a/tex/context/base/font-ini.mkvi b/tex/context/base/font-ini.mkvi index 9ab1962f6..dc3c491d2 100644 --- a/tex/context/base/font-ini.mkvi +++ b/tex/context/base/font-ini.mkvi @@ -740,7 +740,7 @@    {% we can now set more at the lua end     \global\let\somefontname\defaultfontfile     \let\somefontsize\empty -   \clf_definefont_one{\luaescapestring{#specification}}% the escapestring catches at \somedimen +   \clf_definefont_one{\detokenize\expandafter{\normalexpanded{#specification}}}% the escapestring catches at \somedimen     % sets \scaledfontmode and \somefontname and \somefontsize     \ifcase\fontface\relax     % \let\v_font_size_absolute\textface % fontbody diff --git a/tex/context/base/font-sel.lua b/tex/context/base/font-sel.lua index aef528c53..c3431a213 100644 --- a/tex/context/base/font-sel.lua +++ b/tex/context/base/font-sel.lua @@ -20,6 +20,8 @@ local v_simplefonts           = interfaces.variables.simplefonts  local v_selectfont            = interfaces.variables.selectfont  local v_default               = interfaces.variables.default +local implement               = interfaces.implement +  local selectfont              = fonts.select or { }  fonts.select                  = selectfont @@ -299,12 +301,12 @@ local mathsettings = {      },  } -function commands.defineselectfont(settings) +function selectfont.define(settings)      local index = #data + 1      data[index] = settings      selectfont.searchfiles(index)      selectfont.filterinput(index) -    context(index) +    return index  end  local function savefont(data,alternative,entries) @@ -493,6 +495,14 @@ function selectfont.filterinput(index)      end  end +local ctx_definefontsynonym  = context.definefontsynonym +local ctx_resetfontfallback  = context.resetfontfallback +local ctx_startfontclass     = context.startfontclass +local ctx_stopfontclass      = context.stopfontclass +local ctx_loadfontgoodies    = context.loadfontgoodies +local ctx_definefontfallback = context.definefontfallback +local ctx_definetypeface     = context.definetypeface +  local function definefontsynonym(data,alternative,index,fallback)      local fontdata     = data.fonts and data.fonts[alternative]      local style        = data.metadata.style @@ -534,15 +544,16 @@ local function definefontsynonym(data,alternative,index,fallback)              end          end          if fallback then -            context.definefontsynonym( { fontname }, { fontfile }, { features = features } ) +            -- can we use +            ctx_definefontsynonym( { fontname }, { fontfile }, { features = features } )          else -            context.definefontsynonym( { fontname }, { fontfile }, { features = features, fallbacks = fontfile, goodies = goodies } ) +            ctx_definefontsynonym( { fontname }, { fontfile }, { features = features, fallbacks = fontfile, goodies = goodies } )          end      else          if fallback then -            context.definefontsynonym( { fontname }, { fontparent }, { features = features } ) +            ctx_definefontsynonym( { fontname }, { fontparent }, { features = features } )          else -            context.definefontsynonym( { fontname }, { fontparent }, { features = features, fallbacks = fontfile, goodies = goodies } ) +            ctx_definefontsynonym( { fontname }, { fontparent }, { features = features, fallbacks = fontfile, goodies = goodies } )          end      end  end @@ -555,11 +566,11 @@ local function definetypescript(index)      local typeface     = data.metadata.typeface      local style        = data.metadata.style      if entry and entry["tf"] then -        context.startfontclass( { typeface } ) +        ctx_startfontclass( { typeface } )          if goodies ~= "" then              goodies = utilities.parsers.settings_to_array(goodies)              for _, goodie in next, goodies do -                context.loadfontgoodies( { goodie } ) +                ctx_loadfontgoodies( { goodie } )              end          end          for alternative, _ in next, alternatives do @@ -567,7 +578,7 @@ local function definetypescript(index)                  definefontsynonym(data,alternative)              end          end -        context.stopfontclass() +        ctx_stopfontclass()      else          -- regular style not available, loading aborted      end @@ -598,20 +609,20 @@ local function definetextfontfallback(data,alternative,index)      local synonym  = formatters["%s-%s-%s-fallback-%s"](typeface, style, alternative, index)      local fallback = formatters["%s-%s-%s"]            (typeface, style, alternative)      if index == 1 then -        context.resetfontfallback( { fallback } ) +        ctx_resetfontfallback( { fallback } )      end -    context.definefontfallback( { fallback }, { synonym }, { range }, { rscale = rscale, check = check, force = force } ) +    ctx_definefontfallback( { fallback }, { synonym }, { range }, { rscale = rscale, check = check, force = force } )  end  local function definetextfallback(entry,index)      local data     = data[index]      local typeface = data.metadata.typeface -    context.startfontclass( { typeface } ) +    ctx_startfontclass( { typeface } )      for alternative, _ in next, alternatives do          definefontsynonym     (data,alternative,entry,true)          definetextfontfallback(data,alternative,entry)      end -    context.stopfontclass() +    ctx_stopfontclass()      -- inspect(data)  end @@ -627,14 +638,14 @@ local function definemathfontfallback(data,alternative,index)      local fontdata = data.fonts and data.fonts[alternative]      local fallback = formatters["%s-%s-%s"](typeface, style, alternative)      if index == 1 then -        context.resetfontfallback( { fallback } ) +        ctx_resetfontfallback( { fallback } )      end      if fontdata and #fontdata > 0 then          for _, entry in next, fontdata do              local filename   = entry["filename"]              local designsize = entry["designsize"] or 100              if designsize == 100 or designsize == 110 or designsize == 120 or designsize == 0 or #fontdata == 1 then -                context.definefontfallback( { fallback }, { formatters["file:%s*%s"](filename,features) }, { range }, { rscale = rscale, check = check, force = force, offset = offset } ) +                ctx_definefontfallback( { fallback }, { formatters["file:%s*%s"](filename,features) }, { range }, { rscale = rscale, check = check, force = force, offset = offset } )                  break              end          end @@ -645,13 +656,13 @@ local function definemathfallback(entry,index)      local data     = data[index]      local typeface = data.metadata.typeface      local style    = data.metadata.style -    context.startfontclass( { typeface } ) +    ctx_startfontclass( { typeface } )      for alternative, _ in next, alternatives do          if synonyms[style][alternative] then              definemathfontfallback(data,alternative,entry)          end      end -    context.stopfontclass() +    ctx_stopfontclass()      -- inspect(data)  end @@ -679,7 +690,7 @@ local function definetextfont(index)      local style      = styles[data.metadata.style]      local designsize = data.options.opticals == v_yes and "auto" or "default"      local scale      = data.options.scale ~= "" and data.options.scale or 1 -    context.definetypeface( { fontclass }, { shortstyle }, { style }, { "" }, { "default" }, { designsize = designsize, rscale = scale } ) +    ctx_definetypeface( { fontclass }, { shortstyle }, { style }, { "" }, { "default" }, { designsize = designsize, rscale = scale } )  end  local function definemathfont(index) @@ -691,9 +702,9 @@ local function definemathfont(index)      local typescript = cleanname(data.metadata.family)      local entries    = data.fonts      if entries then -        context.definetypeface( { fontclass }, { shortstyle }, { style }, { "" }, { "default" }, { rscale = scale } ) +        ctx_definetypeface( { fontclass }, { shortstyle }, { style }, { "" }, { "default" }, { rscale = scale } )      else -        context.definetypeface( { fontclass }, { shortstyle }, { style }, { typescript }, { "default" }, { rscale = scale } ) +        ctx_definetypeface( { fontclass }, { shortstyle }, { style }, { typescript }, { "default" }, { rscale = scale } )      end  end @@ -711,5 +722,49 @@ function selectfont.definetypeface(index)      -- inspect(data)  end -commands.definefontfamily     = selectfont.definetypeface -commands.definefallbackfamily = selectfont.registerfallback +local styles = { +    { "tf" }, { "bf" }, { "it" }, { "sl" }, { "bi" }, { "bs" }, { "sc" }, +} + +implement { +    name      = "defineselectfont", +    actions   = { selectfont.define, context }, +    arguments = { +        { +            { +                "metadata", { +                    { "typeface" }, +                    { "style" }, +                    { "family" }, +                } +            }, +            { +                "options", { +                    { "opticals" }, +                    { "scale" }, +                    { "goodies" }, +                    { "alternative" }, +                    { "range" }, +                    { "offset" }, +                    { "check" }, +                    { "force" }, +                } +            }, +            { "alternatives", styles }, +            { "files",        styles }, +            { "features",     styles }, +        } +   } +} + +implement { +    name      = "definefontfamily", +    actions   = selectfont.definetypeface, +    arguments = "integer" +} + +implement { +    name      = "definefallbackfamily", +    actions   = selectfont.registerfallback, +    arguments = { "string", "string", "integer"} +} diff --git a/tex/context/base/font-sel.mkvi b/tex/context/base/font-sel.mkvi index 933afa466..94cd14929 100644 --- a/tex/context/base/font-sel.mkvi +++ b/tex/context/base/font-sel.mkvi @@ -27,51 +27,49 @@     \fi     \setexpandedselectfontparameter\c!style      {\expandnamespaceparameter\??selectfontstyle      \selectfontparameter\c!style      \s!rm     }%     \setexpandedselectfontparameter\c!alternative{\expandnamespaceparameter\??selectfontalternative\selectfontparameter\c!alternative\v!default}% -   \xdef\selectfont_index{\ctxcommand{ -        defineselectfont { -            metadata = { -                typeface    = "\selectfontparameter\c!name", -                style       = "\selectfontparameter\c!style", -                family      = "\selectfontparameter\c!family", -            }, -            options = { -                opticals    = "\selectfontparameter\c!opticalsize", -                scale       = "\selectfontparameter\c!scale", -                goodies     = "\selectfontparameter\c!goodies", -                alternative = "\selectfontparameter\c!alternative", -                range       = "\selectfontparameter\c!range",  % fallback only -                offset      = "\selectfontparameter\c!offset", % fallback only -                check       = "\selectfontparameter\c!check",  % fallback only -                force       = "\selectfontparameter\c!force",  % fallback only -            }, -            alternatives = { -                ["tf"]      = "\selectfontparameter\s!tf", -                ["bf"]      = "\selectfontparameter\s!bf", -                ["it"]      = "\selectfontparameter\s!it", -                ["sl"]      = "\selectfontparameter\s!sl", -                ["bi"]      = "\selectfontparameter\s!bi", -                ["bs"]      = "\selectfontparameter\s!bs", -                ["sc"]      = "\selectfontparameter\s!sc", -            }, -            files = { -                ["tf"]      = "\selectfontparameter\c!regularfont", -                ["bf"]      = "\selectfontparameter\c!boldfont", -                ["it"]      = "\selectfontparameter\c!italicfont", -                ["sl"]      = "\selectfontparameter\c!slantedfont", -                ["bi"]      = "\selectfontparameter\c!bolditalicfont", -                ["bs"]      = "\selectfontparameter\c!boldslantedfont", -                ["sc"]      = "\selectfontparameter\c!smallcapsfont", -            }, -            features = { -                ["tf"]      = "\selectfontparameter\c!regularfeatures", -                ["bf"]      = "\selectfontparameter\c!boldfeatures", -                ["it"]      = "\selectfontparameter\c!italicfeatures", -                ["sl"]      = "\selectfontparameter\c!slantedfeatures", -                ["bi"]      = "\selectfontparameter\c!bolditalicfeatures", -                ["bs"]      = "\selectfontparameter\c!boldslantedfeatures", -                ["sc"]      = "\selectfontparameter\c!smallcapsfeatures", -            } -   }}}% +   \xdef\selectfont_index{\clf_defineselectfont +        metadata {% +            typeface    {\selectfontparameter\c!name}% +            style       {\selectfontparameter\c!style}% +            family      {\selectfontparameter\c!family}% +        } +        options {% +            opticals    {\selectfontparameter\c!opticalsize}% +            scale       {\selectfontparameter\c!scale}% +            goodies     {\selectfontparameter\c!goodies}% +            alternative {\selectfontparameter\c!alternative}% +            range       {\selectfontparameter\c!range}%  fallback only +            offset      {\selectfontparameter\c!offset}% fallback only +            check       {\selectfontparameter\c!check}%  fallback only +            force       {\selectfontparameter\c!force}%  fallback only +        } +        alternatives {% +            tf {\selectfontparameter\s!tf}% +            bf {\selectfontparameter\s!bf}% +            it {\selectfontparameter\s!it}% +            sl {\selectfontparameter\s!sl}% +            bi {\selectfontparameter\s!bi}% +            bs {\selectfontparameter\s!bs}% +            sc {\selectfontparameter\s!sc}% +        } +        files {% +            tf {\selectfontparameter\c!regularfont}% +            bf {\selectfontparameter\c!boldfont}% +            it {\selectfontparameter\c!italicfont}% +            sl {\selectfontparameter\c!slantedfont}% +            bi {\selectfontparameter\c!bolditalicfont}% +            bs {\selectfontparameter\c!boldslantedfont}% +            sc {\selectfontparameter\c!smallcapsfont}% +        } +        features {% +            tf {\selectfontparameter\c!regularfeatures}% +            bf {\selectfontparameter\c!boldfeatures}% +            it {\selectfontparameter\c!italicfeatures}% +            sl {\selectfontparameter\c!slantedfeatures}% +            bi {\selectfontparameter\c!bolditalicfeatures}% +            bs {\selectfontparameter\c!boldslantedfeatures}% +            sc {\selectfontparameter\c!smallcapsfeatures}% +        }}%     \endgroup}  %D \macros @@ -330,7 +328,7 @@    {\doifassignmentelse{#settings}       {\selectfont_setparameters[\c!name={#typeface},\c!style={#style},\c!family={#family},#settings]}       {\selectfont_setparameters[\c!name={#typeface},\c!style={#style},\c!family={#family},\c!preset={#settings}]}% -   \ctxcommand{definefontfamily(\selectfont_index)}} +   \clf_definefontfamily\selectfont_index\relax}  \unexpanded\def\definefallbackfamily    {\doquadrupleempty\selectfont_fallback_define} @@ -340,7 +338,7 @@       {\selectfont_setparameters[\c!name={#typeface},\c!style={#style},\c!family={#family},#settings]}       {\selectfont_setparameters[\c!name={#typeface},\c!style={#style},\c!family={#family},\c!preset={#settings}]}%     \edef\p_selectfont_style{\expandnamespacevalue\??selectfontstyle{#style}\s!rm}% -   \ctxcommand{definefallbackfamily("#typeface","\p_selectfont_style",\selectfont_index)}} +   \clf_definefallbackfamily{#typeface}{\p_selectfont_style}\selectfont_index\relax}  %D \macros  %D   {setupfontfamily,setupfallbackfamily} @@ -428,4 +426,4 @@       \c!smallcapsfeatures=\s!smallcaps,                   \c!style=\s!rm] -\protect
\ No newline at end of file +\protect diff --git a/tex/context/base/font-sol.lua b/tex/context/base/font-sol.lua index a41e4a679..bbb2997f4 100644 --- a/tex/context/base/font-sol.lua +++ b/tex/context/base/font-sol.lua @@ -45,6 +45,8 @@ local v_preroll          = variables.preroll  local v_random           = variables.random  local v_split            = variables.split +local implement          = interfaces.implement +  local settings_to_array  = utilities.parsers.settings_to_array  local settings_to_hash   = utilities.parsers.settings_to_hash @@ -907,8 +909,52 @@ end  -- interface -commands.definefontsolution = splitters.define -commands.startfontsolution  = splitters.start -commands.stopfontsolution   = splitters.stop -commands.setfontsolution    = splitters.set -commands.resetfontsolution  = splitters.reset +implement { +    name      = "definefontsolution", +    actions   = splitters.define, +    arguments = { +        "string", +        { +            { "goodies" }, +            { "solution" }, +            { "less" }, +            { "more" }, +        } +    } +} + +implement { +    name      = "startfontsolution", +    actions   = splitters.start, +    arguments = { +        "string", +        { +            { "method" }, +            { "criterium" }, +            { "randomseed" }, +        } +    } +} + +implement { +    name      = "stopfontsolution", +    actions   = splitters.stop +} + +implement { +    name      = "setfontsolution", +    actions   = splitters.set, +    arguments = { +        "string", +        { +            { "method" }, +            { "criterium" }, +            { "randomseed" }, +        } +    } +} + +implement { +    name      = "resetfontsolution", +    actions   = splitters.reset +} diff --git a/tex/context/base/font-sol.mkvi b/tex/context/base/font-sol.mkvi index b40e37ced..d065b78ea 100644 --- a/tex/context/base/font-sol.mkvi +++ b/tex/context/base/font-sol.mkvi @@ -85,24 +85,30 @@  \let\setupfontsolutions\setupfontsolution  \appendtoks -    \ctxcommand{definefontsolution("\currentfontsolution",{ % these are frozen -        goodies  = "\fontsolutionparameter\s!goodies", -        solution = "\fontsolutionparameter\c!solution", -        less     = "\fontsolutionparameter\c!less", -        more     = "\fontsolutionparameter\c!more", -    })} +    \clf_definefontsolution +      {\currentfontsolution}% +      {% these are frozen +        goodies  {\fontsolutionparameter\s!goodies}% +        solution {\fontsolutionparameter\c!solution}% +        less     {\fontsolutionparameter\c!less}% +        more     {\fontsolutionparameter\c!more}% +      }% +    \relax  \to \everydefinefontsolution  \unexpanded\def\setfontsolution[#solution]% just one    {\edef\currentfontsolution{#solution}% -   \ctxcommand{setfontsolution("\currentfontsolution",{ -        method     = "\fontsolutionparameter\c!method", -        criterium  = "\fontsolutionparameter\c!criterium", -      % randomseed = "\fontsolutionparameter\c!random", -  })}} +   \clf_setfontsolution +     {\currentfontsolution}% +     {% +        method     {\fontsolutionparameter\c!method}% +        criterium  {\fontsolutionparameter\c!criterium}% +      % randomseed {\fontsolutionparameter\c!random}% +     }% +   \relax}  \unexpanded\def\resetfontsolution % resets all -  {\ctxcommand{resetfontsolution()}% +  {\clf_resetfontsolution     \let\currentfontsolution\empty}  \unexpanded\def\startfontsolution % [#1] @@ -111,7 +117,7 @@  \unexpanded\def\stopfontsolution    {\ifhmode\par\fi -   \ctxcommand{stopfontsolution()}% +   \clf_stopfontsolution     \popmacro\currentfontsolution}  % We initialize this module at the \LUA\ end. diff --git a/tex/context/base/font-sym.mkvi b/tex/context/base/font-sym.mkvi index c8ca49f74..1badf338f 100644 --- a/tex/context/base/font-sym.mkvi +++ b/tex/context/base/font-sym.mkvi @@ -167,8 +167,8 @@     \currentsymbolfont     \global\expandafter\let\csname\??symbolfont\askedsymbolfont\endcsname\lastrawfontcall} -\unexpanded\def\getnamedglyphstyled#fontname#character{{\setstyledsymbolicfont{#fontname}\ctxcommand{fontchar("#character")}}} -\unexpanded\def\getnamedglyphdirect#fontname#character{{\setdirectsymbolicfont{#fontname}\ctxcommand{fontchar("#character")}}} +\unexpanded\def\getnamedglyphstyled#fontname#character{{\setstyledsymbolicfont{#fontname}\clf_fontchar{#character}}} +\unexpanded\def\getnamedglyphdirect#fontname#character{{\setdirectsymbolicfont{#fontname}\clf_fontchar{#character}}}  \unexpanded\def\getglyphstyled     #fontname#character{{\setstyledsymbolicfont{#fontname}\doifnumberelse{#character}\char\donothing#character}}  \unexpanded\def\getglyphdirect     #fontname#character{{\setdirectsymbolicfont{#fontname}\doifnumberelse{#character}\char\donothing#character}} diff --git a/tex/context/base/lpdf-col.lua b/tex/context/base/lpdf-col.lua index 030291c29..a2fda8ca5 100644 --- a/tex/context/base/lpdf-col.lua +++ b/tex/context/base/lpdf-col.lua @@ -48,6 +48,7 @@ local registercolor           = colors.register  local colorsvalue             = colors.value  local transparenciesvalue     = transparencies.value  local forcedmodel             = colors.forcedmodel +local getpagecolormodel       = colors.getpagecolormodel  local c_transparency          = pdfconstant("Transparency") @@ -98,11 +99,10 @@ table.setmetatableindex(transparencygroups, function(transparencygroups,colormod      end  end) -local currentgroupcolormodel -  local function addpagegroup() -    if currentgroupcolormodel then -        local g = transparencygroups[currentgroupcolormodel] +    local model = getpagecolormodel() +    if model then +        local g = transparencygroups[model]          if g then              addtopageattributes("Group",g)          end @@ -111,13 +111,6 @@ end  lpdf.registerpagefinalizer(addpagegroup,3,"pagegroup") -local function synchronizecolormodel(model) -    currentgroupcolormodel = model -end - -backends.codeinjections.synchronizecolormodel = synchronizecolormodel -commands.synchronizecolormodel                = synchronizecolormodel -  -- injection code (needs a bit reordering)  -- color injection @@ -491,8 +484,11 @@ function registrations.transparency(n,a,t)  end  statistics.register("page group warning", function() -    if done and not transparencygroups[currentgroupcolormodel] then -        return "transparencies are used but no pagecolormodel is set" +    if done then +        local model = getpagecolormodel() +        if model and not transparencygroups[model] then +            return "transparencies are used but no pagecolormodel is set" +        end      end  end) diff --git a/tex/context/base/luat-ini.mkiv b/tex/context/base/luat-ini.mkiv index 78a324db2..38b8be3ae 100644 --- a/tex/context/base/luat-ini.mkiv +++ b/tex/context/base/luat-ini.mkiv @@ -193,19 +193,22 @@  %D \edef\luaescapestring#1{\!!bs#1\!!es}  %D \stoptyping -\def\setdocumentfilename       #1#2{\ctxlua{document.setfilename(#1,"#2")}} -\def\setdocumentargument       #1#2{\ctxlua{document.setargument("#1","#2")}} -\def\setdocumentargumentdefault#1#2{\ctxlua{document.setdefaultargument("#1","#2")}} -\def\getdocumentfilename         #1{\ctxlua{document.getfilename("#1")}} -\def\getdocumentargument         #1{\ctxlua{document.getargument("#1")}} -\def\setdocumentargument       #1#2{\ctxlua{document.setargument("#1","#2")}} -\def\getdocumentargumentdefault#1#2{\ctxlua{document.getargument("#1","#2")}} -\def\doifdocumentargumentelse    #1{\doifsomethingelse{\getdocumentargument{#1}}} -\def\doifdocumentargument        #1{\doifsomething    {\getdocumentargument{#1}}} -\def\doifnotdocumentargument     #1{\doifnothing      {\getdocumentargument{#1}}} -\def\doifdocumentfilenameelse    #1{\doifsomethingelse{\getdocumentfilename{#1}}} -\def\doifdocumentfilename        #1{\doifsomething    {\getdocumentfilename{#1}}} -\def\doifnotdocumentfilename     #1{\doifnothing      {\getdocumentfilename{#1}}} +\def\setdocumentfilename       #1#2{\clf_setdocumentfilename\numexpr#1\relax{#2}} +\def\setdocumentargument       #1#2{\clf_setdocumentargument{#1}{#2}} +\def\setdocumentargumentdefault#1#2{\clf_setdocumentdefaultargument{#1}{#2}} +\def\getdocumentfilename         #1{\clf_getdocumentfilename\numexpr#1\relax} +\def\getdocumentargument         #1{\clf_getdocumentargument{#1}} +\def\setdocumentargument       #1#2{\clf_setdocumentargument{#1}{#2}} +\def\getdocumentargumentdefault#1#2{\clf_getdocumentargument{#1}{#2}} + +% seldom used so no need for speedy variants: + +\def\doifdocumentargumentelse    #1{\doifsomethingelse{\clf_getdocumentargument{#1}}} +\def\doifdocumentargument        #1{\doifsomething    {\clf_getdocumentargument{#1}}} +\def\doifnotdocumentargument     #1{\doifnothing      {\clf_getdocumentargument{#1}}} +\def\doifdocumentfilenameelse    #1{\doifsomethingelse{\clf_getdocumentfilename\numexpr#1\relax}} +\def\doifdocumentfilename        #1{\doifsomething    {\clf_getdocumentfilename\numexpr#1\relax}} +\def\doifnotdocumentfilename     #1{\doifnothing      {\clf_getdocumentfilename\numexpr#1\relax}}  \let\doifelsedocumentargument\doifdocumentargumentelse diff --git a/tex/context/base/lxml-ini.lua b/tex/context/base/lxml-ini.lua index 434814b66..8506e1096 100644 --- a/tex/context/base/lxml-ini.lua +++ b/tex/context/base/lxml-ini.lua @@ -39,8 +39,8 @@ implement { name = "xmlatt",                  actions = lxml.att,  implement { name = "xmlattdef",               actions = lxml.att,               arguments = { "string", "string", "string" } }  implement { name = "xmlattribute",            actions = lxml.attribute,         arguments = { "string", "string", "string" } }  implement { name = "xmlattributedef",         actions = lxml.attribute,         arguments = { "string", "string", "string", "string" } } -implement { name = "xmlchainatt",             actions = lxml.chainattribute,    arguments = { "string", "string", "string" } } -implement { name = "xmlchainattdef",          actions = lxml.chainattribute,    arguments = { "string", "string", "string", "string"  } } +implement { name = "xmlchainatt",             actions = lxml.chainattribute,    arguments = { "string", "'/'", "string" } } +implement { name = "xmlchainattdef",          actions = lxml.chainattribute,    arguments = { "string", "'/'", "string", "string"  } }  implement { name = "xmlchecknamespace",       actions =  xml.checknamespace,    arguments = { "lxmlid", "string", "string" } }  implement { name = "xmlcommand",              actions = lxml.command,           arguments = { "string", "string", "string" } }  implement { name = "xmlconcat",               actions = lxml.concat,            arguments = { "string", "string", "string" } }                     --  \detokenize{#3} @@ -53,7 +53,7 @@ implement { name = "xmldirectives",           actions = lxml.directives.setup,  implement { name = "xmldirectivesafter",      actions = lxml.directives.after,  arguments = "string" }  implement { name = "xmldirectivesbefore",     actions = lxml.directives.before, arguments = "string" }  implement { name = "xmldisplayverbatim",      actions = lxml.displayverbatim,   arguments = "string" } -implement { name = "xmlelement",              actions = lxml.element,           arguments = { "string", "integer" } } +implement { name = "xmlelement",              actions = lxml.element,           arguments = { "string", "string" } } -- could be integer but now we can alias  implement { name = "xmlfilter",               actions = lxml.filter,            arguments = { "string", "string" } }  implement { name = "xmlfilterlist",           actions = lxml.filterlist,        arguments = { "string", "string" } }  implement { name = "xmlfirst",                actions = lxml.first,             arguments = { "string", "string" } } @@ -66,7 +66,7 @@ implement { name = "xmlinclude",              actions = lxml.include,  implement { name = "xmlincludeoptions",       actions = lxml.include,           arguments = { "string", "string", "string", "string" } }  implement { name = "xmlinclusion",            actions = lxml.inclusion,         arguments = "string" }  implement { name = "xmlinclusions",           actions = lxml.inclusions,        arguments = "string" } -implement { name = "xmlindex",                actions = lxml.index,             arguments = { "string", "string", "integer" } } +implement { name = "xmlindex",                actions = lxml.index,             arguments = { "string", "string", "string" } } -- can be integer but now we can alias  implement { name = "xmlinfo",                 actions = lxml.info,              arguments = "string" }  implement { name = "xmlinlineverbatim",       actions = lxml.inlineverbatim,    arguments = "string" }  implement { name = "xmllast",                 actions = lxml.last,              arguments = "string" } diff --git a/tex/context/base/lxml-ini.mkiv b/tex/context/base/lxml-ini.mkiv index 22654bc14..728bfcd00 100644 --- a/tex/context/base/lxml-ini.mkiv +++ b/tex/context/base/lxml-ini.mkiv @@ -33,74 +33,142 @@  \def\ctxlxml                #1{\ctxlua{lxml.#1}} -%def\xmlcontent             #1{\clf_xmlcontent          {#1}} -%def\xmlflushstripped       #1{\clf_xmlflushstripped    {#1}} -\def\xmlall               #1#2{\clf_xmlall              {#1}{#2}} -\def\xmlatt               #1#2{\clf_xmlatt              {#1}{#2}} -\def\xmlattdef          #1#2#3{\clf_xmlattdef           {#1}{#2}{#3}} -\def\xmlattribute       #1#2#3{\clf_xmlattribute        {#1}{#2}{#3}} -\def\xmlattributedef  #1#2#3#4{\clf_xmlattributedef     {#1}{#2}{#3}{#4}} -\def\xmlchainatt          #1#2{\clf_xmlchainatt         {#1}{/}{#2}} -\def\xmlchainattdef     #1#2#3{\clf_xmlchainattdef      {#1}{/}{#2}{#3}} -\def\xmlchecknamespace  #1#2#3{\clf_xmlchecknamespace   {#1}{#2}{#3}} % element -\def\xmlcommand         #1#2#3{\clf_xmlcommand          {#1}{#2}{#3}} +%def\xmlall               #1#2{\clf_xmlall              {#1}{#2}} +%def\xmlatt               #1#2{\clf_xmlatt              {#1}{#2}} +%def\xmlattdef          #1#2#3{\clf_xmlattdef           {#1}{#2}{#3}} +%def\xmlattribute       #1#2#3{\clf_xmlattribute        {#1}{#2}{#3}} +%def\xmlattributedef  #1#2#3#4{\clf_xmlattributedef     {#1}{#2}{#3}{#4}} +%def\xmlchainatt          #1#2{\clf_xmlchainatt         {#1}{#2}} +%def\xmlchainattdef     #1#2#3{\clf_xmlchainattdef      {#1}{#2}{#3}} +%def\xmlchecknamespace  #1#2#3{\clf_xmlchecknamespace   {#1}{#2}{#3}} % element +%def\xmlcommand         #1#2#3{\clf_xmlcommand          {#1}{#2}{#3}}  \def\xmlconcat          #1#2#3{\clf_xmlconcat           {#1}{#2}{\detokenize{#3}}}  \def\xmlconcatrange #1#2#3#4#5{\clf_xmlconcatrange      {#1}{#2}{#3}{#4}{\detokenize{#5}}} -\def\xmlcontext           #1#2{\clf_xmlcontext          {#1}{#2}} -\def\xmlcount             #1#2{\clf_xmlcount            {#1}{#2}} -\def\xmldelete            #1#2{\clf_xmldelete           {#1}{#2}} -\def\xmldirect              #1{\clf_xmldirect           {#1}} % in loops, not dt but root -\def\xmldirectives          #1{\clf_xmldirectives       {#1}} -\def\xmldirectivesafter     #1{\clf_xmldirectivesafter  {#1}} -\def\xmldirectivesbefore    #1{\clf_xmldirectivesbefore {#1}} -\def\xmldisplayverbatim     #1{\clf_xmldisplayverbatim  {#1}} -\def\xmlelement           #1#2{\clf_xmlelement          {#1}{#2}} -\def\xmlfilter            #1#2{\clf_xmlfilter           {#1}{#2}} -\def\xmlfilterlist        #1#2{\clf_xmlfilterlist       {#1}{#2}} -\def\xmlfirst             #1#2{\clf_xmlfirst            {#1}{#2}} -\def\xmlflush               #1{\clf_xmlflush            {#1}} -\def\xmlflushcontext        #1{\clf_xmlflushcontext     {#1}} -\def\xmlflushlinewise       #1{\clf_xmlflushlinewise    {#1}} -\def\xmlflushspacewise      #1{\clf_xmlflushspacewise   {#1}} -\def\xmlfunction          #1#2{\clf_xmlfunction         {#1}{#2}} -\def\xmlinclude         #1#2#3{\clf_xmlinclude          {#1}{#2}{#3}} -\def\xmlincludeoptions#1#2#3#4{\clf_xmlincludeoptions   {#1}{#2}{#3}{#4}} -\def\xmlinclusion           #1{\clf_xmlinclusion        {#1}} -\def\xmlinclusions          #1{\clf_xmlinclusions       {#1}} -\def\xmlindex           #1#2#3{\clf_xmlindex            {#1}{#2}\numexpr#3\relax} -\def\xmlinlineverbatim      #1{\clf_xmlinlineverbatim   {#1}} -\def\xmllast              #1#2{\clf_xmllast             {#1}{#2}} +%def\xmlcontext           #1#2{\clf_xmlcontext          {#1}{#2}} +%def\xmlcount             #1#2{\clf_xmlcount            {#1}{#2}} +%def\xmldelete            #1#2{\clf_xmldelete           {#1}{#2}} +%def\xmldirect              #1{\clf_xmldirect           {#1}} % in loops, not dt but root +%def\xmldirectives          #1{\clf_xmldirectives       {#1}} +%def\xmldirectivesafter     #1{\clf_xmldirectivesafter  {#1}} +%def\xmldirectivesbefore    #1{\clf_xmldirectivesbefore {#1}} +%def\xmldisplayverbatim     #1{\clf_xmldisplayverbatim  {#1}} +%def\xmlelement           #1#2{\clf_xmlelement          {#1}{#2}} +%def\xmlfilter            #1#2{\clf_xmlfilter           {#1}{#2}} +%def\xmlfilterlist        #1#2{\clf_xmlfilterlist       {#1}{#2}} +%def\xmlfirst             #1#2{\clf_xmlfirst            {#1}{#2}} +%def\xmlflush               #1{\clf_xmlflush            {#1}} +%def\xmlflushcontext        #1{\clf_xmlflushcontext     {#1}} +%def\xmlflushlinewise       #1{\clf_xmlflushlinewise    {#1}} +%def\xmlflushspacewise      #1{\clf_xmlflushspacewise   {#1}} +%def\xmlfunction          #1#2{\clf_xmlfunction         {#1}{#2}} +%def\xmlinclude         #1#2#3{\clf_xmlinclude          {#1}{#2}{#3}} +%def\xmlincludeoptions#1#2#3#4{\clf_xmlincludeoptions   {#1}{#2}{#3}{#4}} +%def\xmlinclusion           #1{\clf_xmlinclusion        {#1}} +%def\xmlinclusions          #1{\clf_xmlinclusions       {#1}} +%def\xmlindex           #1#2#3{\clf_xmlindex            {#1}{#2}{#3}} +%let\xmlposition               \xmlindex +%def\xmlinlineverbatim      #1{\clf_xmlinlineverbatim   {#1}} +%def\xmllast              #1#2{\clf_xmllast             {#1}{#2}}  \def\xmlload              #1#2{\clf_xmlload             {#1}{#2}{\directxmlparameter\c!entities}{\directxmlparameter\c!compress}}  \def\xmlloadbuffer        #1#2{\clf_xmlloadbuffer       {#1}{#2}{\directxmlparameter\c!entities}{\directxmlparameter\c!compress}}  \def\xmlloaddata          #1#2{\clf_xmlloaddata         {#1}{#2}{\directxmlparameter\c!entities}{\directxmlparameter\c!compress}} -\def\xmlloaddirectives      #1{\clf_xmlloaddirectives   {#1}} +%def\xmlloaddirectives      #1{\clf_xmlloaddirectives   {#1}}  \def\xmlloadregistered    #1#2{\clf_xmlloadregistered   {#1}{\directxmlparameter\c!entities}{\directxmlparameter\c!compress}} -\def\xmlmain                #1{\clf_xmlmain             {#1}} -\def\xmlmatch               #1{\clf_xmlmatch            {#1}} -\def\xmlname                #1{\clf_xmlname             {#1}} -\def\xmlnamespace           #1{\clf_xmlnamespace        {#1}} -\def\xmlnonspace          #1#2{\clf_xmlnonspace         {#1}{#2}} -\def\xmlpos                 #1{\clf_xmlpos              {#1}} -\def\xmlraw               #1#2{\clf_xmlraw              {#1}{#2}} -\def\xmlregisterns        #1#2{\clf_xmlregisterns       {#1}{#2}}         % document -\def\xmlremapname     #1#2#3#4{\clf_xmlremapname        {#1}{#2}{#3}{#4}} % element -\def\xmlremapnamespace  #1#2#3{\clf_xmlremapnamespace   {#1}{#2}{#3}}     % document -\def\xmlsave              #1#2{\clf_xmlsave             {#1}{#2}} -\def\xmlsetfunction     #1#2#3{\clf_xmlsetfunction      {#1}{#2}{#3}} -\def\xmlsetsetup        #1#2#3{\clf_xmlsetsetup         {#1}{#2}{#3}} -\def\xmlsnippet           #1#2{\clf_xmlsnippet          {#1}{#2}} -\def\xmlstrip             #1#2{\clf_xmlstrip            {#1}{#2}} -\def\xmlstripanywhere     #1#2{\clf_xmlstripanywhere    {#1}{#2}} -\def\xmlstripnolines      #1#2{\clf_xmlstripnolines     {#1}{#2}} -\def\xmlstripped          #1#2{\clf_xmlstripped         {#1}{#2}} -\def\xmlstrippednolines   #1#2{\clf_xmlstrippednolines  {#1}{#2}} -\def\xmltag                 #1{\clf_xmltag              {#1}} -\def\xmltext              #1#2{\clf_xmltext             {#1}{#2}} -\def\xmltobuffer        #1#2#3{\clf_xmltobuffer         {#1}{#2}{#3}} % id pattern name -\def\xmltobufferverbose #1#2#3{\clf_xmltobufferverbose  {#1}{#2}{#3}} % id pattern name -\def\xmltofile          #1#2#3{\clf_xmltofile           {#1}{#2}{#3}} % id pattern filename -\def\xmltoparameters        #1{\clf_xmltoparameters     {#1}} -\def\xmlverbatim            #1{\clf_xmlverbatim         {#1}} +%def\xmlmain                #1{\clf_xmlmain             {#1}} +%def\xmlmatch               #1{\clf_xmlmatch            {#1}} +%def\xmlname                #1{\clf_xmlname             {#1}} +%def\xmlnamespace           #1{\clf_xmlnamespace        {#1}} +%def\xmlnonspace          #1#2{\clf_xmlnonspace         {#1}{#2}} +%def\xmlpos                 #1{\clf_xmlpos              {#1}} +%def\xmlraw               #1#2{\clf_xmlraw              {#1}{#2}} +%def\xmlregisterns        #1#2{\clf_xmlregisterns       {#1}{#2}}         % document +%def\xmlremapname     #1#2#3#4{\clf_xmlremapname        {#1}{#2}{#3}{#4}} % element +%def\xmlremapnamespace  #1#2#3{\clf_xmlremapnamespace   {#1}{#2}{#3}}     % document +%def\xmlsave              #1#2{\clf_xmlsave             {#1}{#2}} +%def\xmlsetfunction     #1#2#3{\clf_xmlsetfunction      {#1}{#2}{#3}} +%def\xmlsetsetup        #1#2#3{\clf_xmlsetsetup         {#1}{#2}{#3}} +%def\xmlsnippet           #1#2{\clf_xmlsnippet          {#1}{#2}} +%def\xmlstrip             #1#2{\clf_xmlstrip            {#1}{#2}} +%def\xmlstripanywhere     #1#2{\clf_xmlstripanywhere    {#1}{#2}} +%def\xmlstripnolines      #1#2{\clf_xmlstripnolines     {#1}{#2}} +%def\xmlstripped          #1#2{\clf_xmlstripped         {#1}{#2}} +%def\xmlstrippednolines   #1#2{\clf_xmlstrippednolines  {#1}{#2}} +%def\xmltag                 #1{\clf_xmltag              {#1}} +%def\xmltext              #1#2{\clf_xmltext             {#1}{#2}} +%def\xmltobuffer        #1#2#3{\clf_xmltobuffer         {#1}{#2}{#3}} % id pattern name +%def\xmltobufferverbose #1#2#3{\clf_xmltobufferverbose  {#1}{#2}{#3}} % id pattern name +%def\xmltofile          #1#2#3{\clf_xmltofile           {#1}{#2}{#3}} % id pattern filename +%def\xmltoparameters        #1{\clf_xmltoparameters     {#1}} +%def\xmlverbatim            #1{\clf_xmlverbatim         {#1}} + +% experiment: +\let\xmlall                    \clf_xmlall +\let\xmlatt                    \clf_xmlatt +\let\xmlattdef                 \clf_xmlattdef +\let\xmlattribute              \clf_xmlattribute +\let\xmlattributedef           \clf_xmlattributedef +\let\xmlchainatt               \clf_xmlchainatt +\let\xmlchainattdef            \clf_xmlchainattdef +\let\xmlchecknamespace         \clf_xmlchecknamespace +\let\xmlcommand                \clf_xmlcommand +%   \xmlconcat +%   \xmlconcatrange +\let\xmlcontext                \clf_xmlcontext +\let\xmlcount                  \clf_xmlcount +\let\xmldelete                 \clf_xmldelete +\let\xmldirect                 \clf_xmldirect             % in loops, not dt but root +\let\xmldirectives             \clf_xmldirectives +\let\xmldirectivesafter        \clf_xmldirectivesafter +\let\xmldirectivesbefore       \clf_xmldirectivesbefore +\let\xmldisplayverbatim        \clf_xmldisplayverbatim +\let\xmlelement                \clf_xmlelement +\let\xmlfilter                 \clf_xmlfilter +\let\xmlfilterlist             \clf_xmlfilterlist +\let\xmlfirst                  \clf_xmlfirst +\let\xmlflush                  \clf_xmlflush +\let\xmlflushcontext           \clf_xmlflushcontext +\let\xmlflushlinewise          \clf_xmlflushlinewise +\let\xmlflushspacewise         \clf_xmlflushspacewise +\let\xmlfunction               \clf_xmlfunction +\let\xmlinclude                \clf_xmlinclude +\let\xmlincludeoptions         \clf_xmlincludeoptions +\let\xmlinclusion              \clf_xmlinclusion +\let\xmlinclusions             \clf_xmlinclusions +\let\xmlindex                  \clf_xmlindex +\let\xmlposition               \clf_xmlindex +\let\xmlinlineverbatim         \clf_xmlinlineverbatim +\let\xmllast                   \clf_xmllast +%   \xmlload +%   \xmlloadbuffer +%   \xmlloaddata +\let\xmlloaddirectives         \clf_xmlloaddirectives +%   \xmlloadregistered +\let\xmlmain                   \clf_xmlmain +\let\xmlmatch                  \clf_xmlmatch +\let\xmlname                   \clf_xmlname +\let\xmlnamespace              \clf_xmlnamespace +\let\xmlnonspace               \clf_xmlnonspace +\let\xmlpos                    \clf_xmlpos +\let\xmlraw                    \clf_xmlraw +\let\xmlregisterns             \clf_xmlregisterns         % document +\let\xmlremapname              \clf_xmlremapname          % element +\let\xmlremapnamespace         \clf_xmlremapnamespace     % document +\let\xmlsave                   \clf_xmlsave +\let\xmlsetfunction            \clf_xmlsetfunction +\let\xmlsetsetup               \clf_xmlsetsetup +\let\xmlsnippet                \clf_xmlsnippet +\let\xmlstrip                  \clf_xmlstrip +\let\xmlstripanywhere          \clf_xmlstripanywhere +\let\xmlstripnolines           \clf_xmlstripnolines +\let\xmlstripped               \clf_xmlstripped +\let\xmlstrippednolines        \clf_xmlstrippednolines +\let\xmltag                    \clf_xmltag +\let\xmltext                   \clf_xmltext +\let\xmltobuffer               \clf_xmltobuffer           % id pattern name +\let\xmltobufferverbose        \clf_xmltobufferverbose    % id pattern name +\let\xmltofile                 \clf_xmltofile             % id pattern filename +\let\xmltoparameters           \clf_xmltoparameters +\let\xmlverbatim               \clf_xmlverbatim  \def\xmlinfo                #1{\hbox{\ttxx[\clf_xmlinfo{#1}]}}  \def\xmlshow                #1{\startpacked\ttx\xmlverbatim{#1}\stoppacked} @@ -117,24 +185,41 @@  % kind of special: -\def\xmlstartraw{\clf_xmlstartraw}  % \let -\def\xmlstopraw {\clf_xmlstopraw}   % \let - -% todo: \xmldoifelseattribute - -\def\xmldoif              #1#2{\clf_xmldoif             {#1}{#2}} % expandable -\def\xmldoifnot           #1#2{\clf_xmldoifnot          {#1}{#2}} % expandable -\def\xmldoifelse          #1#2{\clf_xmldoifelse         {#1}{#2}} % expandable -\def\xmldoiftext          #1#2{\clf_xmldoiftext         {#1}{#2}} % expandable -\def\xmldoifnottext       #1#2{\clf_xmldoifnottext      {#1}{#2}} % expandable -\def\xmldoifelsetext      #1#2{\clf_xmldoifelsetext     {#1}{#2}} % expandable - -\def\xmldoifempty         #1#2{\clf_xmldoifempty        {#1}{#2}} -\def\xmldoifnotempty      #1#2{\clf_xmldoifnotempty     {#1}{#2}} -\def\xmldoifelseempty     #1#2{\clf_xmldoifelseempty    {#1}{#2}} -\def\xmldoifselfempty       #1{\clf_xmldoifselfempty    {#1}} -\def\xmldoifnotselfempty    #1{\clf_xmldoifnotselfempty {#1}} -\def\xmldoifelseselfempty   #1{\clf_xmldoifelseselfempty{#1}} +%def\xmlstartraw{\clf_xmlstartraw} +%def\xmlstopraw {\clf_xmlstopraw} + +\let\xmlstartraw\clf_xmlstartraw +\let\xmlstopraw \clf_xmlstopraw + +% these are expandable! todo: \xmldoifelseattribute + +%def\xmldoif              #1#2{\clf_xmldoif             {#1}{#2}} +%def\xmldoifnot           #1#2{\clf_xmldoifnot          {#1}{#2}} +%def\xmldoifelse          #1#2{\clf_xmldoifelse         {#1}{#2}} +%def\xmldoiftext          #1#2{\clf_xmldoiftext         {#1}{#2}} +%def\xmldoifnottext       #1#2{\clf_xmldoifnottext      {#1}{#2}} +%def\xmldoifelsetext      #1#2{\clf_xmldoifelsetext     {#1}{#2}} + +%def\xmldoifempty         #1#2{\clf_xmldoifempty        {#1}{#2}} +%def\xmldoifnotempty      #1#2{\clf_xmldoifnotempty     {#1}{#2}} +%def\xmldoifelseempty     #1#2{\clf_xmldoifelseempty    {#1}{#2}} +%def\xmldoifselfempty       #1{\clf_xmldoifselfempty    {#1}} +%def\xmldoifnotselfempty    #1{\clf_xmldoifnotselfempty {#1}} +%def\xmldoifelseselfempty   #1{\clf_xmldoifelseselfempty{#1}} + +\let\xmldoif              \clf_xmldoif +\let\xmldoifnot           \clf_xmldoifnot +\let\xmldoifelse          \clf_xmldoifelse +\let\xmldoiftext          \clf_xmldoiftext +\let\xmldoifnottext       \clf_xmldoifnottext +\let\xmldoifelsetext      \clf_xmldoifelsetext + +\let\xmldoifempty         \clf_xmldoifempty +\let\xmldoifnotempty      \clf_xmldoifnotempty +\let\xmldoifelseempty     \clf_xmldoifelseempty +\let\xmldoifselfempty     \clf_xmldoifselfempty +\let\xmldoifnotselfempty  \clf_xmldoifnotselfempty +\let\xmldoifelseselfempty \clf_xmldoifelseselfempty  % \startxmlsetups xml:include  %     \xmlinclude{main}{include}{filename|href} @@ -349,8 +434,8 @@  \setnewconstant\xmlautoentities\plusone % 0=off, 1=upper, 2=upper,lower -\def\xmlsetentity#1#2{\clf_xmlsetentity{#1}{\detokenize{#2}}} -\def\xmltexentity#1#2{\clf_xmltexentity{#1}{\detokenize{#2}}} +\unexpanded\def\xmlsetentity#1#2{\clf_xmlsetentity{#1}{\detokenize{#2}}} +\unexpanded\def\xmltexentity#1#2{\clf_xmltexentity{#1}{\detokenize{#2}}}  % \xmlsetentity{tex}{\TEX{}} % {} needed diff --git a/tex/context/base/lxml-tex.lua b/tex/context/base/lxml-tex.lua index 3e2ce82c5..383c06aa0 100644 --- a/tex/context/base/lxml-tex.lua +++ b/tex/context/base/lxml-tex.lua @@ -1490,7 +1490,7 @@ end  lxml.content = text  function lxml.position(id,pattern,n) -    position(xmlapplylpath(getid(id),pattern),n) +    position(xmlapplylpath(getid(id),pattern),tonumber(n))  end  function lxml.chainattribute(id,pattern,a,default) @@ -1506,7 +1506,7 @@ function lxml.concat(id,pattern,separator,lastseparator,textonly)  end  function lxml.element(id,n) -    position(xmlapplylpath(getid(id),"/*"),n) +    position(xmlapplylpath(getid(id),"/*"),tonumber(n)) -- tonumber handy  end  lxml.index = lxml.position diff --git a/tex/context/base/math-frc.lua b/tex/context/base/math-frc.lua index 1485c2159..639edc94b 100644 --- a/tex/context/base/math-frc.lua +++ b/tex/context/base/math-frc.lua @@ -53,5 +53,5 @@ end  interfaces.implement {      name      = "mathfraction",      actions   = mathfraction, -    arguments = { "string", "integer", "dimen", "dimen" } +    arguments = { "string", "number", "number", "dimen" }  } diff --git a/tex/context/base/math-frc.mkiv b/tex/context/base/math-frc.mkiv index 90778810e..6b7b91d7b 100644 --- a/tex/context/base/math-frc.mkiv +++ b/tex/context/base/math-frc.mkiv @@ -223,8 +223,8 @@  \def\math_frac_command    {\clf_mathfraction       {\mathfractionparameter\c!rule}% -     \numexpr\mathfractionparameter\c!left\relax -     \numexpr\mathfractionparameter\c!right\relax +     \mathfractionparameter\c!left\space +     \mathfractionparameter\c!right\space       \dimexpr\mathfractionparameter\c!rulethickness\relax     \relax} diff --git a/tex/context/base/math-ini.mkiv b/tex/context/base/math-ini.mkiv index 2002834b1..1c6179523 100644 --- a/tex/context/base/math-ini.mkiv +++ b/tex/context/base/math-ini.mkiv @@ -331,21 +331,21 @@  \unexpanded\def\boldsymbol    {\mathortext\mathboldsymbol\bold} -%D Helpers (assume {} being used): +%D Helpers -\let\utfmathclass        \clf_utfmathclass -\let\utfmathstretch      \clf_utfmathstretch -\let\utfmathcommand      \clf_utfmathcommand -\let\utfmathfiller       \clf_utfmathfiller +\def\utfmathclass  #1{\clf_utfmathclass  {#1}} +\def\utfmathstretch#1{\clf_utfmathstretch{#1}} +\def\utfmathcommand#1{\clf_utfmathcommand{#1}} +\def\utfmathfiller #1{\clf_utfmathfiller {#1}} -\let\utfmathcommandabove \clf_utfmathcommandabove -\let\utfmathcommandbelow \clf_utfmathcommandbelow -\let\utfmathcommandfiller\clf_utfmathcommandfiller +\def\utfmathcommandabove #1{\clf_utfmathcommandabove {#1}} +\def\utfmathcommandbelow #1{\clf_utfmathcommandbelow {#1}} +\def\utfmathcommandfiller#1{\clf_utfmathcommandfiller{#1}} -\unexpanded\def\doifelseutfmathaccent{\clf_doifelseutfmathaccent} -\unexpanded\def\doifelseutfmathabove {\clf_doifelseutfmathabove } -\unexpanded\def\doifelseutfmathbelow {\clf_doifelseutfmathbelow } -\unexpanded\def\doifelseutfmathfiller{\clf_doifelseutfmathfiller} +\unexpanded\def\doifelseutfmathaccent#1{\clf_doifelseutfmathaccent{#1}} +\unexpanded\def\doifelseutfmathabove #1{\clf_doifelseutfmathabove {#1}} +\unexpanded\def\doifelseutfmathbelow #1{\clf_doifelseutfmathbelow {#1}} +\unexpanded\def\doifelseutfmathfiller#1{\clf_doifelseutfmathfiller{#1}}  %D Not used that much: diff --git a/tex/context/base/meta-ini.mkiv b/tex/context/base/meta-ini.mkiv index 3d70feb34..2c4023de8 100644 --- a/tex/context/base/meta-ini.mkiv +++ b/tex/context/base/meta-ini.mkiv @@ -297,28 +297,6 @@     \edef\currentMPformat{\MPinstanceparameter\s!format}%     \meta_process_graphic} -% \unexpanded\def\meta_process_graphic#1% todo: extensions and inclusions outside beginfig -%   {\meta_start_current_graphic -%    \forgetall -%    \edef\p_extensions{\MPinstanceparameter\s!extensions}% -%    \meta_process_graphic_start -%      \normalexpanded{\noexpand\ctxlua{metapost.graphic { -%        instance        = "\currentMPinstance", -%        format          = "\currentMPformat", -%        data            = \!!bs#1;\!!es, -%        initializations = \!!bs\meta_flush_current_initializations\!!es, -%      % useextensions   = "\MPinstanceparameter\s!extensions", -% \ifx\p_extensions\v!yes -%        extensions      = \!!bs\clf_getmpextensions{\currentMPinstance}\!!es, -% \fi -%        inclusions      = \!!bs\meta_flush_current_inclusions\!!es, -%        definitions     = \!!bs\meta_flush_current_definitions\!!es, -%        figure          = "\MPaskedfigure", -%        method          = "\MPinstanceparameter\c!method", -%      }}}% -%    \meta_process_graphic_stop -%    \meta_stop_current_graphic} -  \unexpanded\def\meta_process_graphic#1% todo: extensions and inclusions outside beginfig    {\meta_start_current_graphic     \forgetall @@ -330,7 +308,7 @@           data            {#1;}%           initializations {\meta_flush_current_initializations}%      \ifx\p_extensions\v!yes -         extensions      {\clf_getmpextensions{\currentMPinstance}}% +         extensions      {\clf_getmpextensions{\currentMPinstance}}% goes through tex again      \fi           inclusions      {\meta_flush_current_inclusions}%           definitions     {\meta_flush_current_definitions}% @@ -460,19 +438,6 @@     \fi     \endgroup} -% \def\meta_grab_clip_path_indeed -%   {\meta_start_current_graphic -%      \xdef\MPclippath{\normalexpanded{\noexpand\ctxlua{metapost.theclippath { -%           instance        = "\currentMPinstance", -%           format          = "\currentMPformat", -%           data            = \!!bs\csname\??mpclip\currentMPclip\endcsname\!!es, -%           initializations = \!!bs\meta_flush_current_initializations\!!es, -%           useextensions   = "\MPinstanceparameter\s!extensions", -%           inclusions      = \!!bs\meta_flush_current_inclusions\!!es, -%           method          = "\MPinstanceparameter\c!method", -%      }}}}% -%    \meta_stop_current_graphic} -  \def\meta_grab_clip_path_indeed    {\meta_start_current_graphic       \normalexpanded{\noexpand\clf_mpsetclippath diff --git a/tex/context/base/mlib-ctx.lua b/tex/context/base/mlib-ctx.lua index 43c4b4c42..f259113f4 100644 --- a/tex/context/base/mlib-ctx.lua +++ b/tex/context/base/mlib-ctx.lua @@ -23,14 +23,9 @@ local mplib              = mplib  metapost                 = metapost or {}  local metapost           = metapost -local scanners           = tokens.scanners -local scanstring         = scanners.string -local scaninteger        = scanners.integer  local setters            = tokens.setters  local setmacro           = setters.macro - -local compilescanner     = tokens.compile -local scanners           = interfaces.scanners +local implement          = interfaces.implement  local v_no               = interfaces.variables.no @@ -94,12 +89,14 @@ end  --     context(metapost.getextensions(instance,state))  -- end -scanners.setmpextensions = compilescanner { +implement { +    name      = "setmpextensions",      actions   = metapost.setextensions,      arguments = { "string", "string" }  } -scanners.getmpextensions = compilescanner { +implement { +    name      = "getmpextensions",      actions   = { metapost.getextensions, context } ,      arguments = "string"  } @@ -107,7 +104,13 @@ scanners.getmpextensions = compilescanner {  local report_metapost = logs.reporter ("metapost")  local status_metapost = logs.messenger("metapost") -local patterns = { "meta-imp-%s.mkiv", "meta-imp-%s.tex", "meta-%s.mkiv", "meta-%s.tex" } -- we are compatible +local patterns = { +    "meta-imp-%s.mkiv", +    "meta-imp-%s.tex", +    -- obsolete: +    "meta-%s.mkiv", +    "meta-%s.tex" +}  local function action(name,foundname)      status_metapost("library %a is loaded",name) @@ -120,59 +123,74 @@ local function failure(name)      report_metapost("library %a is unknown or invalid",name)  end -scanners.useMPlibrary = function() -- name -    commands.uselibrary { -        name     = scanstring(), -        patterns = patterns, -        action   = action, -        failure  = failure, -        onlyonce = true, -    } -end +implement { +    name      = "useMPlibrary", +    arguments = "string", +    actions   = function(name) +        resolvers.uselibrary { +            name     = name, +            patterns = patterns, +            action   = action, +            failure  = failure, +            onlyonce = true, +        } +    end +}  -- metapost.variables  = { } -- to be stacked -scanners.mprunvar = function() -- name -    local value = metapost.variables[scanstring()] -    if value ~= nil then -        local tvalue = type(value) -        if tvalue == "table" then -            context(concat(value," ")) -        elseif tvalue == "number" or tvalue == "boolean" then -            context(tostring(value)) -        elseif tvalue == "string" then -            context(value) +implement { +    name      = "mprunvar", +    arguments = "string", +    actions   = function(name) +        local value = metapost.variables[name] +        if value ~= nil then +            local tvalue = type(value) +            if tvalue == "table" then +                context(concat(value," ")) +            elseif tvalue == "number" or tvalue == "boolean" then +                context(tostring(value)) +            elseif tvalue == "string" then +                context(value) +            end          end      end -end +} -scanners.mpruntab = function() -- name n -    local value = metapost.variables[scanstring()] -    if value ~= nil then -        local tvalue = type(value) -        if tvalue == "table" then -            context(value[scaninteger()]) -        elseif tvalue == "number" or tvalue == "boolean" then -            context(tostring(value)) -        elseif tvalue == "string" then -            context(value) +implement { +    name      = "mpruntab", +    arguments = { "string", "integer" }, +    actions   = function(name,n) +        local value = metapost.variables[name] +        if value ~= nil then +            local tvalue = type(value) +            if tvalue == "table" then +                context(value[n]) +            elseif tvalue == "number" or tvalue == "boolean" then +                context(tostring(value)) +            elseif tvalue == "string" then +                context(value) +            end          end      end -end +} -scanners.mprunset = function() -- name connector -    local value = metapost.variables[scanstring()] -    if value ~= nil then -        local tvalue = type(value) -        if tvalue == "table" then -            context(concat(value,scanstring())) -        elseif tvalue == "number" or tvalue == "boolean" then -            context(tostring(value)) -        elseif tvalue == "string" then -            context(value) +implement { +    name      = "mprunset", +    actions   = function(name,connector) +        local value = metapost.variables[name] +        if value ~= nil then +            local tvalue = type(value) +            if tvalue == "table" then +                context(concat(value,connector)) +            elseif tvalue == "number" or tvalue == "boolean" then +                context(tostring(value)) +            elseif tvalue == "string" then +                context(value) +            end          end      end -end +}  -- we need to move more from pps to here as pps is the plugin .. the order is a mess  -- or just move the scanners to pps @@ -181,64 +199,40 @@ function metapost.graphic(specification)      metapost.graphic_base_pass(setmpsformat(specification))  end --- scanners.mpgraphic = compilescanner { ---     actions = { setmpsformat, metapost.graphic_base_pass }, -- not yet implemented ---     arguments = { ---         { ---             { "instance" }, ---             { "format" }, ---             { "data" }, ---             { "initializations" }, ---             { "extensions" }, ---             { "inclusions" }, ---             { "definitions" }, ---             { "figure" }, ---             { "method" }, ---         }, ---     } --- } - -local get_mpgraphic_spec = compilescanner { -    { -        { "instance" }, -        { "format" }, -        { "data" }, -        { "initializations" }, -        { "extensions" }, -        { "inclusions" }, -        { "definitions" }, -        { "figure" }, -        { "method" }, +implement { +    name      = "mpgraphic", +    actions   = function(specification) metapost.graphic_base_pass(setmpsformat(specification)) end, -- not yet implemented +    arguments = { +        { +            { "instance" }, +            { "format" }, +            { "data" }, +            { "initializations" }, +            { "extensions" }, +            { "inclusions" }, +            { "definitions" }, +            { "figure" }, +            { "method" }, +        }      }  } -scanners.mpgraphic = function() -    metapost.graphic_base_pass(setmpsformat(get_mpgraphic_spec())) -end - --- scanners.mpsetoutercolor = compilescanner { ---     action    = metapost.setoutercolor, -- not yet implemented ---     arguments = { "integer", "integer", "integer", "integer" } --- } - -scanners.mpsetoutercolor = function() -    metapost.setoutercolor(scaninteger(),scaninteger(),scaninteger(),scaninteger()) -end - --- scanners.mpflushreset = metapost.flushreset -- will become obsolete and internal - -scanners.mpflushreset = function() -    metapost.flushreset() -end +implement { +    name      = "mpsetoutercolor", +    actions   = function(...) metapost.setoutercolor(...) end, -- not yet implemented +    arguments = { "integer", "integer", "integer", "integer" } +} --- scanners.mpflushliteral = compilescanner { ---     action    = metapost.flushliteral, -- not yet implemented ---     arguments = "string", --- } +implement { +    name      = "mpflushreset", +    actions   = function() metapost.flushreset() end -- not yet implemented +} -scanners.mpflushliteral = function() -    metapost.flushliteral(scanstring()) -end +implement { +    name      = "mpflushliteral", +    actions   = function(str) metapost.flushliteral(str) end, -- not yet implemented +    arguments = "string", +}  function metapost.getclippath(specification) -- why not a special instance for this      setmpsformat(specification) @@ -295,22 +289,24 @@ function metapost.theclippath(...)      end  end -local get_mpsetclippath_spec = compilescanner { -    { -        { "instance" }, -        { "format" }, -        { "data" }, -        { "initializations" }, -        { "useextensions" }, -        { "inclusions" }, -        { "method" }, -    }, +implement { +    name      = "mpsetclippath", +    actions   = function(specification) +        setmacro("MPclippath",metapost.theclippath(specification),"global") +    end, +    arguments = { +        { +            { "instance" }, +            { "format" }, +            { "data" }, +            { "initializations" }, +            { "useextensions" }, +            { "inclusions" }, +            { "method" }, +        }, +    }  } -scanners.mpsetclippath = function() -    setmacro("MPclippath",metapost.theclippath(get_mpsetclippath_spec()),"global") -end -  statistics.register("metapost processing time", function()      local n =  metapost.n      if n and n > 0 then @@ -344,6 +340,10 @@ function mptex.set(str)      environments[#environments+1] = str  end +function mptex.setfrombuffer(name) +    environments[#environments+1] = buffers.content(name) +end +  function mptex.get()      return concat(environments,"\n")  end @@ -352,18 +352,24 @@ function mptex.reset()      environments = { }  end -scanners.mptexset = function() -    environments[#environments+1] = scanstring() -end +implement { +    name      = "mptexset", +    arguments = "string", +    actions   = mptex.set +} -scanners.mptexget = function() -    context(concat(environments,"\n")) -end +implement { +    name      = "mptexsetfrombuffer", +    arguments = "string", +    actions   = mptex.setfrombuffer +} -scanners.mptexsetfrombuffer = function() -    environments[#environments+1] = buffers.content(scanstring()) -end +implement { +    name      = "mptexget", +    actions   = { mptex.get, context } +} -scanners.mptexreset = function() -    environments = { } -end +implement { +    name      = "mptexreset", +    actions   = mptex.reset +} diff --git a/tex/context/base/mult-aux.mkiv b/tex/context/base/mult-aux.mkiv index 2cc1c6399..bc178fdb6 100644 --- a/tex/context/base/mult-aux.mkiv +++ b/tex/context/base/mult-aux.mkiv @@ -783,11 +783,11 @@     \else       \global\advance\c_mult_interfaces_n_of_namespaces\plusone       \expandafter\edef\csname ??#1\endcsname{\v_interfaces_prefix_template}% -     \ctxcommand{registernamespace(\number\c_mult_interfaces_n_of_namespaces,"#1")}% +     \clf_registernamespace\c_mult_interfaces_n_of_namespaces{#1}%     \fi}  \def\mult_interfaces_get_parameters_error_indeed#1#2% -  {\ctxcommand{showassignerror("#1","#2",\the\inputlineno)}} % no longer \waitonfatalerror +  {\clf_showassignerror{#1}{#2}\inputlineno} % no longer \waitonfatalerror  % We install two core namespaces here, as we want nice error messages. Maybe  % we will reserve the first 9. diff --git a/tex/context/base/mult-ini.lua b/tex/context/base/mult-ini.lua index c64ac8c05..17b92de28 100644 --- a/tex/context/base/mult-ini.lua +++ b/tex/context/base/mult-ini.lua @@ -287,7 +287,7 @@ function interfaces.writestatus(category,message)      reporters[category](message) -- could also be a setmetatablecall  end -implement { name = "registernamespace",    actions = interfaces.registernamespace, arguments = { "string", "string" } } +implement { name = "registernamespace",    actions = interfaces.registernamespace, arguments = { "integer", "string" } }  implement { name = "setinterfaceconstant", actions = interfaces.setconstant,       arguments = { "string", "string" } }  implement { name = "setinterfacevariable", actions = interfaces.setvariable,       arguments = { "string", "string" } }  implement { name = "setinterfaceelement",  actions = interfaces.setelement,        arguments = { "string", "string" } } @@ -319,6 +319,7 @@ local function showassignerror(namespace,key,line)      if ns then          namespace = corenamespaces[tonumber(ns)] or ns      end +    -- injected in the stream for timing:      if instance and instance ~= "" then          context.writestatus("setup",formatters["error in line %a, namespace %a, instance %a, key %a"](line,namespace,instance,key))      else diff --git a/tex/context/base/node-ref.lua b/tex/context/base/node-ref.lua index 9527cc2e8..d14f4a6da 100644 --- a/tex/context/base/node-ref.lua +++ b/tex/context/base/node-ref.lua @@ -90,6 +90,8 @@ local free_node           = nuts.free  local tosequence          = nodes.tosequence +local implement           = interfaces.implement +  -- Normally a (destination) area is a box or a simple stretch if nodes but when it is  -- a paragraph we hav ea problem: we cannot calculate the height well. This happens  -- with footnotes or content broken across a page. @@ -667,17 +669,17 @@ function references.mark(reference,h,d,view)      return setdestination(tex.currentgrouplevel,h,d,reference,view)  end -function references.inject(prefix,reference,h,d,highlight,newwindow,layer) -- todo: use currentreference is possible +function references.inject(prefix,reference,specification) -- todo: use currentreference is possible  -- print(prefix,reference,h,d,highlight,newwindow,layer)      local set, bug = references.identify(prefix,reference)      if bug or #set == 0 then          -- unknown ref, just don't set it and issue an error      else          -- check -        set.highlight = highlight -        set.newwindow = newwindow -        set.layer     = layer -        setreference(h,d,set) -- sets attribute / todo: for set[*].error +        set.highlight = specification.highlight +        set.newwindow = specification.newwindow +        set.layer     = specification.layer +        setreference(specification.height,specification.depth,set) -- sets attribute / todo: for set[*].error      end  end @@ -688,8 +690,32 @@ function references.injectcurrentset(h,d) -- used inside doifelse      end  end -commands.injectreference        = references.inject -commands.injectcurrentreference = references.injectcurrentset +implement { +    name      = "injectreference", +    actions   = references.inject, +    arguments = { +        "string", +        "string", +        { +            { "highlight", "boolean" }, +            { "newwindow", "boolean" }, +            { "layer" }, +            { "height", "dimen" }, +            { "depth", "dimen" }, +        } +    } +} + +implement { +    name      = "injectcurrentreference", +    actions   = references.injectcurrentset, +} + +implement { +    name      = "injectcurrentreference_dimensions", +    actions   = references.injectcurrentset, +    arguments = { "dimen", "dimen" }, +}  -- diff --git a/tex/context/base/pack-com.mkiv b/tex/context/base/pack-com.mkiv index 4f4bc9f47..735f04714 100644 --- a/tex/context/base/pack-com.mkiv +++ b/tex/context/base/pack-com.mkiv @@ -178,7 +178,7 @@  \unexpanded\def\pack_common_caption_stop {\removeunwantedspaces\egroup}  \unexpanded\def\stopcombination -  {\bgroup\normalexpanded{\egroup{}\ctxcommand{ntimes("{}{}",\number\c_pack_combinations_n)}}% brr +  {\bgroup\normalexpanded{\egroup{}\ntimes{{}{}}\c_pack_combinations_n}% brr     \dostoptagged     \egroup     \egroup} diff --git a/tex/context/base/page-lin.mkvi b/tex/context/base/page-lin.mkvi index c55a1228b..7fbde3df8 100644 --- a/tex/context/base/page-lin.mkvi +++ b/tex/context/base/page-lin.mkvi @@ -535,7 +535,7 @@  % eventually we will do this in lua -\def\currentreferencelinenumber{\ctxcommand{filterreference("linenumber")}} +\def\currentreferencelinenumber{\clf_filterreference{linenumber}}  \let\m_page_lines_from\empty  \let\m_page_lines_to  \empty diff --git a/tex/context/base/page-mix.lua b/tex/context/base/page-mix.lua index e5e5cdb5e..474d010bf 100644 --- a/tex/context/base/page-mix.lua +++ b/tex/context/base/page-mix.lua @@ -13,6 +13,7 @@ if not modules then modules = { } end modules ["page-mix"] = {  -- local trackers, logs, storage = trackers, logs, storage  -- local number, table = number, table +local next, type = next, type  local concat = table.concat  local ceil, floor = math.ceil, math.floor @@ -84,6 +85,9 @@ local v_more              = variables.more  local v_less              = variables.less  local v_halfline          = variables.halfline +local context             = context +local implement           = interfaces.implement +  pagebuilders              = pagebuilders or { }  pagebuilders.mixedcolumns = pagebuilders.mixedcolumns or { }  local mixedcolumns        = pagebuilders.mixedcolumns @@ -224,7 +228,7 @@ local function stripbottomglue(results,discarded)      return height  end -local function setsplit(specification) -- a rather large function +local function preparesplit(specification) -- a rather large function      local box = specification.box      if not box then          report_state("fatal error, no box") @@ -718,7 +722,7 @@ local kept = head      return specification  end -function mixedcolumns.finalize(result) +local function finalize(result)      if result then          local results  = result.results          local columns  = result.nofcolumns @@ -775,12 +779,12 @@ local function report_deltas(result,str)      report_state("%s, cycles %s, deltas % | t",str,result.cycle or 1,t)  end -function mixedcolumns.setsplit(specification) +local function setsplit(specification)      splitruns = splitruns + 1      if trace_state then          report_state("split run %s",splitruns)      end -    local result = setsplit(specification) +    local result = preparesplit(specification)      if result then          if result.overflow then              if trace_state then @@ -793,7 +797,7 @@ function mixedcolumns.setsplit(specification)              local cycles = specification.cycles or 100              while result.rest and cycle <= cycles do                  specification.extra = cycle * step -                result = setsplit(specification) or result +                result = preparesplit(specification) or result                  if trace_state then                      report_state("cycle: %s.%s, original height %p, total height %p",                          splitruns,cycle,result.originalheight,result.nofcolumns*result.targetheight) @@ -815,7 +819,7 @@ function mixedcolumns.setsplit(specification)      end  end -function mixedcolumns.getsplit(result,n) +local function getsplit(result,n)      if not result then          report_state("flush, column %s, no result",n)          return @@ -927,19 +931,19 @@ function mixedcolumns.getsplit(result,n)      return v  end -function mixedcolumns.getrest(result) +local function getrest(result)      local rest = result and result.rest      result.rest = nil -- to be sure      return rest  end -function mixedcolumns.getlist(result) +local function getlist(result)      local originalhead = result and result.originalhead      result.originalhead = nil -- to be sure      return originalhead  end -function mixedcolumns.cleanup(result) +local function cleanup(result)      local discarded = result.discarded      for i=1,#discarded do          freenode(discarded[i]) @@ -947,52 +951,100 @@ function mixedcolumns.cleanup(result)      result.discarded = { }  end +mixedcolumns.setsplit = setsplit +mixedcolumns.getsplit = getsplit +mixedcolumns.finalize = finalize +mixedcolumns.getrest  = getrest +mixedcolumns.getlist  = getlist +mixedcolumns.cleanup  = cleanup +  -- interface --  local result -function commands.mixsetsplit(specification) -    if result then -        for k, v in next, specification do -            result[k] = v +implement { +    name      = "mixsetsplit", +    actions   = function(specification) +        if result then +            for k, v in next, specification do +                result[k] = v +            end +            result = setsplit(result) +        else +            result = setsplit(specification)          end -        result = mixedcolumns.setsplit(result) -    else -        result = mixedcolumns.setsplit(specification) -    end -end +    end, +    arguments = { +        { +           { "box", "integer" }, +           { "nofcolumns", "integer" }, +           { "maxheight", "dimen" }, +           { "step", "dimen" }, +           { "cycles", "integer" }, +           { "preheight", "dimen" }, +           { "prebox", "integer" }, +           { "strutht", "dimen" }, +           { "strutdp", "dimen" }, +           { "threshold", "dimen" }, +           { "splitmethod" }, +           { "balance" }, +           { "alternative" }, +           { "internalgrid" }, +           { "grid", "boolean" }, +        } +    } +} -function commands.mixgetsplit(n) -    if result then -        context(tonode(mixedcolumns.getsplit(result,n))) -    end -end +implement { +    name      = "mixgetsplit", +    arguments = "integer", +    actions   = function(n) +        if result then +            context(tonode(getsplit(result,n))) +        end +    end, +} -function commands.mixfinalize() -    if result then -        mixedcolumns.finalize(result) +implement { +    name    = "mixfinalize", +    actions = function() +        if result then +            finalize(result) +        end      end -end +} -function commands.mixflushrest() -    if result then -        context(tonode(mixedcolumns.getrest(result))) +implement { +    name    = "mixflushrest", +    actions = function() +        if result then +            context(tonode(getrest(result))) +        end      end -end +} -function commands.mixflushlist() -    if result then -        context(tonode(mixedcolumns.getlist(result))) +implement { +    name = "mixflushlist", +    actions = function() +        if result then +            context(tonode(getlist(result))) +        end      end -end +} -function commands.mixstate() -    context(result and result.rest and 1 or 0) -end +implement { +    name    = "mixstate", +    actions = function() +        context(result and result.rest and 1 or 0) +    end +} -function commands.mixcleanup() -    if result then -        mixedcolumns.cleanup(result) -        result = nil +implement { +    name = "mixcleanup", +    actions = function() +        if result then +            cleanup(result) +            result = nil +        end      end -end +} diff --git a/tex/context/base/page-mix.mkiv b/tex/context/base/page-mix.mkiv index 4a86dfcf4..f69f6ac0e 100644 --- a/tex/context/base/page-mix.mkiv +++ b/tex/context/base/page-mix.mkiv @@ -544,23 +544,23 @@  \unexpanded\def\page_mix_routine_construct#1%    {\d_page_mix_max_height\mixedcolumnsparameter\c!maxheight % can have changed due to header=high -   \ctxcommand{mixsetsplit { -       box          = \number\b_page_mix_collected, -       nofcolumns   = \number\c_page_mix_n_of_columns, -       maxheight    = \number\d_page_mix_max_height, -       step         = \number\d_page_mix_balance_step, -       cycles       = \number\c_page_mix_balance_cycles, -       preheight    = \number\d_page_mix_preceding_height, -       prebox       = \number\b_page_mix_preceding, -       strutht      = \number\strutht, -       strutdp      = \number\strutdp, -       threshold    = \number\d_page_mix_threshold, -       splitmethod  = "\mixedcolumnsparameter\c!splitmethod", -       balance      = "#1", -       alternative  = "\mixedcolumnsparameter\c!alternative", -       grid         = \ifgridsnapping true\else false\fi, -       internalgrid = "\mixedcolumnsparameter\c!internalgrid", -   }}% +   \clf_mixsetsplit +       box          \b_page_mix_collected +       nofcolumns   \c_page_mix_n_of_columns +       maxheight    \d_page_mix_max_height +       step         \d_page_mix_balance_step +       cycles       \c_page_mix_balance_cycles +       preheight    \d_page_mix_preceding_height +       prebox       \b_page_mix_preceding +       strutht      \strutht +       strutdp      \strutdp +       threshold    \d_page_mix_threshold +       splitmethod  {\mixedcolumnsparameter\c!splitmethod}% +       balance      {#1}% +       alternative  {\mixedcolumnsparameter\c!alternative}% +       internalgrid {\mixedcolumnsparameter\c!internalgrid}% +       grid         \ifgridsnapping true\else false\fi +   \relax     \deadcycles\zerocount}  \newdimen\mixedcolumnseparatorheight @@ -589,7 +589,7 @@     \fi}  \unexpanded\def\page_mix_routine_package -  {\ctxcommand{mixfinalize()}% +  {\clf_mixfinalize     \setbox\b_page_mix_collected\vbox \bgroup       \ifvoid\b_page_mix_preceding \else         \page_postprocessors_linenumbers_deepbox\b_page_mix_preceding @@ -608,7 +608,7 @@  \unexpanded\def\page_mix_command_package_column    {\page_mix_hbox to \d_page_mix_column_width \bgroup       % maybe intercept empty -     \ctxcommand{mixgetsplit(\recurselevel)}% +     \clf_mixgetsplit\recurselevel\relax       \hskip-\d_page_mix_column_width       \page_mix_hbox to \d_page_mix_column_width \bgroup         \placenoteinserts @@ -624,8 +624,8 @@     \page_mix_routine_construct\v!no     \page_mix_routine_package     \page_otr_construct_and_shipout\box\b_page_mix_collected -   \ctxcommand{mixflushrest()}% -   \ctxcommand{mixcleanup()}% +   \clf_mixflushrest +   \clf_mixcleanup     \egroup}  \unexpanded\def\page_mix_routine_balance @@ -636,9 +636,9 @@     \doloop       {%writestatus\m!columns{construct continue (\the\htdp\b_page_mix_collected)}%        \page_mix_routine_construct\v!no -      \ifcase\ctxcommand{mixstate()}\relax +      \ifcase\clf_mixstate\relax          % 0 = okay, we can balance -        \setbox\b_page_mix_collected\vbox{\ctxcommand{mixflushlist()}}% we could avoid this +        \setbox\b_page_mix_collected\vbox{\clf_mixflushlist}% we could avoid this          %writestatus\m!columns{construct balance}%          \page_mix_routine_construct\v!yes          \page_mix_routine_package @@ -653,16 +653,16 @@          \par          \nointerlineskip          \prevdepth\strutdp -        \ctxcommand{mixflushrest()}% rubish -        \ctxcommand{mixcleanup()}%   rubish +        \clf_mixflushrest% rubish +        \clf_mixcleanup  % rubish          \exitloop        \or          % 1 = we have stuff left, so flush and rebalance          %writestatus\m!columns{flush continue}%          \page_mix_routine_package          \page_otr_construct_and_shipout\box\b_page_mix_collected -        \setbox\b_page_mix_collected\vbox{\ctxcommand{mixflushrest()}}% we could avoid this -        \ctxcommand{mixcleanup()}% +        \setbox\b_page_mix_collected\vbox{\clf_mixflushrest}% we could avoid this +        \clf_mixcleanup          \ifdim\ht\b_page_mix_collected=\zeropoint              \exitloop          \fi @@ -757,8 +757,8 @@     \page_mix_routine_construct\v!yes     \page_mix_routine_package     \dontleavehmode\box\b_page_mix_collected -   \ctxcommand{mixflushrest()}% -   \ctxcommand{mixcleanup()}% +   \clf_mixflushrest +   \clf_mixcleanup     \egroup}  %D As usual, floats complicates matters and this is where experimental code diff --git a/tex/context/base/publ-imp-apa.mkvi b/tex/context/base/publ-imp-apa.mkvi index c812a76be..3651fd036 100644 --- a/tex/context/base/publ-imp-apa.mkvi +++ b/tex/context/base/publ-imp-apa.mkvi @@ -27,6 +27,18 @@  %D }  %D \stopTEX +% set ALL specific APA compliant values + +\definebtx +  [apa] +  [\c!default=default, +   \c!specification=apa, +   \c!otherstext={\space\btxlabeltext{apa:others}}, +   %c!journalconversion=\v!normal, +   \c!monthconversion=\v!month] + +% First, define list and rendering parameters +  % The APA style sorts the unnumbered rendered list by authoryear  \definebtxrendering @@ -42,15 +54,6 @@     \c!distance=.5\emwidth,     \c!margin=3\emwidth] -% set ALL specific APA compliant values - -\definebtx -  [apa] -  [\c!default=default, -   \c!otherstext={\space\btxlabeltext{apa:others}}, -   %c!journalconversion=\v!normal, -   \c!monthconversion=\v!month] -  \definebtx    [apa:list]    [apa] @@ -62,8 +65,6 @@     \c!separator:names:3={,\nobreakspace\textampersand\space}, % comma separated list     \c!separator:names:4= {\nobreakspace\textampersand\space}] % last of two, no comma! -% The following are similar to default, but inherit from apa:list -  \definebtx    [apa:list:author]    [apa:list] @@ -225,11 +226,11 @@    [apa:page]    [\c!command={\wordright}] -% The APA style defines authoryear citations. +% Then define and set cite parameters.  \definebtx    [apa:cite] -  [apa:list] +  [apa]    [\c!alternative=authoryear,     \c!otherstext={,\space\btxlabeltext{apa:others}},     \c!etallimit=5, @@ -244,8 +245,6 @@    [apa:cite:author]    [apa:cite] -% The following are similar to default, but inherit from apa:cite -  \definebtx    [apa:cite:authoryear]    [apa:cite:author] @@ -441,8 +440,6 @@     apa:Retrieved={Available from},    % {Retrieved from},     apa:In=In] -% Check this (google translate!!): -  \setupbtxlabeltext    [nl]    [apa:and=en, @@ -791,7 +788,8 @@              \texdefinition{btx:apa:suffixedyear}              \btxrightparenthesis          } -    \btxperiod % outside of interaction +    % outside of interaction +    \btxperiod      \doif {\btxfoundname{author}} {title} {          \setmode{btx:apa:title-placed}      } diff --git a/tex/context/base/publ-imp-aps.lua b/tex/context/base/publ-imp-aps.lua index 5977fdb27..efd1c85c1 100644 --- a/tex/context/base/publ-imp-aps.lua +++ b/tex/context/base/publ-imp-aps.lua @@ -62,7 +62,6 @@ local generic = {      -- allows the substitution of an alternate field.      --      -- note that anything can get assigned a doi or be available online. -    doi        = { "doi", "url" },      editionset = { "edition", "volume", "number", "pages" },  } @@ -87,19 +86,16 @@ local categories = specification.categories  categories.article = {      sets = {          author = { "author", "editor" }, -	volume = { "volume", "number", "pages" }, -        doi    = generic.doi, -        isbn   = { "issn" },      },      required = { -        "author" +        "author",      },      optional = {          "collaboration",          "year",          "title", "subtitle", "type", "file", -        "journal", "volume", -        "doi", "note", "isbn" +        "journal", "volume", "number", "pages", +        "doi", "url", "note",      },  } @@ -115,9 +111,9 @@ categories.magazine = {      optional = {          "collaboration",          "title", "subtitle", "type", "file", -        "number", +        "number", "pages",          "month", "day", -        "doi", "note", "isbn" +        "doi", "url", "note",      },  } @@ -128,8 +124,6 @@ categories.newspaper = categories.magazine  categories.periodical = {      sets = {          author = { "editor", "publisher" }, -        doi    = generic.doi, -        isbn   = { "issn" },      },      required = {          "title", @@ -141,7 +135,7 @@ categories.periodical = {          "subtitle", "file",          "series", "volume", "number", "month",          "organization", -        "doi", "note", "isbn" +        "doi", "url", "note",      },  } @@ -150,7 +144,6 @@ categories.periodical = {  categories.standard = {      sets = {          author = { "author", "institution", "organization" }, -        doi    = generic.doi,      },      required = {          "author", @@ -160,6 +153,7 @@ categories.standard = {      },      optional = {          "collaboration", +        "url",      },  } @@ -169,7 +163,6 @@ categories.book = {      sets = {          author     = { "author", "editor", "publisher" },          editionset = generic.editionset, -        doi        = generic.doi,      },      required = {          "author", @@ -181,7 +174,7 @@ categories.book = {          "title", "subtitle", "type",  "file",          "editionset", "series",          "address", -        "doi", "note", "isbn" +        "doi", "url", "note",      },  } @@ -191,7 +184,6 @@ categories.inbook = {      sets = {          author     = { "author", "editor", "publisher", },          editionset = generic.editionset, -        doi        = generic.doi,      },      required = {          "author", @@ -206,7 +198,7 @@ categories.inbook = {          "editionset", "series",          "month",          "address", -        "doi", "note", "isbn" +        "doi", "url", "note",      },  } @@ -217,7 +209,6 @@ categories.incollection = {      sets = {          author     = { "author", "editor", "publisher" },          editionset = generic.editionset, -        doi        = generic.doi,      },      required = {          "author", @@ -231,7 +222,7 @@ categories.incollection = {          "chapter",          "month",          "address", -        "doi", "note", "isbn" +        "doi", "url", "note",      },  } @@ -240,7 +231,6 @@ categories.incollection = {  categories.booklet = {      sets = {          publisher = { "howpublished" }, -- no "publisher"! -        doi    = generic.doi,      },      required = {          "author", @@ -252,7 +242,7 @@ categories.booklet = {          "year", "month",          "subtitle", "type", "file",          "address", -        "doi", "note", "isbn" +        "doi", "url", "note",       },  } @@ -263,7 +253,6 @@ categories.proceedings = {          author     = { "editor", "organization", "publisher" }, -- no "author"!          publisher  = { "publisher", "organization" },          editionset = generic.editionset, -        doi        = generic.doi,      },      required = {          "author", @@ -276,7 +265,7 @@ categories.proceedings = {          "editionset", "series",          "month",          "address", -        "doi", "note", "isbn" +        "doi", "url", "note",      },  } @@ -291,7 +280,7 @@ categories.inproceedings = {          "month",          "edition", "series",          "address", "organization", -        "doi", "note", "isbn" +        "doi", "url", "note",      },  } @@ -300,9 +289,6 @@ categories.conference = categories.inproceedings  -- a thesis (of course).  categories.thesis = { -    sets = { -        doi = generic.doi, -    },      required = {          "author",          "title", @@ -315,7 +301,7 @@ categories.thesis = {          "subtitle", "file",          "month",          "address", -        "doi", "note", "isbn" +        "doi", "url", "note",      },  } @@ -333,7 +319,7 @@ categories.mastersthesis = {          "subtitle", "file",          "month",          "address", -        "doi", "note", "isbn" +        "doi", "url", "note",      },  }  categories.phdthesis = categories.mastersthesis @@ -345,7 +331,6 @@ categories.techreport = {          author     = { "author", "institution", "publisher" },          publisher  = { "publisher", "institution", },          editionset = { "type", "volume", "number", "pages" }, -- no "edition"! -        doi        = generic.doi,      },      required = {          "author", @@ -360,7 +345,7 @@ categories.techreport = {          "subtitle", "file",          "editionset",          "month", -        "doi", "note", "isbn" +        "doi", "url", "note",      },  } @@ -371,7 +356,6 @@ categories.manual = {          author     = { "author", "organization", "publisher" },          publisher  = { "publisher", "organization", },          editionset = generic.editionset, -        doi        = generic.doi,      },      required = {          "title" @@ -382,7 +366,7 @@ categories.manual = {          "address",          "subtitle", "file",          "editionset", "month", "year", -        "doi", "note", "isbn", +        "doi", "url", "note",      },  } @@ -395,7 +379,6 @@ categories.patent = {          year = { "year", "yearfiled", },          month = { "month", "monthfiled", },          day = { "day", "dayfiled", }, -        doi = generic.doi,      },      required = {          "nationality", @@ -410,16 +393,13 @@ categories.patent = {          "title", "subtitle", "file",          "address",          "day", "month", -        "doi", "note" +        "doi", "url", "note",      },  }  -- a document having an author and title, but not formally published.  categories.unpublished = { -    sets = { -        doi = generic.doi, -    },      required = {          "author",          "title", @@ -429,16 +409,13 @@ categories.unpublished = {          "collaboration",          "subtitle", "file",          "year", "month", -        "doi" +        "doi", "url",      },  }  -- like misc below but includes organization.  categories.electronic = { -    sets = { -        doi = generic.doi, -    },      required = {          "title"      }, @@ -450,17 +427,13 @@ categories.electronic = {          "address",          "organization",          "howpublished", -        "doi", "note" +        "doi", "url", "note",      },  }  -- use this type when nothing else fits.  categories.misc = { -    sets = { -        doi  = generic.doi, -        isbn = { "isbn", "issn" }, -    },      required = {          -- nothing is really important here      }, @@ -470,17 +443,13 @@ categories.misc = {          "title", "subtitle", "file",          "year", "month",          "howpublished", -        "doi", "note", "isbn" +        "doi", "url", "note",      },  }  -- other (whatever jabref does not know!)  categories.other = { -    sets = { -        doi  = generic.doi, -        isbn = { "isbn", "issn" }, -    },      required = {          "author",          "title", @@ -489,7 +458,7 @@ categories.other = {      optional = {          "collaboration",          "subtitle", "file", -        "doi", "note", "isbn" +        "doi", "url", "note",      },  } @@ -498,14 +467,13 @@ categories.other = {  categories.literal = {      sets = {          author = { "key" }, -- need to check this! -        doi    = generic.doi,      },      required = {          "text"      },      optional = {          "author", -        "doi", "note" +        "doi", "url", "note"      },      virtual = false,  } diff --git a/tex/context/base/publ-imp-aps.mkvi b/tex/context/base/publ-imp-aps.mkvi index 3179e8149..e5ea2459a 100644 --- a/tex/context/base/publ-imp-aps.mkvi +++ b/tex/context/base/publ-imp-aps.mkvi @@ -27,37 +27,38 @@  %D }  %D \stopTEX -\definebtxrendering -  [aps] -  [\c!specification=aps] - -\setupbtxlist -  [aps] -  [alternative=paragraph, -   width=auto, -   distance=0pt] -  % set ALL specific APS compliant values  \definebtx    [aps]    [\c!default=default, +   \c!specification=aps,     \c!otherstext={\space\btxlabeltext{aps:others}},     \c!etallimit=10,     \c!etaldisplay=\btxparameter\c!etallimit,     %c!journalconversion=\v!normal,     \c!monthconversion=\v!month, +   optionaltitle=\v!yes,     \c!separator:names:2={,\space},     \c!separator:names:3={,\space\btxlabeltext{aps:and}\space}, % not \textampersand     \c!separator:names:4= {\space\btxlabeltext{aps:and}\space}] % not \textampersand +% First, define and set list and rendering parameters + +\definebtxrendering +  [aps] +  [\c!specification=aps] + +\setupbtxlist +  [aps] +  [alternative=paragraph, +   width=auto, +   distance=0pt] +  \definebtx    [aps:list]    [aps] -  [\c!authorconversion=normalshort, -   placetitle=\v!yes] % can be set to no for journal, for example. - -% The following are similar to default, but inherit from aps:list +  [\c!authorconversion=normalshort]  \definebtx    [aps:list:author] @@ -109,6 +110,10 @@    %command=\btxexpandedjournal] % btxabbreviatedjournal  \definebtx +  [aps:list:volume] +  [\c!style=\v!bold] + +\definebtx    [aps:list:title]    [\c!style=\v!italic,     \c!command=\Word] @@ -226,17 +231,17 @@    [aps:page]    [\c!command={\wordright}] +% Then define and set all cite parameters +  \definebtx    [aps:cite] -  [aps:list] +  [aps]    [\c!authorconversion=\v!name]  \definebtx    [aps:cite:author]    [aps:cite] -% The following are similar to default, but inherit from aps:cite -  \definebtx    [aps:cite:authoryear]    [aps:cite:author] @@ -667,7 +672,7 @@  \stoptexdefinition  \starttexdefinition btx:aps:optional-title -    \doif{\btxparameter{placetitle}}\v!yes { +    \doif{\btxparameter{optionaltitle}}\v!yes {          \texdefinition {btx:aps:title}      }  \stoptexdefinition @@ -768,14 +773,15 @@      }  \stoptexdefinition -\starttexdefinition btx:aps:journal-volumeset-year +\starttexdefinition btx:aps:journal-volume-year      \btxdoif {journal} {          % expandedjournal abbreviatedjournal          \btxflush{expandedjournal -> journal} -        % A newspaper may not have a volume but may have a number!          \btxdoifelse {volume} {              \btxspace -            \texdefinition{btx:aps:bold}{volume} +            \btxstartstyleandcolor [aps:list:volume] +                \btxflush{volume} +            \btxstopstyleandcolor              \btxdoif {number} {                  \removeunwantedspaces(                  \btxflush{number} @@ -788,14 +794,13 @@                  \btxcomma              }          } -        \btxdoif {number} { +        \btxdoif {pages} {              \btxspace              \btxflush{pages}          }          \btxleftparenthesis          \texdefinition{btx:aps:year}          \btxrightparenthesis -        \btxperiod      }  \stoptexdefinition @@ -823,58 +828,8 @@      \btxrightparenthesis  \stoptexdefinition -\definebreakpoints[doi] -\definebreakpoint [doi][:][nleft=3,type=1] -\definebreakpoint [doi][/][nleft=3,type=1] -\definebreakpoint [doi][-][nleft=3,type=1] -\definebreakpoint [doi][.][nleft=3,type=1] - -% use \btxentry here? -\starttexdefinition btx:aps:url -    \btxspace -    \begingroup -        \setbreakpoints[doi] -        \ifconditional\btxinteractive -            \goto { -                \btxflush{url} -            } [ -                url(\btxflush{url}) -            ] -        \else -            \btxflush{url} -        \fi -    \endgroup -\stoptexdefinition - -% use \btxentry here? -\starttexdefinition btx:aps:doi -    \btxspace -    \begingroup -        \setbreakpoints[doi] -        \ifconditional\btxinteractive -            \goto { -                doi:\btxflush{doi} -            } [ -                url(http://dx.doi.org/\btxflush{doi}) -            ] -        \else -            doi:\btxflush{doi} -        \fi -    \endgroup -\stoptexdefinition - -% also issn - see publ-imp-aps.lua -\starttexdefinition btx:aps:isbn -    \btxdoif {isbn} { -        \btxleftparenthesis -        \WORD{\btxfoundname{isbn}}:\btxspace -        \setbreakpoints[doi] -        \btxflush{isbn} -        \btxrightparenthesis -    } -\stoptexdefinition -  \starttexdefinition btx:aps:note +    \btxperiod      \btxdoif {note} {          \btxleftparenthesis          \btxflush{note} @@ -882,16 +837,21 @@      }  \stoptexdefinition -\starttexdefinition btx:aps:url-doi-note -    \doif {\btxfoundname{doi}} {url} { -        \texdefinition{btx:aps:url} -    } -    \texdefinition{btx:aps:isbn} -    \doif {\btxfoundname{doi}} {doi} { -        \texdefinition{btx:aps:doi} -    } -    \texdefinition{btx:aps:note} -    \removeunwantedspaces +\starttexdefinition btx:aps:doi-url #text +    \ifconditional\btxinteractive +        \btxdoifelse {doi} { +            \goto {#text} [url(http://dx.doi.org/\btxflush{doi})] +        } { +            \btxdoifelse {url} { +                \goto {#text} [url(\btxflush{url})] +            } { +                #text +            } +        } +    \else +        #text +    \fi +  \stoptexdefinition  % Then setups, by category @@ -904,8 +864,8 @@  \startsetups btx:aps:list:article      \texdefinition{btx:aps:author}      \texdefinition{btx:aps:optional-title} -    \texdefinition{btx:aps:journal-volumeset-year} -    \texdefinition{btx:aps:url-note-doi} +    \texdefinition{btx:aps:doi-url} {\texdefinition{btx:aps:journal-volume-year}} +    \texdefinition{btx:aps:note}  \stopsetups  % An article from a magazine. @@ -918,7 +878,7 @@  % An article from a newspaper.  % Required fields: author or title, journal, (year). -% Optional fields: volume, number, pages, type, month, day, doi, url, note. +% Optional fields: number, pages, type, month, day, doi, url, note.  \startsetups btx:aps:list:newspaper      \fastsetup{btx:aps:list:article} @@ -940,7 +900,7 @@  \startsetups btx:aps:list:standard      \texdefinition{btx:aps:author}      \texdefinition{btx:aps:title} -    \texdefinition{btx:aps:url-doi-note} +    \texdefinition{btx:aps:note}  \stopsetups  % year? @@ -955,8 +915,8 @@      \texdefinition{btx:aps:author}      \texdefinition{btx:aps:title}      \texdefinition{btx:aps:editionset} -    \texdefinition{btx:aps:publisher-wherefrom-year} -    \texdefinition{btx:aps:url-doi-note} +    \texdefinition{btx:aps:doi-url} {\texdefinition{btx:aps:publisher-wherefrom-year}} +    \texdefinition{btx:aps:note}  \stopsetups  % There is some debate about how inbook should differ from incollection @@ -973,8 +933,8 @@      \texdefinition{btx:aps:title}      \texdefinition{btx:aps:editor-in}      \texdefinition{btx:aps:editionset} -    \texdefinition{btx:aps:publisher-wherefrom-year} -    \texdefinition{btx:aps:url-doi-note} +    \texdefinition{btx:aps:doi-url} {\texdefinition{btx:aps:publisher-wherefrom-year}} +    \texdefinition{btx:aps:note}  \stopsetups  % chapter? @@ -1010,8 +970,8 @@          \btxflush{organization}          \btxcomma      } -    \texdefinition{btx:aps:publisher-wherefrom-year} -    \texdefinition{btx:aps:url-doi-note} +    \texdefinition{btx:aps:doi-url} {\texdefinition{btx:aps:publisher-wherefrom-year}} +    \texdefinition{btx:aps:note}  \stopsetups  \startsetups btx:aps:list:conference @@ -1051,7 +1011,7 @@          }      }      \btxperiod -    \texdefinition{btx:aps:url-doi-note} +    \texdefinition{btx:aps:note}  \stopsetups  \startsetups btx:aps:list:phdthesis @@ -1121,7 +1081,7 @@          \btxperiod          \italiccorrection      \endgroup -    \texdefinition{btx:aps:publisher-wherefrom-year} +    \texdefinition{btx:aps:doi-url} {\texdefinition{btx:aps:publisher-wherefrom-year}}      \texdefinition{btx:aps:url}      \texdefinition{btx:aps:note}  \stopsetups @@ -1146,7 +1106,7 @@          \btxflush{howpublished}          \btxperiod      } -    \texdefinition{btx:aps:url-doi-note} +    \texdefinition{btx:aps:note}  \stopsetups  % Other. Note that this category was not defined with BIBTEX. Below from JabRef: @@ -1169,7 +1129,7 @@          \btxflush{howpublished}          \btxperiod      } -    \texdefinition{btx:aps:url-doi-note} +    \texdefinition{btx:aps:note}  \stopsetups  % If all else fails to match: diff --git a/tex/context/base/publ-imp-default.mkvi b/tex/context/base/publ-imp-default.mkvi index 8e7b151c7..c0664f5df 100644 --- a/tex/context/base/publ-imp-default.mkvi +++ b/tex/context/base/publ-imp-default.mkvi @@ -43,7 +43,7 @@  \definebtx    [\s!default:\s!cite] -  [\s!default:\s!list] +  [\s!default]    [\c!alternative=num,     \c!authorconversion=\v!name] diff --git a/tex/context/base/spac-ali.lua b/tex/context/base/spac-ali.lua index 08e33c5b8..880da6213 100644 --- a/tex/context/base/spac-ali.lua +++ b/tex/context/base/spac-ali.lua @@ -133,7 +133,11 @@ function alignments.set(n)      texsetattribute(a_realign,texgetcount("realpageno") * 10 + n)  end -commands.setrealign = alignments.set +interfaces.implement { +    name      = "setrealign", +    actions   = alignments.set, +    arguments = "integer", +}  statistics.register("realigning", function()      if nofrealigned > 0 then diff --git a/tex/context/base/spac-ali.mkiv b/tex/context/base/spac-ali.mkiv index c13e4ca76..13a4ce192 100644 --- a/tex/context/base/spac-ali.mkiv +++ b/tex/context/base/spac-ali.mkiv @@ -38,8 +38,8 @@  \to \everyforgetall  \unexpanded\def\resetrealignsignal{\attribute\realignattribute\attributeunsetvalue} -\unexpanded\def\signalinnerrealign{\ctxcommand{setrealign(2)}} -\unexpanded\def\signalouterrealign{\ctxcommand{setrealign(1)}} +\unexpanded\def\signalinnerrealign{\clf_setrealign\plustwo} +\unexpanded\def\signalouterrealign{\clf_setrealign\plusone}  \installcorenamespace{aligncommand}  \installcorenamespace{alignhorizontal} diff --git a/tex/context/base/spac-hor.lua b/tex/context/base/spac-hor.lua index c9d6e2b15..5d5a43e31 100644 --- a/tex/context/base/spac-hor.lua +++ b/tex/context/base/spac-hor.lua @@ -6,14 +6,15 @@ if not modules then modules = { } end modules ['spac-hor'] = {      license   = "see context related readme files"  } -local match = string.match  local utfbyte = utf.byte +local lpegmatch, P, C = lpeg.match, lpeg.P, lpeg.C  local context  = context -local commands = commands  local chardata = characters.data +local p_check  = P("the ") * (P("letter") + P("character")) * P(" ") * lpeg.patterns.utf8byte -- is a capture already +  local can_have_space = table.tohash {      "lu", "ll", "lt", "lm", "lo", -- letters   -- "mn", "mc", "me",             -- marks @@ -26,10 +27,18 @@ local can_have_space = table.tohash {   -- "cc", "cf", "cs", "co", "cn", -- others  } -function commands.autonextspace(str) -- todo: use nexttoken -    local ch = match(str,"the letter (.)") or match(str,"the character (.)") -    ch = ch and chardata[utfbyte(ch)] -    if ch and can_have_space[ch.category] then -        context.space() +local function autonextspace(str) -- todo: make a real not intrusive lookahead +    local b = lpegmatch(p_check,str) +    if b then +        local d = chardata[b] +        if d and can_have_space[d.category] then +            context.space() +        end      end  end + +interfaces.implement { +    name      = "autonextspace", +    actions   = autonextspace, +    arguments = "string", +} diff --git a/tex/context/base/spac-hor.mkiv b/tex/context/base/spac-hor.mkiv index c61355ae5..72828c1b8 100644 --- a/tex/context/base/spac-hor.mkiv +++ b/tex/context/base/spac-hor.mkiv @@ -1046,7 +1046,7 @@    {\futurelet\nexttoken\spac_spaces_auto_insert_next}  \def\spac_spaces_auto_insert_next -  {\ctxcommand{autonextspace(\!!bs\meaning\nexttoken\!!es)}} % todo, just consult nexttoken at the lua end +  {\clf_autonextspace{\meaning\nexttoken}} % todo, just consult nexttoken at the lua end  %D Moved from bib module: diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdfBinary files differ index 278ee192c..c62a009b8 100644 --- a/tex/context/base/status-files.pdf +++ b/tex/context/base/status-files.pdf diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdfBinary files differ index 2451479e7..21d601a72 100644 --- a/tex/context/base/status-lua.pdf +++ b/tex/context/base/status-lua.pdf diff --git a/tex/context/base/strc-blk.lua b/tex/context/base/strc-blk.lua index 837921972..0ababcfc0 100644 --- a/tex/context/base/strc-blk.lua +++ b/tex/context/base/strc-blk.lua @@ -16,6 +16,8 @@ local allocate = utilities.storage.allocate  local context     = context  local commands    = commands +local implement   = interfaces.implement +  local structures  = structures  structures.blocks = structures.blocks or { } @@ -154,8 +156,7 @@ end  -- interface - -commands.definestructureblock   = blocks.define -commands.savestructureblock     = blocks.save -commands.selectstructureblock   = blocks.select -commands.setstructureblockstate = blocks.setstate +implement { name = "definestructureblock",   actions = blocks.define,   arguments = "string" } +implement { name = "savestructureblock",     actions = blocks.save,     arguments = { "string", "string" ,"string" } } +implement { name = "selectstructureblock",   actions = blocks.select,   arguments = { "string", "string" ,"string", "string" } } +implement { name = "setstructureblockstate", actions = blocks.setstate, arguments = { "string", "string" ,"string" } } diff --git a/tex/context/base/strc-blk.mkiv b/tex/context/base/strc-blk.mkiv index bceb66beb..a2e66da17 100644 --- a/tex/context/base/strc-blk.mkiv +++ b/tex/context/base/strc-blk.mkiv @@ -33,7 +33,7 @@  \installcommandhandler \??block {block} \??block  \appendtoks -    \ctxcommand{definestructureblock("\currentblock")}% +    \clf_definestructureblock{\currentblock}%      \setuevalue{\e!begin\currentblock}{\dodoubleempty\strc_blocks_begin[\currentblock]}%      \setuevalue{\e!end  \currentblock}{}%  \to \everydefineblock @@ -41,7 +41,7 @@  \unexpanded\def\strc_blocks_begin[#1][#2]%    {\normalexpanded{\buff_pickup{@block@}{\e!begin#1}{\e!end#1}}       {}% before -     {\ctxcommand{savestructureblock("#1","#2","@block@")}}% +     {\clf_savestructureblock{#1}{#2}{@block@}}%       \plusone}% after  \let\strc_blocks_setup\relax @@ -72,17 +72,17 @@     \egroup}  \def\strc_blocks_set_state[#1][#2][#3]% state name tag -  {\ctxcommand{setstructureblockstate("#1","#2","#3")}} +  {\clf_setstructureblockstate{#1}{#2}{#3}}  \def\strc_blocks_select[#1][#2][#3][#4]% state name tag setups    {\bgroup     \doifassignmentelse{#3}       {\getparameters[\??blocktemp][\c!criterium=\v!text,#3]%        \def\strc_blocks_setup{\setupcurrentblock[#3]}% -      \ctxcommand{selectstructureblock("#1","#2","","\csname\??blocktemp\c!criterium\endcsname")}} +      \clf_selectstructureblock{#1}{#2}{}{\csname\??blocktemp\c!criterium\endcsname}}       {\getparameters[\??blocktemp][\c!criterium=\v!text,#4]%        \def\strc_blocks_setup{\setupcurrentblock[#4]}% -      \ctxcommand{selectstructureblock("#1","#2","#3","\csname\??blocktemp\c!criterium\endcsname")}}% +      \clf_selectstructureblock{#1}{#2}{#3}{\csname\??blocktemp\c!criterium\endcsname}}%     \egroup}  % hide   : save, if [+] also hidden execute diff --git a/tex/context/base/strc-con.mkvi b/tex/context/base/strc-con.mkvi index d3d698481..63c609070 100644 --- a/tex/context/base/strc-con.mkvi +++ b/tex/context/base/strc-con.mkvi @@ -1009,7 +1009,7 @@  % macros.  \def\reinstateconstructionnumberentry#1% was xdef -  {\edef\currentconstructionattribute  {\ctxcommand    {getinternallistreference(#1)}}% +  {\edef\currentconstructionattribute  {\clf_getinternallistreference#1}%     \edef\currentconstructionsynchronize{\ctxlatecommand{enhancelist(#1)}}}  \installstructurelistprocessor{construction}{\usestructurelistprocessor{number+title}} diff --git a/tex/context/base/strc-enu.mkvi b/tex/context/base/strc-enu.mkvi index 2db542c6b..0da71ecdf 100644 --- a/tex/context/base/strc-enu.mkvi +++ b/tex/context/base/strc-enu.mkvi @@ -371,6 +371,6 @@     \fi}  \unexpanded\def\strc_enumerations_skip_number_coupling[#tag]% e.g. for questions with no answer -  {\ctxcommand{setnextreferenceorder("construction","#tag")}} +  {\clf_setnextreferenceorder{construction}{#tag}}  \protect \endinput diff --git a/tex/context/base/strc-ini.lua b/tex/context/base/strc-ini.lua index e7dc97dcd..b21e31ace 100644 --- a/tex/context/base/strc-ini.lua +++ b/tex/context/base/strc-ini.lua @@ -377,4 +377,8 @@ end  -- interface -commands.definestructureset = sets.define +interfaces.implement { +    name      = "definestructureset", +    actions   = sets.define, +    arguments = { "string", "string", "string", "string", "boolean" } +} diff --git a/tex/context/base/strc-ini.mkvi b/tex/context/base/strc-ini.mkvi index 8488d1dab..ad83cbc58 100644 --- a/tex/context/base/strc-ini.mkvi +++ b/tex/context/base/strc-ini.mkvi @@ -70,12 +70,12 @@  \unexpanded\def\defineconversionset{\dotripleempty\strc_sets_define_conversion_set}  \unexpanded\def\defineprefixset    {\dotripleempty\strc_sets_define_prefix_set} -% Low level versions (no optional checking). The detokenize and escaping might go away. +% Low level versions (no optional checking). The detokenize might go away. -\unexpanded\def\strc_sets_define_reset_set     [#name][#set][#default]{\ctxcommand{definestructureset("structure:resets",     "#name","\luaescapestring{\detokenize{#set}}","\luaescapestring{\detokenize{#default}}",true)}} -\unexpanded\def\strc_sets_define_separator_set [#name][#set][#default]{\ctxcommand{definestructureset("structure:separators", "#name","\luaescapestring{\detokenize{#set}}","\luaescapestring{\detokenize{#default}}")}} -\unexpanded\def\strc_sets_define_conversion_set[#name][#set][#default]{\ctxcommand{definestructureset("structure:conversions","#name","\luaescapestring{\detokenize{#set}}","\luaescapestring{\detokenize{#default}}")}} -\unexpanded\def\strc_sets_define_prefix_set    [#name][#set][#default]{\ctxcommand{definestructureset("structure:prefixes",   "#name","\luaescapestring{\detokenize{#set}}","\luaescapestring{\detokenize{#default}}")}} +\unexpanded\def\strc_sets_define_reset_set     [#name][#set][#default]{\clf_definestructureset{structure:resets}     {#name}{\detokenize{#set}}{\detokenize{#default}}true\relax} +\unexpanded\def\strc_sets_define_separator_set [#name][#set][#default]{\clf_definestructureset{structure:separators} {#name}{\detokenize{#set}}{\detokenize{#default}}false\relax} +\unexpanded\def\strc_sets_define_conversion_set[#name][#set][#default]{\clf_definestructureset{structure:conversions}{#name}{\detokenize{#set}}{\detokenize{#default}}false\relax} +\unexpanded\def\strc_sets_define_prefix_set    [#name][#set][#default]{\clf_definestructureset{structure:prefixes}   {#name}{\detokenize{#set}}{\detokenize{#default}}false\relax}  \let\definestructureresetset     \defineresetset  \let\definestructureseparatorset \defineseparatorset diff --git a/tex/context/base/strc-itm.lua b/tex/context/base/strc-itm.lua index b736ff4e3..adec591c1 100644 --- a/tex/context/base/strc-itm.lua +++ b/tex/context/base/strc-itm.lua @@ -10,6 +10,8 @@ local structures  = structures  local itemgroups  = structures.itemgroups  local jobpasses   = job.passes +local implement   = interfaces.implement +  local setvariable = jobpasses.save  local getvariable = jobpasses.getfield @@ -25,7 +27,7 @@ local counts      = table.setmetatableindex("number")  local trialtypesetting = context.trialtypesetting -function commands.analyzeitemgroup(name,level) +local function analyzeitemgroup(name,level)      local n = counts[name]      if level == 1 then          n = n + 1 @@ -38,7 +40,7 @@ function commands.analyzeitemgroup(name,level)      texsetdimen("local","d_strc_itemgroups_max_width",w)  end -function commands.registeritemgroup(name,level,nofitems,maxwidth) +local function registeritemgroup(name,level,nofitems,maxwidth)      local n = counts[name]      if not trialtypesetting() then          -- no trialtypsetting @@ -47,3 +49,15 @@ function commands.registeritemgroup(name,level,nofitems,maxwidth)          counts[name] = n - 1      end  end + +implement { +    name      = "analyzeitemgroup", +    actions   = analyzeitemgroup, +    arguments = { "string", "integer" } +} + +implement { +    name      = "registeritemgroup", +    actions   = registeritemgroup, +    arguments = { "string", "integer", "integer", "dimen" } +} diff --git a/tex/context/base/strc-itm.mkvi b/tex/context/base/strc-itm.mkvi index dccf1c85c..c709463a8 100644 --- a/tex/context/base/strc-itm.mkvi +++ b/tex/context/base/strc-itm.mkvi @@ -229,10 +229,10 @@  \let           \currentitemgroupsegments       \empty  \def\strc_itemgroups_register_status -  {\ctxcommand{registeritemgroup("\currentparentitemgroup",\number\c_strc_itemgroups_nesting,\number\c_strc_itemgroups_n_of_items,\number\dimexpr\itemgroupparameter\c!maxwidth)}} +  {\clf_registeritemgroup{\currentparentitemgroup}\c_strc_itemgroups_nesting\c_strc_itemgroups_n_of_items\dimexpr\itemgroupparameter\c!maxwidth\relax}  \def\strc_itemgroups_check_n_of_items % we could do this at the lua end and save a call (i.e. will be dimen and counter) -  {\ctxcommand{analyzeitemgroup("\currentparentitemgroup",\number\c_strc_itemgroups_nesting)}\relax +  {\clf_analyzeitemgroup{\currentparentitemgroup}\c_strc_itemgroups_nesting\relax     \edef\currentnofitems{\the\c_strc_itemgroups_max_items}}  % todo: \dodosetreference -> \strc_counters_register_component (to be checked) @@ -251,44 +251,47 @@    {%\setnextinternalreference     % no need to collect nodes in \b_strc_destination_nodes here ... maybe at some point     \strc_references_start_destination_nodes -     % this is somewhat over the top ... we should use the counter's reference -     \ctxcommand{setreferenceattribute("\s!full", "\referenceprefix","\currentitemreference", -        { -            metadata = { -                kind     = "item",% ? -                catcodes = \the\catcodetable, -                xmlroot  = \ifx\currentreferencecoding\s!xml "\xmldocument" \else nil \fi, % only useful when text -            }, -            references = { -    %           internal = \nextinternalreference, % no: this spoils references -                block    = "\currentsectionblock", -                section  = structures.sections.currentid(), -            }, -            prefixdata = structures.helpers.simplify { -                prefix        = "\namedcounterparameter\v_strc_itemgroups_counter\c!prefix", -                separatorset  = "\namedcounterparameter\v_strc_itemgroups_counter\c!prefixseparatorset", -                conversion    = \!!bs\namedcounterparameter\v_strc_itemgroups_counter\c!prefixconversion\!!es, -                conversionset = "\namedcounterparameter\v_strc_itemgroups_counter\c!prefixconversionset", -                set           = "\namedcounterparameter\v_strc_itemgroups_counter\c!prefixset", -                segments      = "\namedcounterparameter\v_strc_itemgroups_counter\c!prefixsegments", -            %   segments      = "\askedprefixsegments", -                connector     = \!!bs\namedcounterparameter\v_strc_itemgroups_counter\c!prefixconnector\!!es, -            }, -            numberdata = structures.helpers.simplify { -                numbers       = structures.counters.compact("\v_strc_itemgroups_counter",nil,true), -                separatorset  = "\namedcounterparameter\v_strc_itemgroups_counter\c!numberseparatorset", -  %             conversion    = "\namedcounterparameter\v_strc_itemgroups_counter\c!numberconversion", -  %             conversion    = "\currentitemgroupconversionset", -  %             conversionset = "\namedcounterparameter\v_strc_itemgroups_counter\c!numberconversionset", -  % todo:       fixedconversion = "\currentitemgroupconversionset", % temp hack: -                conversionset = "fixed::\currentitemgroupconversionset", +   % this is somewhat over the top ... we should use the counter's reference +   \clf_setreferenceattribute +        {\referenceprefix}% +        {\currentitemreference}% +        {% +            metadata {% +                kind            {\s!full}% was item, why? +            \ifx\currentreferencecoding\s!xml +                xmlroot         {\xmldocument}% only useful when text +            \fi +                catcodes        \catcodetable +            }% +            references {% +              % internal        \nextinternalreference % no: this spoils references +                block           {\currentsectionblock}% +                view            {\interactionparameter\c!focus}% +            }% +            prefixdata {% +                prefix          {\namedcounterparameter\v_strc_itemgroups_counter\c!prefix}% +                separatorset    {\namedcounterparameter\v_strc_itemgroups_counter\c!prefixseparatorset}% +                conversion      {\namedcounterparameter\v_strc_itemgroups_counter\c!prefixconversion}% +                conversionset   {\namedcounterparameter\v_strc_itemgroups_counter\c!prefixconversionset}% +                set             {\namedcounterparameter\v_strc_itemgroups_counter\c!prefixset}% +                segments        {\namedcounterparameter\v_strc_itemgroups_counter\c!prefixsegments}% +              % segments        {\askedprefixsegments}% +                connector       {\namedcounterparameter\v_strc_itemgroups_counter\c!prefixconnector}% +            }% +            numberdata {% +                numbers         {\v_strc_itemgroups_counter}% +                separatorset    {\namedcounterparameter\v_strc_itemgroups_counter\c!numberseparatorset}% +              % conversion      {\namedcounterparameter\v_strc_itemgroups_counter\c!numberconversion}% +              % conversionset   {\namedcounterparameter\v_strc_itemgroups_counter\c!numberconversionset}% +              % fixedconversion {\currentitemgroupconversionset}% +                conversionset   {fixed::\currentitemgroupconversionset}% temp hack                %                % for the moment no stopper, we need to make references configurable first -              % stopper       = \!!bs\namedcounterparameter\v_strc_itemgroups_counter\c!numberstopper\!!es, -                segments      = "\namedcounterparameter\v_strc_itemgroups_counter\c!numbersegments", -            }, -        }) -     }% +              % stopper         {\namedcounterparameter\v_strc_itemgroups_counter\c!numberstopper}% +                segments        {\namedcounterparameter\v_strc_itemgroups_counter\c!numbersegments}% +            }% +        }% +   \relax     \strc_references_stop_destination_nodes     \xdef\currentdestinationattribute{\number\lastdestinationattribute}%     % will become an option: @@ -482,6 +485,7 @@     \fi}  \ifdefined\dotagsetitemgroup \else \let\dotagsetitemgroup\relax \fi +\ifdefined\dotagsetitem      \else \let\dotagsetitem     \relax \fi  \def\strc_itemgroups_tag_start_group    {\dostarttaggedchained\t!itemgroup\currentparentitemgroup\??itemgroup @@ -1040,6 +1044,7 @@       \setfalse\c_strc_itemgroups_concat     \fi     \dostarttagged\t!item\empty +   \dotagsetitem     \dostarttagged\t!itemtag\empty     \strc_itemgroups_insert_item     \dostoptagged @@ -1087,6 +1092,7 @@  \unexpanded\def\strc_itemgroups_start_head_indeed    {\settrue\c_strc_itemgroups_head +   \dotagsetitem % weird place     \useitemgroupstyleandcolor\c!headstyle\c!headcolor\ignorespaces}  \unexpanded\def\strc_itemgroups_stop_head_indeed diff --git a/tex/context/base/strc-lev.lua b/tex/context/base/strc-lev.lua index 947889e1e..d7ffd6af4 100644 --- a/tex/context/base/strc-lev.lua +++ b/tex/context/base/strc-lev.lua @@ -8,26 +8,30 @@ if not modules then modules = { } end modules ['strc-lev'] = {  local insert, remove = table.insert, table.remove -local context  = context -local commands = commands +local context     = context +local interfaces  = interfaces -local sections = structures.sections -local default  = interfaces.variables.default +local sections    = structures.sections +local implement   = interfaces.implement -sections.levels = sections.levels or { } +local v_default   = interfaces.variables.default -local level, levels, categories = 0, sections.levels, { } +sections.levels   = sections.levels or { } -storage.register("structures/sections/levels", levels, "structures.sections.levels") +local level       = 0 +local levels      = sections.levels +local categories  = { }  local f_two_colon = string.formatters["%s:%s"] -function commands.definesectionlevels(category,list) +storage.register("structures/sections/levels", levels, "structures.sections.levels") + +local function definesectionlevels(category,list)      levels[category] = utilities.parsers.settings_to_array(list)  end -function commands.startsectionlevel(category) -    category = category ~= "" and category or default +local function startsectionlevel(category) +    category = category ~= "" and category or v_default      level = level + 1      local lc = levels[category]      if not lc or level > #lc then @@ -38,7 +42,7 @@ function commands.startsectionlevel(category)      insert(categories,category)  end -function commands.stopsectionlevel() +local function stopsectionlevel()      local category = remove(categories)      if category then          local lc = levels[category] @@ -52,3 +56,20 @@ function commands.stopsectionlevel()          -- error      end  end + +implement { +    name      = "definesectionlevels", +    actions   = definesectionlevels, +    arguments = { "string", "string" } +} + +implement { +    name      = "startsectionlevel", +    actions   = startsectionlevel, +    arguments = "string" +} + +implement { +    name      = "stopsectionlevel", +    actions   = stopsectionlevel, +} diff --git a/tex/context/base/strc-lev.mkvi b/tex/context/base/strc-lev.mkvi index b3ec2a2d5..1384f5f2f 100644 --- a/tex/context/base/strc-lev.mkvi +++ b/tex/context/base/strc-lev.mkvi @@ -26,17 +26,17 @@  \unexpanded\def\definesectionlevels{\dodoubleargument\strc_levels_define}  \unexpanded\def\startsectionlevel  {\dosingleempty   \strc_levels_start } -\unexpanded\def\strc_levels_define[#category][#list]{\ctxcommand{definesectionlevels("#category","#list")}} -\unexpanded\def\strc_levels_start        [#category]{\ctxcommand{startsectionlevel("#category")}} -\unexpanded\def\stopsectionlevel                    {\ctxcommand{stopsectionlevel()}} +\unexpanded\def\strc_levels_define[#category][#list]{\clf_definesectionlevels{#category}{#list}} +\unexpanded\def\strc_levels_start        [#category]{\clf_startsectionlevel{#category}} +\unexpanded\def\stopsectionlevel                    {\clf_stopsectionlevel}  \unexpanded\def\nostarthead{\dotripleargument\strc_levels_start_nop} % used at the lua end  \unexpanded\def\nostophead {\dosingleargument\strc_levels_stop_nop } % used at the lua end  \unexpanded\def\strc_levels_start[#category]%    {\doifassignmentelse{#category} -     {\ctxcommand{startsectionlevel("\v!default")}[#category]} -     {\ctxcommand{startsectionlevel("#category")}}} +     {\clf_startsectionlevel{\v!default}[#category]} +     {\clf_startsectionlevel{#category}}}  \unexpanded\def\strc_levels_start_nop[#category][#settings][#userdata]%    {\blank diff --git a/tex/context/base/strc-num.mkiv b/tex/context/base/strc-num.mkiv index 8cee9c3b0..42634fb9a 100644 --- a/tex/context/base/strc-num.mkiv +++ b/tex/context/base/strc-num.mkiv @@ -517,24 +517,21 @@  \def\strc_counters_register_component_page#1%    {\xdef\currentstructurecomponentreference      {#1\c!reference}%     \xdef\currentstructurecomponentreferenceprefix{#1\c!referenceprefix}% -   % maybe have a helper in strc-ref.mkvi     \setnextinternalreference -   \ctxcommand{setreferenceattribute(% can be helper with less passed -      "\s!page", -      "\currentstructurecomponentreferenceprefix", -      "\currentstructurecomponentreference", -      { -          references = { -              internal = \nextinternalreference, -              block    = "\currentsectionblock", -              section  = structures.sections.currentid(), -          }, -          metadata = { -              kind = "page", -          }, -      }, -      "\interactionparameter\c!focus") -   }% +   \clf_setreferenceattribute +        {\currentstructurecomponentreferenceprefix}% +        {\currentstructurecomponentreference}% +        {% +            references {% +                  internal \nextinternalreference +                  block    {\currentsectionblock}% +                  view     {\interactionparameter\c!focus}% +            }% +            metadata {% +                kind {\s!page}% +            }% +        }% +   \relax     \xdef\m_strc_counters_last_registered_attribute  {\the\lastdestinationattribute}%     \glet\m_strc_counters_last_registered_index      \relax     \glet\m_strc_counters_last_registered_synchronize\relax} diff --git a/tex/context/base/strc-ref.lua b/tex/context/base/strc-ref.lua index aa7acd542..5627fffbc 100644 --- a/tex/context/base/strc-ref.lua +++ b/tex/context/base/strc-ref.lua @@ -358,12 +358,23 @@ references.setnextinternal = setnextinternal  references.currentorder    = currentorder  references.setcomponent    = setcomponent -commands.setnextreferenceorder    = setnextorder -commands.setnextinternalreference = setnextinternal +implement { +    name      = "setnextreferenceorder", +    actions   = setnextorder, +    arguments = { "string", "string" } +} -function commands.currentreferenceorder(kind,name) -    context(currentorder(kind,name)) -end +implement { +    name      = "setnextinternalreference", +    actions   = setnextinternal, +    arguments = { "string", "string" } +} + +implement { +    name      = "currentreferenceorder", +    actions = { currentorder, context }, +    arguments = { "string", "string" } +}  function references.set(kind,prefix,tag,data)  --  setcomponent(data) @@ -417,7 +428,11 @@ function references.enhance(prefix,tag)      end  end -commands.enhancereference = references.enhance +implement { +    name      = "enhancereference", +    actions   = references.enhance, +    arguments = { "string", "string" } +}  -- -- -- related to strc-ini.lua -- -- -- @@ -510,7 +525,11 @@ function urls.get(name)      end  end -function commands.geturl(name) +function urls.found(name) +    return urldata[name] +end + +local function geturl(name)      local url = urls.get(name)      if url and url ~= "" then          ctx_pushcatcodes(txtcatcodes) @@ -519,18 +538,23 @@ function commands.geturl(name)      end  end --- function commands.gethyphenatedurl(name,...) ---     local url = urls.get(name) ---     if url and url ~= "" then ---         hyphenatedurl(url,...) ---     end --- end +implement { +    name      = "doifurldefinedelse", +    actions   = { urls.found, commands.doifelse }, +    arguments = "string" +} -function commands.doifurldefinedelse(name) -    commands.doifelse(urldata[name]) -end +implement { +    name      = "useurl", +    actions   = urls.define, +    arguments = { "string", "string", "string", "string" } +} -commands.useurl= urls.define +implement { +    name      = "geturl", +    actions   = geturl, +    arguments = "string", +}  -- files @@ -552,11 +576,36 @@ function files.get(name,method,space) -- method: none, before, after, both, spac      end  end -function commands.doiffiledefinedelse(name) -    commands.doifelse(filedata[name]) +function files.found(name) +    return filedata[name] +end + +local function getfile(name) +    local fil = files.get(name) +    if fil and fil ~= "" then +        ctx_pushcatcodes(txtcatcodes) +        context(fil) +        ctx_popcatcodes() +    end  end -commands.usefile= files.define +implement { +    name      = "doiffiledefinedelse", +    actions   = { files.found, commands.doifelse }, +    arguments = "string" +} + +implement { +    name      = "usefile", +    actions   = files.define, +    arguments = { "string", "string", "string" } +} + +implement { +    name      = "getfile", +    actions   = getfile, +    arguments = "string" +}  -- helpers @@ -636,20 +685,30 @@ function references.checkedprogram(whatever) -- return whatever if not resolved      end  end -commands.defineprogram = programs.define +implement { +    name      = "defineprogram", +    actions   = programs.define, +    arguments = { "string", "string", "string" } +} -function commands.getprogram(name) -    local f = programdata[name] -    if f then -        context(f[1]) +local function getprogram(name) +    local p = programdata[name] +    if p then +        context(p[1])      end  end +implement { +    name      = "getprogram", +    actions   = getprogram, +    arguments = "string" +} +  -- shared by urls and files -function references.whatfrom(name) -    context((urldata[name] and v_url) or (filedata[name] and v_file) or v_unknown) -end +-- function references.whatfrom(name) +--     context((urldata[name] and v_url) or (filedata[name] and v_file) or v_unknown) +-- end  function references.from(name)      local u = urldata[name] @@ -676,7 +735,7 @@ function references.from(name)      end  end -function commands.from(name) +local function from(name)      local u = urldata[name]      if u then          local url, file, description = u[1], u[2], u[3] @@ -701,6 +760,12 @@ function commands.from(name)      end  end +implement { +    name      = "from", +    actions   = from, +    arguments = "string" +} +  function references.define(prefix,reference,list)      local d = defined[prefix] if not d then d = { } defined[prefix] = d end      d[reference] = list @@ -713,86 +778,17 @@ function references.reset(prefix,reference)      end  end -commands.definereference = references.define -commands.resetreference  = references.reset - --- \primaryreferencefoundaction --- \secondaryreferencefoundaction --- \referenceunknownaction - --- t.special t.operation t.arguments t.outer t.inner - --- to what extend do we check the non prefixed variant +implement { +    name      = "definereference", +    actions   = references.define, +    arguments = { "string", "string", "string" } +} --- local strict = false --- --- local function resolve(prefix,reference,args,set) -- we start with prefix,reference ---     if reference and reference ~= "" then ---         if not set then ---             set = { prefix = prefix, reference = reference } ---         else ---             if not set.reference then set.reference = reference end ---             if not set.prefix    then set.prefix    = prefix    end ---         end ---         local r = settings_to_array(reference) ---         for i=1,#r do ---             local ri = r[i] ---             local d ---             if strict then ---                 d = defined[prefix] or defined[""] ---                 d = d and d[ri] ---             else ---                 d = defined[prefix] ---                 d = d and d[ri] ---                 if not d then ---                     d = defined[""] ---                     d = d and d[ri] ---                 end ---             end ---             if d then ---                 resolve(prefix,d,nil,set) ---             else ---                 local var = splitreference(ri) ---                 if var then ---                     var.reference = ri ---                     local vo, vi = var.outer, var.inner ---                     if not vo and vi then ---                         -- to be checked ---                         if strict then ---                             d = defined[prefix] or defined[""] ---                             d = d and d[vi] ---                         else ---                             d = defined[prefix] ---                             d = d and d[vi] ---                             if not d then ---                                 d = defined[""] ---                                 d = d and d[vi] ---                             end ---                         end ---                         -- ---                         if d then ---                             resolve(prefix,d,var.arguments,set) -- args can be nil ---                         else ---                             if args then var.arguments = args end ---                             set[#set+1] = var ---                         end ---                     else ---                         if args then var.arguments = args end ---                         set[#set+1] = var ---                     end ---                     if var.has_tex then ---                         set.has_tex = true ---                     end ---                 else ---                 --  report_references("funny pattern %a",ri) ---                 end ---             end ---         end ---         return set ---     else ---         return { } ---     end --- end +implement { +    name      = "resetreference", +    actions   = references.reset, +    arguments = { "string", "string" } +}  setmetatableindex(defined,"table") @@ -847,11 +843,11 @@ end  references.currentset = nil -function commands.setreferenceoperation(k,v) +local function setreferenceoperation(k,v)      references.currentset[k].operation = v  end -function commands.setreferencearguments(k,v) +local function setreferencearguments(k,v)      references.currentset[k].arguments = v  end @@ -872,7 +868,22 @@ function references.expandcurrent() -- todo: two booleans: o_has_tex& a_has_tex      end  end -commands.expandcurrentreference = references.expandcurrent -- for the moment the same +implement { +    name      = "expandcurrentreference", +    actions   = references.expandcurrent +} + +implement { +    name      = "setreferenceoperation", +    actions   = setreferenceoperation, +    arguments = { "integer", "string" } +} + +implement { +    name      = "setreferencearguments", +    actions   = setreferencearguments, +    arguments = { "integer", "string" } +}  local externals = { } @@ -1164,7 +1175,7 @@ local useproduct = commands.useproduct  if useproduct then -    function commands.useproduct(product) +    local function newuseproduct(product)          useproduct(product)          if texconditionals.autocrossfilereferences then              local component = justacomponent() @@ -1177,6 +1188,13 @@ if useproduct then          end      end +    implement { +        name      = "useproduct", +        actions   = newuseproduct, +        arguments = "string", +        overload  = true, +    } +  end  -- productdata.firstsection.numberdata.numbers @@ -1702,7 +1720,7 @@ references.identify = identify  local unknowns, nofunknowns, f_valid = { }, 0, formatters["[%s][%s]"] -function references.valid(prefix,reference,highlight,newwindow,layer) +function references.valid(prefix,reference,specification)      local set, bug = identify(prefix,reference)      local unknown = bug or #set == 0      if unknown then @@ -1717,18 +1735,28 @@ function references.valid(prefix,reference,highlight,newwindow,layer)              unknowns[str] = u + 1          end      else -        set.highlight    = highlight -        set.newwindow    = newwindow -        set.layer        = layer +        set.highlight    = specification.highlight +        set.newwindow    = specification.newwindow +        set.layer        = specification.layer          currentreference = set[1]      end      -- we can do the expansion here which saves a call      return not unknown  end -function commands.doifelsereference(prefix,reference,highlight,newwindow,layer) -    commands.doifelse(references.valid(prefix,reference,highlight,newwindow,layer)) -end +implement { +    name      = "doifelsereference", +    actions   = { references.valid, commands.doifelse }, +    arguments = { +        "string", +        "string", +        { +            { "highlight", "boolean" }, +            { "newwindow", "boolean" }, +            { "layer" }, +        } +    } +}  function references.reportproblems() -- might become local      if nofunknowns > 0 then @@ -1847,13 +1875,75 @@ implement {  --     arguments = "integer",  -- } -function references.setandgetattribute(kind,prefix,tag,data,view) -- maybe do internal automatically here -    local attr = references.set(kind,prefix,tag,data) and setinternalreference(prefix,tag,nil,view) or unsetvalue +function references.setandgetattribute(prefix,tag,data) -- maybe do internal automatically here +    local attr = unsetvalue +    local mdat = data.metadata +    local rdat = data.references +    if mdat and rdat then +        if not rdat.section then +            rdat.section = structures.sections.currentid() +        end +        local ndat = data.numberdata +        if ndat then +            local numbers = ndat.numbers +            if type(numbers) == "string" then +                ndat.numbers = structures.counters.compact(numbers) +            end +            data.numberdata = structures.helpers.simplify(ndat) +        end +        local pdat = data.prefixdata +        if pdat then +            data.prefixdata = structures.helpers.simplify(pdat) +        end +        local udat = data.userdata +        if type(udat) == "string"  then +            data.userdata = structures.helpers.touserdata(udat) +        end +        local done = references.set(mdat.kind or "page",prefix,tag,data) +        if done then +            attr = setinternalreference(prefix,tag,nil,rdat.view) or unsetvalue +        end +    end      texsetcount("lastdestinationattribute",attr)      return attr  end -commands.setreferenceattribute = references.setandgetattribute +implement { +    name      = "setreferenceattribute", +    actions   = references.setandgetattribute, +    arguments = { +        "string", +        "string", +        { +            { +                "references", { +                    { "internal", "integer" }, +                    { "block" }, +                    { "view" }, +                }, +            }, +            { +                "metadata", { +                    { "kind" }, +                    { "xmlroot" }, +                    { "catcodes", "integer" }, +                }, +            }, +            { +                "prefixdata", { "*" } +            }, +            { +                "numberdata", { "*" } +            }, +            { +                "entries", { "*" } +            }, +            { +                "userdata" +            } +        } +    } +}  function references.getinternallistreference(n) -- n points into list (todo: registers)      local l = lists.collected[n] @@ -1861,11 +1951,11 @@ function references.getinternallistreference(n) -- n points into list (todo: reg      return i and destinationattributes[i] or 0  end -function commands.getinternallistreference(n) -- this will also be a texcount -    local l = lists.collected[n] -    local i = l and l.references.internal -    context(i and destinationattributes[i] or 0) -end +implement { +    name      = "getinternallistreference", +    actions   = { references.getinternallistreference, context }, +    arguments = "integer" +}  -- @@ -1874,12 +1964,11 @@ function references.getcurrentmetadata(tag)      return data and data.metadata and data.metadata[tag]  end -function commands.getcurrentreferencemetadata(tag) -    local data = references.getcurrentmetadata(tag) -    if data then -        context(data) -    end -end +implement { +    name      = "getcurrentreferencemetadata", +    actions   = { references.getcurrentmetadata, context }, +    arguments = "string", +}  local function currentmetadata(tag)      local data = currentreference and currentreference.i @@ -1889,15 +1978,19 @@ end  references.currentmetadata = currentmetadata  local function getcurrentprefixspec(default) -    -- todo: message -    return currentmetadata("kind") or "?", currentmetadata("name") or "?", default or "?" +    return +        currentmetadata("kind") or "?", +        currentmetadata("name") or "?", +        default                 or "?"  end  references.getcurrentprefixspec = getcurrentprefixspec -function commands.getcurrentprefixspec(default) -    ctx_getreferencestructureprefix(getcurrentprefixspec(default)) -end +implement { +    name      = "getcurrentprefixspec", +    actions   = { getcurrentprefixspec, context }, -- returns 3 arguments +    arguments = "string", +}  local genericfilters = { }  local userfilters    = { } @@ -1916,7 +2009,7 @@ local function filterreference(name,...) -- number page title ...      if data then          if name == "realpage" then              local cs = references.analyze() -- normally already analyzed but also sets state -            context(tonumber(cs.realpage) or 0) -- todo, return and in command namespace +            context(tonumber(cs.realpage) or 0)          else -- assumes data is table              local kind = type(data) == "table" and data.metadata and data.metadata.kind              if kind then @@ -1942,21 +2035,27 @@ local function filterreference(name,...) -- number page title ...  end  local function filterreferencedefault() -    return filterreference("default",getcurrentprefixspec(v_default)) +    return filterreference("default",getcurrentprefixspec("default"))  end  references.filter        = filterreference  references.filterdefault = filterreferencedefault -commands.filterreference        = filterreference -commands.filterdefaultreference = filterreferencedefault +implement { +    name      = "filterreference", +    actions   = filterreference, +    arguments = "string", +} -function commands.currentreferencedefault(tag) -    if not tag then -        tag = "default" -    end -    filterreference(tag,context_delayed(getcurrentprefixspec(tag))) -end +implement { +    name      = "filterdefaultreference", +    actions   = filterreference, +    arguments = { +        "string",    -- 'default' +        { { "*" } }, -- prefixspec +        { { "*" } }, -- numberspec +    } +}  function genericfilters.title(data)      if data then @@ -2235,46 +2334,50 @@ function references.analyze(actions,position,spread)      return actions  end --- function commands.referencepagestate(actions) ---     if not actions then ---         actions = references.currentset ---     end ---     if not actions then ---         context(0) ---     else ---         if not actions.pagestate then ---             references.analyze(actions) -- delayed unless explicitly asked for ---         end ---         context(actions.pagestate) ---     end --- end - -function commands.referencepagestate(position,detail,spread) +local function referencepagestate(position,detail,spread)      local actions = references.currentset      if not actions then -        context(0) +        return 0      else          if not actions.pagestate then              references.analyze(actions,position,spread) -- delayed unless explicitly asked for          end          local pagestate = actions.pagestate          if detail then -            context(pagestate) +            return pagestate          elseif pagestate == 4 then -            context(2) -- compatible +            return 2 -- compatible          elseif pagestate == 5 then -            context(3) -- compatible +            return 3 -- compatible          else -            context(pagestate) +            return pagestate          end      end  end -function commands.referencerealpage(actions) +implement { +    name      = "referencepagestate", +    actions   = { referencepagestate, context }, +    arguments = "string" +} + +implement { +    name      = "referencepagedetail", +    actions   = { referencepagestate, context }, +    arguments = { "string", "boolean", "boolean" } +} + +local function referencerealpage(actions)      actions = actions or references.currentset -    context(not actions and 0 or actions.realpage or setreferencerealpage(actions)) +    return not actions and 0 or actions.realpage or setreferencerealpage(actions)  end +implement { +    name      = "referencerealpage", +    actions   = { referencerealpage, context }, +    arguments = "string" +} +  local plist, nofrealpages  local function realpageofpage(p) -- the last one counts ! @@ -2515,24 +2618,36 @@ function references.export(usedname) end  function references.import(usedname) end  function references.load  (usedname) end -commands.exportreferences = references.export +implement { name = "exportreferences", actions =references.export }  -- better done here .... we don't insert/remove, just use a pointer  local prefixstack = { "" }  local prefixlevel = 1 -function commands.pushreferenceprefix(prefix) +local function pushreferenceprefix(prefix)      prefixlevel = prefixlevel + 1      prefixstack[prefixlevel] = prefix -    context(prefix) +    return prefix  end -function commands.popreferenceprefix() +local function popreferenceprefix()      prefixlevel = prefixlevel - 1      if prefixlevel > 0 then -        context(prefixstack[prefixlevel]) +        return prefixstack[prefixlevel]      else          report_references("unable to pop referenceprefix") +        return ""      end  end + +implement { +    name      = "pushreferenceprefix", +    actions   = { pushreferenceprefix, context }, -- we can use setmacro +    arguments = "string", +} + +implement { +    name      = "popreferenceprefix", +    actions   = { popreferenceprefix, context }, -- we can use setmacro +} diff --git a/tex/context/base/strc-ref.mkvi b/tex/context/base/strc-ref.mkvi index 3c4cf80a5..678f9ca4f 100644 --- a/tex/context/base/strc-ref.mkvi +++ b/tex/context/base/strc-ref.mkvi @@ -143,7 +143,7 @@  \newcount\lastdestinationattribute  \def\dofinishfullreference#prefix#label{\normalexpanded{\ctxlatecommand{enhancereference("#prefix","#label")}}} -\def\dofinishtextreference#prefix#label{\normalexpanded{\ctxlatecommand{enhancereference("#prefix","#label",{})}}} +\def\dofinishtextreference#prefix#label{\normalexpanded{\ctxlatecommand{enhancereference("#prefix","#label")}}}  \let\dofinishpagereference\dofinishfullreference  \let\dofinishuserreference\dofinishfullreference @@ -216,30 +216,34 @@         % beware, the structures.references.set writes a         \setnextinternalreference         \strc_references_start_destination_nodes -         \ctxcommand{setreferenceattribute("\currentreferencekind", "\referenceprefix","\currentreferencelabels", -           { -                references = { -                    internal = \nextinternalreference, -                    block    = "\currentsectionblock", -                    section  = structures.sections.currentid(), -                }, -                metadata = { % we could assume page to have no metadata -                    kind = "#kind",  % \currentreferencekind -                    \ifx\currentreferencekind\s!page\else -                        catcodes = \the\catcodetable, -                        xmlroot  = \ifx\currentreferencecoding\s!xml "\xmldocument"\else nil\fi, % only useful when text -                    \fi -                }, +       \clf_setreferenceattribute +            {\referenceprefix}% +            {\currentreferencelabels}% +            {% +                references {% +                    internal \nextinternalreference +                    block    {\currentsectionblock}% +                    view     {\interactionparameter\c!focus}% +                }% +                metadata {% +                    kind     {\currentreferencekind}% +            \ifx\currentreferencekind\s!page\else +                \ifx\currentreferencecoding\s!xml +                    xmlroot  {\xmldocument}% +                \fi +                    catcodes \catcodetable +            \fi +                }%              \ifx\currentreferencedata\empty\else -                entries = { -                    text = \!!bs\currentreferencedata\!!es -                }, +                entries {% +                    text {\currentreferencedata}% +                }%              \fi              \ifx\currentreferenceuserdata\empty\else -                userdata = structures.helpers.touserdata(\!!bs\detokenize{#userdata}\!!es) +                userdata {\detokenize{#userdata}}%              \fi -            },"\interactionparameter\c!focus") -           }% +            }% +       \relax         \strc_references_stop_destination_nodes       \fi     \else @@ -265,19 +269,21 @@         \lastdestinationattribute\attributeunsetvalue       \else         \strc_references_start_destination_nodes -\setnextinternalreference -       \ctxcommand{setreferenceattribute("\s!page", "\referenceprefix","\currentreferencelabels", -            { -                references = { -                    internal = \nextinternalreference, -                    block    = "\currentsectionblock", -                    section  = structures.sections.currentid(), -                }, -                metadata = { -                    kind = "page", -                }, -            },"\interactionparameter\c!focus") -         }% +       \setnextinternalreference +       \clf_setreferenceattribute +            {\referenceprefix}% +            {\currentreferencelabels}% +            {% +                references {% +                    internal \nextinternalreference +                    block    {\currentsectionblock}% +                    view     {\interactionparameter\c!focus}% +                }% +                metadata {% +                    kind {page}% +                }% +            }% +       \relax         \strc_references_stop_destination_nodes       \fi     \else @@ -291,28 +297,28 @@       \setnextinternalreference       \edef\m_strc_references_user{#user}%       \edef\m_strc_references_text{#text}% -     \ctxcommand{setreferenceattribute("\s!full", "\referenceprefix","#labels", -         { -              references = { -                  internal = \nextinternalreference, -                  block    = "\currentsectionblock", -                  section  = structures.sections.currentid(), -              }, -              metadata = { -                  kind = "\s!full", -              }, -          \ifx\m_strc_references_text\empty \else -              entries = { -                  text = \!!bs\m_strc_references_text\!!es -              }, -          \fi -          \ifx\m_strc_references_user\empty \else -              userdata = { -                  \m_strc_references_user -              } -          \fi -          },"\interactionparameter\c!focus") -         }% +     \clf_setreferenceattribute +        {\referenceprefix}% +        {#labels}% +        {% +            references {% +                internal \nextinternalreference +                block    {\currentsectionblock}% +                view     {\interactionparameter\c!focus}% +            }% +            metadata {% +                kind {\s!full}% +            }% +        \ifx\m_strc_references_text\empty \else +            entries {% +                text {\m_strc_references_text}% +            }% +        \fi +        \ifx\m_strc_references_user\empty \else +            userdata {\m_strc_references_user}% +        \fi +        }% +     \relax       \strc_references_stop_destination_nodes     \else       \setbox\b_strc_destination_nodes\emptyhbox @@ -368,17 +374,19 @@  \def\strc_references_set_simple_page_reference#label%    {\iflocation       \strc_references_start_destination_nodes -       \ctxcommand{setreferenceattribute("\s!page", "\referenceprefix","#label", -          { -            references = { -            %   block    = "\currentsectionblock", -            %   section  = structures.sections.currentid(), -            }, -            metadata = { % we could assume page to have no metadata -                kind = "\s!page", -            }, -          },"\interactionparameter\c!focus") -       }% +     \clf_setreferenceattribute +        {\referenceprefix}% +        {#label}% +        {% +            references {% +                block {\currentsectionblock}% +                view  {\interactionparameter\c!focus}% +            }% +            metadata {% +                kind {\s!page}% +            }% +        }% +     \relax       \strc_references_stop_destination_nodes       \xdef\currentdestinationattribute{\number\lastdestinationattribute}%     \else @@ -388,7 +396,15 @@  \def\strc_references_get_simple_page_reference#label%    {\iflocation -     \ctxcommand{injectreference("\referenceprefix","#label",\number\ht\strutbox,\number\dp\strutbox,\extrareferencearguments)}% +     \clf_injectreference +        {\referenceprefix}% +        {#label}% +        {% +            height \ht\strutbox +            depth  \dp\strutbox +            \extrareferencearguments +        }% +     \relax       \xdef\currentreferenceattribute{\number\lastreferenceattribute}%     \else       \xdef\currentreferenceattribute{\number\attributeunsetvalue}% @@ -528,9 +544,6 @@  \newcount\referencehastexstate % set in backend -\def\referencepagestate{\ctxcommand{referencepagestate()}} -\def\referencerealpage {\ctxcommand{referencerealpage ()}} -  % referencepagestate:  %  % 0 = no page ref, 1=same page, 2=before, 3=after @@ -618,13 +631,13 @@    {\dodoubleempty\strc_references_define_reference}  \def\strc_references_define_reference[#name][#specification]% -  {\ctxcommand{definereference("\referenceprefix","#name",\!!bs\detokenize{#specification}\!!es)}} +  {\clf_definereference{\referenceprefix}{#name}{\detokenize{#specification}}}  \unexpanded\def\resetreference[#name]% -  {\ctxcommand{resetreference("\referenceprefix","#name")}} +  {\clf_resetreference{\referenceprefix}{#name}}  \def\setpagereference#name#specification% hm,. low level ? -  {\ctxcommand{definereference("","#name",\!!bs\v!page(\luaescapestring{#specification})\!!es)}} +  {\clf_definereference{}{#name}{\v!page(\detokenize{#specification}}} % is detokenize needed here?  %D Chained references are defined as:  %D @@ -654,13 +667,13 @@  \newconditional\gotonewwindow \setfalse\gotonewwindow  \def\expandtexincurrentreference % will happen in lua some time -  {\ifcase\referencehastexstate\else\ctxcommand{expandcurrentreference()}\fi} +  {\ifcase\referencehastexstate\else\clf_expandcurrentreference\fi} -\def\expandreferenceoperation#tag#content{\ctxcommand{setreferenceoperation(#tag,\!!bs#content\!!es)}} -\def\expandreferencearguments#tag#content{\ctxcommand{setreferencearguments(#tag,\!!bs#content\!!es)}} +\def\expandreferenceoperation#tag#content{\clf_setreferenceoperation#tag{#content}} +\def\expandreferencearguments#tag#content{\clf_setreferencearguments#tag{#content}} -\def\doifreferencefoundelse#labels#yes#nop% -  {\ctxcommand{doifelsereference("\referenceprefix",\!!bs#labels\!!es,\luaconditional\highlighthyperlinks,\luaconditional\gotonewwindow)}% +\def\doifreferencefoundelse#label#yes#nop% +  {\clf_doifelsereference{\referenceprefix}{#label}{\extrareferencearguments}%       {\expandtexincurrentreference        #yes}%       {#nop}} @@ -770,10 +783,10 @@    {\global\advance\locationcount\plusone}  \def\setnextinternalreferences#kind#name% plural -  {\ctxcommand{setnextinternalreference("#kind","#name")}} +  {\clf_setnextinternalreference{#kind}{#name}}  \def\getinternalorderreference#kind#name% -  {\ctxcommand{currentreferenceorder("#kind","#name")}} +  {\clf_currentreferenceorder{#kind}{#name}}  \def\thisissomeinternal#kind#name% only for old time sake    {\begingroup @@ -840,7 +853,7 @@  \appendtoks      \edef\p_export{\referencingparameter\c!export}%      \ifx\p_export\v!yes -      \ctxcommand{exportreferences()}% +      \clf_exportreferences      \fi  \to \everygoodbye @@ -855,16 +868,16 @@  %   {\popmacro\referenceprefix}  \unexpanded\def\globalpushreferenceprefix#prefix% -  {\xdef\referenceprefix{\ctxcommand{pushreferenceprefix("#prefix")}}} +  {\xdef\referenceprefix{\clf_pushreferenceprefix{#prefix}}}  \unexpanded\def\globalpopreferenceprefix -  {\xdef\referenceprefix{\ctxcommand{popreferenceprefix()}}} +  {\xdef\referenceprefix{\clf_popreferenceprefix}}  \unexpanded\def\pushreferenceprefix#prefix% -  {\edef\referenceprefix{\ctxcommand{pushreferenceprefix("#prefix")}}} +  {\edef\referenceprefix{\clf_pushreferenceprefix{#prefix}}}  \unexpanded\def\popreferenceprefix -  {\edef\referenceprefix{\ctxcommand{popreferenceprefix()}}} +  {\edef\referenceprefix{\clf_popreferenceprefix}}  \def\m_strc_references_prefix_yes{+}  \def\m_strc_references_prefix_nop{-} @@ -954,15 +967,15 @@      \ifdefined\over  \let\normalmathover \over  \unexpanded\def\over {\mathortext\normalmathover \strc_references_about} \else \let\over \strc_references_about \fi  \to \everydump -           \def\filterreference  #key{\ctxcommand{filterreference("#key")}} % no checking, expanded -\unexpanded\def\getreferenceentry#key{\ctxcommand{filterreference("#key")}} % no checking, unexpanded +           \def\filterreference  #key{\clf_filterreference{#key}} % no checking, expanded +\unexpanded\def\getreferenceentry#key{\clf_filterreference{#key}} % no checking, unexpanded -\def\currentreferencenumber  {\filterreference{number}} -\def\currentreferencepage    {\filterreference{page}} -\def\currentreferencetitle   {\filterreference{title}} -\def\currentreferencetext    {\filterreference{text}} -\def\currentreferencedefault {\filterreference{default}} -\def\currentreferencerealpage{\filterreference{realpage}} +\def\currentreferencenumber  {\clf_filterreference{number}} +\def\currentreferencepage    {\clf_filterreference{page}} +\def\currentreferencetitle   {\clf_filterreference{title}} +\def\currentreferencetext    {\clf_filterreference{text}} +\def\currentreferencedefault {\clf_filterreference{default}} +\def\currentreferencerealpage{\clf_filterreference{realpage}}  %D The most straightforward way of retrieving references is  %D using \type{\ref}. @@ -972,7 +985,7 @@  \def\strc_references_get_reference[#key][#label]% #key = number page title text default realpage ...    {\ifsecondargument -     \doifreferencefoundelse{#label}{\ctxcommand{filterreference("#key")}}\dummyreference +     \doifreferencefoundelse{#label}{\clf_filterreference{#key}}\dummyreference     \else       \dummyreference     \fi} @@ -1007,42 +1020,6 @@  %D ... \atpage[someref] ...  %D \stoptyping -% % 0 = unknown -% % 1 = same -% % 2 = before -% % 3 = after -% -% \def\strc_references_by_reference_page_state#unknown#before#current#after% -%   {\ifcase\referencepagestate\space#unknown\or#current\or#before\or#after\fi} -% -% % \unexpanded\def\somewhere#backward#foreward#dummy[#label]% #dummy gobbles space around #foreward -% %   {\doifreferencefoundelse{#label}% usage needs checking (useless) -% %      {\goto{\strc_references_by_reference_page_state{#label}{#backward}{}{#foreward}}[#label]} -% %      {[#label]}} -% % -% % better: -% -% \unexpanded\def\somewhere#backward#foreward#dummy[#label]% #dummy gobbles space around #foreward -%   {\doifreferencefoundelse{#label}% -%      {\strc_references_by_reference_page_state{#label}{\goto{#backward}[#label]}{}{\goto{#foreward}[#label]}} -%      {[#label]}} -% -% \unexpanded\def\atpage[#label]% todo -%   {\doifreferencefoundelse{#label}% kind of inefficient as \goto also analyzes -%      {\goto -%         {\strc_references_by_reference_page_state -%            {\labeltexts\v!page\dummyreference}% -%            {\labeltext\v!hencefore}% -%            {\labeltexts\v!atpage\currentreferencepage}% -%            {\labeltext\v!hereafter}}% -%            [#label]} -%      {[#label]}} -% -% \unexpanded\def\referencesymbol -%   {\hbox{\strut\high -%      {\setupsymbolset[\interactionparameter\c!symbolset]% -%       \symbol[\strc_references_by_reference_page_state\v!somewhere\v!nowhere\v!previous\v!next]}}} -  % standard      detail  %  % 0 = unknown   unknown @@ -1085,8 +1062,20 @@  \setupreferencing    [\c!doublesided=\v!yes] -\def\referencepagestate {\numexpr\ctxcommand{referencepagestate("rst::\number\nofreferencestates")}\relax} -\def\referencepagedetail{\numexpr\ctxcommand{referencepagestate("rst::\number\nofreferencestates",true\ifconditional\pagestatespread\ifdoublesided,\s!true\fi\fi)}\relax} +\def\referencepagestate +  {\numexpr\clf_referencepagestate +     {rst::\number\nofreferencestates}% +   \relax} + +\def\referencepagedetail +   {\numexpr\clf_referencepagestate +      {rst::\number\nofreferencestates}% +      true % +      \ifconditional\pagestatespread false\ifdoublesided true\else false\fi\fi +    \relax} + +\def\referencerealpage +  {\clf_referencerealpage}  \unexpanded\def\tracedpagestate    {{\blue\tttf(\ifcase\referencepagedetail unknown\or same\or previous\or next\or above\or below\else unknown\fi)}} @@ -1268,8 +1257,15 @@        \goto{\referencesequence}[#label]}%     \strc_references_stop_goto} -\unexpanded\def\strc_references_in{\strc_references_start_goto\let\currentreferencecontent\currentreferencedefault\strc_references_pickup_goto} -\unexpanded\def\strc_references_at{\strc_references_start_goto\let\currentreferencecontent\currentreferencepage   \strc_references_pickup_goto} +\unexpanded\def\strc_references_in +  {\strc_references_start_goto +   \let\currentreferencecontent\currentreferencedefault +   \strc_references_pickup_goto} + +\unexpanded\def\strc_references_at +  {\strc_references_start_goto +   \let\currentreferencecontent\currentreferencepage +   \strc_references_pickup_goto}  %D \macros  %D   {definereferenceformat} @@ -1380,7 +1376,7 @@  \def\autoreferencelabeltextflag{*} % a proper key like 'auto' or 'name' can clash with a label key  \unexpanded\def\autoreferencelabeltext -  {\ctxcommand{getcurrentreferencemetadata("name")}} +  {\clf_getcurrentreferencemetadata{name}}  % \starttext  %     \definereferenceformat[inxx]  [left=(,right=),text=txt] @@ -1425,7 +1421,9 @@  \newconditional\uselocationstrut \settrue\uselocationstrut  \def\extrareferencearguments -  {\luaconditional\highlighthyperlinks,\luaconditional\gotonewwindow,"\currentviewerlayer"} +  {highlight \luaconditional\highlighthyperlinks\space +   newwindow \luaconditional\gotonewwindow\space +   layer     {\currentviewerlayer}}  \unexpanded\def\directgoto    {\ifconditional\uselocationstrut @@ -1457,7 +1455,15 @@     \attribute\referenceattribute\attributeunsetvalue     \global\lastsavedreferenceattribute\attributeunsetvalue     \iflocation -     \ctxcommand{injectreference("\referenceprefix","#label",\number\ht\strutbox,\number\dp\strutbox,\extrareferencearguments)}% +     \clf_injectreference +        {\referenceprefix}% +        {#label}% +        {% +            height \ht\strutbox +            depth  \dp\strutbox +            \extrareferencearguments +        }% +     \relax       \setlocationattributes       \setstrut % can be option       \global\lastsavedreferenceattribute\lastreferenceattribute @@ -1476,7 +1482,15 @@     \global\lastsavedreferenceattribute\attributeunsetvalue     \attribute\referenceattribute\attributeunsetvalue     \iflocation -     \ctxcommand{injectreference("\referenceprefix","#label",\number\dimexpr\interactionparameter\c!height\relax,\number\dimexpr\interactionparameter\c!depth\relax,\extrareferencearguments)}% +     \clf_injectreference +        {\referenceprefix}% +        {#label}% +        {% +            height \dimexpr\interactionparameter\c!height\relax +            depth  \dimexpr\interactionparameter\c!depth \relax +            \extrareferencearguments +        }% +     \relax       \setlocationattributes       \attribute\referenceattribute\lastreferenceattribute       \global\lastsavedreferenceattribute\lastreferenceattribute @@ -1495,9 +1509,12 @@     \global\lastsavedreferenceattribute\attributeunsetvalue     \attribute\referenceattribute\attributeunsetvalue     \iflocation -     \ctxcommand{doifelsereference("\referenceprefix","#label",\extrareferencearguments)}% +     \clf_doifelsereference{\referenceprefix}{#label}{\extrareferencearguments}%         {\expandtexincurrentreference -        \ctxcommand{injectcurrentreference(\number\ht\strutbox,\number\dp\strutbox)}% +        \clf_injectcurrentreference_dimensions +          \ht\strutbox +          \dp\strutbox +        \relax          \setlocationattributes          \setstrut % can be option          \global\lastsavedreferenceattribute\lastreferenceattribute @@ -1516,7 +1533,9 @@    {\dontleavehmode     \begingroup     \iflocation -     \ctxcommand{doifelsereference("\referenceprefix","#label",\extrareferencearguments)}{\expandafter\startgoto_yes}{\expandafter\startgoto_nop}% +     \clf_doifelsereference{\referenceprefix}{#label}{\extrareferencearguments}% +       {\expandafter\startgoto_yes}% +       {\expandafter\startgoto_nop}%     \else       \expandafter\startgoto_nop     \fi} @@ -1529,7 +1548,10 @@  \unexpanded\def\startgoto_yes    {\expandtexincurrentreference -   \ctxcommand{injectcurrentreference(\number\ht\strutbox,\number\dp\strutbox)}% +   \clf_injectcurrentreference_dimensions +     \ht\strutbox +     \dp\strutbox +   \relax     \setlocationattributes     \setstrut % can be option     \global\lastsavedreferenceattribute\lastreferenceattribute @@ -1547,9 +1569,12 @@     \global\lastsavedreferenceattribute\attributeunsetvalue     \attribute\referenceattribute\attributeunsetvalue     \iflocation -     \ctxcommand{doifelsereference("\referenceprefix","#label",\extrareferencearguments)}% +     \clf_doifelsereference{\referenceprefix}{#label}{\extrareferencearguments}%         {\expandtexincurrentreference -        \ctxcommand{injectcurrentreference(\number\dimexpr\interactionparameter\c!height\relax,\number\dimexpr\interactionparameter\c!depth\relax)}% +        \clf_injectcurrentreference_dimensions +          \dimexpr\interactionparameter\c!height\relax +          \dimexpr\interactionparameter\c!depth \relax +        \relax          \setlocationattributes          \global\lastsavedreferenceattribute\lastreferenceattribute          \attribute\referenceattribute\lastreferenceattribute @@ -1568,7 +1593,11 @@     \global\lastsavedreferenceattribute\attributeunsetvalue     \attribute\referenceattribute\attributeunsetvalue     \iflocation -     \ctxcommand{injectreference("\referenceprefix","#label",nil,nil,\extrareferencearguments)}% +     \clf_injectreference +       {\referenceprefix}% +       {#label}% +       {\extrareferencearguments}% +     \relax       \setlocationattributes       \global\lastsavedreferenceattribute\lastreferenceattribute       \dostarttagged\t!link\empty @@ -1585,7 +1614,11 @@     \global\lastsavedreferenceattribute\attributeunsetvalue     \attribute\referenceattribute\attributeunsetvalue     \iflocation -     \ctxcommand{injectreference("\referenceprefix","#label",nil,nil,\extrareferencearguments)}% +     \clf_injectreference +       {\referenceprefix}% +       {#label}% +       {\extrareferencearguments}% +     \relax       \setlocationcolorspec{#resolver}% no consequence for strut       \global\lastsavedreferenceattribute\lastreferenceattribute       \dostarttagged\t!link\empty @@ -1602,7 +1635,11 @@     \global\lastsavedreferenceattribute\attributeunsetvalue     \attribute\referenceattribute\attributeunsetvalue     \iflocation -     \ctxcommand{injectreference("\referenceprefix","#label",nil,nil,\extrareferencearguments)}% +     \clf_injectreference +       {\referenceprefix}% +       {#label}% +       {\extrareferencearguments}% +     \relax       \global\lastsavedreferenceattribute\lastreferenceattribute       \dostarttagged\t!link\empty       \hbox attr \referenceattribute \lastreferenceattribute {#content}% @@ -1618,9 +1655,9 @@     \global\lastsavedreferenceattribute\attributeunsetvalue     \attribute\referenceattribute\attributeunsetvalue     \iflocation -     \ctxcommand{doifelsereference("\referenceprefix","#label",\extrareferencearguments)}% +     \clf_doifelsereference{\referenceprefix}{#label}{\extrareferencearguments}%         {\expandtexincurrentreference -        \ctxcommand{injectcurrentreference(nil,nil)}% +        \clf_injectcurrentreference          \setlocationattributes          \global\lastsavedreferenceattribute\lastreferenceattribute          \dostarttagged\t!link\empty @@ -1640,8 +1677,8 @@     \ht\scratchbox#height%     \global\lastsavedreferenceattribute\attributeunsetvalue     \attribute\referenceattribute\attributeunsetvalue -   \ctxcommand{doifelsereference("\referenceprefix","#label",\extrareferencearguments)}% -     {\ctxcommand{injectcurrentreference(nil,nil)}% +   \clf_doifelsereference{\referenceprefix}{#label}{\extrareferencearguments}% +     {\clf_injectcurrentreference        \global\lastsavedreferenceattribute\lastreferenceattribute        \hbox attr \referenceattribute \lastreferenceattribute {\box\scratchbox}}       {\box\scratchbox}% @@ -1703,13 +1740,13 @@  \let\useexternaldocument\usefile  \def\strc_references_use_url[#label][#url][#file][#description]% -  {\ctxcommand{useurl("#label",\!!bs\detokenize{#url}\!!es,\!!bs\detokenize{#file}\!!es,\!!bs\detokenize{#description}\!!es)}} +  {\clf_useurl{#label}{\detokenize{#url}}{\detokenize{#file}}{\detokenize{#description}}}  \def\strc_references_use_file[#label][#file][#description]% -  {\ctxcommand{usefile("#label",\!!bs\detokenize{#file}\!!es,\!!bs\detokenize{#description}\!!es)}} +  {\clf_usefile{#label}{\detokenize{#file}}{\detokenize{#description}}} -\def\doifurldefinedelse #label{\ctxcommand{doifurldefinedelse ("#label")}} -\def\doiffiledefinedelse#label{\ctxcommand{doiffiledefinedelse("#label")}} +\def\doifurldefinedelse #label{\clf_doifurldefinedelse {#label}} +\def\doiffiledefinedelse#label{\clf_doiffiledefinedelse{#label}}  %D \macros  %D   {url,setupurl} @@ -1740,7 +1777,7 @@    {\dontleavehmode     \begingroup     \useurlstyleandcolor\c!style\c!color -   \hyphenatedurl{\ctxcommand{geturl("#label")}}% +   \hyphenatedurl{\clf_geturl{#label}}%     \endgroup}  %D This macro is hooked into a support macro, and thereby @@ -1771,7 +1808,7 @@  \def\strc_references_do_special_from[#label]%    {\dontleavehmode -   \goto{\ctxcommand{from("#label")}}[fileorurl(#label)]} +   \goto{\clf_from{#label}}[fileorurl(#label)]}  \def\dofromurldescription#content% called at the lua end    {#content} @@ -1816,13 +1853,13 @@    {\dotripleargument\strc_references_define_program}  \def\strc_references_define_program[#name][#program][#description]% -  {\ctxcommand{defineprogram("#name",\!!bs#program\!!es,\!!bs#description\!!es)}} +  {\clf_defineprogram{#name}{#program}{#description}}  \def\program[#name]% incompatible, more consistent, hardy used anyway    {\dontleavehmode     \begingroup     \useprogramsstyleandcolor\c!style\c!color -   \ctxcommand{getprogram("#name","\directprogramsparameter\c!alternative","\directprogramsparameter\c!space")}% +   \clf_getprogram{#name}%     \endgroup}  %D As we can see, we directly use the special reference @@ -2046,36 +2083,25 @@  \installcorenamespace{referencingprefix} -% \def\getreferencestructureprefix#kind#name#category% name will change -%   {{ -%         prefix        =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefix", -%         separatorset  =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixseparatorset", -%         conversion    =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixconversion", -%         conversionset =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixconversionset", -%         set           =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixset", -%         segments      =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixsegments", -%         connector     = \!!bs\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixconnector\!!es, -%   }} -  \def\getreferencestructureprefix#kind#name#category% name will change    {{ -        prefix        =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefix", -        separatorset  =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixseparatorset", -        conversion    =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixconversion", -        conversionset =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixconversionset", -        starter       = \!!bs\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixstarter\!!es, -        stopper       = \!!bs\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixstopper\!!es, -        set           =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixset", -        segments      =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixsegments", -        connector     = \!!bs\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixconnector\!!es, -  }, +        prefix        {\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefix}% +        separatorset  {\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixseparatorset}% +        conversion    {\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixconversion}% +        conversionset {\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixconversionset}% +        starter       {\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixstarter}% +        stopper       {\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixstopper}% +        set           {\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixset}% +        segments      {\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixsegments}% +        connector     {\referencestructureprefixparameter{#kind}{#name}{#category}\c!prefixconnector}% +  }    { -        separatorset  =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!numberseparatorset", -        conversion    =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!numberconversion", -        conversionset =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!numberconversionset", -        starter       = \!!bs\referencestructureprefixparameter{#kind}{#name}{#category}\c!numberstarter\!!es, -        stopper       = \!!bs\referencestructureprefixparameter{#kind}{#name}{#category}\c!numberstopper\!!es, -        segments      =     "\referencestructureprefixparameter{#kind}{#name}{#category}\c!numbersegments", +        separatorset  {\referencestructureprefixparameter{#kind}{#name}{#category}\c!numberseparatorset}% +        conversion    {\referencestructureprefixparameter{#kind}{#name}{#category}\c!numberconversion}% +        conversionset {\referencestructureprefixparameter{#kind}{#name}{#category}\c!numberconversionset}% +        starter       {\referencestructureprefixparameter{#kind}{#name}{#category}\c!numberstarter}% +        stopper       {\referencestructureprefixparameter{#kind}{#name}{#category}\c!numberstopper}% +        segments      {\referencestructureprefixparameter{#kind}{#name}{#category}\c!numbersegments}%    }}  \unexpanded\def\setupreferencestructureprefix @@ -2097,16 +2123,11 @@       \csname     \??referencingprefix:#category#parameter\endcsname     \fi\fi\fi} -% \def\currentreferencedefault -%   {\ctxcommand{filterdefaultreference()}} -  \def\currentreferencedefault -  {\ctxcommand{filterreference("\s!default",\ctxcommand{getcurrentprefixspec("\s!default")})}} - -% needs testing -% -% \def\currentreferencedefault -%   {\ctxcommand{currentreferencedefault()}} +  {\clf_filterdefaultreference +     {\s!default}% +     \getreferencestructureprefix\clf_getcurrentprefixspec{\s!default}% returns #kind#name#category +   \relax}  %D Not all support is visible by looking at the \TEX\ code; here is one of those:^  %D diff --git a/tex/context/base/strc-reg.lua b/tex/context/base/strc-reg.lua index 4268001fa..99cad84a7 100644 --- a/tex/context/base/strc-reg.lua +++ b/tex/context/base/strc-reg.lua @@ -47,6 +47,8 @@ local v_text               = variables.text  local context              = context  local commands             = commands +local implement            = interfaces.implement +  local matchingtilldepth    = sections.matchingtilldepth  local numberatdepth        = sections.numberatdepth  local currentlevel         = sections.currentlevel @@ -416,8 +418,18 @@ end  registers.define           = defineregister -- 4 times is somewhat over the top but we want consistency  registers.setmethod        = defineregister -- and we might have a difference some day -commands.defineregister    = defineregister -commands.setregistermethod = defineregister + +implement { +    name      = "defineregister", +    actions   = defineregister, +    arguments = { "string", "string" } +} + +implement { +    name      = "setregistermethod", +    actions   = defineregister, -- duplicate use +    arguments = { "string", "string" } +}  local entrysplitter = lpeg.tsplitat('+') -- & obsolete in mkiv @@ -845,13 +857,11 @@ function registers.userdata(index,name)      return data and data.userdata and data.userdata[name] or nil  end -function commands.registeruserdata(index,name) -    local data = references.internals[tonumber(index)] -    data = data and data.userdata and data.userdata[name] -    if data then -        context(data) -    end -end +implement { +    name      = "registeruserdata", +    actions   = { registers.userdata, context }, +    arguments = { "integer", "string" } +}  -- todo: ownnumber @@ -990,8 +1000,8 @@ function registers.flush(data,options,prefixspec,pagespec)                  if #list > 1 then                      list[#list] = nil                  else -                    -- we have an \seeindex{Foo}{Bar} without Foo being defined anywhere -                    report_registers("invalid see entry in register %a, reference %a",entry.metadata.name,list[1][1]) +                 -- we have an \seeindex{Foo}{Bar} without Foo being defined anywhere .. somehow this message is wrong +                 -- report_registers("invalid see entry in register %a, reference %a",entry.metadata.name,list[1][1])                  end              end          end diff --git a/tex/context/base/strc-reg.mkiv b/tex/context/base/strc-reg.mkiv index 30fc698be..d4dbea9d5 100644 --- a/tex/context/base/strc-reg.mkiv +++ b/tex/context/base/strc-reg.mkiv @@ -134,7 +134,7 @@      \ifconditional\c_strc_registers_defining \else % todo: dosingle ...        \settrue\c_strc_registers_defining        \definemixedcolumns[\currentregister][\v!register]% first as otherwise it overloads start/stop -      \ctxcommand{defineregister("\currentregister","\registerparameter\c!referencemethod")}% +      \clf_defineregister{\currentregister}{\registerparameter\c!referencemethod}%        \normalexpanded{\presetheadtext[\currentregister=\Word{\currentregister}]}%        \setuevalue{\currentregister}{\dodoubleempty\strc_registers_insert_entry[\currentregister]}%        \setuevalue{\e!see\currentregister}{\dodoubleempty\strc_registers_insert_see[\currentregister]}% @@ -155,7 +155,7 @@  \to \everydefineregister  \appendtoks -    \ctxcommand{setregistermethod("\currentregister","\registerparameter\c!referencemethod")}% +    \clf_setregistermethod{\currentregister}{\registerparameter\c!referencemethod}%  \to \everysetupregister  %D Registering: @@ -923,7 +923,7 @@  %     \placeregister[index][n=1,pagecommand=\MyRegisterPageCommand]  % \stoptext -\def\registerpageuserdata       #1#2{\ctxcommand{registeruserdata(#1,"#2")}} +\def\registerpageuserdata       #1#2{\clf_registeruserdata#1{#2}}  \def\currentregisterpageuserdata    {\registerpageuserdata\currentregisterpageindex} % {#1}  % not yet ok : new internal handler names diff --git a/tex/context/base/strc-tag.lua b/tex/context/base/strc-tag.lua index a20375448..aa7311947 100644 --- a/tex/context/base/strc-tag.lua +++ b/tex/context/base/strc-tag.lua @@ -389,10 +389,10 @@ function tags.elementtag()  end  function tags.setuserproperties(tag,list) -    if list then -        tag = tagcontext[tag] -    else +    if not list or list == "" then          tag, list = chain[stacksize], tag +    else +        tag = tagcontext[tag]      end      if tag then -- an attribute now          local l = settings_to_hash(list) @@ -478,14 +478,7 @@ implement { name = "settagproperty_n", actions = tags.setproperty, arguments = {  implement { name = "getelementtag",    actions = { tags.elementtag, context } }  implement { -    name      = "setelementuserproperties_o", -    scope     = "private", -    actions   = tags.setuserproperties, -    arguments = "string" -} - -implement { -    name      = "setelementuserproperties_t", +    name      = "setelementuserproperties",      scope     = "private",      actions   = tags.setuserproperties,      arguments = { "string", "string" } diff --git a/tex/context/base/strc-tag.mkiv b/tex/context/base/strc-tag.mkiv index d114c15b5..804eadc61 100644 --- a/tex/context/base/strc-tag.mkiv +++ b/tex/context/base/strc-tag.mkiv @@ -295,16 +295,13 @@  \def\strc_tags_setup_element_user_properties_indeed    {\iftrialtypesetting -     \expandafter      \strc_tags_setup_element_user_properties_indeed_nop -   \else\ifsecondargument -     \doubleexpandafter\strc_tags_setup_element_user_properties_indeed_two +     \expandafter\strc_tags_setup_element_user_properties_indeed_nop     \else -     \doubleexpandafter\strc_tags_setup_element_user_properties_indeed_one -   \fi\fi} +     \expandafter\strc_tags_setup_element_user_properties_indeed_yes +   \fi}  \def\strc_tags_setup_element_user_properties_indeed_nop[#1][#2]{} -\def\strc_tags_setup_element_user_properties_indeed_one[#1][#2]{\clf_setelementuserproperties_o{#1}} -\def\strc_tags_setup_element_user_properties_indeed_two[#1][#2]{\clf_setelementuserproperties_u{#1}{#2}} +\def\strc_tags_setup_element_user_properties_indeed_yes[#1][#2]{\clf_setelementuserproperties{#1}{#2}}  \unexpanded\def\strc_tags_enable_properties    {\let\getelementtag             \strc_tags_get_element_tag_yes @@ -486,7 +483,7 @@  %D \stoptyping  \unexpanded\def\settaggedmetadata[#1]% -  {\clf_registermetadata{#1}} +  {\clf_settaggedmetadata{#1}}  %D An overload: diff --git a/tex/context/base/syst-aux.mkiv b/tex/context/base/syst-aux.mkiv index 9546026e9..bf936caa4 100644 --- a/tex/context/base/syst-aux.mkiv +++ b/tex/context/base/syst-aux.mkiv @@ -7038,7 +7038,7 @@  %def\getsubstring#1#2#3{\cldcontext{utf.sub([[#3]],tonumber("#1"),tonumber("#2"))}}  \def\getsubstring#1#2#3{\ctxcommand{getsubstring(\!!bs#3\!!es,"#1","#2")}} -%D Other dimensions that pt: +%D Other dimensions than pt:  % \def\converteddimen#1#2{\ctxcommand{converteddimen(\number\dimexpr#1,"#2")}} @@ -7095,6 +7095,22 @@  % \def\syst_aux_case_nop#1%  %   {\syst_aux_case} +%D \macros +%D   {ntimes} +%D +%D some repetition: +%D +%D \startbuffer +%D \ntimes{*}{20} +%D \stopbuffer +%D +%D \typebuffer \blank gives: \getbuffer \blank +%D +%D This is not real fast but quite okay: + +%def\ntimes#1#2{\ifnum#2>\zerocount#1\ntimes{#1}{\numexpr#2-\plusone\relax}\fi} % 1.72 +\def\ntimes#1#2{\clf_ntimes{#1}\numexpr#2\relax}                                % 0.33 +  \protect \endinput  % \edef\choicetokenyes{+} diff --git a/tex/context/base/syst-con.lua b/tex/context/base/syst-con.lua index dfbd49051..0fa685b2d 100644 --- a/tex/context/base/syst-con.lua +++ b/tex/context/base/syst-con.lua @@ -7,16 +7,18 @@ if not modules then modules = { } end modules ['syst-con'] = {  }  local tonumber = tonumber +local math = math  local utfchar = utf.char -local gsub, format = string.gsub, string.format +local gsub = string.gsub  converters       = converters or { }  local converters = converters  local context    = context -local comands    = commands +local commands   = commands +local implement  = interfaces.implement -local formatters = string,formatters +local formatters = string.formatters  --[[ldx--  <p>For raw 8 bit characters, the offset is 0x110000 (bottom of plane 18) at @@ -28,45 +30,39 @@ function converters.octstringtonumber(n) tonumber(n, 8) end  function converters.rawcharacter     (n) utfchar(0x110000+n) end -converters.lchexnumber  = formatters["%x"  ] -converters.uchexnumber  = formatters["%X"  ] -converters.lchexnumbers = formatters["%02x"] -converters.uchexnumbers = formatters["%02X"] -converters.octnumber    = formatters["%03o"] - -function commands.hexstringtonumber(n) context(tonumber(n,16)) end -function commands.octstringtonumber(n) context(tonumber(n, 8)) end - -function commands.rawcharacter     (n) context(utfchar(0x110000+n)) end - -function commands.lchexnumber      (n) context("%x"  ,n) end -function commands.uchexnumber      (n) context("%X"  ,n) end -function commands.lchexnumbers     (n) context("%02x",n) end -function commands.uchexnumbers     (n) context("%02X",n) end -function commands.octnumber        (n) context("%03o",n) end - -function commands.format(fmt,...) -- used ? -    fmt = gsub(fmt,"@","%%") -    context(fmt,...) -end - -local cosd, sind, tand = math.cosd, math.sind, math.tand -local cos, sin, tan = math.cos, math.sin, math.tan - --- unfortunately %s spits out: 6.1230317691119e-017 --- --- function commands.sind(n) context(sind(n)) end --- function commands.cosd(n) context(cosd(n)) end --- function commands.tand(n) context(tand(n)) end --- --- function commands.sin (n) context(sin (n)) end --- function commands.cos (n) context(cos (n)) end --- function commands.tan (n) context(tan (n)) end - -function commands.sind(n) context("%0.6F",sind(n)) end -function commands.cosd(n) context("%0.6F",cosd(n)) end -function commands.tand(n) context("%0.6F",tand(n)) end - -function commands.sin (n) context("%0.6F",sin (n)) end -function commands.cos (n) context("%0.6F",cos (n)) end -function commands.tan (n) context("%0.6F",tan (n)) end +local lchexnumber  = formatters["%x"] +local uchexnumber  = formatters["%X"] +local lchexnumbers = formatters["%02x"] +local uchexnumbers = formatters["%02X"] +local octnumber    = formatters["%03o"] +local nicenumber   = formatters["%0.6F"] + +converters.lchexnumber  = lchexnumber +converters.uchexnumber  = uchexnumber +converters.lchexnumbers = lchexnumbers +converters.uchexnumbers = uchexnumbers +converters.octnumber    = octnumber +converters.nicenumber   = nicenumber + +implement { name = "hexstringtonumber", actions = { tonumber, context }, arguments = { "integer", 16 } } +implement { name = "octstringtonumber", actions = { tonumber, context }, arguments = { "integer",  8 } } + +implement { name = "rawcharacter", actions = function(n) context(utfchar(0x110000+n)) end, arguments = "integer" } + +implement { name = "lchexnumber",  actions = { lchexnumber,  context }, arguments = "integer" } +implement { name = "uchexnumber",  actions = { uchexnumber,  context }, arguments = "integer" } +implement { name = "lchexnumbers", actions = { lchexnumbers, context }, arguments = "integer" } +implement { name = "uchexnumbers", actions = { uchexnumbers, context }, arguments = "integer" } +implement { name = "octnumber",    actions = { octnumber,    context }, arguments = "integer" } + +implement { name = "sin",  actions = { math.sin,  nicenumber, context }, arguments = "number" } +implement { name = "cos",  actions = { math.cos,  nicenumber, context }, arguments = "number" } +implement { name = "tan",  actions = { math.tan,  nicenumber, context }, arguments = "number" } + +implement { name = "sind", actions = { math.sind, nicenumber, context }, arguments = "number" } +implement { name = "cosd", actions = { math.cosd, nicenumber, context }, arguments = "number" } +implement { name = "tand", actions = { math.tand, nicenumber, context }, arguments = "number" } + +-- only as commands + +function commands.format(fmt,...) context((gsub(fmt,"@","%%")),...) end diff --git a/tex/context/base/syst-con.mkiv b/tex/context/base/syst-con.mkiv index de8ed597e..17c407819 100644 --- a/tex/context/base/syst-con.mkiv +++ b/tex/context/base/syst-con.mkiv @@ -46,10 +46,10 @@  %D [\expandafter\uchexnumber\expandafter{\the\zerocount}]  %D \stoptyping -\def\lchexnumber #1{\ctxcommand{lchexnumber(\number#1)}} -\def\uchexnumber #1{\ctxcommand{uchexnumber(\number#1)}} -\def\lchexnumbers#1{\ctxcommand{lchexnumbers(\number#1)}} -\def\uchexnumbers#1{\ctxcommand{uchexnumbers(\number#1)}} +\def\lchexnumber #1{\clf_lchexnumber \numexpr#1\relax} +\def\uchexnumber #1{\clf_uchexnumber \numexpr#1\relax} +\def\lchexnumbers#1{\clf_lchexnumbers\numexpr#1\relax} +\def\uchexnumbers#1{\clf_uchexnumbers\numexpr#1\relax}  \let\hexnumber\uchexnumber @@ -58,7 +58,7 @@  %D  %D For unicode remapping purposes, we need octal numbers. -\def\octnumber#1{\ctxcommand{octnumber(\number#1)}} +\def\octnumber#1{\clf_octnumber\numexpr#1\relax}  %D \macros  %D   {hexstringtonumber,octstringtonumber} @@ -67,8 +67,8 @@  %D a decimal number, thereby taking care of lowercase characters  %D as well. -\def\hexstringtonumber#1{\ctxcommand{hexstringtonumber("#1")}} -\def\octstringtonumber#1{\ctxcommand{octstringtonumber("#1")}} +\def\hexstringtonumber#1{\clf_hexstringtonumber\numexpr#1\relax} +\def\octstringtonumber#1{\clf_octstringtonumber\numexpr#1\relax}  %D \macros  %D   {rawcharacter} @@ -76,7 +76,7 @@  %D This macro can be used to produce proper 8 bit characters  %D that we sometimes need in backends and round||trips. -\def\rawcharacter#1{\ctxcommand{rawcharacter(\number#1)}} +\def\rawcharacter#1{\clf_rawcharacter\numexpr#1\relax}  %D \macros  %D   {twodigits, threedigits} @@ -126,23 +126,12 @@  %D \macros  %D    {setcalculatedsin,setcalculatedcos,setcalculatedtan} -%D -%D This saves some 2K in the format. At some point we will redo the -%D code that calls this. Beware: in \MKII\ this is a separate module. - -% \let\calculatesin\gobbleoneargument -% \let\calculatecos\gobbleoneargument -% \let\calculatetan\gobbleoneargument - -% \def\setcalculatedsin#1#2{\edef#1{\cldcontext{math.sind(#2)}}} % jit-unsafe -% \def\setcalculatedcos#1#2{\edef#1{\cldcontext{math.cosd(#2)}}} % jit-unsafe -% \def\setcalculatedtan#1#2{\edef#1{\cldcontext{math.tand(#2)}}} % jit-unsafe -\def\setcalculatedsin#1#2{\edef#1{\ctxcommand{sind(#2)}}} -\def\setcalculatedcos#1#2{\edef#1{\ctxcommand{cosd(#2)}}} -\def\setcalculatedtan#1#2{\edef#1{\ctxcommand{tand(#2)}}} +\def\setcalculatedsin#1#2{\edef#1{\clf_sind#2}} +\def\setcalculatedcos#1#2{\edef#1{\clf_cosd#2}} +\def\setcalculatedtan#1#2{\edef#1{\clf_tand#2}} -           \def\formatted#1{\ctxcommand{format(#1)}} -\unexpanded\def\format   #1{\ctxcommand{format(#1)}} +           \def\formatted#1{\ctxcommand{format(#1)}} % not clf +\unexpanded\def\format   #1{\ctxcommand{format(#1)}} % not clf  \protect \endinput diff --git a/tex/context/base/syst-lua.lua b/tex/context/base/syst-lua.lua index 8fa43588f..9466ed94b 100644 --- a/tex/context/base/syst-lua.lua +++ b/tex/context/base/syst-lua.lua @@ -6,15 +6,17 @@ if not modules then modules = { } end modules ['syst-lua'] = {      license   = "see context related readme files"  } -local format, find, match, rep = string.format, string.find, string.match, string.rep +local find, match = string.find, string.match  local tonumber = tonumber  local S, lpegmatch, lpegtsplitat = lpeg.S, lpeg.match, lpeg.tsplitat -commands       = commands or { } -local commands = commands +commands          = commands or { } +local commands    = commands -local context  = context -local csprint  = context.sprint +local implement   = interfaces.implement + +local context     = context +local csprint     = context.sprint  local prtcatcodes = tex.prtcatcodes @@ -158,9 +160,11 @@ function commands.firstinset(str)      context(first or str)  end -function commands.ntimes(str,n) -    context(rep(str,n or 1)) -end +implement { +    name      = "ntimes", +    actions   = { string.rep, context }, +    arguments = { "string", "integer" } +}  function commands.execute(str)      os.execute(str) -- wrapped in sandbox diff --git a/tex/context/base/toks-scn.lua b/tex/context/base/toks-scn.lua index 3da962dad..b01376b60 100644 --- a/tex/context/base/toks-scn.lua +++ b/tex/context/base/toks-scn.lua @@ -21,8 +21,6 @@ local loadstring     = loadstring  local scanners       = tokens.scanners  local tokenbits      = tokens.bits -if not scanners then return end -- for now -  local scanstring     = scanners.string  local scaninteger    = scanners.integer  local scannumber     = scanners.number @@ -32,12 +30,11 @@ local scancode       = scanners.code  local scanboolean    = scanners.boolean  local scandimen      = scanners.dimen -if not scanstring then return end -- for now -  local todimen        = number.todimen +local toboolean      = toboolean  local lpegmatch      = lpeg.match -local p_unquoted     = lpeg.patterns.unquoted +local p_unquoted     = lpeg.Cs(lpeg.patterns.unquoted)  local trace_compile  = false  trackers.register("tokens.compile", function(v) trace_compile = v end)  local report_compile = logs.reporter("tokens","compile") @@ -93,6 +90,7 @@ local shortcuts = {      todimen       = todimen,      tonumber      = tonumber,      tostring      = tostring, +    toboolean     = toboolean,      inspect       = inspect,      report        = report_scan,  } @@ -108,10 +106,11 @@ local function loadstripped(code)  end  tokens.converters = { -    tonumber = "tonumber", -    todimen  = "todimen", -    toglue   = "todimen", -    tostring = "tostring", +    tonumber  = "tonumber", +    tostring  = "tostring", +    toboolean = "toboolean", +    todimen   = "todimen", +    toglue    = "todimen",  }  local f_if       = formatters[    "  if scankeyword('%s') then data['%s'] = scan%s()"] @@ -128,6 +127,9 @@ local f_any      = formatters["  else local key = scanword() if key then data[ke  local f_any_c    = formatters["  else local key = scanword() if key then data[key] = %s(scan%s()) else break end end"]  local s_done     = "  else break end" +local f_any_all  = formatters["  local key = scanword() if key then data[key] = scan%s() else break end"] +local f_any_all_c= formatters["  local key = scanword() if key then data[key] = %s(scan%s()) else break end"] +  local f_table    = formatters["%\nt\nreturn function()\n  local data = { }\n%s\n  return %s\nend\n"]  local f_sequence = formatters["%\nt\n%\nt\n%\nt\nreturn function()\n    return %s\nend\n"]  local f_simple   = formatters["%\nt\nreturn function()\n    return %s\nend\n"] @@ -190,30 +192,44 @@ function tokens.compile(specification)          local m = 0          for i=1,#t do              local ti = t[i] -            local t1 = ti[1] -            local t2 = ti[2] or "string" -            if type(t2) == "table" then -                n = n + 1 -                f[n] = compile(t2,n) -                t2 = n -            end -            local t3 = ti[3] -            if type(t3) == "function" then -                -- todo: also create shortcut -            elseif t3 then -                c[t3] = f_shortcut(t3,t3) -                if t1 == "*" then -                    done = f_any_c(t3,t2) -                else -                    m = m + 1 -                    r[m] = (m > 1 and f_elseif_c or f_if_c)(t1,t1,t3,t2) -                end +            if ti == "*" and i == 1 then +                done = f_any_all("string")              else -                if t1 == "*" then -                    done = f_any(t2) +                local t1 = ti[1] +                local t2 = ti[2] or "string" +                if type(t2) == "table" then +                    n = n + 1 +                    f[n] = compile(t2,n) +                    t2 = n +                end +                local t3 = ti[3] +                if type(t3) == "function" then +                    -- todo: also create shortcut +                elseif t3 then +                    c[t3] = f_shortcut(t3,t3) +                    if t1 == "*" then +                        if i == 1 then +                            done = f_any_all_c(t3,t2) +                            break +                        else +                            done = f_any_c(t3,t2) +                        end +                    else +                        m = m + 1 +                        r[m] = (m > 1 and f_elseif_c or f_if_c)(t1,t1,t3,t2) +                    end                  else -                    m = m + 1 -                    r[m] = (m > 1 and f_elseif   or f_if  )(t1,t1,t2) +                    if t1 == "*" then +                        if i == 1 then +                            done = f_any_all(t2) +                            break +                        else +                            done = f_any(t2) +                        end +                    else +                        m = m + 1 +                        r[m] = (m > 1 and f_elseif   or f_if  )(t1,t1,t2) +                    end                  end              end          end @@ -227,7 +243,12 @@ function tokens.compile(specification)      local tt = type(t)      if tt == "string" then          if a then -            code = f_scan(t) +            local s = lpegmatch(p_unquoted,t) +            if s and t ~= s then +                code = t +            else +                code = f_scan(t) +            end              tokens._action = a              for i=1,#a do                  code    = f_action_f(i,code) diff --git a/tex/context/base/trac-ctx.lua b/tex/context/base/trac-ctx.lua index 706e7a244..493ce7936 100644 --- a/tex/context/base/trac-ctx.lua +++ b/tex/context/base/trac-ctx.lua @@ -6,15 +6,15 @@ if not modules then modules = { } end modules ['trac-ctx'] = {      license   = "see context related readme files"  } -local commands = commands -local context  = context -local register = trackers.register +local context       = context +local implement     = interfaces.implement +local register      = trackers.register  local textrackers   = tex.trackers   or { }  local texdirectives = tex.directives or { } -tex.trackers   = textrackers -tex.directives = texdirectives +tex.trackers        = textrackers +tex.directives      = texdirectives  storage.register("tex/trackers",  textrackers,  "tex.trackers")  storage.register("tex/directives",texdirectives,"tex.directives") @@ -39,10 +39,32 @@ local function install(category,register,tag,enable,disable)      register(tag, function(v) doit(category,tag,v) end) -- todo: v,tag in caller  end -function commands.initializetextrackers  () initialize(textrackers  ,trackers  .register  ) end -function commands.initializetexdirectives() initialize(texdirectives,directives.register) end +implement { +    name    = "initializetextrackers", +    actions = function() +        initialize(textrackers,trackers.register) +    end +} --- commands.install(tag,enable,disable): +implement { +    name    = "initializetexdirectives", +    actions = function() +        initialize(texdirectives,directives.register) +    end +} -function commands.installtextracker  (...) install(textrackers  ,trackers  .register,...) end -function commands.installtexdirective(...) install(texdirectives,directives.register,...) end +implement { +    name    = "installtextracker", +    actions = function(tag,enable,disable) +        install(textrackers,trackers.register,tag,enable,disable) +    end, +    arguments = { "string", "string", "string" } +} + +implement { +    name      = "installtexdirective", +    actions   = function(tag,enable,disable) +        install(texdirectives,directives.register,tag,enable,disable) +    end, +    arguments = { "string", "string", "string" } +} diff --git a/tex/context/base/trac-ctx.mkiv b/tex/context/base/trac-ctx.mkiv index 3eb53713c..4240281a6 100644 --- a/tex/context/base/trac-ctx.mkiv +++ b/tex/context/base/trac-ctx.mkiv @@ -18,14 +18,14 @@  \unprotect  \unexpanded\def\installtextracker#1#2#3% -  {\ctxcommand{installtextracker("#1",\!!bs\detokenize{#2}\!!es,\!!bs\detokenize{#3}\!!es)}} +  {\clf_installtextracker{#1}{\detokenize{#2}}{\detokenize{#3}}}  \unexpanded\def\installtexdirective#1#2#3% -  {\ctxcommand{installtexdirective("#1",\!!bs\detokenize{#2}\!!es,\!!bs\detokenize{#3}\!!es)}} +  {\clf_installtexdirective{#1}{\detokenize{#2}}{\detokenize{#3}}}  \appendtoks -    \ctxcommand{initializetextrackers  ()}% -    \ctxcommand{initializetexdirectives()}% +    \clf_initializetextrackers +    \clf_initializetexdirectives  \to \everyjob  \protect \endinput diff --git a/tex/context/base/type-ini.lua b/tex/context/base/type-ini.lua index 4f53fbf40..cd5b32d3e 100644 --- a/tex/context/base/type-ini.lua +++ b/tex/context/base/type-ini.lua @@ -6,15 +6,23 @@ if not modules then modules = { } end modules ['type-ini'] = {      license   = "see context related readme files"  } +local gsub = string.gsub +local lpegmatch, P, Cs = lpeg.match, lpeg.P, lpeg.Cs +  -- more code will move here -local commands, context = commands, context +local commands   = commands +local context    = context +local implement  = interfaces.implement -local gsub = string.gsub +local uselibrary = resolvers.uselibrary + +local name_one   = nil +local name_two   = nil -local report_typescripts = logs.reporter("fonts","typescripts") +local p_strip    = Cs((P("type-") * (P("imp-")^0))^0/"" * P(1)^0) -local patterns = { "type-imp-%s.mkiv", "type-imp-%s.tex", "type-%s.mkiv", "type-%s.tex" } -- this will be imp only +local report     = logs.reporter("fonts","typescripts")  local function action(name,foundname)   -- context.startreadingfile() @@ -27,52 +35,83 @@ local function action(name,foundname)      context.loadfoundtypescriptfile(foundname)  end -local name_one, name_two - -local function failure_two(name) -    report_typescripts("unknown library %a or %a",name_one,name_two) -end +local patterns = { +    "type-imp-%s.mkiv", +    "type-imp-%s.tex" +} -local function failure_one(name) -    name_two = gsub(name,"%-.*$","") +local function failure(name)      if name == "loc" then          -- ignore -    elseif name_two == name then -        report_typescripts("unknown library %a",name_one)      else -        commands.uselibrary { -            name     = name_two, +        report("unknown library %a",name) +    end +end + +implement { +    name      = "loadtypescriptfile", +    arguments = "string", +    actions   = function(name) -- a more specific name +        uselibrary { +            name     = lpegmatch(p_strip,name) or name,              patterns = patterns,              action   = action, -            failure  = failure_two, +            failure  = failure,              onlyonce = false, -- will become true          }      end -end - -function commands.doprocesstypescriptfile(name) -    name_one = gsub(name,"^type%-","") -    commands.uselibrary { -        name     = name_one, -        patterns = patterns, -        action   = action, -        failure  = failure_one, -        onlyonce = false, -- will become true -    } -end +} -local patterns = { "type-imp-%s.mkiv", "type-imp-%s.tex" } +local patterns = { +    "type-imp-%s.mkiv", +    "type-imp-%s.tex", +    -- obsolete +    "type-%s.mkiv", +    "type-%s.tex" +} -local function failure(name) -    report_typescripts("unknown library %a",name) -end +-- local function failure_two(name) +--     report("unknown library %a or %a",name_one,name_two) +-- end +-- +-- local function failure_one(name) +--     name_two = gsub(name,"%-.*$","") +--     if name == "loc" then +--         -- ignore +--     elseif name_two == name then +--         report("unknown library %a",name_one) +--     else +--         commands.uselibrary { +--             name     = name_two, +--             patterns = patterns, +--             action   = action, +--             failure  = failure_two, +--             onlyonce = false, -- will become true +--         } +--     end +-- end +-- +-- function commands.doprocesstypescriptfile(name) +--     name_one = lpegmatch(p_strip,name) or name +--     uselibrary { +--         name     = name_one, +--         patterns = patterns, +--         action   = action, +--         failure  = failure_one, +--         onlyonce = false, -- will become true +--     } +-- end -function commands.loadtypescriptfile(name) -- a more specific name -    commands.uselibrary { -        name     = gsub(name,"^type%-",""), -        patterns = patterns, -        action   = action, -        failure  = failure, -        onlyonce = false, -- will become true -    } -end +implement { +    name      = "doprocesstypescriptfile", +    arguments = "string", +    actions   = function(name) +        uselibrary { +            name     = lpegmatch(p_strip,name) or name, +            patterns = patterns, +            action   = action, +            failure  = failure, +            onlyonce = false, -- will become true +        } +    end +} diff --git a/tex/context/base/type-ini.mkvi b/tex/context/base/type-ini.mkvi index faa9c667c..4514a8b5f 100644 --- a/tex/context/base/type-ini.mkvi +++ b/tex/context/base/type-ini.mkvi @@ -172,7 +172,7 @@  \unexpanded\def\loadtypescriptfile[#1]%    {\pushmacro\typescriptstate     \let\typescriptstate\plustwo % assumes 2 at the outer level -   \ctxcommand{loadtypescriptfile("#1")}% +   \clf_loadtypescriptfile{#1}%     \popmacro\typescriptstate}  \unexpanded\def\loadfoundtypescriptfile#1% @@ -237,7 +237,7 @@     \expandafter\let\csname\??typescriptfiles\currenttypefile\endcsname\t_font_typescripts}  \def\font_typescript_process_typescript_file -  {\ctxcommand{doprocesstypescriptfile("\currenttypefile")}} +  {\clf_doprocesstypescriptfile{\currenttypefile}}  \unexpanded\def\usetypescriptonce    {\dotripleempty\font_typescripts_use_once} @@ -575,12 +575,6 @@     \fi \fi \fi     \ifmmode\mr\else\tf\fi} % needed ? -% obsolete -% -% \unexpanded\def\usetypefile[#type]% recurses on path ! % no storage -%   {\edef\currenttypefile{#type}% -%    \ctxcommand{doprocesstypescriptfile("\currenttypefile")}} -  %D For Taco:  %D  %D \starttyping diff --git a/tex/context/base/typo-prc.lua b/tex/context/base/typo-prc.lua index 3b94a0f10..cde66df00 100644 --- a/tex/context/base/typo-prc.lua +++ b/tex/context/base/typo-prc.lua @@ -11,7 +11,7 @@ local lpegmatch, patterns, P, C, Cs = lpeg.match, lpeg.patterns, lpeg.P, lpeg.C,  -- processors: syntax: processor->data ... not ok yet  local context           = context -local commands          = commands +local implement         = interfaces.implement  local formatters        = string.formatters @@ -125,5 +125,5 @@ end  -- interface -commands.registerstructureprocessor = processors.register -commands.resetstructureprocessor    = processors.reset +implement { name = "registerstructureprocessor", actions = processors.register, arguments = "string" } +implement { name = "resetstructureprocessor",    actions = processors.reset,    arguments = "string" } diff --git a/tex/context/base/typo-prc.mkvi b/tex/context/base/typo-prc.mkvi index 038abb304..49a165696 100644 --- a/tex/context/base/typo-prc.mkvi +++ b/tex/context/base/typo-prc.mkvi @@ -55,7 +55,7 @@  \appendtoks      \letvalue{\??processorcheck\currentprocessor}\relax -    \ctxcommand{registerstructureprocessor("\currentprocessor")}% global, but it permits using processor that are yet undefined +    \clf_registerstructureprocessor{\currentprocessor}% global, but it permits using processor that are yet undefined  \to \everydefineprocessor  %D The following command can be used by users but normally it will be diff --git a/tex/context/base/typo-spa.lua b/tex/context/base/typo-spa.lua index eb84eb7d7..519ba3f34 100644 --- a/tex/context/base/typo-spa.lua +++ b/tex/context/base/typo-spa.lua @@ -230,6 +230,30 @@ end  -- interface -commands.definecharacterspacing = spacings.define -commands.setupcharacterspacing  = spacings.setup -commands.setcharacterspacing    = spacings.set +local implement = interfaces.implement + +implement { +    name      = "definecharacterspacing", +    actions   = spacings.define, +    arguments = "string" +} + +implement { +    name      = "setupcharacterspacing", +    actions   = spacings.setup, +    arguments = { +        "string", +        "integer", +        { +            { "left",        "number" }, +            { "right",       "number" }, +            { "alternative", "integer" }, +        } +    } +} + +implement { +    name      = "setcharacterspacing", +    actions   = spacings.set, +    arguments = "string" +} diff --git a/tex/context/base/typo-spa.mkiv b/tex/context/base/typo-spa.mkiv index d783353d6..2e3e71bf3 100644 --- a/tex/context/base/typo-spa.mkiv +++ b/tex/context/base/typo-spa.mkiv @@ -35,7 +35,7 @@     \c!alternative=0]  \unexpanded\def\definecharacterspacing[#1]% -  {\ctxcommand{definecharacterspacing("#1")}} +  {\clf_definecharacterspacing{#1}}  \unexpanded\def\setupcharacterspacing    {\dotripleargument\typo_characterspacing_setup} @@ -43,15 +43,19 @@  \def\typo_characterspacing_setup[#1][#2][#3]% todo: #2 list    {\begingroup     \setupcurrent_p_characterspacing[#3]% -   \ctxcommand{setupcharacterspacing("#1",\number#2, { % todo: just pass #3 to the lua end -      left        = \direct_p_characterspacingparameter\c!left, -      right       = \direct_p_characterspacingparameter\c!right, -      alternative = \direct_p_characterspacingparameter\c!alternative -    })}% +   \clf_setupcharacterspacing +      {#1}% +      \numexpr#2\relax +      {% +        left        \direct_p_characterspacingparameter\c!left\space +        right       \direct_p_characterspacingparameter\c!right\space +        alternative \direct_p_characterspacingparameter\c!alternative +      }% +   \relax     \endgroup}  \unexpanded\def\setcharacterspacing[#1]% we can store the attribute if we want speed -  {\ctxcommand{setcharacterspacing("#1")}} +  {\clf_setcharacterspacing{#1}}  \unexpanded\def\resetcharacterspacing % fast one    {\attribute\spacingattribute\attributeunsetvalue} diff --git a/tex/context/base/x-asciimath.lua b/tex/context/base/x-asciimath.lua index 5914c3c69..1fc9ae5a4 100644 --- a/tex/context/base/x-asciimath.lua +++ b/tex/context/base/x-asciimath.lua @@ -787,7 +787,7 @@ local p_aftercomma  = p_fourafter                      + d_one   * d_spaced  local digitized_2   = Cs ( -                         p_fourbefore  *   p_aftercomma + +                         p_fourbefore  *   (p_aftercomma^0) +                           p_beforecomma * ((p_aftercomma + d_one^1)^0)                        ) @@ -796,7 +796,7 @@ local p_aftercomma  = p_fourafter                      + d_three * d_spaced * P(1)^0  local digitized_3   = Cs ( -                         p_fourbefore  *   p_aftercomma + +                         p_fourbefore  *   (p_aftercomma^0) +                           p_beforecomma * ((p_aftercomma + d_one^1)^0)                        ) @@ -838,28 +838,26 @@ function numbermess(s)      return s  end -asciimath.setup { splitmethod = 3 } - -local t = { -    "1", "12", "123", "1234", "12345", "123456", "1234567", "12345678", "123456789", -    "1,1", -    "12,12", -    "123,123", -    "1234,1234", -    "12345,1234", -    "1234,12345", -    "12345,12345", -    "123456,123456", -    "1234567,1234567", -    "12345678,12345678", -    "123456789,123456789", -    "0,1234", -    "1234,0", -    "1234,00", -    "0,123456789", -} -for i=1,#t do print(formatters["%-20s : [%s]"](t[i],numbermess(t[i]))) end - +-- asciimath.setup { splitmethod = 3 } +-- local t = { +--     "1", "12", "123", "1234", "12345", "123456", "1234567", "12345678", "123456789", +--     "1,1", +--     "12,12", +--     "123,123", +--     "1234,1234", +--     "12345,1234", +--     "1234,12345", +--     "12345,12345", +--     "123456,123456", +--     "1234567,1234567", +--     "12345678,12345678", +--     "123456789,123456789", +--     "0,1234", +--     "1234,0", +--     "1234,00", +--     "0,123456789", +-- } +-- for i=1,#t do print(formatters["%-20s : [%s]"](t[i],numbermess(t[i]))) end  statistics.register("asciimath",function()      if trace_digits then diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index b47d49e37..cc3e40272 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@  -- merged file : luatex-fonts-merged.lua  -- parent file : luatex-fonts.lua --- merge date  : 03/28/15 22:37:53 +-- merge date  : 03/30/15 23:33:48  do -- begin closure to overcome local limits and interference | 
