From c36e19abdfd15bf6cae6fa379c6ce51f3ef5332d Mon Sep 17 00:00:00 2001
From: Marius
We reserve this one as we really want it to be always set (faster).
+--ldx]]-- + +names[0], numbers["fontdynamic"] = "fontdynamic", 0 + --[[ldx--We can use the attributes in the range 127-255 (outside user space). These
are only used when no attribute is set at the \TEX\ end which normally
happens in
The
The next code is an adaptation of code from Wolfgang Schuster @@ -62,9 +62,9 @@ local high = Cc("\\high{%s}") * superscript * content local justtext = (1 - somescript)^1 local parser = Cs((csname + lowhigh + highlow + low + high + sign + any)^0) -chemicals.moleculeparser = parser -- can be used to avoid functioncall +chemistry.moleculeparser = parser -- can be used to avoid functioncall -function chemicals.molecule(str) +function chemistry.molecule(str) return lpegmatch(parser,str) end diff --git a/tex/context/base/chem-str.lua b/tex/context/base/chem-str.lua index fb325ccea..db1849c5a 100644 --- a/tex/context/base/chem-str.lua +++ b/tex/context/base/chem-str.lua @@ -1,12 +1,15 @@ if not modules then modules = { } end modules ['chem-str'] = { version = 1.001, comment = "companion to chem-str.mkiv", - author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + author = "Hans Hagen and Alan Braslau", copyright = "PRAGMA ADE / ConTeXt Development Team", license = "see context related readme files" } --- This module in incomplete and experimental. +-- The original \PPCHTEX\ code was written in pure \TEX\, although later we made +-- the move from \PICTEX\ to \METAPOST\. The current implementation is a mix between +-- \TEX\, \LUA\ and \METAPOST. Although the first objective is to get a compatible +-- but better implementation, later versions might provide more, -- We can push snippets into an mp instance. @@ -26,12 +29,12 @@ local P, R, S, C, Cs, Ct, Cc = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cs, lpeg.Ct, local variables = interfaces.variables local context = context -chemicals = chemicals or { } -local chemicals = chemicals +chemistry = chemistry or { } +local chemistry = chemistry -chemicals.instance = "metafun" -- "ppchtex" -chemicals.format = "metafun" -chemicals.structures = 0 +chemistry.instance = "metafun" -- "ppchtex" +chemistry.format = "metafun" +chemistry.structures = 0 local remapper = { ["+"] = "p", @@ -52,7 +55,9 @@ local common_keys = { mid = "fixed", mids = "fixed", midz = "text", z = "text", rz = "text", mrz = "text", prz = "text", crz = "text", rt = "text", rtt = "text", rbt = "text", zt = "text", zn = "number", - mov = "transform", rot = "transform", adj = "transform", dir = "transform", sub = "transform", + zbt = "text", zbn = "number", ztt = "text", ztn = "number", + mov = "transform", rot = "transform", adj = "transform", sub = "transform", + off = "transform", } local front_keys = { @@ -60,9 +65,11 @@ local front_keys = { sb = "line", msb = "line", psb = "line", r = "line", pr = "line", mr = "line", z = "text", mrz = "text", prz = "text", + zt = "text", zn = "number", } local one_keys = { + b = "line", msb = "line", psb = "line", sb = "line", db = "line", tb = "line", ep = "line", es = "line", ed = "line", et = "line", sd = "line", ldd = "line", rdd = "line", @@ -81,15 +88,16 @@ local syntax = { one = { n = 1, max = 8, keys = one_keys, align = { - z = { { "r", "r_b", "b", "l_b", "l", "l_t", "t", "r_t" } }, ---~ z = { { "r", "r", "b", "l", "l", "l", "t", "r" } }, + -- z = { { "r", "r_b", "b", "l_b", "l", "l_t", "t", "r_t" } }, + -- z = { { "r", "r", "b", "l", "l", "l", "t", "r" } }, } }, three = { n = 3, max = 3, keys = common_keys, align = { mrz = { { "r","b","l" }, { "b","l","t" }, { "l","t","r" }, { "t","r","b" } }, - rz = { { "r","l_b","l_t" }, { "b","l_t","r_t" }, { "l","r_t","r_b" }, { "t","r_b","l_b" } }, + rz = { { "auto","auto","auto" }, { "auto","auto","auto" }, { "auto","auto","auto" }, { "auto","auto","auto" } }, + -- rz = { { "r_t","r_b","l" }, { "r_b","l_b","t" }, { "l_b","l_t","r" }, { "l_t","r_t","b" } }, prz = { { "r","l","t" }, { "b","t","r" }, { "l","r","b" }, { "t","b","l" } }, } }, @@ -97,7 +105,8 @@ local syntax = { n = 4, max = 4, keys = common_keys, align = { mrz = { { "t","r","b","l" }, { "r","b","l","t" }, { "b","l","t","r" }, { "l","t","r","b" } }, - rz = { { "r_t","r_b","l_b","l_t" }, { "r_b","l_b","l_t","r_t" }, { "l_b","l_t","r_t","r_b" }, { "l_t","r_t","r_b","l_b" } }, + rz = { { "auto","auto","auto","auto" }, { "auto","auto","auto","auto" }, { "auto","auto","auto","auto" }, { "auto","auto","auto","auto" } }, + -- rz = { { "r_t","r_b","l_b","l_t" }, { "r_b","l_b","l_t","r_t" }, { "l_b","l_t","r_t","r_b" }, { "l_t","r_t","r_b","l_b" } }, prz = { { "r","b","l","t" }, { "b","l","t","r" }, { "l","t","r","b" }, { "t","r","b","l" } }, } }, @@ -105,7 +114,8 @@ local syntax = { n = 5, max = 5, keys = common_keys, align = { mrz = { { "t","r","b","b","l" }, { "r","b","l","l","t" }, { "b","l","t","r","r" }, { "l","t","r","r","b" } }, - rz = { { "r","r","b","l","t" }, { "b","b","l","t","r" }, { "l","l","t","r","b" }, { "t","t","r","b","l" } }, + rz = { { "auto","auto","auto","auto","auto" }, { "auto","auto","auto","auto","auto" }, { "auto","auto","auto","auto","auto" }, { "auto","auto","auto","auto","auto" } }, + -- rz = { { "r","r","b","l","t" }, { "b","b","l","t","r" }, { "l","l","t","r","b" }, { "t","t","r","b","l" } }, prz = { { "r","b","l","t","t" }, { "b","l","t","r","r" }, { "l","t","r","b","b" }, { "t","r","b","l","l" } }, } }, @@ -113,7 +123,8 @@ local syntax = { n = 6, max = 6, keys = common_keys, align = { mrz = { { "t","t","r","b","b","l" }, { "r","b","b","l","t","t" }, { "b","b","l","t","t","r" }, { "l","t","t","r","b","b" } }, - rz = { { "r","r","b","l","l","t" }, { "b","b","l","t","t","r" }, { "l","l","t","r","r","b" }, { "t","t","r","b","b","l" } }, + rz = { { "auto","auto","auto","auto","auto","auto" }, { "auto","auto","auto","auto","auto","auto" }, { "auto","auto","auto","auto","auto","auto" }, { "auto","auto","auto","auto","auto","auto" } }, + -- rz = { { "r","r","b","l","l","t" }, { "b","b","l","t","t","r" }, { "l","l","t","r","r","b" }, { "t","t","r","b","b","l" } }, prz = { { "r","b","l","l","t","r" }, { "b","l","t","t","r","b" }, { "l","t","r","r","b","l" }, { "t","r","b","b","l","t" } }, } }, @@ -121,7 +132,8 @@ local syntax = { n = 8, max = 8, keys = common_keys, align = { -- todo mrz = { { "t","r","r","b","b","l","l","t" }, { "r","b","b","l","l","t","t","r" }, { "b","l","l","t","t","r","r","b" }, { "l","t","t","r","r","b","b","l" } }, - rz = { { "r","r","b","b","l","l","t","t" }, { "b","b","l","l","t","t","r","r" }, { "l","l","t","t","r","r","b","b" }, { "t","t","r","r","b","b","l","l" } }, + rz = { { "auto","auto","auto","auto","auto","auto","auto","auto" }, { "auto","auto","auto","auto","auto","auto","auto","auto" }, { "auto","auto","auto","auto","auto","auto","auto","auto" }, { "auto","auto","auto","auto","auto","auto","auto","auto" } }, + -- rz = { { "r","r","b","b","l","l","t","t" }, { "b","b","l","l","t","t","r","r" }, { "l","l","t","t","r","r","b","b" }, { "t","t","r","r","b","b","l","l" } }, prz = { { "r","b","b","l","l","t","t","r" }, { "b","l","l","t","t","r","r","b" }, { "l","t","t","r","r","b","b","l" }, { "t","r","r","b","b","l","l","t" } }, } }, @@ -147,11 +159,11 @@ local syntax = { local definitions = { } -function chemicals.undefine(name) +function chemistry.undefine(name) definitions[lower(name)] = nil end -function chemicals.define(name,spec,text) +function chemistry.define(name,spec,text) name = lower(name) local dn = definitions[name] if not dn then dn = { } definitions[name] = dn end @@ -162,7 +174,7 @@ function chemicals.define(name,spec,text) end local metacode, variant, keys, bonds, max, txt, textsize, rot, pstack -local molecule = chemicals.molecule -- or use lpegmatch(chemicals.moleculeparser,...) +local molecule = chemistry.molecule -- or use lpegmatch(chemistry.moleculeparser,...) local function fetch(txt) local st = stack[txt] @@ -196,35 +208,46 @@ local text = (equal * C(P(1)^0)) + Cc(false) local pattern = (amount + Cc(1)) * - operation * - special * ( + Cs(operation/lower) * + Cs(special/lower) * ( +-- operation * +-- special * ( range * Cc(false) * text + Cc(false) * Cc(false) * set * text + single * Cc(false) * Cc(false) * text + Cc(false) * Cc(false) * Cc(false) * text ) ---~ local n, operation, index, upto, set, text = lpegmatch(pattern,"RZ1357") +-- local n, operation, index, upto, set, text = lpegmatch(pattern,"RZ1357") ---~ print(lpegmatch(pattern,"RZ=x")) 1 RZ false false false x ---~ print(lpegmatch(pattern,"RZ1=x")) 1 RZ 1 false false x ---~ print(lpegmatch(pattern,"RZ1..3=x")) 1 RZ 1 3 false x ---~ print(lpegmatch(pattern,"RZ13=x")) 1 RZ false false table x +-- print(lpegmatch(pattern,"RZ=x")) -- 1 RZ false false false x +-- print(lpegmatch(pattern,"RZ1=x")) -- 1 RZ 1 false false x +-- print(lpegmatch(pattern,"RZ1..3=x")) -- 1 RZ 1 3 false x +-- print(lpegmatch(pattern,"RZ13=x")) -- 1 RZ false false table x local function process(spec,text,n,rulethickness,rulecolor,offset) insert(stack,{ spec=spec, text=text, n=n }) local txt = #stack local m = #metacode for i=1,#spec do - local s = spec[i] + local step = spec[i] + local s = lower(step) local d = definitions[s] if d then + if trace_structure then + report_chemistry("%s => definition: %s",step,s) + end for i=1,#d do local di = d[i] process(di.spec,di.text,1,rulethickness,rulecolor) end else - local rep, operation, special, index, upto, set, text = lpegmatch(pattern,s) + local rep, operation, special, index, upto, set, text = lpegmatch(pattern,step) + if trace_structure then + local set = set and concat(set," ") or "-" + report_chemistry("%s => rep: %s, operation: %s, special: %s, index: %s, upto: %s, set: %s, text: %s", + step,rep or "-",operation or "-",special and special ~= "" or "-",index or "-",upto or "-",set or "-",text or "-") + end if operation == "pb" then insert(pstack,variant) m = m + 1 ; metacode[m] = syntax.pb.direct @@ -339,7 +362,8 @@ local function process(spec,text,n,rulethickness,rulecolor,offset) if not t then txt, t = fetch(txt) end if t then t = molecule(processor_tostring(t)) - m = m + 1 ; metacode[m] = format('chem_%s_zero("\\chemicaltext{%s}");',operation,t) + m = m + 1 ; metacode[m] = format('chem_%s(%s,%s,"\\chemicaltext{%s}");',operation,bonds,index,t) + -- m = m + 1 ; metacode[m] = format('chem_%s_zero("\\chemicaltext{%s}");',operation,t) end elseif index then local t = text @@ -388,8 +412,8 @@ end -- -- rulethickness in points -function chemicals.start(settings) - chemicals.structures = chemicals.structures + 1 +function chemistry.start(settings) + chemistry.structures = chemistry.structures + 1 local textsize, rulethickness, rulecolor = settings.size, settings.rulethickness, settings.rulecolor local width, height, scale, offset = settings.width or 0, settings.height or 0, settings.scale or "medium", settings.offset or 0 local l, r, t, b = settings.left or 0, settings.right or 0, settings.top or 0, settings.bottom or 0 @@ -445,63 +469,73 @@ function chemicals.start(settings) scale = 0.75 * scale/625 -- metacode[#metacode+1] = format("chem_start_structure(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) ;", - chemicals.structures, + chemistry.structures, l/25, r/25, t/25, b/25, scale, tostring(settings.axis == variables.on), tostring(width), tostring(height), tostring(offset) ) -- - variant, keys, bonds, stack, rot, pstack = "six", { }, 6, { }, 1, { } + -- variant, keys, bonds, stack, rot, pstack = "six", { }, 6, { }, 1, { } + variant, keys, bonds, stack, rot, pstack = "one", { }, 1, { }, 1, { } end -function chemicals.stop() +function chemistry.stop() metacode[#metacode+1] = "chem_stop_structure ;" -- local mpcode = concat(metacode,"\n") if trace_structure then report_chemistry("metapost code:\n%s", mpcode) end - metapost.graphic(chemicals.instance,chemicals.format,mpcode) + metapost.graphic(chemistry.instance,chemistry.format,mpcode) metacode = nil end -function chemicals.component(spec,text,settings) +function chemistry.component(spec,text,settings) rulethickness, rulecolor, offset = settings.rulethickness, settings.rulecolor - local spec = settings_to_array(lower(spec)) +-- local spec = settings_to_array(lower(spec)) + local spec = settings_to_array(spec) local text = settings_to_array(text) metacode[#metacode+1] = "chem_start_component ;" process(spec,text,1,rulethickness,rulecolor) metacode[#metacode+1] = "chem_stop_component ;" end +statistics.register("chemical formulas", function() + if chemistry.structures > 0 then + return format("%s chemical structure formulas",chemistry.structures) -- no timing needed, part of metapost + end +end) + +-- interfaces + +commands.undefinechemical = chemistry.undefine +commands.definechemical = chemistry.define +commands.startchemical = chemistry.start +commands.stopchemical = chemistry.stop +commands.chemicalcomponent = chemistry.component + +-- todo: top / bottom + local inline = { ["single"] = "\\chemicalsinglebond", ["-"] = "\\chemicalsinglebond", - ["double"] = "\\chemicaldoublebond", ["--"] = "\\chemicaldoublebond", + ["double"] = "\\chemicaldoublebond", ["--"] = "\\chemicaldoublebond", -- also =? and unicode triple? ["triple"] = "\\chemicaltriplebond", ["---"] = "\\chemicaltriplebond", ["gives"] = "\\chemicalgives", ["->"] = "\\chemicalgives", ["equilibrium"] = "\\chemicalequilibrium", ["<->"] = "\\chemicalequilibrium", ["mesomeric"] = "\\chemicalmesomeric", ["<>"] = "\\chemicalmesomeric", - ["plus"] = "\\chemicalsplus", ["+"] = "\\chemicalsplus", - ["minus"] = "\\chemicalsminus", - ["space"] = "\\chemicalsspace", + ["plus"] = "\\chemicalplus", ["+"] = "\\chemicalplus", + ["minus"] = "\\chemicalminus", + ["space"] = "\\chemicalspace", } --- todo: top / bottom - -function chemicals.inline(spec) +function commands.inlinechemical(spec) local spec = settings_to_array(spec) for i=1,#spec do local s = spec[i] local inl = inline[lower(s)] if inl then - context(inl) + context(inl) -- could be a fast context.sprint else context.chemicalinline(molecule(s)) end end end - -statistics.register("chemical formulas", function() - if chemicals.structures > 0 then - return format("%s chemical structure formulas",chemicals.structures) -- no timing needed, part of metapost - end -end) diff --git a/tex/context/base/chem-str.mkiv b/tex/context/base/chem-str.mkiv index 1d60a293e..c4b03dd1e 100644 --- a/tex/context/base/chem-str.mkiv +++ b/tex/context/base/chem-str.mkiv @@ -2,7 +2,7 @@ %D [ file=chem-ini, %D version=2009.05.13, %D subtitle=Chemistry, -%D author=Hans Hagen, +%D author=Hans Hagen \& Alan Braslau, %D date=\currentdate, %D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] %C @@ -10,8 +10,10 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -%D This module in incomplete and experimental. Eventually this code -%D will replace \PPCHTEX. +%D The original \PPCHTEX\ code was written in pure \TEX\, although later we made +%D the move from \PICTEX\ to \METAPOST\. The current implementation is a mix between +%D \TEX\, \LUA\ and \METAPOST. Although the first objective is to get a compatible +%D but better implementation, later versions might provide more, \writestatus{loading}{ConTeXt Chemistry Macros / Structure} @@ -26,24 +28,24 @@ % Here we use chemicalformula instead, so no longer a mix: % % \startchemicalformula -% \chemical{H_2}{top}{bottom} +% \chemical{2H_2}{top}{bottom} % \chemical{PLUS}{top}{bottom} -% \chemical{O}{top}{bottom} +% \chemical{O_2}{top}{bottom} % \chemical{GIVES}{top}{bottom} -% \chemical{H_2O}{top}{bottom} +% \chemical{2H_2O}{top}{bottom} % \stopchemicalformula % % \startchemicalformula -% \chemical{H_2} +% \chemical{2H_2} % \chemical{PLUS} -% \chemical{O} +% \chemical{O_2} % \chemical{GIVES} -% \chemical{H_2O} +% \chemical{2H_2O} % \stopchemicalformula % % The inline variant has only one argument: % -% \chemical{H_2,PLUS,O,GIVES,H_2O} +% \chemical{2H_2,PLUS,O_2,GIVES,2H_2O} % todo: seven | eight | frontsix | fontfive | carbon | newmans | chair @@ -58,11 +60,17 @@ \let\setupchemicals\setupchemical -\unexpanded\def\setupchemicalframed - {\dosingleempty\dosetupchemicalframed} +%D We use a dedicated framed macro instead of inheriting one. This is both +%D a historical and practical reason (like shared keys with different meaning +%D that could clash, e.g.\ align). + +\defineframed + [\??chemicalframed] + [\c!align=\v!normal, + \c!strut=\v!no] -\def\dosetupchemicalframed - {\getparameters[\??chemicalframed]} +\unexpanded\def\setupchemicalframed + {\setupframed[\??chemicalframed]} \unexpanded\def\definechemical % is global (so we don't use the commandhandler) {\dosingleargument\chem_define} @@ -71,7 +79,7 @@ {\startnointerference \edef\currentdefinedchemical{#1}% \let\chemical\chem_chemical_nested - \ctxlua{chemicals.undefine("#1")}% + \ctxcommand{undefinechemical("#1")}% #2% flush \stopnointerference} @@ -79,7 +87,7 @@ {\dodoubleempty\chem_chemical_nested_indeed} \def\chem_chemical_nested_indeed[#1][#2]% - {\ctxlua{chemicals.define("\currentdefinedchemical",\!!bs#1\!!es,\!!bs\detokenize{#2}\!!es)}} + {\ctxcommand{definechemical("\currentdefinedchemical",\!!bs#1\!!es,\!!bs\detokenize{#2}\!!es)}} % chemical symbols @@ -90,20 +98,15 @@ {\setvalue{\??chemicalsymbol#1}{#2}} \unexpanded\def\chemicalsymbol[#1]% - {\csname\??chemicalsymbol\ifcsname\??chemicalsymbol#1\endcsname\s!unknown\else#1\fi\endcsname} + {\csname\??chemicalsymbol\ifcsname\??chemicalsymbol#1\endcsname#1\else\s!unknown\fi\endcsname} -\definechemicalsymbol[\s!unknown][] % empty +\definechemicalsymbol[\s!unknown][] % \char"FFFD empty % size (small medium big) \edef\chemicaltoplocation{t} \edef\chemicalbotlocation{b} -% \unexpanded\def\chemicaltext#1% in ppchtex we had a more clever alignment -% {\usechemicalstyleandcolor\c!style\c!color -% \strut -% #1} % maybe also \setstrut - \unexpanded\def\chemicaltext#1% {\mathematics {\usechemicalstyleandcolor\c!style\c!color @@ -147,7 +150,7 @@ \fi\fi \the\everystructurechemical \setbox\b_chem_result\hbox\bgroup - \ctxlua{chemicals.start { + \ctxcommand{startchemical { width = "\chemicalparameter\c!width", height = "\chemicalparameter\c!height", left = \chemicalparameter\c!left, @@ -162,7 +165,7 @@ \unexpanded\def\stopchemical {\stopnointerference - \ctxlua{chemicals.stop()}% + \ctxcommand{stopchemical()}% \egroup \d_chem_width \wd\b_chem_result \d_chem_height\ht\b_chem_result @@ -171,15 +174,16 @@ \doifelsenothing{\chemicalparameter\c!frame}\chem_framed_nop\chem_framed_yes \egroup} -\def\chem_framed_yes - {\localframed% +\unexpanded\def\chem_framed_yes + {\localframedwithsettings [\??chemicalframed]% - [\c!frame=\chemicalparameter\c!frame,\c!align=\v!normal,\c!strut=\v!no]{\vbox{\box\b_chem_result\vss}}} % remove depth + [\c!frame=\chemicalparameter\c!frame]% + {\vbox{\box\b_chem_result\vss}}} % remove depth -\def\chem_framed_nop - {\localframed% +\unexpanded\def\chem_framed_nop + {\directlocalframed [\??chemicalframed]% - [\c!align=\v!normal,\c!strut=\v!no]{\vbox{\box\b_chem_result\vss}}} % remove depth + {\vbox{\box\b_chem_result\vss}}} % remove depth \let\startstructurechemical\startchemical \let\stopstructurechemical \stopchemical @@ -200,14 +204,14 @@ \def\strc_chem_indeed_three[#1][#2][#3]% {\writestatus\m!chemicals{hyperlinked chemicals not yet supported}% todo reference, for the moment ignored - \ctxlua{chemicals.component(\!!bs#2\!!es, \!!bs\detokenize{#3}\!!es, { % maybe also pass first two args this way + \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 } ) }% \ignorespaces} \def\strc_chem_indeed_two[#1][#2]% - {\ctxlua{chemicals.component(\!!bs#1\!!es,\!!bs\detokenize{#2}\!!es, { % maybe also pass first two args this way + {\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 } ) }% @@ -289,8 +293,8 @@ \def\chem_arrow_construct#1#2#3% {\enspace \mathematics{#1% - {\strut\hbox \!!spread 2\emwidth{\hss\ctxlua{chemicals.inline(\!!bs#2\!!es)}\hss}}% {\strut\hbox \!!spread 2em{\hss#2\hss}}% - {\strut\hbox \!!spread 2\emwidth{\hss\ctxlua{chemicals.inline(\!!bs#3\!!es)}\hss}}}% {\strut\hbox \!!spread 2em{\hss#3\hss}}}% + {\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}}% \enspace} % special macros (probably needs some more work) @@ -428,9 +432,9 @@ \usechemicalstyleandcolor\c!style\c!color \ifthirdargument \ifsecondargument - \halign{&\hss##\hss\cr#2\cr\molecule{#1}\cr#3\cr}% + \halign{\aligntab\hss\alignmark\alignmark\hss\cr#2\cr\molecule{#1}\cr#3\cr}% \else - \halign{&\hss##\hss\cr\molecule{#1}\cr#2\cr}% + \halign{\aligntab\hss\alignmark\alignmark\hss \cr\molecule{#1}\cr#2\cr}% \fi \else \hbox{\molecule{#1}}% @@ -440,30 +444,30 @@ \unexpanded\def\inlinechemical#1% {\dontleavehmode - \hbox{\usechemicalstyleandcolor\c!style\c!color\ctxlua{chemicals.inline(\!!bs#1\!!es)}}} + \hbox{\usechemicalstyleandcolor\c!style\c!color\ctxcommand{inlinechemical(\!!bs#1\!!es)}}} \unexpanded\def\chemicalbondrule - {\hbox{\vrule\!!height.75ex\!!depth-\dimexpr.75ex-\linewidth\relax\!!width1em\relax}} + {\hbox{\vrule\s!height.75\exheight\s!depth-\dimexpr.75\exheight-\linewidth\relax\s!width\emwidth\relax}} \definechemicalsymbol[i:space] [\enspace\quad\enspace] \definechemicalsymbol[i:plus] [\enspace\mathematics{+}\enspace] \definechemicalsymbol[i:minus] [\enspace\mathematics{-}\enspace] \definechemicalsymbol[i:gives] [\enspace\mathematics{\xrightarrow{}{}}\enspace] -\definechemicalsymbol[i:equilibrium] [\enspace\mathematics{\xrightpverleftarrow{}{}}\enspace] +\definechemicalsymbol[i:equilibrium] [\enspace\mathematics{\xrightoverleftarrow{}{}}\enspace] \definechemicalsymbol[i:mesomeric] [\enspace\mathematics{\xleftrightarrow{}{}}\enspace] \definechemicalsymbol[i:single] [\chemicalbondrule] -\definechemicalsymbol[i:tripple] [\hbox{\lower.5ex\chemicalbondrule\hskip-1em\raise.5ex\chemicalbondrule}] -\definechemicalsymbol[i:double] [\hbox{\chemicalbondrule\hskip-1em\lower.5ex\chemicalbondrule\hskip-1em\raise.5ex\chemicalbondrule}] +\definechemicalsymbol[i:double] [\hbox{\lower.5ex\chemicalbondrule\hskip-1em\raise.5ex\chemicalbondrule}] +\definechemicalsymbol[i:triple] [\hbox{\chemicalbondrule\hskip-1em\lower.5ex\chemicalbondrule\hskip-1em\raise.5ex\chemicalbondrule}] \unexpanded\def\chemicalsinglebond {\chemicalsymbol[i:single]} -\unexpanded\def\chemicaldoublebond {\chemicalsymbol[i:tripple]} -\unexpanded\def\chemicaltriplebond {\chemicalsymbol[i:double]} +\unexpanded\def\chemicaldoublebond {\chemicalsymbol[i:double]} +\unexpanded\def\chemicaltriplebond {\chemicalsymbol[i:triple]} \unexpanded\def\chemicalgives {\chemicalsymbol[i:gives]} \unexpanded\def\chemicalmesomeric {\chemicalsymbol[i:mesomeric]} \unexpanded\def\chemicalequilibrium{\chemicalsymbol[i:equilibrium]} -\unexpanded\def\chemicalsplus {\chemicalsymbol[i:plus]} -\unexpanded\def\chemicalsminus {\chemicalsymbol[i:minus]} -\unexpanded\def\chemicalsspace {\chemicalsymbol[i:space]} +\unexpanded\def\chemicalplus {\chemicalsymbol[i:plus]} +\unexpanded\def\chemicalminus {\chemicalsymbol[i:minus]} +\unexpanded\def\chemicalspace {\chemicalsymbol[i:space]} \unexpanded\def\chemicalinline #1{#1} % display @@ -491,61 +495,133 @@ \setfalse\c_chem_has_bot} \unexpanded\def\stopchemicalformula - {\tabskip1em\relax + {\tabskip\emwidth\relax \nointerlineskip \ifconditional\c_chem_has_top \ifconditional\c_chem_has_bot - \halign{&\hss\usechemicalstyleandcolor\c!style\c!color##\hss\cr\the\t_chem_top\cr\the\t_chem_mid\cr\the\t_chem_bot\cr}% + \halign{\aligntab\hss\usechemicalstyleandcolor\c!style\c!color\alignmark\alignmark\hss\cr\the\t_chem_top\cr\the\t_chem_mid\cr\the\t_chem_bot\cr}% \else - \halign{&\hss\usechemicalstyleandcolor\c!style\c!color##\hss\cr\the\t_chem_top\cr\the\t_chem_mid\cr}% + \halign{\aligntab\hss\usechemicalstyleandcolor\c!style\c!color\alignmark\alignmark\hss\cr\the\t_chem_top\cr\the\t_chem_mid\cr}% \fi \else \ifconditional\c_chem_has_bot - \halign{&\hss\usechemicalstyleandcolor\c!style\c!color##\hss\cr\the\t_chem_mid\cr\the\t_chem_bot\cr}% + \halign{\aligntab\hss\usechemicalstyleandcolor\c!style\c!color\alignmark\alignmark\hss\cr\the\t_chem_mid\cr\the\t_chem_bot\cr}% \else - \halign{&\hss\usechemicalstyleandcolor\c!style\c!color##\hss\cr\the\t_chem_mid\cr}% + \halign{\aligntab\hss\usechemicalstyleandcolor\c!style\c!color\alignmark\alignmark\hss\cr\the\t_chem_mid\cr}% \fi \fi \egroup} +% for the moment we have a special set + +\definechemicalsymbol[d:space] [\enspace\quad\enspace] +\definechemicalsymbol[d:plus] [\enspace+\enspace] +\definechemicalsymbol[d:minus] [\enspace-\enspace] +\definechemicalsymbol[d:gives] [\rightarrowfill] % \chem_arrow_construct\xrightarrow +\definechemicalsymbol[d:equilibrium] [\rightoverleftarrowfill] % \chem_arrow_construct\xrightoverleftarrow +\definechemicalsymbol[d:mesomeric] [\leftarrowfill] % \chem_arrow_construct\xleftrightarrow +\definechemicalsymbol[d:opencomplex] [\mathematics{\Bigg[}] % not yet ok +\definechemicalsymbol[d:closecomplex][\mathematics{\Bigg]}] % not yet ok + +\definechemicalsymbol[d:SPACE] [{\chemicalsymbol[d:space]}] +\definechemicalsymbol[d:PLUS] [{\chemicalsymbol[d:plus]}] +\definechemicalsymbol[d:MINUS] [{\chemicalsymbol[d:minus]}] +\definechemicalsymbol[d:GIVES] [{\chemicalsymbol[d:gives]}] +\definechemicalsymbol[d:EQUILIBRIUM] [{\chemicalsymbol[d:equilibrium]}] +\definechemicalsymbol[d:MESOMERIC] [{\chemicalsymbol[d:mesomeric]}] +\definechemicalsymbol[d:OPENCOMPLEX] [{\chemicalsymbol[d:opencomplex]}] +\definechemicalsymbol[d:CLOSECOMPLEX][{\chemicalsymbol[d:closecomplex]}] + \unexpanded\def\formulachemical {\relax\dotriplegroupempty\chem_formula} +% \def\chem_formula#1#2#3% we could do hboxes and measure +% {\ifcsname\??chemicalsymbol\detokenize{#1}\endcsname +% \t_chem_mid\expandafter{\the\t_chem_mid\chem_formula_mid{#1}{#2}{#3}}% +% \else +% \ifthirdargument +% \doifelsenothing{#2}\chem_formula_top_nop{\chem_formula_top_yes{#2}}% +% \doifelsenothing{#3}\chem_formula_bot_nop{\chem_formula_bot_yes{#3}}% +% \else\ifsecondargument +% \chem_formula_top_nop +% \doifelsenothing{#2}\chem_formula_bot_nop{\chem_formula_bot_yes{#2}}% +% \else +% \chem_formula_top_nop +% \chem_formula_bot_nop +% \fi\fi +% \t_chem_mid\expandafter{\the\t_chem_mid\molecule{#1}\aligntab}% +% \fi} + \def\chem_formula#1#2#3% we could do hboxes and measure - {\ifcsname\??chemicalsymbol\detokenize{#1}\endcsname - \t_chem_mid\expandafter{\the\t_chem_mid\chem_formula_mid{#1}{#2}{#3}}% + {\ifthirdargument + \doifelsenothing{#2}\chem_formula_top_nop{\chem_formula_top_yes{#2}}% + \doifelsenothing{#3}\chem_formula_bot_nop{\chem_formula_bot_yes{#3}}% + \else\ifsecondargument + \chem_formula_top_nop + \doifelsenothing{#2}\chem_formula_bot_nop{\chem_formula_bot_yes{#2}}% \else - \ifthirdargument - \doifelsenothing{#2}\chem_formula_top_nop{\chem_formula_top_yes{#2}}% - \doifelsenothing{#3}\chem_formula_bot_nop{\chem_formula_bot_yes{#3}}% - \else\ifsecondargument - \chem_formula_top_nop - \doifelsenothing{#2}\chem_formula_bot_nop{\chem_formula_bot_yes{#2}}% - \else - \chem_formula_top_nop - \chem_formula_bot_nop - \fi\fi - \t_chem_mid\expandafter{\the\t_chem_mid\molecule{#1}&}% + \chem_formula_top_nop + \chem_formula_bot_nop + \fi\fi + \ifcsname\??chemicalsymbol d:\detokenize{#1}\endcsname + \t_chem_mid\expandafter{\the\t_chem_mid\chemicalsymbol[d:#1]\aligntab}% + \else + \t_chem_mid\expandafter{\the\t_chem_mid\molecule{#1}\aligntab}% \fi} \def\chem_formula_mid#1% {\csname\??chemicalsymbol\detokenize{#1}\endcsname} -\def\chem_formula_top_nop {\t_chem_top\expandafter{\the\t_chem_top&}} -\def\chem_formula_bot_nop {\t_chem_bot\expandafter{\the\t_chem_bot&}} -\def\chem_formula_top_yes#1{\t_chem_top\expandafter{\the\t_chem_top\chem_formula_top_indeed{#1}&}\settrue\c_chem_has_top} -\def\chem_formula_bot_yes#1{\t_chem_bot\expandafter{\the\t_chem_bot\chem_formula_bot_indeed{#1}&}\settrue\c_chem_has_bot} +\def\chem_formula_top_nop {\t_chem_top\expandafter{\the\t_chem_top\aligntab}} +\def\chem_formula_bot_nop {\t_chem_bot\expandafter{\the\t_chem_bot\aligntab}} +\def\chem_formula_top_yes#1{\t_chem_top\expandafter{\the\t_chem_top\chem_formula_top_indeed{#1}\aligntab}\settrue\c_chem_has_top} +\def\chem_formula_bot_yes#1{\t_chem_bot\expandafter{\the\t_chem_bot\chem_formula_bot_indeed{#1}\aligntab}\settrue\c_chem_has_bot} \def\chem_formula_top_indeed#1{\strut#1} \def\chem_formula_bot_indeed#1{\strut#1} +% Experimental: defaults might change. + +\definefloat + [\v!chemical] + [\v!chemicals] + +\setuplabeltext + [\v!chemical=] + +\setupfloat + [\v!chemical] + [\c!location=\v!here, + \c!inner=\hsize.8\textwidth\dontleavehmode, % brr + \c!align={\v!flushleft,\v!lohi}] + +\setupcaption + [\v!chemical] + [\c!location=\v!right, + \c!distance=\zeropoint, + \c!width=.2\textwidth, + \c!align=\v!flushright] + +% Can be used as for displayed math: \startplaceformula... to display a chemical formula +% or a chemical structure: +% +% \startplacechemical +% \startchemicalformula +% \chemical{2H_2} +% \chemical{PLUS} +% \chemical{O_2} +% \chemical{GIVES} +% \chemical{2H_2O} +% \stopchemicalformula +% \stopplacechemical + % gone: state option resolution offset (now frame offset) alternative \setupchemicalframed [\c!align=\v!normal, \c!strut=\v!no, \c!offset=\v!overlay, - \c!frame=off] + \c!frame=\v!off] \setupchemical [\c!frame=, diff --git a/tex/context/base/cldf-bas.lua b/tex/context/base/cldf-bas.lua index 30a9265bc..9cf8dcd4a 100644 --- a/tex/context/base/cldf-bas.lua +++ b/tex/context/base/cldf-bas.lua @@ -1,4 +1,4 @@ -if not modules then modules = { } end modules ['cldf-ini'] = { +if not modules then modules = { } end modules ['cldf-bas'] = { version = 1.001, comment = "companion to cldf-ini.mkiv", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", @@ -22,6 +22,8 @@ if not modules then modules = { } end modules ['cldf-ini'] = { -- flush(ctxcatcodes,"}") -- end +-- maybe use context.generics + local type = type local format = string.format local utfchar = utf.char @@ -32,13 +34,16 @@ local generics = context.generics local variables = interfaces.variables local new_rule = nodes.pool.rule +local texcount = tex.count function context.char(k) -- used as escape too, so don't change to utf if type(k) == "table" then - -- for i=1,#k do - -- context(format([[\char%s\relax]],k[i])) - -- end - context([[\char%s\relax]],concat(k,[[\relax\char]])) + local n = #k + if n == 1 then + context([[\char%s\relax]],k[1]) + elseif n > 0 then + context([[\char%s\relax]],concat(k,[[\relax\char]])) + end elseif k then context([[\char%s\relax]],k) end @@ -98,22 +103,22 @@ context.vrule = context.hrule -- not yet used ... but will get variant at the tex end as well -function context.sethboxregister (n) context("\\setbox %s\\hbox",n) end -function context.setvboxregister (n) context("\\setbox %s\\vbox",n) end +function context.sethboxregister(n) context([[\setbox %s\hbox]],n) end +function context.setvboxregister(n) context([[\setbox %s\vbox]],n) end function context.starthboxregister(n) if type(n) == "number" then - context("\\setbox%s\\hbox\\bgroup",n) + context([[\setbox%s\hbox{]],n) else - context("\\setbox\\%s\\hbox\\bgroup",n) + context([[\setbox\%s\hbox{]],n) end end function context.startvboxregister(n) if type(n) == "number" then - context("\\setbox%s\\vbox\\bgroup",n) + context([[\setbox%s\vbox{]],n) else - context("\\setbox\\%s\\vbox\\bgroup",n) + context([[\setbox\%s\vbox{]],n) end end @@ -122,19 +127,36 @@ context.stopvboxregister = context.egroup function context.flushboxregister(n) if type(n) == "number" then - context("\\box%s ",n) + context([[\box%s ]],n) else - context("\\box\\%s",n) + context([[\box\%s]],n) end end function context.beginvbox() - context("\\vbox\\bgroup") -- we can do \bvbox ... \evbox (less tokens) + context([[\vbox{]]) -- we can do \bvbox ... \evbox (less tokens) end function context.beginhbox() - context("\\hbox\\bgroup") -- todo: use fast one + context([[\hbox{]]) -- todo: use fast one end context.endvbox = context.egroup context.endhbox = context.egroup + +local function allocate(name,what,cmd) + local a = format("c_syst_last_allocated_%s",what) + local n = texcount[a] + 1 + if n <= texcount.c_syst_max_allocated_register then + texcount[a] = n + end + context("\\global\\expandafter\\%sdef\\csname %s\\endcsname %s\\relax",cmd or what,name,n) + return n +end + +function context.newdimen (name) return allocate(name,"dimen") end +function context.newskip (name) return allocate(name,"skip") end +function context.newcount (name) return allocate(name,"count") end +function context.newmuskip(name) return allocate(name,"muskip") end +function context.newtoks (name) return allocate(name,"toks") end +function context.newbox (name) return allocate(name,"box","mathchar") end diff --git a/tex/context/base/cldf-com.lua b/tex/context/base/cldf-com.lua index bacbbeafd..d9062594e 100644 --- a/tex/context/base/cldf-com.lua +++ b/tex/context/base/cldf-com.lua @@ -11,8 +11,8 @@ local context = context local generics = context.generics -- needs documentation local variables = interfaces.variables -generics.starttabulate = "start" .. variables.tabulate -- todo: e!start -generics.stoptabulate = "stop" .. variables.tabulate -- todo: e!stop +generics.starttabulate = "starttabulate" -- "start" .. variables.tabulate -- todo: e!start +generics.stoptabulate = "stoptabulate" -- "stop" .. variables.tabulate -- todo: e!stop local NC, NR = context.NC, context.NR diff --git a/tex/context/base/cldf-ini.lua b/tex/context/base/cldf-ini.lua index ed86c2923..ad5f14855 100644 --- a/tex/context/base/cldf-ini.lua +++ b/tex/context/base/cldf-ini.lua @@ -25,7 +25,7 @@ local tex = tex context = context or { } local context = context -local format, find, gmatch, gsub = string.format, string.find, string.gmatch, string.gsub +local format, find, gmatch, gsub, validstring = string.format, string.find, string.gmatch, string.gsub, string.valid local next, type, tostring, tonumber, setmetatable = next, type, tostring, tonumber, setmetatable local insert, remove, concat = table.insert, table.remove, table.concat local lpegmatch, lpegC, lpegS, lpegP, lpegCc = lpeg.match, lpeg.C, lpeg.S, lpeg.P, lpeg.Cc @@ -40,12 +40,14 @@ local isnode = node.is_node -- after 0.65 just node.type local writenode = node.write local copynodelist = node.copy_list -local ctxcatcodes = tex.ctxcatcodes -local prtcatcodes = tex.prtcatcodes -local texcatcodes = tex.texcatcodes -local txtcatcodes = tex.txtcatcodes -local vrbcatcodes = tex.vrbcatcodes -local xmlcatcodes = tex.xmlcatcodes +local catcodenumbers = catcodes.numbers + +local ctxcatcodes = catcodenumbers.ctxcatcodes +local prtcatcodes = catcodenumbers.prtcatcodes +local texcatcodes = catcodenumbers.texcatcodes +local txtcatcodes = catcodenumbers.txtcatcodes +local vrbcatcodes = catcodenumbers.vrbcatcodes +local xmlcatcodes = catcodenumbers.xmlcatcodes local flush = texsprint local flushdirect = texprint @@ -344,9 +346,9 @@ end local methodhandler = resolvers.methodhandler -function context.viafile(data) +function context.viafile(data,tag) if data and data ~= "" then - local filename = resolvers.savers.byscheme("virtual","viafile",data) + local filename = resolvers.savers.byscheme("virtual",validstring(tag,"viafile"),data) -- context.startregime { "utf" } context.input(filename) -- context.stopregime() @@ -410,7 +412,11 @@ local function writer(parent,command,first,...) -- already optimized before call done = true end end - flush(currentcatcodes,"]") + if done then + flush(currentcatcodes,"]") + else + flush(currentcatcodes,"[]") + end elseif tn == 1 then -- some 20% faster than the next loop local tj = ti[1] if type(tj) == "function" then diff --git a/tex/context/base/cldf-int.lua b/tex/context/base/cldf-int.lua index 55db9fa0b..6cbfd666f 100644 --- a/tex/context/base/cldf-int.lua +++ b/tex/context/base/cldf-int.lua @@ -1,4 +1,4 @@ -if not modules then modules = { } end modules ['mult-clm'] = { +if not modules then modules = { } end modules ['cldf-int'] = { version = 1.001, comment = "companion to mult-clm.mkiv", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", @@ -14,9 +14,12 @@ if not modules then modules = { } end modules ['mult-clm'] = { local format, insert, remove, concat = string.format, table.insert, table.remove, table.concat local unpack = unpack or table.unpack -local contextsprint = context.sprint -local ctxcatcodes = tex.ctxcatcodes -local vrbcatcodes = tex.vrbcatcodes +local catcodenumbers = catcodes.numbers + +local ctxcatcodes = catcodenumbers.ctxcatcodes +local vrbcatcodes = catcodenumbers.vrbcatcodes + +local contextsprint = context.sprint local trace_define = false trackers.register("context.define", function(v) trace_define = v end) diff --git a/tex/context/base/cldf-ver.lua b/tex/context/base/cldf-ver.lua index 237078157..b48fd253a 100644 --- a/tex/context/base/cldf-ver.lua +++ b/tex/context/base/cldf-ver.lua @@ -6,6 +6,10 @@ if not modules then modules = { } end modules ['cldf-ver'] = { license = "see context related readme files" } +-- We have better verbatim: context.verbatim so that needs to be looked +-- into. We can also directly store in buffers although this variant works +-- better when used mixed with other code (synchronization issue). + local concat, tohandle = table.concat, table.tohandle local find, splitlines = string.find, string.splitlines local tostring, type = tostring, type @@ -41,7 +45,7 @@ table .tocontext = t_tocontext string .tocontext = s_tocontext boolean.tocontext = b_tocontext -function tocontext(first,...) +function context.tocontext(first,...) local t = type(first) if t == "string" then s_tocontext(first,...) diff --git a/tex/context/base/colo-ext.mkiv b/tex/context/base/colo-ext.mkiv index af6c3830e..8878da485 100644 --- a/tex/context/base/colo-ext.mkiv +++ b/tex/context/base/colo-ext.mkiv @@ -29,18 +29,10 @@ %D %D will negate the colors in box zero. -% \unexpanded\def\negatecolorbox#1% -% {\setbox#1\hbox -% {\startnegative % might change -% \startcolor[\s!white]\vrule\!!height\ht#1\!!depth\dp#1\!!width\wd#1\stopcolor -% \hskip-\wd#1% -% \box#1% -% \stopnegative}} - \unexpanded\def\negatecolorbox#1% {\setbox#1\hbox {\startnegative % might change -% \startcolor[\s!white]\vrule\!!height\ht#1\!!depth\dp#1\!!width\wd#1\stopcolor + % \startcolor[\s!white]\vrule\s!height\ht#1\s!depth\dp#1\s!width\wd#1\stopcolor \blackrule[\c!color=\s!white,\c!height=\ht#1,\c!depth=\dp#1,\c!width=\wd#1]% \hskip-\wd#1% \box#1% diff --git a/tex/context/base/colo-icc.lua b/tex/context/base/colo-icc.lua index 904d42143..4ab28eb68 100644 --- a/tex/context/base/colo-icc.lua +++ b/tex/context/base/colo-icc.lua @@ -1,4 +1,4 @@ -if not modules then modules = { } end modules ['colo-ini'] = { +if not modules then modules = { } end modules ['colo-icc'] = { version = 1.000, comment = "companion to colo-ini.mkiv", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", diff --git a/tex/context/base/colo-ini.lua b/tex/context/base/colo-ini.lua index 747e2116f..e08f3d387 100644 --- a/tex/context/base/colo-ini.lua +++ b/tex/context/base/colo-ini.lua @@ -16,7 +16,8 @@ local trace_define = false trackers.register("colors.define",function(v) trace_ local report_colors = logs.reporter("colors","defining") -local attributes, context, commands = attributes, context, commands +local attributes, backends, storage = attributes, backends, storage +local context, commands = context, commands local settings_to_hash_strict = utilities.parsers.settings_to_hash_strict @@ -666,83 +667,51 @@ function colors.defineintermediatecolor(name,fraction,c_one,c_two,a_one,a_two,sp end end ---~ local function f(one,two,i,fraction_one,fraction_two) ---~ local otf = fraction_one * one[i] + fraction_two * two[i] ---~ if otf > 1 then ---~ otf = 1 ---~ end ---~ return otf ---~ end - ---~ function colors.defineduocolor(name,fraction_one,c_one,fraction_two,c_two,global,freeze) ---~ local one, two = colorvalues[c_one], colorvalues[c_two] ---~ if one and two then ---~ fraction_one = tonumber(fraction_one) or 1 ---~ fraction_two = tonumber(fraction_two) or 1 ---~ local csone, cstwo = one[1], two[1] ---~ local ca ---~ if csone == 2 then ---~ ca = register_color(name,'gray',f(one,two,2,fraction_one,fraction_two)) ---~ elseif csone == 3 then ---~ ca = register_color(name,'rgb', f(one,two,3,fraction_one,fraction_two), ---~ f(one,two,4,fraction_one,fraction_two), ---~ f(one,two,5,fraction_one,fraction_two)) ---~ elseif csone == 4 then ---~ ca = register_color(name,'cmyk',f(one,two,6,fraction_one,fraction_two), ---~ f(one,two,7,fraction_one,fraction_two), ---~ f(one,two,8,fraction_one,fraction_two), ---~ f(one,two,9,fraction_one,fraction_two)) ---~ else ---~ ca = register_color(name,'gray',f(one,two,2,fraction_one,fraction_two)) ---~ end ---~ definecolor(name,ca,global,freeze) ---~ end ---~ end - - local function f(i,colors,fraction) - local otf = 0 - for c=1,#colors do - otf = otf + (tonumber(fraction[c]) or 1) * colors[c][i] - end - if otf > 1 then - otf = 1 - end - return otf +local function f(i,colors,fraction) + local otf = 0 + for c=1,#colors do + otf = otf + (tonumber(fraction[c]) or 1) * colors[c][i] + end + if otf > 1 then + otf = 1 end + return otf +end - function colors.definemixcolor(name,fractions,cs,global,freeze) - local values = { } - for i=1,#cs do -- do fraction in here - local v = colorvalues[cs[i]] - if not v then - return - end - values[i] = v - end - local csone = values[1][1] - local ca - if csone == 2 then - ca = register_color(name,'gray',f(2,values,fractions)) - elseif csone == 3 then - ca = register_color(name,'rgb', f(3,values,fractions), - f(4,values,fractions), - f(5,values,fractions)) - elseif csone == 4 then - ca = register_color(name,'cmyk',f(6,values,fractions), - f(7,values,fractions), - f(8,values,fractions), - f(9,values,fractions)) - else - ca = register_color(name,'gray',f(2,values,fractions)) +function colors.definemixcolor(name,fractions,cs,global,freeze) + local values = { } + for i=1,#cs do -- do fraction in here + local v = colorvalues[cs[i]] + if not v then + return end - definecolor(name,ca,global,freeze) + values[i] = v end + local csone = values[1][1] + local ca + if csone == 2 then + ca = register_color(name,'gray',f(2,values,fractions)) + elseif csone == 3 then + ca = register_color(name,'rgb', f(3,values,fractions), + f(4,values,fractions), + f(5,values,fractions)) + elseif csone == 4 then + ca = register_color(name,'cmyk',f(6,values,fractions), + f(7,values,fractions), + f(8,values,fractions), + f(9,values,fractions)) + else + ca = register_color(name,'gray',f(2,values,fractions)) + end + definecolor(name,ca,global,freeze) +end -- for the moment downward compatible local patterns = { "colo-imp-%s.mkiv", "colo-imp-%s.tex", "colo-%s.mkiv", "colo-%s.tex" } local function action(name,foundname) + -- could be one command context.startreadingfile() context.startcolorset { name } context.input(foundname) @@ -877,3 +846,22 @@ end -- context.popcatcodes() -- end +-- handy + +local models = storage.allocate { "all", "gray", "rgb", "cmyk", "spot" } + +colors.models = models -- check for usage elsewhere + +function colors.spec(name) + local l = attributes_list[a_color] + local t = colorvalues[l[name]] or colorvalues[l.black] + return { + model = models[t[1]] or models[1], + s = t[2], + r = t[3], g = t[4], b = t[5], + c = t[6], m = t[7], y = t[8], k = t[9], + } +end + +-- inspect(attributes.colors.spec("red")) +-- inspect(attributes.colors.spec("red socks")) diff --git a/tex/context/base/colo-ini.mkiv b/tex/context/base/colo-ini.mkiv index 5721bb513..629f2b96a 100644 --- a/tex/context/base/colo-ini.mkiv +++ b/tex/context/base/colo-ini.mkiv @@ -242,8 +242,8 @@ \setfalse\c_colo_convert_gray \getvalue{\??colorconversions\directcolorsparameter\c!conversion}% could be a nice \ifcsname % too often: - \ifconditional\c_colo_rgb_supported \colo_helpers_show_message\m!colors9\v!rgb \fi - \ifconditional\c_colo_cmyk_supported\colo_helpers_show_message\m!colors9\v!cmyk\fi + \ifconditional\c_colo_rgb_supported \colo_helpers_show_message\m!colors{10}\v!rgb \fi + \ifconditional\c_colo_cmyk_supported\colo_helpers_show_message\m!colors{10}\v!cmyk\fi \colo_helpers_set_current_model \ifproductionrun \edef\p_pagecolormodel{\directcolorsparameter\c!pagecolormodel}% @@ -357,16 +357,26 @@ \normalexpanded{\colo_palets_define[#1][\csname\??colorpaletspecification#2\endcsname]}% \fi}} -\def\colo_palets_define_one#1#2% get rid of { } in #2 - {\colo_palets_define_two{#1}[#2]}% +% \def\colo_palets_define_one#1#2% get rid of { } in #2 +% {\colo_palets_define_two{#1}[#2]}% + +\def\colo_palets_define_one#1#2% get rid of { } + {\doifassignmentelse{#2} % catch empty entries + {\colo_palets_define_two{#1}[#2]} + {\colo_palets_define_three{#1}{#2}}} \def\colo_palets_define_two#1[#2=#3]% {\edef\m_colo_palets_tmp{\ifx\m_colo_palets_tmp\empty\else\m_colo_palets_tmp,\fi#2}% \colo_palets_define_set{#1}{#2}{#3}}% +\def\colo_palets_define_three#1#2% + {\ifcsname\??colorpaletspecification#2\endcsname + \processcommacommand[\csname\??colorpaletspecification#2\endcsname]{\colo_palets_define_one{#1}}% + \fi} + \let\paletsize\!!zerocount -\def\getpaletsize[#1]% +\unexpanded\def\getpaletsize[#1]% only works for valid k=v definitions {\getcommacommandsize[\csname\??colorpaletspecification#1\endcsname]% \edef\paletsize{\number\commalistsize}} @@ -802,9 +812,19 @@ \def\defaulttextcolor {black} \def\s!themaintextcolor{themaintextcolor} +\unexpanded\def\inheritmaintextcolor + {\ifx\maintextcolor\empty\else\colo_helpers_activate\maintextcolor\fi} + +\unexpanded\def\onlyinheritmaintextcolor + {\ifx\maintextcolor\empty + \deactivatecolor + \else + \colo_helpers_activate\maintextcolor + \fi} + \appendtoks \deactivatecolor % public? - \ifx\maintextcolor\empty\else\colo_helpers_activate\maintextcolor\fi + \inheritmaintextcolor \to \everybeforeoutput \def\colo_helpers_switch_to_maintextcolor#1% @@ -961,7 +981,7 @@ % ignores in attribute handler % -% \def\forcecolorhack{\vrule\!!width\zeropoint\!!height\zeropoint\!!depth\zeropoint} +% \def\forcecolorhack{\vrule\s!width\zeropoint\s!height\zeropoint\s!depth\zeropoint} % \normal added else fails in metafun manual (leaders do a hard scan) diff --git a/tex/context/base/colo-run.lua b/tex/context/base/colo-run.lua index 4f1916d5a..27f7c6b12 100644 --- a/tex/context/base/colo-run.lua +++ b/tex/context/base/colo-run.lua @@ -6,8 +6,10 @@ if not modules then modules = { } end modules ['colo-run'] = { license = "see context related readme files" } --- For historic reasons the core has a couple of tracing --- features. Nowadays these would end up in modules. +-- For historic reasons the core has a couple of tracing features. Nowadays +-- these would end up in modules. + +local colors, commands, context, utilities = colors, commands, context, utilities local colors= attributes.colors diff --git a/tex/context/base/colo-run.mkiv b/tex/context/base/colo-run.mkiv index c330accf3..5084fdd35 100644 --- a/tex/context/base/colo-run.mkiv +++ b/tex/context/base/colo-run.mkiv @@ -42,9 +42,9 @@ %D Palets \unexpanded\gdef\showpalet - {\dodoubleargument\doshowpalet} + {\dodoubleargument\colo_show_palet} -\gdef\doshowpalet[#1][#2]% +\gdef\colo_show_palet[#1][#2]% {\ifcsname\??colorpalet#1\endcsname \doifinsetelse\v!vertical{#2} \colo_palets_show_vertical \colo_palets_show_horizontal [#1][#2]% \fi} @@ -59,8 +59,8 @@ \tabskip\zeropoint \def\colo_palets_show_palet##1% {\doifinsetelse\v!number{#2}{##1\hskip.5em}{}& - \color[##1]{\vrule\!!width3em\!!height\strutht\!!depth\strutdp}% - \graycolor[##1]{\vrule\!!width3em\!!height\strutht\!!depth\strutdp}& + \color[##1]{\vrule\s!width3em\s!height\strutht\s!depth\strutdp}% + \graycolor[##1]{\vrule\s!width3em\s!height\strutht\s!depth\strutdp}& \doifinset\v!value{#2}{\hskip.5em\colorvalue{##1}}\crcr} \halign {\hss##&\hss##\hss#\cr @@ -92,11 +92,11 @@ \colo_palets_process[#1]\colo_palets_show_palet}\cr \doifinset\v!name{#2}{#1\hskip.5em}% \def\colo_palets_show_palet##1% - {&\strut\color[##1]{\vrule\!!width\!!widtha\!!height\strutht\!!depth\zeropoint}}% + {&\strut\color[##1]{\vrule\s!width\!!widtha\s!height\strutht\s!depth\zeropoint}}% \colo_palets_process[#1]\colo_palets_show_palet\crcr \noalign{\vskip-\strutdepth}% \def\colo_palets_show_palet##1% - {&\graycolor[##1]{\vrule\!!width\!!widtha\!!height\zeropoint\!!depth\strutdp}}% + {&\graycolor[##1]{\vrule\s!width\!!widtha\s!height\zeropoint\s!depth\strutdp}}% \colo_palets_process[#1]\colo_palets_show_palet\crcr \doifinset\v!value{#2} {\def\colo_palets_show_palet##1% @@ -137,13 +137,13 @@ \def\colo_palets_compare##1% {\hbox {\setbox0\hbox - {#1[##1]{\vrule\!!width\hsize\!!height3ex}}% + {#1[##1]{\vrule\s!width\hsize\s!height3ex}}% \wd0\zeropoint \box0 \hbox to \hsize {\def\colo_palets_compare####1% {\hbox to \!!widtha - {\hss#1[####1]{\vrule\!!width.5\!!widtha\!!height2.25ex\!!depth-.75ex}\hss}}% + {\hss#1[####1]{\vrule\s!width.5\!!widtha\s!height2.25ex\s!depth-.75ex}\hss}}% \processcommacommand[\getvalue{\??colorpalet#2}]\colo_palets_compare}} \endgraf} \processcommacommand[\getvalue{\??colorpalet#2}]\colo_palets_compare}} @@ -171,8 +171,8 @@ {\halign {\hss####\hss\cr \doifinset\v!number{#2}{\strut##1}\cr - \color[#1:##1]{\vrule\!!width4em\!!height\strutht\!!depth\zeropoint}\cr - \graycolor[#1:##1]{\vrule\!!width4em\!!height\zeropoint\!!depth\strutdp}\cr + \color[#1:##1]{\vrule\s!width4em\s!height\strutht\s!depth\zeropoint}\cr + \graycolor[#1:##1]{\vrule\s!width4em\s!height\zeropoint\s!depth\strutdp}\cr \doifinset\v!value{#2}{\colorvalue{#1:##1}\strut}\crcr}}}}% \hbox {\doifinset\v!name{#2} @@ -195,8 +195,8 @@ \def\colo_groups_show_group##1% {\doifcolor{#1:##1} {\doifinset\v!number{#2}{##1\hskip.5em}& - \color[#1:##1]{\vrule\!!width2.5em\!!height\strutht\!!depth\strutdp}% - \graycolor[#1:##1]{\vrule\!!width2.5em\!!height\strutht\!!depth\strutdp}& + \color[#1:##1]{\vrule\s!width2.5em\s!height\strutht\s!depth\strutdp}% + \graycolor[#1:##1]{\vrule\s!width2.5em\s!height\strutht\s!depth\strutdp}& \doifinset\v!value{#2}{\hskip.5em\colorvalue{#1:##1}}\crcr}}% \halign {\hss##&\hss##\hss#\hss\cr @@ -228,11 +228,11 @@ \def\colo_groups_compare_step#1#2#3% {\hbox to \hsize {\setbox0\hbox - {#1[#2:#3]{\vrule\!!width\hsize\!!height3ex}}% + {#1[#2:#3]{\vrule\s!width\hsize\s!height3ex}}% \wd0\zeropoint \box0 \hbox to \hsize - {\hss\dorecurse\!!counta{#1[#2:\recurselevel]{\vrule\!!width.5\!!widtha\!!height2.25ex\!!depth-.75ex}\hss}}} + {\hss\dorecurse\!!counta{#1[#2:\recurselevel]{\vrule\s!width.5\!!widtha\s!height2.25ex\s!depth-.75ex}\hss}}} \endgraf} \protect \endinput diff --git a/tex/context/base/cont-log.mkiv b/tex/context/base/cont-log.mkiv index 67647920d..5d4133143 100644 --- a/tex/context/base/cont-log.mkiv +++ b/tex/context/base/cont-log.mkiv @@ -118,7 +118,7 @@ \logofont} \def\syst_logos_meta_hyphen % there is no hyphenchar in this font - {\discretionary{\vrule\!!height.33em\!!depth-.27em\!!width.33em}{}{}} + {\discretionary{\vrule\s!height.33em\s!depth-.27em\s!width.33em}{}{}} \unexpanded\def\MetaFont {\dontleavehmode @@ -270,4 +270,12 @@ \unexpanded\def\MPII{MpII} \unexpanded\def\MPIV{MpIV} +\appendtoks + \def\ConTeXt {ConTeXt}% + \def\MetaPost{MetaPost}% + \def\MetaFont{MetaFont}% + \def\MetaFun {MetaFun}% + \def\TeX {TeX}% +\to \everysimplifycommands + \protect \endinput diff --git a/tex/context/base/cont-new.mkii b/tex/context/base/cont-new.mkii index b4958762f..2c07401d8 100644 --- a/tex/context/base/cont-new.mkii +++ b/tex/context/base/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2012.05.30 11:26} +\newcontextversion{2012.10.19 00:06} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index 5a28f8e29..e791d3ba8 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,515 +11,60 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2012.05.30 11:26} +\newcontextversion{2012.10.19 00:06} -%D This file is loaded at runtime, thereby providing an -%D excellent place for hacks, patches, extensions and new -%D features. +%D This file is loaded at runtime, thereby providing an excellent place for +%D hacks, patches, extensions and new features. \unprotect \writestatus\m!system{beware: some patches loaded from cont-new.mkiv} -\def\dividedsize#1#2#3% size gap n - {\dimexpr - \ifnum\dimexpr#1\relax>\plusone - (\dimexpr#1\relax-\numexpr#3-1\relax\dimexpr#2\relax)/#3\else#1% - \fi - \relax} - -\def\singlewidened #1{\hbox spread 1em{\hss#1\hss}} -\def\complexwidened[#1]#2{\hbox spread #1{\hss#2\hss}} +%D Maybe: -\definecomplexorsimple\widened - -\let\active\activecatcode % for a while (tikz) - -% todo -% -% \def\definelocation{\dodoubleargument\dodefinelocation} -% \def\dodefinelocation[#1][#2]{\setvalue{loc:#1}{#2}} -% -% \definelocation[lt] [\v!left\v!top] -% \definelocation[tl] [\v!left\v!top] -% \definelocation[\v!top\v!left][\v!left\v!top] -% -% \def\getlocation#1{\executeifdefined{loc:#1}{#1}} - -% \let\cs\getvalue % no, we want \cs to be czech - -% experimental so this may change +\unexpanded\def\tightvbox{\dowithnextbox{\dp\nextbox\zeropoint\box\nextbox}\vbox} +\unexpanded\def\tightvtop{\dowithnextbox{\ht\nextbox\zeropoint\box\nextbox}\vtop} -\def\startdescriptions - {\dosingleempty\dostartdescriptions} +%D Needs some work: -\def\dostartdescriptions[#1]% - {\begingroup - \def\item{\getvalue{#1}}% - \let\dostoppairdescription \donothing - \let\@@description \dostartpairdescription - \let\@@startsomedescription\dostartsomedescription} +\unexpanded\def\startgridcorrection + {\dosingleempty\spac_grid_correction_start} -\def\stopdescriptions - {\dostoppairdescription - \endgroup} - -\def\dostartpairdescription[#1][#2]% - {\dostoppairdescription - \def\dostoppairdescription{\@@stopdescription{#1}}% - \bgroup - \def\currentdescription{#1}% - \doifelse{\descriptionparameter{\s!do\c!state}}\v!start - {\@@makedescription{#1}[#2]{}} - {\@@makedescription{#1}[#2]}} - -\def\dostartsomedescription% #1[#2]#3% - {\bgroup - \@@makedescription} % {#1}[#2]{#3}} - -% \starttext -% -% \definedescription[test] -% -% \startdescriptions -% \test{Foo} Bar bar bar -% \test{Foo} Bar bar bar -% \test{Foo} Bar bar bar -% \stopdescriptions -% -% \startdescriptions[test] -% \item{Foo} Bar bar bar -% \item{Foo} Bar bar bar -% \item{Foo} Bar bar bar -% \stopdescriptions -% -% \startdescriptions -% \starttest{Foo} Bar bar bar \stoptest -% \starttest{Foo} Bar bar bar \stoptest -% \starttest{Foo} Bar bar bar \stoptest -% \stopdescriptions -% -% \startdescriptions[test] -% \item{Foo} Bar bar bar -% \item{Foo} Bar bar bar -% \item{Foo} Bar bar bar -% \stopdescriptions -% -% \stoptext - -% this will be activated when -% -% \newinsert\thispageinsert % <- installinsertion -% -% \def\flushatthispage -% {\bgroup -% \dowithnextbox{\insert\thispageinsert{\box\nextbox}\egroup}% -% \hbox} -% -% \appendtoks -% \ifvoid\thispageinsert\else\hbox{\smashedbox\thispageinsert}\fi -% \to \everyshipout - -% \definemarkedpage[nobackgrounds] -% \markpage[nobackgrounds] -% \doifmarkedpageelse{nobackgrounds} - -% Just a simple and fast hanger, for usage in macros. - -\def\setuphanging - {\dodoubleempty\getparameters[\??ha]} - -\setuphanging - [\c!distance=.5em] - -\def\starthanging - {\noindent\bgroup - \dowithnextbox - {\setbox\nextbox\hbox{\flushnextbox\hskip\@@hadistance}% - \hangindent\nextboxwd - \hangafter\plusone - \flushnextbox\ignorespaces} - \hbox} - -\def\stophanging - {\endgraf - \egroup} - -% experimental - -\def\stophangaround - {\endgraf - \egroup} - -\def\starthangaround - {\noindent\bgroup - \dowithnextbox - {\ifdim\nextboxht>\strutht\setbox\nextbox\tbox{\flushnextbox}\fi - \setbox\nextbox\hbox{\flushnextbox\hskip\@@hadistance}% - \getboxheight\scratchdimen\of\box\nextbox - \getnoflines\scratchdimen - \nextboxht\strutht - \nextboxdp\strutdp - \hangindent\nextboxwd - \hangafter-\noflines - \llap{\flushnextbox}\ignorespaces} - \hbox} - -\def\modevalue#1#2#3% - {\@EA\ifx\csname\@mode@\systemmodeprefix#1\endcsname\endcsname\enabledmode#2\else#2\fi} - -\def\systemmodevalue#1% - {\modevalue{\systemmodeprefix#1}} - -% new, still to be improved -% -% \dorecurse{10} -% {\input thuan -% \placefigure{}{\framed[height=1.5cm]{test}} -% \placefloatplaceholder} - -\def\placefloatplaceholder - {\ifroomforfloat \else - \scratchdimen\pagegoal - \advance\scratchdimen-\pagetotal - \advance\scratchdimen-3\lineheight - \ifdim\scratchdimen>\zeropoint - \startlinecorrection[blank] - \mhbox{\inframed{\labeltexts{placeholder}{\lastcaptiontag}}}% - \stoplinecorrection - \else - \allowbreak - \fi - \fi} - -\setuplabeltext - [placeholder={, moved}] - -% move to support module, and then use context(...) - -\startluacode - function commands.percentageof(str,dim) - local n = str:match("^(.*)%%$") - context.sprint(tex.ctxcatcodes,(n and (tonumber(n)/100)*dim .. "sp") or str) - end -\stopluacode - -\gdef\setpercentdimen#1#2% - {#1=\ctxcommand{percentageof("#2",\number#1)}\relax} - -% \scratchdimen=100pt \setpercentdimen\scratchdimen{10\letterpercent} \the\scratchdimen -% \scratchdimen=100pt \setpercentdimen\scratchdimen{5pt} \the\scratchdimen - -\bgroup \permitcircumflexescape - -\obeylines % don't remove %'s ! - -\gdef\collapsedspace#1% - {\ifx#1^^M% - \expandafter\collapsedspace - \else - \space - \expandafter#1% - \fi} - -\gdef\collapsespaces - {\prependtoksonce\relax\to\everyeof% - \ignorelines% - \ignoretabs% - \let\obeyedspace\collapsedspace% - \obeyspaces} - -\egroup - -\def\inlinedbox - {\bgroup - \dowithnextbox - {\scratchdimen\nextboxht - \advance\scratchdimen\nextboxdp - \advance\scratchdimen-\lineheight - \divide\scratchdimen\plustwo - \advance\scratchdimen\strutdepth - \setbox\nextbox\hbox{\lower\scratchdimen\flushnextbox}% - \nextboxht\strutht - \nextboxdp\strutdp - \flushnextbox - \egroup}% - \hbox} - -\def\dimenratio#1#2% etex only - {\withoutpt\the\dimexpr2\dimexpr(#1)/\dimexpr(#2)/32768\relax\relax} - -\def\doxprecurse#1#2% - {\ifnum#1=\zerocount % no \ifcase - \expandafter\gobblethreearguments - \else - #2\expandafter\expandafter\expandafter\doxprecurse\expandafter - \fi\expandafter{\the\numexpr#1-1\relax}{#2}} - -\def\buttonframed{\dodoubleempty\localframed[\??bt]} % goodie - -\unexpanded\def\asciistr#1{\dontleavehmode{\defconvertedargument\ascii{#1}\verbatimfont\ascii}} - -\def\shapefill{\vskip\zeropoint\!!plus\lineheight\!!minus\lineheight\relax} - -% \ruledhbox -% {\startignorespaces -% \def\oeps{a} -% \startignorespaces -% \def\oeps{a} -% \stopignorespaces -% \def\oeps{a} -% \stopignorespaces -% \oeps} - -\newsignal\boissignal -\newcount \boislevel - -\long\def\startignorespaces - {\advance\boislevel\plusone - \ifcase\boislevel\or \ifhmode - \hskip\boissignal - \fi \fi - \ignorespaces} - -\long\def\stopignorespaces - {\ifcase\boislevel\or \ifhmode - \doloop - {\ifdim\lastskip=\zeropoint - \exitloop - \else\ifdim\lastskip=\boissignal - \unskip - \exitloop - \else - \unskip - \fi\fi}% - \fi \fi - \advance\boislevel\minusone} - -\def\minimalhbox#1#% - {\dowithnextbox - {\bgroup - \setbox\scratchbox\hbox#1{\hss}% - \ifdim\nextboxwd<\wd\scratchbox\nextboxwd\wd\scratchbox\fi - \flushnextbox - \egroup} - \hbox} - -\def\gobbleuntilempty#1\empty{} - -\def\dodimchoice#1#2#3% - {\ifdim#1#2% - #3\@EA\gobbleuntilempty - \else - \@EA\dodimchoice - \fi{#1}} - -\def\donumchoice#1#2#3% - {\ifnum#1#2% - #3\@EA\gobbleuntilempty - \else - \@EA\dodimchoice - \fi{#1}} - -\def\dimchoice#1#2{\dodimchoice{#1}#2{=#1}{#1}\empty} -\def\numchoice#1#2{\donumchoice{#1}#2{=#1}{#1}\empty} - -% \the\dimexpr(\dimchoice {7pt}{{<10pt}{8pt}{<12pt}{9pt}{<15pt}{10pt}{=11pt}{12pt}}) -% \the\dimexpr(\dimchoice{11pt}{{<10pt}{8pt}{<12pt}{9pt}{<15pt}{10pt}{=11pt}{12pt}}) -% \the\dimexpr(\dimchoice{14pt}{{<10pt}{8pt}{<12pt}{9pt}{<15pt}{10pt}{=11pt}{12pt}}) - -\def\tabulaterule % to be redone, not correct - {\dotabulaterule - {\hrule\!!height.5\scratchdimen\!!depth.5\scratchdimen\relax - \doifvalue{\??tt\currenttabulate\c!distance}\v!grid - {\kern-\scratchdimen}}} % experimental tm-prikkels -% so far - -% between alignment lines certain rules apply, and even a -% simple test can mess up a table, which is why we have a -% special test facility -% -% \ruledvbox -% {\starttabulate[|l|p|] -% \NC 1test \NC test \NC \NR -% \tableifelse{\doifelse{a}{a}}{\NC Xtest \NC test \NC \NR}{}% -% \stoptabulate} - -\long\def\tableifelse#1% - {\tablenoalign - {#1% - {\aftergroup \firstoftwoarguments}% - {\aftergroup\secondoftwoarguments}}} - -\long \def\tableiftextelse#1{\tableifelse{\doiftextelse{#1}}} - -\def\tightvbox{\dowithnextbox{\nextboxdp\zeropoint\flushnextbox}\vbox} -\def\tightvtop{\dowithnextbox{\nextboxht\zeropoint\flushnextbox}\vtop} - -% what is this stupid macro meant for: - -\def\hyphenationpoint - {\hskip\zeropoint} - -\def\hyphenated#1% - {\bgroup - \!!counta\zerocount - \def\hyphenated##1{\advance\!!counta\plusone}% - \handletokens#1\with\hyphenated - \!!countb\plusone - \def\hyphenated##1% - {##1% - \advance\!!countb\plusone\relax - \ifnum\!!countb>2 \ifnum\!!countb<\!!counta - \hyphenationpoint - \fi\fi}% - \handletokens#1\with\hyphenated - \egroup} - -\def\obeysupersubletters - {\let\super\normalsuper - \let\suber\normalsuber - \let\normalsuper\letterhat - \let\normalsuber\letterunderscore - \enablesupersub} - -\def\obeysupersubmath - {\let\normalsuper\letterhat - \let\normalsuber\letterunderscore - \enablesupersub} - -\def\startgridcorrection - {\dosingleempty\dostartgridcorrection} - -\def\dostartgridcorrection[#1]% +\def\spac_grid_correction_start[#1]% {\ifgridsnapping \snaptogrid[#1]\vbox\bgroup \else \startbaselinecorrection \fi} -\def\stopgridcorrection +\unexpanded\def\stopgridcorrection {\ifgridsnapping \egroup \else \stopbaselinecorrection \fi} - -\def\checkgridsnapping + +\unexpanded\def\checkgridsnapping {\lineskip\ifgridsnapping\zeropoint\else\normallineskip\fi} - -\def\startplaatsen - {\dosingleempty\dostartplaatsen} -\def\dostartplaatsen[#1]% tzt n*links etc - {\endgraf - \noindent\bgroup - \setlocalhsize - \hbox to \localhsize\bgroup - \doifnot{#1}\v!left\hss - \def\stopplaatsen - {\unskip\unskip\unskip - \doifnot{#1}\v!right\hss - \egroup - \egroup - \endgraf}% - \gobblespacetokens} +%D Probably obsolete: -% \startplaatsen[links] bla \stopplaatsen - -\def\startcolumnmakeup % don't change +\unexpanded\def\startcolumnmakeup % don't change {\bgroup - \getrawnoflines\textheight % teksthoogte kan topskip hebben, dus raw - \scratchdimen\noflines\lineheight - \advance\scratchdimen-\lineheight - \advance\scratchdimen\topskip - \setbox\scratchbox - \ifcase\showgridstate\vbox\else\ruledvbox\fi to \scratchdimen\bgroup - \forgetall} % ! don't change + \getrawnoflines\textheight % raw as we cna have topskip + \setbox\scratchbox\vbox to \dimexpr\noflines\lineheight-\lineheight+\topskip\relax + \bgroup + \forgetall} -\def\stopcolumnmakeup +\unexpanded\def\stopcolumnmakeup {\egroup \dp\scratchbox\zeropoint \wd\scratchbox\textwidth \box\scratchbox \egroup \page_otr_command_synchronize_hsize} - -\long\def\startexternalfigure - {\dotripleempty\dostartexternalfigure} - -\long\def\dostartexternalfigure[#1][#2][#3]#4\stopexternalfigure - {\gdef\figuredescription{#4}% - \externalfigure[#1][#2][#3]% - \globallet\figuredescription\empty} - -\let\figuredescription\empty - -% incomplete, will be a special case of float placement - -\def\startfixed{\dosingleempty\dostartfixed} - -\def\dostartfixed[#1]% - {\expanded{\dowithnextbox{\noexpand\dodofixed{\ifhmode0\else1\fi}{#1}}}% - \vbox\bgroup - \setlocalhsize} - -\def\stopfixed - {\egroup} - -\def\dodofixed#1#2% - {\ifcase#1\relax - \processaction - [#2] - [ \v!high=>\bbox {\flushnextbox}, - \v!low=>\tbox {\flushnextbox}, - \v!middle=>\vcenter{\flushnextbox}, - \v!lohi=>\vcenter{\flushnextbox}, - \s!unknown=>\tbox {\flushnextbox}, - \s!default=>\tbox {\flushnextbox}]% - \else - \startbaselinecorrection - \noindent\flushnextbox - \stopbaselinecorrection - \fi} - -% \startitemize -% -% \item \externalfigure[koe][height=2cm] -% \item \externalfigure[koe][height=2cm] -% \item \externalfigure[koe][height=2cm] -% \item \externalfigure[koe][height=2cm] -% -% \page -% -% \item \startfixed \externalfigure[koe][height=2cm]\stopfixed -% \item \startfixed[high]\externalfigure[koe][height=2cm]\stopfixed -% \item \startfixed[low] \externalfigure[koe][height=2cm]\stopfixed -% \item \startfixed[lohi]\externalfigure[koe][height=2cm]\stopfixed -% -% \page -% -% \item test \startfixed \externalfigure[koe][height=2cm]\stopfixed -% \item test \startfixed[high]\externalfigure[koe][height=2cm]\stopfixed -% \item test \startfixed[low] \externalfigure[koe][height=2cm]\stopfixed -% \item test \startfixed[lohi]\externalfigure[koe][height=2cm]\stopfixed -% -% \page -% -% \item test \par \startfixed \externalfigure[koe][height=2cm]\stopfixed -% \item test \par \startfixed[high]\externalfigure[koe][height=2cm]\stopfixed -% \item test \par \startfixed[low] \externalfigure[koe][height=2cm]\stopfixed -% \item test \par \startfixed[lohi]\externalfigure[koe][height=2cm]\stopfixed -% -% \stopitemize - -\def\obeyfollowingtoken{{}} % end \cs scanning - -% potential new defaults: -% -% \setbreakpoints[compound] -% till we fixed all styles: +%D Till we fixed all styles: \let\\=\crlf diff --git a/tex/context/base/cont-nop.mkiv b/tex/context/base/cont-nop.mkiv new file mode 100644 index 000000000..c8188503e --- /dev/null +++ b/tex/context/base/cont-nop.mkiv @@ -0,0 +1,22 @@ +%D \module +%D [ file=cont-nop, +%D version=2012.06.01, +%D title=\CONTEXT\ Miscellaneous Macros, +%D subtitle=Startup Dummy, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +\unprotect + +\writestatus\m!system{loading dummy replacement for jobname} + +\protect + +\finishjob + +\endinput diff --git a/tex/context/base/cont-yes.mkiv b/tex/context/base/cont-yes.mkiv new file mode 100644 index 000000000..2a032fc0b --- /dev/null +++ b/tex/context/base/cont-yes.mkiv @@ -0,0 +1,80 @@ +%D \module +%D [ file=cont-yes, +%D version=2012.06.01, +%D title=\CONTEXT\ Miscellaneous Macros, +%D subtitle=Startup Stub, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +% At some point I will reconsider the \starttext .. \stoptext +% wraping as we can assume proper styling. It's a left-over from +% mkii that we need to get rid of. + +\startluacode + + -- When a style is loaded there is a good change that we never enter + -- this code. + + environment.initializefilenames() + + local arguments = environment.arguments + local suffix = environment.suffix + local filename = environment.filename + + if suffix == "xml" or arguments.forcexml then + + -- Maybe we should move the preamble parsing here as it + -- can be part of (any) loaded (sub) file. The \starttext + -- wrapping might go away. + + context.starttext() + context.xmlprocess("main",filename,"") + context.stoptext() + + elseif suffix == "cld" or arguments.forcecld then + + context.runfile(filename) + + elseif suffix == "lua" or arguments.forcelua then + + -- The wrapping might go away. Why is is it there in the + -- first place. + + context.starttext() + context.ctxlua(string.format('dofile("%s")',filename)) + context.stoptext() + + elseif suffix == "mp" or arguments.forcemp then + + context.starttext() + context.processMPfigurefile(filename) + context.stoptext() + + -- elseif suffix == "prep" then + -- + -- -- Why do we wrap here. Because it can be xml? Let's get rid + -- -- of prepping in general. + -- + -- context.starttext() + -- context.input(filename) + -- context.stoptext() + + else + + -- We have a regular tex file so no \starttext yet as we can + -- load fonts. + + context.input(filename) + + end + + context.finishjob() + +\stopluacode + +\endinput diff --git a/tex/context/base/context-base.lmx b/tex/context/base/context-base.lmx index 09817463b..2b093c3e1 100644 --- a/tex/context/base/context-base.lmx +++ b/tex/context/base/context-base.lmx @@ -19,7 +19,9 @@ + + + diff --git a/tex/context/base/context-help.lmx b/tex/context/base/context-help.lmx index 5401fb65d..939b70cb6 100644 --- a/tex/context/base/context-help.lmx +++ b/tex/context/base/context-help.lmx @@ -19,6 +19,7 @@