summaryrefslogtreecommitdiff
path: root/tex/context/modules
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/modules')
-rw-r--r--tex/context/modules/mkiv/m-chart.lua16
-rw-r--r--tex/context/modules/mkiv/m-chart.mkvi12
-rw-r--r--tex/context/modules/mkiv/m-gnuplot.mkxl97
-rw-r--r--tex/context/modules/mkiv/m-tikz.mkiv29
4 files changed, 144 insertions, 10 deletions
diff --git a/tex/context/modules/mkiv/m-chart.lua b/tex/context/modules/mkiv/m-chart.lua
index 1cdfd9f65..76efbedfd 100644
--- a/tex/context/modules/mkiv/m-chart.lua
+++ b/tex/context/modules/mkiv/m-chart.lua
@@ -718,8 +718,8 @@ local function process_connections(g,chart,xoffset,yoffset)
end
end
-local f_texttemplate_t = formatters["\\setvariables[flowcell:text][x=%s,y=%s,n=%i,align={%s},figure={%s},overlay={%s},destination={%s}]"]
-local f_texttemplate_l = formatters["\\doFLOWlabel{%i}{%i}{%i}"]
+local f_texttemplate_t = formatters["\\setvariables[flowcell:text][x=%s,y=%s,n=%i,align={%s},figure={%s},overlay={%s},destination={%s},realx=%s,realy=%s]"]
+local f_texttemplate_l = formatters["\\doFLOWlabel{%i}{%i}{%i}{%i}{%i}"]
local splitter = lpeg.splitat(":")
local charttexts = { } -- permits " etc in mp
@@ -751,6 +751,8 @@ local function process_texts(g,chart,xoffset,yoffset)
local destination = cell.destination or ""
local texts = cell.texts
local noftexts = #texts
+ local realx = cell.realx or x
+ local realy = cell.realy or y
if noftexts > 0 then
for i=1,noftexts do
local text = texts[i]
@@ -758,7 +760,7 @@ local function process_texts(g,chart,xoffset,yoffset)
local align = text.align or ""
local align = validlabellocations[align] or align
charttexts[#charttexts+1] = data
- ctx_tographic(g,'flow_chart_draw_text(%s,%s,textext("%s")) ;',x,y,f_texttemplate_t(x,y,#charttexts,align,figure,overlay,destination))
+ ctx_tographic(g,'flow_chart_draw_text(%s,%s,textext("%s")) ;',x,y,f_texttemplate_t(x,y,#charttexts,align,figure,overlay,destination,realx,realy))
if i == 1 then
figure = ""
overlay = ""
@@ -766,7 +768,7 @@ local function process_texts(g,chart,xoffset,yoffset)
end
end
elseif figure ~= "" or overlay ~= "" or destination ~= "" then
- ctx_tographic(g,'flow_chart_draw_text(%s,%s,textext("%s")) ;',x,y,f_texttemplate_t(x,y,0,"",figure,overlay,destination))
+ ctx_tographic(g,'flow_chart_draw_text(%s,%s,textext("%s")) ;',x,y,f_texttemplate_t(x,y,0,"",figure,overlay,destination,realx,realy))
end
local labels = cell.labels
for i=1,#labels do
@@ -776,7 +778,7 @@ local function process_texts(g,chart,xoffset,yoffset)
local location = validlabellocations[location] or location
if text and text ~= "" then
charttexts[#charttexts+1] = text
- ctx_tographic(g,'flow_chart_draw_label(%s,%s,"%s",textext("%s")) ;',x,y,location,f_texttemplate_l(x,y,#charttexts))
+ ctx_tographic(g,'flow_chart_draw_label(%s,%s,"%s",textext("%s")) ;',x,y,location,f_texttemplate_l(x,y,#charttexts,realx,realy))
end
end
local exits = cell.exits
@@ -792,7 +794,7 @@ local function process_texts(g,chart,xoffset,yoffset)
location == "t" and y == chart.to_y - 1 or
location == "b" and y == chart.from_y + 1 then
charttexts[#charttexts+1] = text
- ctx_tographic(g,'flow_chart_draw_exit(%s,%s,"%s",textext("%s")) ;',x,y,location,f_texttemplate_l(x,y,#charttexts))
+ ctx_tographic(g,'flow_chart_draw_exit(%s,%s,"%s",textext("%s")) ;',x,y,location,f_texttemplate_l(x,y,#charttexts,realx,realy))
end
end
end
@@ -821,7 +823,7 @@ local function process_texts(g,chart,xoffset,yoffset)
end
if text and text ~= "" then
charttexts[#charttexts+1] = text
- ctx_tographic(g,'flow_chart_draw_comment(%s,%s,%s,"%s",%s,textext("%s")) ;',x,y,i,location,length,f_texttemplate_l(x,y,#charttexts))
+ ctx_tographic(g,'flow_chart_draw_comment(%s,%s,%s,"%s",%s,textext("%s")) ;',x,y,i,location,length,f_texttemplate_l(x,y,#charttexts,realx,realy))
end
end
end
diff --git a/tex/context/modules/mkiv/m-chart.mkvi b/tex/context/modules/mkiv/m-chart.mkvi
index a9d3dfdd9..c48869928 100644
--- a/tex/context/modules/mkiv/m-chart.mkvi
+++ b/tex/context/modules/mkiv/m-chart.mkvi
@@ -322,12 +322,16 @@
[n=0,
x=1,
y=1,
+ realx=1,
+ realy=1,
text=,
align=,
set=\setups{flowcell:text:place}]
-\def\FLOWx{\getvariable{flowcell:text}{x}} % compatibility (for Willi)
-\def\FLOWy{\getvariable{flowcell:text}{y}} % compatibility (for Willi)
+\def\FLOWx {\getvariable{flowcell:text}{x}} % compatibility (for Willi)
+\def\FLOWy {\getvariable{flowcell:text}{y}} % compatibility (for Willi)
+\def\FLOWrealx{\getvariable{flowcell:text}{realx}} % compatibility (for Willi)
+\def\FLOWrealy{\getvariable{flowcell:text}{realy}} % compatibility (for Willi)
\defineoverlay
[flowcell:figure]
@@ -380,10 +384,12 @@
\endgroup
\stopsetups
-\unexpanded\def\doFLOWlabel#1#2#3%
+\unexpanded\def\doFLOWlabel#1#2#3#4#5%
{\begingroup
\def\FLOWx{#1}%
\def\FLOWy{#2}%
+ \def\FLOWrealx{#4}%
+ \def\FLOWrealy{#5}%
\strut
\getFLOWtext{#3}%
\endgroup}
diff --git a/tex/context/modules/mkiv/m-gnuplot.mkxl b/tex/context/modules/mkiv/m-gnuplot.mkxl
new file mode 100644
index 000000000..2077b1741
--- /dev/null
+++ b/tex/context/modules/mkiv/m-gnuplot.mkxl
@@ -0,0 +1,97 @@
+%D \module
+%D [ file=m-gnuplot,
+%D version=2020.02.10,
+%D title=\CONTEXT\ Extra Modules,
+%D subtitle=Gnuplot,
+%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.
+
+%D This is a variant on the \GNUPLOT\ terminal code. At some point (when there is a
+%D reason) I will make a proper environment that can be used for embedded code.
+
+\unexpanded\def\includegnuplotsvgfile[#1]%
+ {\hbox\bgroup
+ \ctxlua{metapost.startsvghashing()}%
+ \includesvgfile[#1]%
+ \ctxlua{metapost.stopsvghashing()}%
+ \egroup}
+
+\startluacode
+
+local modificationtime = lfs.modification
+local longtostring = string.longtostring
+local formatters = string.formatters
+local expandfilename = dir.expandname
+local isfile = lfs.isfile
+
+local runner = sandbox.registerrunner {
+ name = "gnuplot to svg",
+ program = "gnuplot",
+ template = longtostring [[
+ -e "set output '%newname%'; set terminal svg"
+ "%oldname%"
+ ]],
+ checkers = {
+ oldname = "readable",
+ newname = "writable",
+ },
+}
+
+figures.programs.gnuplot = {
+ runner = runner,
+}
+
+local function remap(specification)
+ local oldname = specification.fullname
+ if oldname then
+ local newname = file.replacesuffix(oldname,"svg")
+ local oldtime = modificationtime(oldname) or 0
+ local newtime = modificationtime(newname) or 0
+ if newtime == 0 or oldtime > newtime then
+ runner {
+ newname = expandfilename(newname),
+ oldname = expandfilename(oldname),
+ }
+ end
+ if isfile(newname) then
+ local only = file.nameonly(newname)
+ local name = formatters["svg-%s-inclusion"](only)
+ local code = formatters["\\includegnuplotsvgfile[%s]\\resetbuffer[%s]"](newname,name)
+ buffers.assign(name,code)
+ specification.format = "buffer"
+ specification.fullname = name
+ end
+ end
+ return specification
+end
+
+figures.remappers.gp = { svg = remap }
+
+\stopluacode
+
+\continueifinputfile{m-gnuplot.mkxl}
+
+\startluacode
+io.savedata("m-gnuplot-demo.gp", [[
+set format xy "$%g$"
+
+set title 'This is a plot of $y=\\sin(x)$'
+set xlabel 'This is the $x$ axis'
+set ylabel 'This is the $y$ axis'
+
+plot [0:6.28] [0:1] sin(x)
+]])
+\stopluacode
+
+\starttext
+
+ \externalfigure[m-gnuplot-demo.gp][conversion=svg,width=4cm]
+
+ \externalfigure[m-gnuplot-demo.gp][conversion=svg,width=8cm]
+
+\stoptext
diff --git a/tex/context/modules/mkiv/m-tikz.mkiv b/tex/context/modules/mkiv/m-tikz.mkiv
new file mode 100644
index 000000000..73c0ec01e
--- /dev/null
+++ b/tex/context/modules/mkiv/m-tikz.mkiv
@@ -0,0 +1,29 @@
+%D A fixed variant if the t-tikz module distributed with tikz.
+
+\unprotect
+
+ \ifcase\contextlmtxmode \else
+ \unexpanded\def\pdflastxpos{\numexpr\clf_lastxpos\relax}
+ \unexpanded\def\pdflastypos{\numexpr\clf_lastypos\relax}
+ \fi
+
+\protect
+
+\pushcatcodetable
+
+ \setcatcodetable\texcatcodes
+
+ \catcode`\@=11
+ \catcode`\|=12
+ \catcode`\!=12
+
+ \input t-pgf.tex
+ \input t-pgffor.tex
+ \input tikz.code.tex
+
+\popcatcodetable
+
+\let\starttikzpicture\tikzpicture
+\let\stoptikzpicture \endtikzpicture
+
+\stopmodule