Changes

Jump to navigation Jump to search
=Introduction=
 
'''After [http://www.ntg.nl/EuroTeX2009 eurotex meeting 2009],
I'm going to fix some typos here and there and
maybe expand some examples too. I estimated that around 20 September article and site will be in synch.'''
 
 
----
'''!! W A R N I N G !! '''
* ghostscript 8.64 ✔ [[#Ghostscript|here]]
* graphviz 2.24.0 ✔ [[#Graphviz|here]]
* ImageMagick-6.4.9 with pythonmagickwand ✔[[#ImageMagick|here]]
* fontforge 20090224 ✔ [[#Fontforge|here]] Useful to check symbols collision, and if one want to play with the last fontforge, eg to draw the outline of a glyph .
* R-2.8.1 with rpy2-2.0.3 (For Maurizio "Mau" Himmelman , GUIT) ✔ [[#R|here]] (see someone says also [http://micahelliott.com/2009/03/considering-r-as-python-supplement hereconsidering-r-as-python-supplement ]) .* quantlib 0.9.7 ✔ (need an example with output in pdf)* dbxml-2.4.16 (and sqlite) [[#dbxml|here]]
= Dedicated systems =
$HOME_LUN/sage/local/bin/python setup.py build
cd $HOME_LUN
mkdir tests-SAGEMATH && cd tests-SAGEMATH
##
## I have already installed prev. python.so, I don't want mess things
For more infos, see [http://root.cern.ch here] ([http://root.cern.ch/cgi-bin/print_hit_bold.pl/root/HowtoPyROOT.html?python#first_hit here] for python stuffs).
Under Linux installation is not difficult at all, so but in this case I choose to not create a luatex-lunatic apart, as done above for sagemath.<br/>See an example [[#ROOT| here]] .
= ConTeXt mkIV examples=This example shot how to literally embedHere I will collect some tex snippets,just to show some ideasoriginal python source code .
== Scipy ==Watch how python code <tttable> z = x*np.exp(-x**2-y**2) </tttr>is translated in lua code <tttd> z = x.__mul__( np.exp( (x.__pow__(2).__add__(y.__pow__(2))).__neg__() ) )</tt>  {| class="wikitable" |-|<texcode>
\startluacode
function testSCIPYtest_ROOT(figname,dpifilename)
require("python")
pg = python.globals()
python.apply = python.eval('apply') or {}
np = python.import("numpy")
mlab = python.import("matplotlib.mlab")
griddata = mlab.griddata
plt = python.import("matplotlib.pyplot")
ma = np.ma
random = python.import("numpy.random")
uniform = random.uniform
-- make up some randomly distributed data npts = 200 x = uniform(-2,2,npts) y = uniform(-2,2,npts) -- z = x*nppython.expexecute(-x**2-y**2)[[ z = x.__mul__( np.exp( (x.__pow__def run(2).__add__(y.__pow__(2))).__neg__() ) ) -- define grid. xi = np.linspace(-2.1,2.1,100filename): yi = np.linspace(-2.1 from ROOT import TCanvas,2.1,100)TGraph -- grid the data. from ROOT import gROOT zi = griddata(x,y,z,xi,yi) from math import sin -- contour the gridded data, plotting dots from array import array -- at the randomly spaced data points. -- we put this in python globals space -- CS = plt gROOT.contourReset(xi,yi,zi,15,linewidths=0.5,colors='k') pg.xi = xi ; pg.yi = yi ; pg.zi = zi args c1 = python.evalTCanvas("[xi,yi,zi,15]") kv = python.eval("{'linewidthc1': 0.5 ,'colors' :'kA Simple Graph Example'}") CS = python.apply(plt.contour, args,kv) -- pg.jet = plt.cm.jet args = python.eval("[xi200,yi10,zi700,15]"500 ) kv = python.eval("{'cmap': jet}") CS = python c1.applySetFillColor(plt.contourf, args,kv42 ) -- draw colorbar plt c1.colorbarSetGrid() -- plot data points. pg.x n = x; pg.y = y 20 args = python.eval("[ x,y]") kv = python.evalarray("{'marker': 'od'), array( 'cd':'b','s':5}") CS = python.apply(plt.scatter, args,kv) plt.xlim(-2,2) plt.ylim for i in range(-2,2n ): plt x.titleappend(string0.format('griddata test (%1*i points)',npts)) --plt y.savefigappend(figname, dpi, 'white') -- pg.figname = figname ; pg.dpi = dpi args = python.eval10*sin("x[fignamei]") kv = python+0.eval("{'dpi': dpi ,'facecolor' :'white'}"2 ) CS = python.apply(plt.savefig, args,kv)end\stopluacode
gr = TGraph( n, x, y ) gr.SetLineColor( 2 ) gr.SetLineWidth( 4 ) gr.SetMarkerColor( 4 ) gr.SetMarkerStyle( 21 ) gr.SetTitle( 'a simple graph' ) gr.GetXaxis().SetTitle( 'X title' )\def\testSCIPY[#1]{% gr.GetYaxis().SetTitle( 'Y title' ) gr.Draw( 'ACP' ) c1.Update() c1.Print(filename)\getparameters[scipy][#1]%)\ctxlua{testSCIPY run = pg.run run("\csname scipyfigname\endcsname",filename) "\csname scipydpi\endcsname")}%end\externalfigure[\csname scipyfigname\endcsname]%}stopluacode
\starttext
\startTEXpage
\testSCIPYctxlua{test_ROOT("testsin.pdf")}\rotate[fignamerotation=90]{test-scipy-1\externalfigure[testsin.pdf},dpi][width={1505cm]}]
\stopTEXpage
\stoptext
</texcode>|| </td><td> [[Image:Test-scipyTestsin.pngjpg|600px512px]] </td> |}</tr></table>
== Python Imaging Library We can do a bit better: separate python code from lua code .<br/>Save this in <tt>test-ROOT1.py</tt> (PILso it's also easy to test) ==:<pre>from ROOT import TCanvas, TGraph ,TGraphErrors,TMultiGraphfrom ROOT import gROOTfrom math import sinfrom array import array
{| classdef run(filename): c1 = TCanvas("c1","multigraph",200,10,700,500) c1.SetGrid()  # draw a frame to define the range mg = TMultiGraph() # create first graph n = 24; x = array('d',range(24)) data = file('data').readlines() for line in data: line = line.strip() y = array('d',[float(d) for d in line.split()]) gr = TGraph(n,x,y) gr.Fit("wikitablepol6" ,"q") mg.Add(gr)  mg.Draw("ap")  #force drawing of canvas to generate the fit TPaveStats c1.Update() c1.Print(filename) </pre>Here file 'data' is a 110 lines file with 24 floats values space separated,ie <br/><tt> 20.6000 19.4000 19.4000 18.3000 17.8000 16.1000 16.7000 21.1000 23.3000 26.1000 26.1000 27.2000 27.8000 28.3000 28.3000 27.2000 25.6000 22.8000 21.7000 21.7000 21.7000 21.7000 21.7000 21.7000 </tt>.<br/>Now a tex file, with a simple layer in lua as interface for python:{||-|<texcode>
\startluacode
function testPILtest_ROOT(imageorig,imagesepiafilename)
require("python")
PIL_Image test = python.import("PIL.Image") PIL_ImageOps = python.import("PIL.ImageOps"'test-ROOT1') python.execute([[def make_linear_ramp(white): ramp = [] r, g, b = white for i in range(255): ramp.extend((r*i/255, g*i/255, b*i/255)) return ramp]]) -- make sepia ramp (tweak color as necessary) sepia = python.eval("make_linear_ramp((255, 240, 192))") im = PIL_Image.open(imageorig) -- convert to grayscale if not(im.mode == "L") then im = im.convert("L") end -- optional: apply contrast enhancement here, e.g. im = PIL_ImageOps.autocontrast(im)  -- apply sepia palette im.putpalette(sepia)  -- convert back to RGB so we can save it as JPEG -- (alternatively, save it in PNG or similar) im = im.convert("RGB")  imtest.saverun(imagesepiafilename)
end
\stopluacode
\defstarttext\SepiaImage#1#2{%startTEXpage\ctxlua{testPILtest_ROOT("#1","#2data.pdf")}%\startcombinationrotate[2*1rotation=90]{\externalfigure[#1]}{\ss Origdata.}{\externalfigure[#2pdf]}{\ss Sepia}\stopcombination}  \starttext\startTEXpage\SepiaImage{lena.jpg}{lena-sepia.jpg}
\stopTEXpage
\stoptext
</texcode> || [[Image:Test-PILROOT1.pngjpg|330px300px]]
|}
=ConTeXt mkIV examples= ROOT Here I will collect some tex snippets,just to show some ideas. == Scipy ==This example shot Watch how to literally embedpython code <tt> z = x*np.exp(-x**2-y**2) </tt>original python source is translated in lua code <tt> z = x.__mul__( np.exp( (x.__pow__(2).__add__(y.__pow__(2))).__neg__() ) )</tt> 
{|class="wikitable"
|-
|<texcode>
\startluacode
function test_ROOTtestSCIPY(filenamefigname,dpi)
require("python")
pg = python.globals()
python.apply = python.eval('apply') or {}
np = python.import("numpy")
mlab = python.import("matplotlib.mlab")
griddata = mlab.griddata
plt = python.import("matplotlib.pyplot")
ma = np.ma
random = python.import("numpy.random")
uniform = random.uniform
 
-- make up some randomly distributed data
npts = 200
x = uniform(-2,2,npts)
y = uniform(-2,2,npts)
-- z = x*np.exp(-x**2-y**2)
z = x.__mul__( np.exp( (x.__pow__(2).__add__(y.__pow__(2))).__neg__() ) )
-- define grid.
xi = np.linspace(-2.1,2.1,100)
yi = np.linspace(-2.1,2.1,100)
-- grid the data.
zi = griddata(x,y,z,xi,yi)
-- contour the gridded data, plotting dots
-- at the randomly spaced data points.
-- we put this in python globals space
-- CS = plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k')
pg.xi = xi ; pg.yi = yi ; pg.zi = zi
args = python.eval("[xi,yi,zi,15]")
kv = python.eval("{'linewidth': 0.5 ,'colors' :'k'}")
CS = python.apply(plt.contour, args,kv)
--
pg.jet = plt.cm.jet
args = python.eval("[xi,yi,zi,15]")
kv = python.eval("{'cmap': jet}")
CS = python.apply(plt.contourf, args,kv)
-- draw colorbar
plt.colorbar()
-- plot data points.
pg.x = x; pg.y = y
args = python.eval("[x,y]")
kv = python.eval("{'marker': 'o', 'c':'b','s':5}")
CS = python.apply(plt.scatter, args,kv)
plt.xlim(-2,2)
plt.ylim(-2,2)
plt.title(string.format('griddata test (%i points)',npts))
--plt.savefig(figname, dpi, 'white')
--
pg.figname = figname ; pg.dpi = dpi
args = python.eval("[figname]")
kv = python.eval("{'dpi': dpi ,'facecolor' :'white'}")
CS = python.apply(plt.savefig, args,kv)
end
\stopluacode
python.execute([[
def run(filename):
from ROOT import TCanvas, TGraph
from ROOT import gROOT
from math import sin
from array import array
 
 
gROOT.Reset()
 
c1 = TCanvas( 'c1', 'A Simple Graph Example', 200, 10, 700, 500 )
 
c1.SetFillColor( 42 )
c1.SetGrid()
 
n = 20
x, y = array( 'd' ), array( 'd' )
for i in range( n ): x.append( 0.\def\testSCIPY[#1*i )]{% y.append( 10*sin( x\getparameters[iscipy]+0.2 ) )[#1]%  gr = TGraph\ctxlua{testSCIPY( n"\csname scipyfigname\endcsname", x, y ) gr.SetLineColor( 2 ) gr.SetLineWidth( 4 ) gr.SetMarkerColor( 4 ) gr.SetMarkerStyle( 21 ) gr.SetTitle( 'a simple graph' ) gr.GetXaxis().SetTitle( 'X title' ) gr.GetYaxis().SetTitle( 'Y title' ) gr.Draw( 'ACP' ) c1.Update() c1.Print(filename "\csname scipydpi\endcsname")}%\externalfigure[\csname scipyfigname\endcsname]]) run = pg.run run(filename)end%\stopluacode}
\starttext
\startTEXpage
\ctxluatestSCIPY[figname={test_ROOT("testsintest-scipy-1.pdf")}\rotate[rotation,dpi=90]{\externalfigure[testsin.pdf][width=5cm150}]}
\stopTEXpage
\stoptext
</texcode> || [[Image:TestsinTest-scipy.jpgpng|512px600px]]
|}
We can do a bit better: separate python code from lua code .<br/>== Python Imaging Library (PIL) == {| class="wikitable" Save this in <tt>test|-ROOT1.py|</tttexcode> (so it's also easy to test) :<pre>\startluacodefrom ROOT import TCanvasfunction testPIL(imageorig, TGraph ,TGraphErrors,TMultiGraphimagesepia)from ROOT import gROOT require("python")from math PIL_Image = python.import sin("PIL.Image") from array PIL_ImageOps = python.import array("PIL.ImageOps") python.execute([[def runmake_linear_ramp(filenamewhite): c1 ramp = TCanvas("c1"[] r,"multigraph"g,200,10,700,500b = white for i in range(255): c1 ramp.SetGridextend((r*i/255, g*i/255, b*i/255)# draw a frame to define the rangereturn ramp mg = TMultiGraph(]]) # create first graph n = 24;-- make sepia ramp (tweak color as necessary) x sepia = arraypython.eval('d'"make_linear_ramp((255, 240,range(24192))") data im = file('data')PIL_Image.readlinesopen(imageorig) for line in data: line -- convert to grayscale if not(im.mode == line.strip("L") then y im = array('d',[float(d) for d in lineim.splitconvert("L")]) gr = end -- TGraph(noptional: apply contrast enhancement here,x,y) gre.g.Fit("pol6","q") mg im = PIL_ImageOps.Addautocontrast(grim)
mg-- apply sepia palette im.Drawputpalette("ap"sepia)
#force drawing of canvas -- convert back to generate the fit TPaveStatsRGB so we can save it as JPEG c1-- (alternatively, save it in PNG or similar) im = im.Updateconvert("RGB"c1im.Printsave(filenameimagesepia)end\stopluacode \def\SepiaImage#1#2{%\ctxlua{testPIL("#1","#2")}%\startcombination[2*1]{\externalfigure[#1]}{\ss Orig.}{\externalfigure[#2]}{\ss Sepia}\stopcombination}
</pre>
Here file 'data' is a 110 lines file with 24 floats values space separated,
ie <br/><tt> 20.6000 19.4000 19.4000 18.3000 17.8000 16.1000 16.7000 21.1000 23.3000 26.1000 26.1000 27.2000 27.8000 28.3000 28.3000 27.2000 25.6000 22.8000 21.7000 21.7000 21.7000 21.7000 21.7000 21.7000 </tt>.<br/>
Now a tex file, with a simple layer in lua as interface for python:
{|
|-
|<texcode>
\startluacode
function test_ROOT(filename)
require("python")
test = python.import('test-ROOT1')
test.run(filename)
end
\stopluacode
\starttext
\startTEXpage
\ctxluaSepiaImage{test_ROOT("datalena.pdf")jpg}\rotate[rotation=90]{\externalfigure[datalena-sepia.pdf]jpg}
\stopTEXpage
\stoptext
</texcode> || [[Image:Test-ROOT1PIL.jpgpng|300px330px]]
|}
== Fontforge ==
In this example, we will use Metapost to draw a bezier curve of a glyph (''Note: starting from Metapost 1.200 it is now possible to get the actual path drawing routines from a font glyph, so this example is only to show how to translate a path in metapost'').<br/>
We will use 3-layer approach:
# a python layer that export a class,
# a lua layer to manage objects of this class
# a (con)TeX(t) layer that exports macros, because tex works very well with macros .
Let's start with python code, <tt>test-fontforge.py</tt>:
<pre>
import sys
import fontforge
== ImageMagick ==
''ImageMagick® '' ([http://www.imagemagick.org/script/index.php here]) ''is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.
''
There are at least two python bindings, and this time I consider
[http://www.procoders.net/?p=39 PythonMagickWand] which is a binding "ala" ctypes way .
 
Code is simple
<texcode>
\usetypescriptfile[type-gentium]
\usetypescript[gentium]
\setupbodyfont[gentium,10pt]
\setuppapersize[A5][A5]
\setuplayout[height=middle,topspace=1cm,header={2\lineheight},footer=0pt,backspace=1cm,margin=1cm, width=middle]
class simpledraw(object):
def __init__\startluacodefunction testimagemagick(selfbox,font_filet): self local w local h local d local f local res = 118.font 11023622047244094488 -- 300 dpi local opacity = 25 local sigma = 15 local x = 10 local y = fontforge.open(font_file)10
def getcurve require(self,letter"python"): self pg = python.glname = letterglobals() res PythonMagickWand = dictpython.import("PythonMagickWand") try : glyph_letter w = [ g for g in selfmath.fontfloor((tex.glyphs(wd[box] / 65536 ) if g/ 72.glyphname == self27 * 2.glname][0] except Exception ,e : 54 * res['err'] = str(e) return res cnt h = glyph_letter math.floor(((tex.layersht[1box]/ 65536) + (tex.dp[0box] / 65536)) / 72.27 *2.54 *res['is_quadratic'] = cnt.is_quadratic) res['closed'] f = cntstring.closed res['points'] = [format(p.x,p.y,"%is.png" %p.on_curve,t) for p in cnt ] res['design_size'] = self.font.design_size res['em'] = self.font.em return res
wand = PythonMagickWand.NewMagickWand()
background = PythonMagickWand.NewPixelWand(0)
-- PythonMagickWand.MagickNewImage(wand,w,h,background)
PythonMagickWand.MagickNewImage(wand,w,h,background)
def getmpostoutline PythonMagickWand.MagickSetImageResolution(selfwand,res,letterres): res = self PythonMagickWand.getcurveMagickSetImageUnits(letterwand,PythonMagickWand.PixelsPerCentimeterResolution) path = ' PythonMagickWand.MagickShadowImage(wand,opacity,sigma,x,y) PythonMagickWand.'.join( [str(MagickWriteImage(p[0]wand ,p[1]f)) for p in res['points'] if p[2] == '1'] ) return path
def getmpostpoints print(selfw,letterh,f): res = self.getcurve(letter) path = [str((p[0],p[1])) for p in res['points'] if p[2] == '1'] end return path\stopluacode
def getmpostpointsSugar(self,letter):
res = self.getcurve(letter)
path = 'drawdot '.join( ["%s;" %str((p[0],p[1])) for p in res['points'] if p[2] == '1'] )
return 'drawdot ' +path
if __name__ == '__main__': s = simpledraw("koeieletters.pfb") res = s.getmpostpointsSugar('C') print res</pre> Note the <tt>'__main__'</tt> check, so we can test this class from python. <br/>Next lua layer, which in this case is embed in a tex file:<texcode>\startluacodefunction testFontforge(fontfile,letter) require("python") testoutlines = python.import("test-fontforge") s = testoutlines.simpledraw(fontfile) g = s.getmpostoutline(letter) p = s.getmpostpointsSugar(letter) tex.sprint(tex.ctxcatcodes,"\def\startMPcode") tex.sprint(tex.ctxcatcodes,"pickup pencircle scaled 1pt;") tex.sprint(tex.ctxcatcodes,string.format("draw testimagemagick[#1]{%s .. cycle;",g) ) tex.sprint(tex.ctxcatcodes,"pickup pencircle scaled 8pt;") tex.sprint(tex.ctxcatcodes,string.format("\getparameters[imagemagick][#1]%s",p) ) tex.sprint\ctxlua{testimagemagick(tex.ctxcatcodes\csname imagemagickbox\endcsname,"\csname imagemagickfilename\stopMPcodeendcsname")}%end\stopluacode}
\newcount\shdw\long\def\Outline[startShadowtext#1\stopShadowtext{%\bgroup%\setbox0=\vbox{#1}%\testimagemagick[box=0,filename={shd-\the\shdw}]{%%%\getparametersdefineoverlay[testbackg][#1{\externalfigure[shd-\the\shdw.png]}]%\ctxluaframed[background=backg,frame=off,offset=4pt]{testFontforge("\testfontfile", "box0}%%%\framed{\testletter")box0}\global\advance\shdw by 1%\egroup%}
\starttext
\startTEXpage\Outline[letter={C}, fontfile={lmmono10-regular.otf}]%\Outline[letter={o}, fontfile={lmmono10-regular.otf}]%\Outline[letter={n}, fontfile={lmmono10-regular.otf}]%\Outline[letter={T}, fontfile={lmmono10-regular.otf}]%\Outline[letter={e}, fontfile={lmmono10-regular.otf}]startShadowtext%\Outline[letter={X}, fontfile={lmmono10-regular.otf}]%input tufte\Outline[letter={t}, fontfile={lmmono10-regular.otf}]stopShadowtext%
\stopTEXpage
\stoptext
</texcode>
And here is the result:
Here we use <tt>tex.sprint(tex.ctxcatcodes,"\\stopMPcode")</tt> to inject tex code (actually Metapost code) into TeX parser .<br/><tt>\Outline</tt> is the TeX layer: of course one can write <tt>\Outline</tt> and <tt>testFontforge</tt> in a different manner to avoid use of tex.sprint(..) <br/>And this is the result: <br/>[[Image:Test-fontforgeimagemagick.png|900px]]
== Fontforge ==In this example, we will use Metapost to draw a bezier curve of a glyph (''Note: starting from Metapost 1.200 it is now possible to get the actual path drawing routines from a font glyph, so this example is only to show how to translate a path in metapost'')..ok<br/>We will use 3-layer approach:# a python layer that export a class,it's not correct # a lua layer to manage objects of this class# a (con)TeX(why?t)layer that exports macros, but it looks funny :)because tex works very well with macros .
== Ghostscript ==Let's start with python code, <tt>test-fontforge.py</tt>:<pre>import sysimport fontforgeThere are essentially 2 kind of use of ghostscript :* convert an existing eps / ps file in pdf ;* use a program in postscript that take an input, do something and make a ps output class simpledraw( e.g. a barcode/label generator object).:
For the first case def __init__(self, we consider an implementation of eps2pdf, being ps2pdf virtually the same font_file): self.<br/>Actually there is not a python binding of ghostscript, so we build a simple wrapper using ctypes modulefont = fontforge.open(font_file)
<pre> def getcurve(self,letter):import ctypes self.glname = letterimport sys res_Array = [] res = dict() try : #glyph_letter = [ g for g in self.font.glyphs() if g.glyphname == self.glname][0] g = self.font[letter] except Exception ,e : res['err'] = str(e) res_Array.append(res) return res_Array layer_idx = 0; for layer_name in g.layers: layer = g.layers[layer_name] for contour_idx in range(len(layer)): res = dict() contour = layer[contour_idx] contour_name = contour.name res['name'] = contour.name res['is_quadratic'] = contour.is_quadratic res['closed'] = contour.closed res['points'] = [(p.x,p.y,"%i" %p.on_curve) for p in contour ] res['design_size'] = self.font.design_size res['em'] = self.font.em res_Array.append(res) return res_Array
class gs def drawmpostpath(objectself,letter): res_Array = self.getcurve(letter) state = 0 paths = '' for res in res_Array: temp = '' for p in res['points'] : if p[2]=='1' : if state == 1 : temp = temp + '-- (%s,%s)' %(p[0] ,p[1]) ; state = 1; continue else: temp = temp + '.. (%s,%s)' %(p[0] ,p[1]) ; state = 1; continue if state == 1 : temp = temp + ' .. controls (%s,%s)' %(p[0],p[1]) ; state =2; continue if state == 2 : temp = temp + ' and (%s,%s) ' %(p[0],p[1]) ; state =0; continue if res['closed'] : if state == 1 : temp = 'draw ' + temp[2:] + " -- cycle;\n" else: temp = 'draw ' + temp[2:] + " .. cycle;\n" else: temp = 'draw ' + temp[2:] + ";\n" paths = paths + temp return paths
def __init__(self):
self.ierrors = dict()
self.ierrors['e_unknownerror'] = -1
self.ierrors['e_dictfull'] = -2
self.ierrors['e_dictstackoverflow'] = -3
self.ierrors['e_dictstackunderflow'] = -4
self.ierrors['e_execstackoverflow'] = -5
self.ierrors['e_interrupt'] = -6
self.ierrors['e_invalidaccess'] = -7
self.ierrors['e_invalidexit'] = -8
self.ierrors['e_invalidfileaccess'] = -9
self.ierrors['e_invalidfont'] = -10
self.ierrors['e_invalidrestore'] = -11
self.ierrors['e_ioerror'] = -12
self.ierrors['e_limitcheck'] = -13
self.ierrors['e_nocurrentpoint'] = -14
self.ierrors['e_rangecheck'] = -15
self.ierrors['e_stackoverflow'] = -16
self.ierrors['e_stackunderflow'] = -17
self.ierrors['e_syntaxerror'] = -18
self.ierrors['e_timeout'] = -19
self.ierrors['e_typecheck'] = -20
self.ierrors['e_undefined'] = -21
self.ierrors['e_undefinedfilename'] = -22
self.ierrors['e_undefinedresult'] = -23
self.ierrors['e_unmatchedmark'] = -24
self.ierrors['e_VMerror'] = -25
self.ierrors['e_configurationerror'] = -26
self.ierrors['e_undefinedresource'] = -27
self.ierrors['e_unregistered'] = -28
self.ierrors['e_invalidcontext'] = -29
self.ierrors['e_invalidid'] = -30
self.ierrors['e_Fatal'] = -100
self.ierrors['e_Quit'] = -101
self.ierrors['e_InterpreterExit'] = -102
self.ierrors['e_RemapColor'] = -103
self.ierrors['e_ExecStackUnderflow'] = -104
self.ierrors['e_VMreclaim'] = -105
self.ierrors['e_NeedInput'] = -106
self.ierrors['e_Info'] = -110
def drawmpostpoints(self,letter): res_Array = self.libgspath getcurve(letter) dots = '' for res in res_Array: temp = '/opt/luatex/luatex-lunatic/lib/libgs\n'.sojoin( ["drawdot %s;" %str((p[0],p[1])) for p in res['points'] if p[2] == '1'] ) + "\n" dots = dots + temp return dots
self.OutFile = ''
self.InFile = ''
self.args = []
if __name__ == '__main__': s = simpledraw("lmmono10-regular.otf") def appendargs #res = s.getmpostpointsSugar(self,arg'C'): if arg #print res #print s.findgetmpostoutline('-sOutputFileC')>= 0: return if arg print s.findgetcurve('-c quite')>= 0: return self print s.argsdrawmpostpath('e') print s.appenddrawmpostpoints(arg'e')
</pre>
def rawappendargs(selfNote the <tt>'__main__'</tt> check,arg)so we can test this class from python. <br/>Next lua layer, which in this case is embed in a tex file: self.args.append(arg)<texcode>
\setupcolors[state=start]
\startluacodefunction testFontforge(fontfile,letter) require("python") testoutlines = python.import("test-fontforge") s = testoutlines.simpledraw(fontfile) def rung = s.drawmpostpath(selfletter): libgs p = ctypess.CDLLdrawmpostpoints(letter) --print(selfstring.libgspathformat("\%s = \%s ==", letter,g )) tex.sprint(tex.ctxcatcodes,"\\startMPcode") tex.sprint(tex.ctxcatcodes,"pickup pencircle scaled 1pt;") tex.sprint(tex.ctxcatcodes,string.format("\%s",g) ) tex.sprint(tex.ctxcatcodes,"pickup pencircle scaled 8pt;") tex.sprint(tex.ctxcatcodes,string.format("\%s",p) ) tex.sprint(tex.ctxcatcodes,"\\stopMPcode")end\stopluacode
exit_status = ctypes.c_int()
code = ctypes.c_int(1)
code1 = ctypes.c_int()
instance = ctypes.c_void_p(None)
exit_code = ctypes.c_int()
\def\Outline[#1]{%
\getparameters[test][#1]%
\ctxlua{testFontforge("\testfontfile", "\testletter")}%
}
code.value \starttext\startTEXpage\Outline[letter={C}, fontfile= libgs{lmmono10-regular.gsapi_new_instance(ctypes.byref(instance), None)otf}]% if code.value \Outline[letter={o}, fontfile= 0 : libgs{lmmono10-regular.gsapi_set_stdio(instance, None, None, None)otf}]% self.args.insert(0\Outline[letter={n},'') # if len(selffontfile={lmmono10-regular.OutFile) > 0:otf}]% self.args\Outline[letter={T}, fontfile={lmmono10-regular.append('-sOutputFile=%s' otf}]%self.OutFile) if len(self\Outline[letter={e}, fontfile={lmmono10-regular.InFile) > 0:otf}]% self.args\Outline[letter={X}, fontfile={lmmono10-regular.append("%s" otf}]%self.InFile) self.args.append('\Outline[letter={t}, fontfile={lmmono10-c quit') arguments = selfregular.argsotf}]% #\stopTEXpage argc = ctypes.c_int(len(arguments))\stoptext argv = (ctypes.c_char_p * argc.value)(*arguments) code.value = libgs.gsapi_init_with_args(instance, argc, argv)</texcode>
code1Here we use <tt>tex.value = libgssprint(tex.gsapi_exitctxcatcodes,"\\stopMPcode")</tt> to inject tex code (instanceactually Metapost code)into TeX parser .<br/><tt>\Outline</tt> is the TeX layer: of course one can write <tt>\Outline</tt> and <tt>testFontforge</tt> in a different manner to avoid use of tex.sprint(..) <br/>And this is the result: <br/>[[Image:Test-fontforge.png|900px]]
if code.value == 0 or code.value Ghostscript == self.ierrors['e_Quit']There are essentially 2 kind of use of ghostscript : code* convert an existing eps / ps file in pdf ;* use a program in postscript that take an input, do something and make a ps output ( e.g.value = code1a barcode/label generator ).value
if codeFor the first case, we consider an implementation of eps2pdf, being ps2pdf virtually the same .value == self<br/>Actually there is not a python binding of ghostscript, so we build a simple wrapper using ctypes module <tt>testgs.ierrors['e_Quit']py</tt> : code.value = 0
libgs.gsapi_delete_instance(instance)<pre>import ctypesimport sys
exit_status.value = 0
if __name__ == '__main__': pyctyps = class gs(object) pyctyps.appendargs('-q') pyctyps.appendargs('-dNOPAUSE') pyctyps.appendargs('-dEPSCrop') pyctyps.appendargs('-sDEVICE=pdfwrite') pyctyps.InFile = 'test.eps' pyctyps.OutFile = 'test.pdf' pyctyps.run():
</pre> def __init__(self):
The tex code self.ierrors = dict() self.ierrors['e_unknownerror'] = -1 self.ierrors['e_dictfull'] = -2 self.ierrors['e_dictstackoverflow'] = -3<texcode> self.ierrors['e_dictstackunderflow'] = -4 self.ierrors['e_execstackoverflow'] = -5 self.ierrors['e_interrupt'] = -6 self.ierrors['e_invalidaccess'] = -7 self.ierrors['e_invalidexit'] = -8 self.ierrors['e_invalidfileaccess'] = -9\startluacode self.ierrors['e_invalidfont'] = -10function testgs(epsin,pdfout) self.ierrors['e_invalidrestore'] = -11 require("python") self.ierrors['e_ioerror'] = -12 gsmodule self.ierrors['e_limitcheck'] = python-13 self.import("testgs") ierrors['e_nocurrentpoint'] = -14 ghost self.ierrors['e_rangecheck'] = gsmodule-15 self.gs()ierrors['e_stackoverflow'] = -16 ghost self.appendargs(ierrors['e_stackunderflow'] = -q17 self.ierrors['e_syntaxerror')] = -18 ghost self.appendargs(ierrors['e_timeout'] = -dNOPAUSE19 self.ierrors[')e_typecheck'] = -20 ghost self.appendargs(ierrors['e_undefined'] = -dEPSCrop21 self.ierrors['e_undefinedfilename')] = -22 ghost self.appendargs(ierrors['e_undefinedresult'] = -sDEVICE23 self.ierrors['e_unmatchedmark'] =pdfwrite-24 self.ierrors['e_VMerror')] = -25 ghost self.InFile ierrors['e_configurationerror'] = epsin-26 ghost self.OutFile ierrors['e_undefinedresource'] = pdfout-27 ghost self.run()ierrors['e_unregistered'] = -28end self.ierrors['e_invalidcontext'] = -29\stopluacode self.ierrors['e_invalidid'] = -30 self.ierrors['e_Fatal'] = -100\def\epstopdf#1#2{\ctxlua{testgs("#1","#2")}} self.ierrors['e_Quit'] = -101\def\EPSfigure self.ierrors[#1'e_InterpreterExit']{%lazy way to load eps= -102\epstopdf{#1 self.eps}{#1ierrors['e_RemapColor'] = -103 self.pdf}%ierrors['e_ExecStackUnderflow'] = -104\externalfigure self.ierrors[#1'e_VMreclaim'] = -105 self.pdfierrors['e_NeedInput']%= -106} self.ierrors['e_Info'] = -110
\starttext\startTEXpage\startcombination[2*1]{\EPSfigure[tiger]}{\ss tiger self.eps}{\EPSfigure[golfer]}{\ss golfer.eps}\stopcombination\stopTEXpage\stoptext<libgspath = '/opt/luatex/luatex-lunatic/texcode>and the result :<brlib/>[[Image:Testgslibgs.png|900px]]so'
Another example:<br/>here we use a library to generate barcodes [http://www self.terryburton.co.uk/barcodewriter (see here)] .<texcode>\startluacodefunction epstopdf(epsin,pdfout) require("python") gsmodule OutFile = python.import("testgs") ghost = gsmodule.gs() ghost.appendargs('-q') ghost self.appendargs('-dNOPAUSE') ghost.appendargs('-dEPSCrop') ghost.appendargs(InFile = '-sDEVICE=pdfwrite') ghost.InFile = epsin ghost.OutFile = pdfout ghost.run()end
function barcode(text,type,options,savefile) require("python") gsmodule self.args = python.import("testgs") []
barcode_string def appendargs(self,arg): if arg.find('-sOutputFile')>= string0: return if arg.format("%%!\n100 100 moveto find(%s'-c quit') >= 0: return self.args.append(%s) %s barcode showpage" ,text,options,typearg)
psfile = string.format("%s.ps",savefile)
epsfile = string.format("%s.eps",savefile)
pdffile = string.format("%s.pdf",savefile)
temp = io.open def rawappendargs(psfileself,'w'arg) temp:write(tostring(barcode_string),"\n") temp:flush() io.close(temp) ghost = gsmodule.gs() ghost.rawappendargs('-q') ghost.rawappendargs('-dNOPAUSE') ghost.rawappendargs('-sDEVICE=epswrite') ghost.rawappendargs(string.format('-sOutputFile=%s',epsfile)) ghost self.rawappendargs('barcodeargs.ps') ghost.InFile= psfile ghost.runappend(arg)end\stopluacode
\def\epstopdf#1#2{\ctxlua{epstopdf("#1","#2")}}
\def\EPSfigure[#1]{%lazy way to load eps
\epstopdf{#1.eps}{#1.pdf}%
\externalfigure[#1.pdf]%
}
\ def\PutBarcode[#1]{%run(self):\getparameters[bc][#1]%\ctxlua{barcode libgs = ctypes.CDLL("\csname bctext\endcsname","\csname bctype\endcsname","\csname bcoptions\endcsname","\csname bcsavefile\endcsname" self.libgspath)}%\expanded{\EPSfigure[\csname bcsavefile\endcsname]}%}
\starttext exit_status = ctypes.c_int()\startTEXpage\startcombination[2*2]{\PutBarcode[text={CODE 39},type={code39},options={includecheck includetext},savefile code ={TEMP1}]}{\ss code39}ctypes.c_int(1){\PutBarcode[text code1 ={CONTEXT},type={code93},options={includecheck includetext},savefile={TEMP2}]}{\ss code93}ctypes.c_int(){\PutBarcode[text instance ={977147396801},type={ean13},options={includetext},savefile={TEMP3}]}{\ss ean13}ctypes.c_void_p(None){\PutBarcode[text exit_code ={0123456789},type={interleaved2of5},options={includecheck includetext},savefile={TEMP4}]}{\ss interleaved2of5}\stopcombination\stopTEXpage\stoptext</texcode>ctypes.c_int()
[[Image:Test-ghostscript-barcode.png|900px]]
code.value == Graphviz libgs.gsapi_new_instance(ctypes.byref(instance), None) if code.value == 0 :[http://www libgs.graphvizgsapi_set_stdio(instance, None, None, None) self.org Graphviz] is a Graph Visualization Software args.<br/insert(0,'') # if len(self.OutFile) >0:Standard distribution comes with several binding self.args.append(lua and python among others) so it'-sOutputFile=%s not difficult to integrate in luatex lunatic ' %self.<br/>OutFile)In this example, we draw a graph of the nodes of <context>\TeX</context if len(self.InFile) >0:<pre> self.args.append("%s" %self.InFile)\def\StudyBox#1{% self.args.append('-c quit')\startluacode arguments = self.argsrequire "python" #gv argc = pythonctypes.importc_int("gv"len(arguments))g argv = gv(ctypes.digraphc_char_p * argc.value)("G"*arguments)gv code.value = libgs.setvgsapi_init_with_args(ginstance,'rankdir'argc,'LR'argv)
nodes code1.value = nodes libgs.gsapi_exit(instance)  if code.value == 0 or {}code.value == self.ierrors['e_Quit']: code.value = code1.value  if code.value == self.ierrors['e_Quit']: code.value = 0
local nd = {};local kd = {}; libgs.gsapi_delete_instance(instance)
local k exit_status.value = 0;local function nodesprint(head,n) while head do local id = head.id local oldn = n ndlbl = string.format("nd_\%03d",k) texio.write_nl(string.format("id=\%s, ndlbl=\%s",id,ndlbl))
if id __name__ == node.id("vlist") then k = k + 1'__main__': nd[n] pyctyps = gv.nodegs(g,ndlbl) res = gv pyctyps.setvappendargs(nd[n],"shape","record"'-q') res = gv pyctyps.setvappendargs(nd[n],"label",tostring(k'-dNOPAUSE') .. " " .. "vlist" pyctyps.. "\|id:" .. tostringappendargs(head.id'-dEPSCrop') .. "\|subtype:" pyctyps.. tostringappendargs(head.subtype'-sDEVICE=pdfwrite') .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") pyctyps.InFile = 'test. eps' "\|width:" .. tostring(head.width) pyctyps.OutFile = 'test. pdf' "\|depth:" pyctyps.. tostringrun(head.depth) .. "\|height:" .. tostring(head.height) .. "\|dir:" .. tostring(head.dir) .. "\|shift:" .. tostring(head.shift) .. "\|glue_order:" .. tostring(head.glue_order) .. "\|glue_sign:" .. tostring(head.glue_sign) .. "\|glue_set:" .. tostring(head.glue_set) .. "\|list:" .. string.gsub(tostring(head.list),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([/pre><])","\\\%1")) end
if id =The tex code<texcode>\startluacodefunction testgs(epsin,pdfout) require("python") gsmodule = nodepython.idimport("ruletestgs") then k ghost = k + 1gsmodule.gs() nd[n] = gv ghost.appendargs('-q') ghost.nodeappendargs(g,ndlbl'-dNOPAUSE') res = gv ghost.setvappendargs(nd[n],"shape","record"'-dEPSCrop') res ghost.appendargs('-sDEVICE=pdfwrite') ghost.InFile = epsin ghost.OutFile = gvpdfout ghost.setvrun()end\stopluacode \def\epstopdf#1#2{\ctxlua{testgs(nd[n],"label#1",tostring(k) .. " #2" )}}\def\EPSfigure[#1]{%lazy way to load eps\epstopdf{#1.eps}{#1. "rule" .. pdf}% "\|id:" .. tostring(head.id) .externalfigure[#1. pdf]%} \starttext "\|subtype:" .. tostring(head.subtype) .. startTEXpage "\|attr:" .. string.gsub(tostring(head.attr),"(startcombination[2*1]{\EPSfigure[><tiger])","}{\ss tiger.eps}{\EPSfigure[golfer]}{\%1") .ss golfer. eps}\stopcombination "\|width:" .. tostring(head.width) .. stopTEXpage "\|depthstoptext</texcode>and the result :" <br/>[[Image:Testgs.png|900px]] Another example:<br/>here we use a library to generate barcodes [http://www.terryburton.co. tostringuk/barcodewriter (head.depthsee here) ] .. "<texcode>\|height:startluacodefunction epstopdf(epsin,pdfout) require("python" ) gsmodule = python.import("testgs") ghost = gsmodule. tostringgs(head) ghost.heightappendargs('-q') ghost.. appendargs('-dNOPAUSE') "\|dir:" . ghost. tostringappendargs(head'-dEPSCrop') ghost.dirappendargs('-sDEVICE=pdfwrite') ghost.InFile = epsin ghost. OutFile = pdfout "\|next:" .. string ghost.gsubrun(tostring)end function barcode(head.next)text,type,"options,savefile) require([><])","\\\%1python") gsmodule = python.. import("\|prev:testgs" .. )   barcode_string = string.gsubformat(tostring"%%!\n100 100 moveto (head.prev%s),"([><]%s)%s barcode showpage",text,options,type)  psfile = string.format("\\\%1s.ps"),savefile) end if id epsfile == nodestring.idformat("ins%s.eps",savefile) then k = k + 1 nd[n] pdffile = gvstring.nodeformat(g"%s.pdf",ndlblsavefile) res temp = gvio.setvopen(nd[n]psfile,"shape"'w') temp:write(tostring(barcode_string),"record\n") res = gv temp:flush() io.setvclose(nd[n],"label",tostringtemp) ghost = gsmodule.gs(k) ghost.rawappendargs('-q') ghost. " " rawappendargs('-dNOPAUSE') ghost.rawappendargs('-sDEVICE=epswrite') ghost. "ins" .rawappendargs(string. format('-sOutputFile=%s',epsfile)) "\|id:" . ghost. tostringrawappendargs(head'barcode.idps') ghost.InFile= psfile ghost. run()end "\|subtype:stopluacode \def\epstopdf#1#2{\ctxlua{epstopdf("#1","#2" .. tostring(head.subtype) }}\def\EPSfigure[#1]{%lazy way to load eps\epstopdf{#1.eps}{#1. pdf}% "\|attr:" .. string.gsub(tostring(headexternalfigure[#1.attr),"([><pdf])","%} \def\PutBarcode[#1]{%\getparameters[bc][#1]%1") .. \ctxlua{barcode("\|cost:csname bctext\endcsname" .. tostring(head.cost) .. ,"\|depth:csname bctype\endcsname" .. tostring(head.depth) .. ,"\|height:csname bcoptions\endcsname" .. tostring(head.height) .. ,"\|spec:csname bcsavefile\endcsname" .. string.gsub(tostring(head.spec),"(}%\expanded{\EPSfigure[><\csname bcsavefile\endcsname])","}%} \starttext\startTEXpage\%1") .. startcombination[2*2] "{\|list:" .. string.gsub(tostring(head.list)PutBarcode[text={CODE 39},type={code39},"([><options={includecheck includetext},savefile={TEMP1}])","}{\ss code39}{\PutBarcode[text={CONTEXT},type={code93},options={includecheck includetext},savefile={TEMP2}]}{\%1") .. ss code93} "{\|next:" .. string.gsub(tostring(head.next)PutBarcode[text={977147396801},type={ean13},options={includetext},"([><savefile={TEMP3}])","}{\ss ean13}{\\%1") .. PutBarcode[text={0123456789},type={interleaved2of5},options={includecheck includetext},savefile={TEMP4}]}{\ss interleaved2of5}\stopcombination\stopTEXpage "\|prevstoptext</texcode> [[Image:" Test-ghostscript-barcode.png|900px]] == Graphviz == [http://www.graphviz.org Graphviz] is a Graph Visualization Software . string.gsub<br/>Standard distribution comes with several binding (tostring(headlua and python among others) so it's not difficult to integrate in luatex lunatic .prev)<br/>In this example,"([we draw a graph of the nodes of <context>\TeX<])","/context><pre>\def\StudyBox#1{%\%1startluacoderequire "python")) end if id =gv = nodepython.idimport("markgv") then k = k + 1 nd[n] g = gv.nodedigraph(g,ndlbl"G") res = gv.setv(nd[n]g,"shape"'rankdir',"record"'LR') res nodes = nodes or {} local nd = {};local kd = {}; local k = gv.setv0;local function nodesprint(nd[head,n],"label",tostring(k) while head do local id = head.id local oldn = n ndlbl = string. format(" nd_\%03d" ,k) texio.write_nl(string. format("mark" .. "id=\|id:%s, ndlbl=\%s" .. tostring(head.,id,ndlbl))   if id == node.. "\|subtype:id("vlist" ) then k = k + 1 nd[n] = gv.. tostringnode(head.subtypeg,ndlbl) res = gv.. setv(nd[n],"\|attr:shape" .. string.gsub(tostring(head.attr),"(record") res = gv.setv(nd[><n])","\\\%1label",tostring(k) .. "\|class:" .. tostring "vlist" .. "\|id:" .. tostring(head.classid) .. "\|marksubtype:" .. tostring(head.marksubtype) .. "\|nextattr:" .. string.gsub(tostring(head.nextattr),"([><])","\\\%1") .. "\|prevwidth:" .. string.gsub(tostring(head.prevwidth),.. "\|depth:" .. tostring([><]head.depth)",.. "\\\%1|height:")) end.. tostring(head.height) .. if id == node "\|dir:" ..idtostring(head.dir) .. "adjust") then k = k + 1 nd[n] = gv\|shift:" ..nodetostring(g,ndlblhead.shift) res = gv.setv(nd[n],. "shape","record\|glue_order:".. tostring(head.glue_order).. res = gv.setv(nd[n],"label",tostring(k) .. " " .. "adjust" .. "\ "\|idglue_sign:" .. tostring(head.idglue_sign) .. "\|subtypeglue_set:" .. tostring(head.subtypeglue_set) .. "\|attrlist:" .. string.gsub(tostring(head.attrlist),"([><])","\\\%1") .. "\|listprev:" .. string.gsub(tostring(head.listprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") ) end  if id == node.. id("rule"\|next:" .. string.gsub(tostring(head.next),"(then k = k + 1 nd[><n]= gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","\\\%1record")) end if id == node.id("disc") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "disc" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|pre:" .. string.gsub(tostring(head.pre),"([><])","\\\%1") .. "\|post:" .. string.gsub(tostring(head.post),"([><])","\\\%1") .. "\|replace:" .. string.gsub(tostring(head.replace),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if id == node.id("whatsit") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") if head.subtype == node.subtype("write") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:write" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|stream:" .. tostring(head.stream) .. "\|data:" .. tostring(head.data) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if head.subtype == node.subtype("close") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:close" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|stream:" .. tostring(head.stream) .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if head.subtype == node.subtype("special") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:special" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|data:" .. tostring(head.data) .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if head.subtype == node.subtype("local_par") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:local_par" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|pen_inter:" .. tostring(head.pen_inter) .. "\|pen_broken:" .. tostring(head.pen_broken) .. "\|dir:" .. tostring(head.dir) .. "\|box_left:" .. tostring(head.box_left) .. "\|box_left_width:" .. tostring(head.box_left_width) .. "\|box_right:" .. tostring(head.box_right) .. "\|box_right_width:" .. tostring(head.box_right_width) .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if head.subtype == node.subtype("dir") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:dir" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|dir:" .. tostring(head.dir) .. "\|level:" .. tostring(head.level) .. "\|dvi_ptr:" .. tostring(head.dvi_ptr) .. "\|dvi_h:" .. tostring(head.dvi_h) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if head.subtype == node.subtype("pdf_literal") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_literal" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|mode:" .. tostring(head.mode) .. "\|data:" .. tostring(head.data) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if head.subtype == node.subtype("pdf_refobj") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_refobj" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|objnum:" .. tostring(head.objnum) .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if head.subtype == node.subtype("pdf_refxform") then res res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_refxformrule" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|width:" .. tostring(head.width) ..
"\|depth:" .. tostring(head.depth) ..
"\|height:" .. tostring(head.height) ..
"\|depthdir:" .. tostring(head.depth) .. "\|objnum:" .. tostring(head.objnumdir) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end if headid == node.subtype id("ins") then k =k + 1 nd[n] = gv.node(g,ndlbl) res = gv.subtypesetv(nd[n],"shape"pdf_refximage,"record") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_refximageins" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthcost:" .. tostring(head.widthcost) .. "\|depth:" .. tostring(head.depth) ..
"\|height:" .. tostring(head.height) ..
"\|depthspec:" .. string.gsub(tostring(head.depthspec),"([><])","\\\%1") .. "\|objnumlist:" .. string.gsub(tostring(head.objnumlist),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end if headid == node.subtype id("mark") then k =k + 1 nd[n] = gv.node(g,ndlbl) res = gv.subtypesetv(nd[n],"shape"pdf_annot,"record") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_annotmark" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthclass:" .. tostring(head.widthclass) .. "\|heightmark:" .. tostring(head.height) .. "\|depth:" .. tostring(head.depth) .. "\|objnum:" .. tostring(head.objnum) .. "\|data:" .. tostring(head.datamark) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end if headid == node.subtype id("adjust") then k =k + 1 nd[n] = gv.node(g,ndlbl) res = gv.subtypesetv(nd[n],"pdf_start_linkshape","record") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_start_linkadjust" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthlist:" .. string.gsub(tostring(head.widthlist) .. "\|height:," .. tostring(head.height[><]) .. "\|depth:" .. tostring(head.depth) .. ,"\|objnum:" .. tostring(head.objnum) .. "\|link_attr:" .. tostring(head.link_attr) .. "\|action:%1" .. tostring(head.action) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end if headid == node.subtype id("disc") then k =k + 1 nd[n] = gv.node(g,ndlbl) res = gv.subtypesetv(nd[n],"pdf_end_linkshape","record") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_end_linkdisc" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|prevpre:" .. string.gsub(tostring(head.pre),"([><])","\\\%1") .. "\|post:" .. string.gsub(tostring(head.post),"([><])","\\\%1") .. "\|replace:" .. string.gsub(tostring(head.prevreplace),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if id == node.id("whatsit") then endk = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") if head.subtype == node.subtype("pdf_destwrite") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_destwrite" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthstream:" .. tostring(head.widthstream) .. "\|heightdata:" .. tostring(head.heightdata) .. "\|depth:" .. tostring(head.depth) .. "\|named_id:" .. tostring(head.named_id) .. "\|dest_id:" .. tostring(head.dest_id) .. "\|dest_type:" .. tostring(head.dest_type) .. "\|xyz_zoom:" .. tostring(head.xyz_zoom) .. "\|objnum:" .. tostring(head.objnum) .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_threadclose") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_threadclose" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthstream:" .. tostring(head.width) .. "\|height:" .. tostring(head.height) .. "\|depth:" .. tostring(head.depth) .. "\|named_id:" .. tostring(head.named_id) .. "\|thread_id:" .. tostring(head.thread_id) .. "\|thread_attr:" .. tostring(head.thread_attrstream) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_start_threadspecial") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_start_threadspecial" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthdata:" .. tostring(head.width) .. "\|height:" .. tostring(head.height) .. "\|depth:" .. tostring(head.depth) .. "\|named_id:" .. tostring(head.named_id) .. "\|thread_id:" .. tostring(head.thread_id) .. "\|thread_attr:" .. tostring(head.thread_attrdata) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_end_threadlocal_par") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_end_threadlocal_par" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|pen_inter:" .. tostring(head.pen_inter) ..
"\|pen_broken:" .. tostring(head.pen_broken) ..
"\|dir:" .. tostring(head.dir) ..
"\|box_left:" .. tostring(head.box_left) ..
"\|box_left_width:" .. tostring(head.box_left_width) ..
"\|box_right:" .. tostring(head.box_right) ..
"\|box_right_width:" .. tostring(head.box_right_width) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_save_posdir") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_save_posdir" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|prevdir:" .. tostring(head.dir) .. "\|level:" .. tostring(head.level) .. "\|dvi_ptr:" .. tostring(head.dvi_ptr) .. "\|dvi_h:" .. tostring(head.dvi_h) .. "\|next:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_thread_datapdf_literal") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_thread_datapdf_literal" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|mode:" .. tostring(head.mode) .. "\|data:" .. tostring(head.data) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_link_datapdf_refobj") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_link_datapdf_refobj" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|objnum:" .. tostring(head.objnum) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("openpdf_refxform") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:openpdf_refxform" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|streamwidth:" .. tostring(head.streamwidth) .. "\|nameheight:" .. tostring(head.nameheight) .. "\|areadepth:" .. tostring(head.areadepth) .. "\|extobjnum:" .. tostring(head.extobjnum) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if head.subtype == node.subtype("late_luapdf_refximage") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:late_luapdf_refximage" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|regwidth:" .. tostring(head.regwidth) .. "\|dataheight:" .. tostring(head.dataheight) .. "\|namedepth:" .. tostring(head.namedepth) .. "\|objnum:" .. tostring(head.objnum) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if head.subtype == node.subtype("fakepdf_annot") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:fake" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if head.subtype == node.subtype("pdf_colorstack") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_colorstackpdf_annot" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|stackwidth:" .. tostring(head.stackwidth) .. "\|cmdheight:" .. tostring(head.cmdheight) .. "\|depth:" .. tostring(head.depth) .. "\|objnum:" .. tostring(head.objnum) ..
"\|data:" .. tostring(head.data) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_savepdf_start_link") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_savepdf_start_link" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|width:" .. tostring(head.width) ..
"\|height:" .. tostring(head.height) ..
"\|depth:" .. tostring(head.depth) ..
"\|objnum:" .. tostring(head.objnum) ..
"\|link_attr:" .. tostring(head.link_attr) ..
"\|action:" .. tostring(head.action) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("cancel_boundarypdf_end_link") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:cancel_boundarypdf_end_link" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("close_luapdf_dest") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:close_luapdf_dest" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|regwidth:" .. tostring(head.regwidth) .. "\|height:" .. tostring(head.height) .. "\|depth:" .. tostring(head.depth) .. "\|named_id:" .. tostring(head.named_id) .. "\|dest_id:" .. tostring(head.dest_id) .. "\|dest_type:" .. tostring(head.dest_type) .. "\|xyz_zoom:" .. tostring(head.xyz_zoom) .. "\|objnum:" .. tostring(head.objnum) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_setmatrixpdf_thread") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_setmatrixpdf_thread" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|datawidth:" .. tostring(head.datawidth) .. "\|height:" .. tostring(head.height) .. "\|depth:" .. tostring(head.depth) .. "\|named_id:" .. tostring(head.named_id) .. "\|thread_id:" .. tostring(head.thread_id) .. "\|thread_attr:" .. tostring(head.thread_attr) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_restorepdf_start_thread") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_restorepdf_start_thread" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|width:" .. tostring(head.width) ..
"\|height:" .. tostring(head.height) ..
"\|depth:" .. tostring(head.depth) ..
"\|named_id:" .. tostring(head.named_id) ..
"\|thread_id:" .. tostring(head.thread_id) ..
"\|thread_attr:" .. tostring(head.thread_attr) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("user_definedpdf_end_thread") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:user_definedpdf_end_thread" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|user_id:" .. tostring(head.user_id) .. "\|type:" .. tostring(head.type) .. "\|value:" .. tostring(head.value) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
end if id head.subtype == node.idsubtype("mathpdf_save_pos") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "mathwhatsit:pdf_save_pos" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|surround:" .. tostring(head.surround) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end if id head.subtype == node.idsubtype("gluepdf_thread_data") then k res = k + 1 gv.setv(nd[n] = gv,"label",tostring(k) .. " " .."whatsit:pdf_thread_data" .. "\|id:" .. tostring(head.id) .. "\|subtype:" ..nodetostring(g,ndlblhead.subtype) res = gv.setv. "\|next:" .. string.gsub(tostring(head.next),"(nd[n><])","shape\\\%1",)) end if head.subtype == node.subtype("recordpdf_link_data")then res = gv.setv(nd[n],"label",tostring(k) .. " " .. "gluewhatsit:pdf_link_data" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|spec:" .. string.gsub(tostring(head.spec),"([><])","\\\%1") .. "\|leader:" .. tostring(head.leader) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("kernopen") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "kernwhatsit:open" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|kernstream:" .. tostring(head.kernstream) .. "\|prevname:" .. tostring(head.name) .. "\|area:" .. tostring(head.area) .. "\|ext:" .. tostring(head.ext) .. "\|next:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("penaltylate_lua") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "penaltywhatsit:late_lua" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|penaltyreg:" .. tostring(head.penaltyreg) .. "\|prevdata:" .. tostring(head.data) .. "\|name:" .. tostring(head.name) .. "\|next:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("unsetfake") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "unsetwhatsit:fake" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|width:" .. tostring(head.width) ..
"\|depth:" .. tostring(head.depth) ..
"\|height:" .. tostring(head.height) ..
"\|dir:" .. tostring(head.dir) ..
"\|shrink:" .. tostring(head.shrink) ..
"\|glue_order:" .. tostring(head.glue_order) ..
"\|glue_sign:" .. tostring(head.glue_sign) ..
"\|stretch:" .. tostring(head.stretch) ..
"\|span:" .. tostring(head.span) ..
"\|list:" .. string.gsub(tostring(head.list),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end if id head.subtype == node.idsubtype("stylepdf_colorstack") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "stylewhatsit:pdf_colorstack" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|stylestack:" .. tostring(head.stylestack) .. "\|prevcmd:" .. tostring(head.cmd) .. "\|data:" .. tostring(head.data) .. "\|next:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("choicepdf_save") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "choicewhatsit:pdf_save" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|display:" .. tostring(head.display) .. "\|text:" .. tostring(head.text) .. "\|script:" .. tostring(head.script) .. "\|scriptscript:" .. tostring(head.scriptscript) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("noadcancel_boundary") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "noadwhatsit:cancel_boundary" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleus:" .. tostring(head.nucleus) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("opclose_lua") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "opwhatsit:close_lua" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleusreg:" .. tostring(head.nucleusreg) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("binpdf_setmatrix") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "binwhatsit:pdf_setmatrix" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleusdata:" .. tostring(head.nucleusdata) .. "\|subprev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if head.subtype == node.subtype("pdf_restore") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_restore" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if head.subtype == node.subtype("user_defined") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:user_defined" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|user_id:" .. tostring(head.user_id) .. "\|type:" .. tostring(head.subtype) .. "\|supvalue:" .. tostring(head.supvalue) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
end
if id == node.id("relmath") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "relmath" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleussurround:" .. tostring(head.nucleussurround) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("openglue") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "openglue" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleusspec:" .. string.gsub(tostring(head.nucleusspec),"([><]) .. ","\\|sub:\%1" .. tostring(head.sub) .. "\|supleader:" .. tostring(head.supleader) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("closekern") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "closekern" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleuskern:" .. tostring(head.nucleuskern) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("punctpenalty") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "punctpenalty" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleuspenalty:" .. tostring(head.nucleuspenalty) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("innerunset") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "innerunset" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleuswidth:" .. tostring(head.nucleuswidth) .. "\|subdepth:" .. tostring(head.subdepth) .. "\|supheight:" .. tostring(head.supheight) .. "\|nextdir:" .. tostring(head.dir) .. "\|shrink:" .. tostring(head.shrink) .. "\|glue_order:" .. tostring(head.glue_order) .. "\|glue_sign:" .. tostring(head.glue_sign) .. "\|stretch:" .. tostring(head.stretch) .. "\|span:" .. tostring(head.span) .. "\|list:" .. string.gsub(tostring(head.nextlist),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("radicalstyle") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "radicalstyle" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleusstyle:" .. tostring(head.nucleusstyle) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|left:" .. tostring(head.left) .. "\|degree:" .. tostring(head.degree) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("fractionchoice") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "fractionchoice" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthdisplay:" .. tostring(head.widthdisplay) .. "\|numtext:" .. tostring(head.numtext) .. "\|denomscript:" .. tostring(head.denomscript) .. "\|leftscriptscript:" .. tostring(head.left) .. "\|right:" .. tostring(head.rightscriptscript) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("undernoad") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "undernoad" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("overop") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "overop" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("accentbin") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "accentbin" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|sub:" .. tostring(head.sub) ..
"\|sup:" .. tostring(head.sup) ..
"\|accent:" .. tostring(head.accent) ..
"\|bot_accent:" .. tostring(head.bot_accent) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("vcenterrel") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "vcenterrel" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("fenceopen") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "fenceopen" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|delimnucleus:" .. tostring(head.delimnucleus) .. "\|prevsub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|next:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if id == node.id("math_charclose") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "math_charclose" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|famnucleus:" .. tostring(head.famnucleus) .. "\|charsub:" .. tostring(head.charsub) .. "\|sup:" .. tostring(head.sup) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("sub_boxpunct") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "sub_boxpunct" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|listnucleus:" .. string.gsub(tostring(head.listnucleus),.. "\|sub:".. tostring([><]head.sub)",.. "\\\%1|sup:".. tostring(head.sup) .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if id == node.id("sub_mlistinner") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "sub_mlistinner" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|listnucleus:" .. string.gsub(tostring(head.listnucleus),.. "\|sub:".. tostring([><]head.sub)",.. "\\\%1|sup:".. tostring(head.sup) .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if id == node.id("math_text_charradical") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "math_text_charradical" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|famnucleus:" .. tostring(head.famnucleus) .. "\|charsub:" .. tostring(head.charsub) .. "\|sup:" .. tostring(head.sup) .. "\|left:" .. tostring(head.left) .. "\|degree:" .. tostring(head.degree) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("delimfraction") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "delimfraction" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|small_famwidth:" .. tostring(head.small_famwidth) .. "\|small_charnum:" .. tostring(head.small_charnum) .. "\|large_famdenom:" .. tostring(head.large_famdenom) .. "\|large_charleft:" .. tostring(head.large_charleft) .. "\|right:" .. tostring(head.right) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("margin_kernunder") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "margin_kernunder" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthnucleus:" .. tostring(head.widthnucleus) .. "\|glyphsub:" .. tostring(head.glyphsub) .. "\|sup:" .. tostring(head.sup) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("glyphover") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "glyphover" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|charnucleus:" .. tostring(head.charnucleus) .. "\|fontsub:" .. tostring(head.fontsub) .. "\|langsup:" .. tostring(head.langsup) .. "\|left:" .. tostring(head.left) .. "\|right:" .. tostring(head.right) .. "\|uchyph:" .. tostring(head.uchyph) .. "\|componentsnext:" .. string.gsub(tostring(head.componentsnext),"([><])","\\\%1") .. "\|xoffset:" .. tostring(head.xoffset) .. "\|yoffset:" .. tostring(head.yoffset) .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("align_recordaccent") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "align_recordaccent" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|nucleus:" .. tostring(head.nucleus) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|accent:" .. tostring(head.accent) .. "\|bot_accent:" .. tostring(head.bot_accent) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("pseudo_filevcenter") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "pseudo_filevcenter" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|nucleus:" .. tostring(head.nucleus) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("pseudo_linefence") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "pseudo_linefence" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|delim:" .. tostring(head.delim) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("page_insertmath_char") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "page_insertmath_char" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|heightattr:" .. string.gsub(tostring(head.heightattr),"([><])","\\\%1") .. "\|last_ins_ptrfam:" .. tostring(head.last_ins_ptrfam) .. "\|best_ins_ptrchar:" .. tostring(head.best_ins_ptrchar) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("split_insertsub_box") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "split_insertsub_box" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|heightattr:" .. string.gsub(tostring(head.heightattr),"([><]) .. ","\|last_ins_ptr:\\%1" .. tostring(head.last_ins_ptr) .. "\|best_ins_ptrlist:" .. string.gsub(tostring(head.best_ins_ptrlist) .. ,"\|broken_ptr:" .. tostring(head.broken_ptr[><]) .. ","\|broken_ins:\\%1" .. tostring(head.broken_ins) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("expr_stacksub_mlist") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "expr_stacksub_mlist" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|list:" .. string.gsub(tostring(head.list),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("nested_listmath_text_char") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "nested_listmath_text_char" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|fam:" .. tostring(head.fam) .. "\|char:" .. tostring(head.char) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if id == node.id("spandelim") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "spandelim" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|small_fam:" .. tostring(head.small_fam) .. "\|small_char:" .. tostring(head.small_char) .. "\|large_fam:" .. tostring(head.large_fam) .. "\|large_char:" .. tostring(head.large_char) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("attributemargin_kern") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "attributemargin_kern" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|numberattr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|width:" .. tostring(head.numberwidth) .. "\|valueglyph:" .. tostring(head.valueglyph) .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if id == node.id("glue_specglyph") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "glue_specglyph" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|widthattr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|char:" .. tostring(head.widthchar) .. "\|stretchfont:" .. tostring(head.stretchfont) .. "\|shrinklang:" .. tostring(head.shrinklang) .. "\|stretch_orderleft:" .. tostring(head.stretch_orderleft) .. "\|shrink_orderright:" .. tostring(head.shrink_orderright) .. "\|ref_countuchyph:" .. tostring(head.ref_countuchyph) .. "\|nextcomponents:" .. string.gsub(tostring(head.nextcomponents),"([><])","\\\%1") .. "\|xoffset:" .. tostring(head.xoffset) .. "\|yoffset:" .. tostring(head.yoffset) .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("attribute_listalign_record") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "attribute_listalign_record" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("actionpseudo_file") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "actionpseudo_file" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|action_type:" .. tostring(head.action_type) .. "\|named_id:" .. tostring(head.named_id) .. "\|action_id:" .. tostring(head.action_id) .. "\|file:" .. tostring(head.file) .. "\|new_window:" .. tostring(head.new_window) .. "\|data:" .. tostring(head.data) .. "\|ref_count:" .. tostring(head.ref_count) .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("temppseudo_line") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "temppseudo_line" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("align_stackpage_insert") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "align_stackpage_insert" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|height:" .. tostring(head.height) .. "\|last_ins_ptr:" .. tostring(head.last_ins_ptr) .. "\|best_ins_ptr:" .. tostring(head.best_ins_ptr) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("movement_stacksplit_insert") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "movement_stacksplit_insert" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|nextheight:" .. string.gsub(tostring(head.nextheight),"([><])",.. "\\\%1|last_ins_ptr:")) end if id == node.id. tostring("if_stack"head.last_ins_ptr) then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n], "shape\|best_ins_ptr:","record") res = gv.setv(nd[n],"label",. tostring(khead.best_ins_ptr) .. " \|broken_ptr:" .. "if_stack" tostring(head.broken_ptr) .. "\|idbroken_ins:" .. tostring(head.idbroken_ins) .. "\|subtypenext:" .. string.gsub(tostring(head.subtypenext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if id == node.id("unhyphenatedexpr_stack") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "unhyphenatedexpr_stack" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("hyphenatednested_list") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "hyphenatednested_list" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("deltaspan") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "deltaspan" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("passiveattribute") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "passiveattribute" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|number:" .. tostring(head.number) ..
"\|value:" .. tostring(head.value) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("shapeglue_spec") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "shapeglue_spec" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|width:" .. tostring(head.width) .. "\|stretch:" .. tostring(head.stretch) .. "\|shrink:" .. tostring(head.shrink) .. "\|stretch_order:" .. tostring(head.stretch_order) .. "\|shrink_order:" .. tostring(head.shrink_order) .. "\|ref_count:" .. tostring(head.ref_count) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("hlistattribute_list") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "hlistattribute_list" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attrnext:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|width:" .. tostring(head.width) .. "\|depth:" .. tostring(head.depth) .. "\|height:" .. tostring(head.height) .. "\|dir:" .. tostring(head.dir) .. "\|shift:" .. tostring(head.shift) .. "\|glue_order:" .. tostring(head.glue_order) .. "\|glue_sign:" .. tostring(head.glue_sign) .. "\|glue_set:" .. tostring(head.glue_set) .. "\|list:" .. string.gsub(tostring(head.listnext),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("fakeaction") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "fakeaction" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|action_type:" .. tostring(head.action_type) ..
"\|named_id:" .. tostring(head.named_id) ..
"\|action_id:" .. tostring(head.action_id) ..
"\|file:" .. tostring(head.file) ..
"\|new_window:" .. tostring(head.new_window) ..
"\|data:" .. tostring(head.data) ..
"\|ref_count:" .. tostring(head.ref_count) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
kd[k] = nd[n] e1 = gv.edge(kd[k-1],kd[k]) if id == node.id('hlist'"temp") or id then k =k + 1 nd[n] = gv.node.id('vlist'g,ndlbl) then %% If we want to connect nested (h|v)list %% %%e res = gv.edgesetv(nd[n-1],nd[n]"shape","record") %% res = gv.setv(end[n],'arrowhead'"label",'diamond'tostring(k).. " " .. "temp" .. nodesprint "\|id:" .. tostring(head.list,id) .. "\|subtype:" .. tostring( n or 0) +1head.subtype).. end head = "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
end if id == node.id("align_stack") then k = k + 1local head nd[n] = texgv.box[#1]nodesprintnode(headg,0ndlbl)r res = gv.layoutsetv(gnd[n],"shape","dotrecord")r res = gv.rendersetv(gnd[n],'pdf'"label",tostring(k) .. " " .. "align_stack" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.formatgsub(tostring(head.next),"('box[><])","\\\%d.pdf',#1"))\stopluacode%% end if id == node.id("movement_stack") then} k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")\starttext res = gv.setv(nd[n],"label",tostring(k) .. " " .. "movement_stack" .. "\startTEXpage|id:" .. tostring(head.id) .. "\setbox0=\hbox{\TeX}|subtype:" .. tostring(head.subtype) .. "\hbox to 29cm{|next:" .. string.gsub(tostring(head.next),"([><])","\strut\hss\copy0\hss}%1")) end if id == node.id("if_stack") then\StudyBox{0}% k = k + 1\externalfigure nd[box0n] = gv.pdfnode(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[width=29cmn],"label",tostring(k) .. " " .. "if_stack" .. "\stopTEXpage|id:" .. tostring(head.id) .. "\stoptext|subtype:" .. tostring(head.subtype) .. </pre>[[Image "\|next:Graphviz" .png|900px]. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id == R =node.id("unhyphenated") then k =k + 1R is a language and environment for statistical computing and graphics nd[http://wwwn] = gv.r-projectnode(g,ndlbl) res = gv.org setv(see herend[n],"shape","record") res = gv.setv(nd[n] ,"label",tostring(k) .. " " .. "unhyphenated" .. <br/>RPy is a very simple, yet robust, Python interface to the R Programming Language [http "\|id://rpy" .sourceforge.net tostring(see herehead.id)] . <br/>. As example, let's try to plot a discrete distribution of probability for a set of pseudorandom number "\|subtype:" .. tostring(around 100000 sampleshead.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><pre>])","\\\%1"))import rpy2.robjects as robjects endimport rpy2 if id == node.rinterface as rinterface class densityid(object"hyphenated"):then k = k + 1 def __init__ nd[n] = gv.node(selfg,samplesndlbl) res = gv.setv(nd[n],outpdf"shape",w"record") res = gv.setv(nd[n],h"label",kerneltostring(k).. " " .. "hyphenated" .. "\|id:" .. tostring(head.id) .. self "\|subtype:" .. tostring(head.subtype) ..samples = samples self "\|next:" .. string.gsub(tostring(head.outpdfnext),"([><])","\\\%1")) end if id == outpdfnode.id("delta") then self.kernel k = kernelk + 1 selfnd[n] = gv.widthnode(g,ndlbl) res =w selfgv.height=h  def runsetv(selfnd[n],"shape","record"): r res = robjectsgv.r data = setv(nd[intn],"label",tostring(k) .. " " ..strip"delta" .. "\|id:" .. tostring(head.id)) for k in file.. "\|subtype:" .. tostring(selfhead.samples,'r'subtype).readlines. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end x if id == robjectsnode.IntVectorid(data"passive")then k = k + 1 r nd[n] = gv.pdfnode(fileg,ndlbl) res =selfgv.outpdfsetv(nd[n],"shape",width"record") res =selfgv.widthsetv(nd[n],"label",height=selftostring(k) .. " " .. "passive" .. "\|id:" .. tostring(head.heightid).. z = r "\|subtype:" ..densitytostring(x,kernel=selfhead.kernelsubtype).. #r "\|next:" .. string.gsub(tostring(head.plotnext),"(z[0><])",z"\\\%1")) end if id == node.id("shape") then k = k + 1 nd[1n]= gv.node(g,xlabndlbl) res =''gv.setv(nd[n],"shape",ylab"record") res =''gv.setv(nd[n],"label",xlim=robjectstostring(k) .. " " .. "shape" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.IntVectornext),"([0><])",2**16-"\\\%1]")) r end if id == node.plotid(z"hlist") then k = k + 1 nd[0n]= gv.node(g,zndlbl) res = gv.setv(nd[1n],xlab=''"shape",ylab=''"record") r res = gv.setv(nd['dev.off'n],"label",tostring(k).. " " .. "hlist" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. if __name__ == '__main__' "\|attr: dens = density" .. string.gsub(tostring('u-random-int','test-001head.pdf'attr),10"([><])",7,'o'"\\\%1") .. "\|width:" .. tostring(head.width).. dens "\|depth:" ..runtostring(head.depth).. </pre> "\|height:" .. tostring(head.height) .. "\|dir:" .. tostring(head.dir) .. "\|shift:" .. tostring(head.shift) .. "\|glue_order:" .. tostring(head.glue_order) .. <texcode> "\|glue_sign:" .. tostring(head.glue_sign) .. "\startluacode|glue_set:" .. tostring(head.glue_set) .. function testR "\|list:" .. string.gsub(samplestostring(head.list),outpdf"([><])",w"\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),h"([><])",kernel"\\\%1").. require "\|next:" .. string.gsub(tostring(head.next),"python([><])","\\\%1")) testR end if id == pythonnode.importid("test-Rfake") then dens k = testRk + 1 nd[n] = gv.densitynode(samplesg,ndlbl) res = gv.setv(nd[n],outpdf"shape",w"record") res = gv.setv(nd[n],h"label",kerneltostring(k).. " " .. "fake" .. dens "\|id:" .run. tostring(head.id).. end "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\stopluacode%1")) end\def\plotdenstiy kd[k] = nd[n] e1 = gv.edge(kd[#k-1]{,kd[k]) if id == node.id('hlist') or id == node.id('vlist') then %% If we want to connect nested (h|v)list %%\getparameters %%e = gv.edge(nd[n-1],nd[Rn]) %%gv.setv(e,'arrowhead','diamond') nodesprint(head.list,( n or 0) +1) end head = head.next endend local head = tex.box[#1]%\expanded{\ctxlua{testRnodesprint(head,0)r = gv.layout("\Rsamples"g,"\Routpdfdot")r = gv.render(g,\Rwidth'pdf',string.format('box\Rheight%d.pdf',"#1))\Rkernel")}}stopluacode%%}
\setupbodyfont[sans,10pt]
\starttext
\startTEXpage
\plotdenstiy[samplessetbox0=\hbox{u-random-int},outpdf={test-001.pdf},width={10},height={7\TeX},kernel={o}]\setupcombinations[location=top]hbox to 29cm{\startcombination[1*2]{strut\vbox{hss\hsize=400bpThis is a density plot of around {copy0\tt 100 000hss} random numbers between $0$ and $2^{16}-1$ generated from {\tt \hbox{/dev/urandom}}}}StudyBox{0}%{\externalfigure[test-001box0.pdf][width={400bp}29cm]}{}\stopcombination
\stopTEXpage
\stoptext
</texcodepre>[[Image:Graphviz.png|900px]]
And == R ==R is a language and environment for statistical computing and graphics [http://www.r-project.org (see here )] . <br/>RPy is a very simple, yet robust, Python interface to the plot R Programming Language [http://rpy.sourceforge.net (see here)] . <br/>As example, let's try to plot a discrete distribution of probability for a set of pseudorandom number (around 100000 samples) .<pre>import rpy2.robjects as robjectsimport rpy2.rinterface as rinterface
[[Imageclass density(object):Test-R.png]]
def __init__(self,samples,outpdf,w,h,kernel): self.samples =samples self.outpdf= dbxml outpdf self.kernel =kernel self.width=wFrom site [http://www self.oracle.com/database/berkeley-db/xml/index.html (see here)] :height=h
def run(self): r = robjects.r data = [int(k.strip()) for k in file(self.samples,'r'Oracle Berkeley DB XML is an open source).readlines()] x = robjects.IntVector(data) r.pdf(file=self.outpdf, embeddable XML database with XQuery-based access to documents stored in containers and indexed based on their contentwidth=self.width,height=self. Oracle Berkeley DB XML is built on top of Oracle Berkeley DB and inherits its rich features and attributesheight) z = r. Like Oracle Berkeley DBdensity(x, it runs in process with the application with no need for human administrationkernel=self.kernel) #r. Oracle Berkeley DB XML adds a document parserplot(z[0],z[1], XML indexer and XQuery engine on top of Oracle Berkeley DB to enable the fastestxlab='',ylab='',xlim=robjects.IntVector([0, most efficient retrieval of data2**16-1])) r.plot(z[0],z[1],xlab='',ylab='') r['dev.off']()
As test, we can use a dump from wikiversity [http://en.wikiversity.org/wiki/Getting_stats_out_of_Wikiversity_XML_dumps (see here)] .
if __name__ == '__main__' :
dens = density('u-random-int','test-001.pdf',10,7,'o')
dens.run()
</pre>
First we build the container 'Data.dbxml' in the directory "wikienv" (that must exists) :
<pre>
"""
---
"""
from bsddb3.db import *
from dbxml import *
import sys
import re
import time
def createEnvironment(home): """Create DBEnv and initialize XmlManager"""<texcode> try:\startluacode environment = DBEnvfunction testR() # environment.set_cachesize(0samples,outpdf,w,512 * 1024 *1024h,1kernel) environment.set_lk_max_lockers require(10000"python") environment testR = python.set_lk_max_locksimport(10000"test-R") environment dens = testR.set_lk_max_objectsdensity(10000) # initialize DBEnv for transactions environment.open(homesamples, DB_RECOVER|DB_CREATE|DB_INIT_LOCK|DB_DSYNC_LOG| DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXNoutpdf, 0) except DBErrorw, exc: print exc sys.exit() try: mgr = XmlManager(environmenth, 0kernel) mgr dens.setDefaultPageSizerun(4096) except XmlException, se: print xe sys.exit()end return mgr\stopluacode
\def createContainer\plotdenstiy[#1]{%\getparameters[R][#1]%\expanded{\ctxlua{testR(mgr, containerName, flags): "\Rsamples","create/open a node container\Routpdf",\Rwidth,\Rheight,"\Rkernel")}}% } try: uc = mgr.createUpdateContext() container = mgr.openContainer(containerName\setupbodyfont[sans,10pt] flags|DB_CREATE,\starttext XmlContainer.WholedocContainer)\startTEXpage container.addIndex("","title","edge\plotdenstiy[samples={u-elementrandom-substringint},outpdf={test-string",uc) container001.addIndex(""pdf},"username"width={10},"edge-element-substring-string"height={7},uc)kernel={o}]\setupcombinations[location=top]\startcombination[1*2]{\vbox{\hsize=400bp container.addIndex("","text","edgeThis is a density plot of around {\tt 100 000} random numbers between $0$ and $2^{16}-element1$ generated from {\tt \hbox{/dev/urandom}}}}{}{\externalfigure[test-substring-string",uc)001.pdf][width={400bp}]}{} return container\stopcombination except XmlException, ex:\stopTEXpage print ex\stoptext sys.exit()</texcode>
And here is the plot <br/>
def loadcontent[[Image:Test-R.png]] == dbxml ==From site [http://www.oracle.com/database/berkeley-db/xml/index.html (mgrsee here)] : ''Oracle Berkeley DB XML is an open source, embeddable XML database with XQuery-based access to documents stored in containers and indexed based on their content. Oracle Berkeley DB XML is built on top of Oracle Berkeley DB and inherits its rich features and attributes. Like Oracle Berkeley DB, containerit runs in process with the application with no need for human administration. Oracle Berkeley DB XML adds a document parser,contentXML indexer and XQuery engine on top of Oracle Berkeley DB to enable the fastest,printmsgmost efficient retrieval of data.'' As test,kwe can use a dump from wikiversity [http://en.wikiversity.org/wiki/Getting_stats_out_of_Wikiversity_XML_dumps (see here)] .  === Build the cointainer ===First we build the container 'Data.dbxml' in the directory "wikienv" (that must exists): <pre>""" --- """ id= re.compile(r"<id>(from bsddb3.db import *)</id>") title = re.compile(r"<title>(.from dbxml import *)</title>",import sysimport re.MULTILINE|re.DOTALL)import time
def createEnvironment(home): """Create DBEnv and initialize XmlManager""" id_text try: environment = idDBEnv() # environment.searchset_cachesize(content0,512 * 1024 *1024,re1) environment.MULTILINE|reset_lk_max_lockers(10000) environment.DOTALLset_lk_max_locks(10000) environment.groupset_lk_max_objects(110000) title_text = title # initialize DBEnv for transactions environment.searchopen(contenthome, DB_RECOVER|DB_CREATE|DB_INIT_LOCK|DB_DSYNC_LOG| DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN, 0) except DBError, exc: print exc sys.groupexit(1) docName try: mgr = '_'XmlManager(environment, 0) mgr.joinsetDefaultPageSize(title_text4096) except XmlException, se: print xe sys.splitexit() return mgr def createContainer(mgr, containerName, flags) + '_' +id_text: """create/open a node container""" txn = False
try:
# all Container modification operations need XmlUpdateContext
uc = mgr.createUpdateContext()
container = mgr.openContainer(containerName, flags|DB_CREATE, XmlContainer.WholedocContainer) container.addIndex("","title","edge-element-substring-string",uc) container.addIndex("","username","edge-element-substring-string",uc) container.addIndex("","text","edge-element-substring-string",uc) return container except XmlException, ex: print ex sys.exit()  def loadcontent(mgr, container,content,printmsg,k): """ -- """ id= re.compile(r"<id>(.*)</id>") title = re.compile(r"<title>(.*)</title>",re.MULTILINE|re.DOTALL)  id_text = id.search(content,re.MULTILINE|re.DOTALL).group(1) title_text = title.search(content).group(1) docName = '_'.join(title_text.split()) + '_' +id_text txn = False try: # all Container modification operations need XmlUpdateContext uc = mgr.createUpdateContext() # create XmlTransaction for the operation txn = mgr.createTransaction() # use the DBXML_GEN_NAME flag to make sure this # succeeds by creating a new, unique name # Use a try/except block to allow the transaction to
# be aborted in the proper scope upon error
try:
</pre>
=== Make pdf ===We use this modules <tt>wikidbxml_queryTxn.py</tt>to retrive a page, given a title (it can be also used as basis to build more complex queries, but for now it's adeguate ):
<pre>
def managepara(c,res):
if c.tag == 'para' and (len(c.text.strip()) > 0is not None):
res.append(c.text.strip()+r"\par")
if c.tag == 'para' and (len(c.getchildren())>0):
#open('res.dbk','w').write( " ".join(res.split()) )
res = getConTeXt(title,res)
return res except Exception,e: print "error on read:" ,e fcntl.flock(lockfile, fcntl.LOCK_UN) lockfile.close() def writeres(title,preamble,postamble,filename):  res = getArtitleByTitle(title=title) if res is not None : res = res.replace('&',r'\&') res = res.replace('#',r'\#') else: res = '' open(filename,'wb').write( '\n'.join((preamble,res,postamble)) )  pass if __name__ == '__main__':  preamble = r"""\usetypescriptfile[type-gentium]\usetypescript[gentium]\setupbodyfont[gentium,10pt]\setuppapersize[A5][A5]\setuplayout[height=middle,topspace=1cm,header={2\lineheight},footer=0pt,backspace=1cm,margin=1cm, width=middle]\starttext"""  postamble = r"""\stoptext"""   title="Primary mathematics/Numbers" filename = 'res.tex' writeres(title,preamble,postamble,filename)</pre> And in the end mkiv wrapper:<texcode>\usetypescriptfile[type-gentium]\usetypescript[gentium]\setupbodyfont[gentium,10pt]\setuppapersize[A5][A5]\setuplayout[height=middle,topspace=1cm,header={2\lineheight},footer=0pt,backspace=1cm,margin=1cm, width=middle]  \startluacodefunction testdbxml(title,preamble,postamble,filename) require("python") pg = python.globals() wikiversity = python.import("wikidbxml_queryTxn") wikiversity.writeres(title,preamble,postamble,filename) end\stopluacode \def\testdbxml[#1]{%\getparameters[dbxml][#1]%\ctxlua{testdbxml("\csname dbxmltitle\endcsname","\csname dbxmlpreamble\endcsname", "\csname dbxmlpostamble\endcsname","\csname dbxmlfilename\endcsname")}%\input \csname dbxmlfilename\endcsname %}   \starttext\testdbxml[title={Primary mathematics/Numbers}, preamble={}, postamble={}, filename={testres.tex}]\stoptext</texcode> Here here the result: <table class="wikitable"> <tr><td></td> <td>[[Image:Dbxml-1.png]]</td></tr><tr><td>[[Image:Dbxml-2.png]]</td> <td>[[Image:Dbxml-3.png]]</td></tr></table> One can also use sqlite that comes with python to query for titles <tt>category.db</tt>made from (for example) <tt>enwikiversity-20090627-category.sql</tt>,so reports are more simpler:just put this in python code above, right before 'if __name__' ...:<pre>import sqlite3def querycategory(title): conn = sqlite3.connect('category.db') c = conn.cursor() t = (title,) c.execute('select cat_title from category where cat_title like "%%%s%%" ;' % t) res = [row[0] for row in c] conn.commit() c.close() return res  def simplereports(title): res = querycategory(title) j = 0 for r in res: g = r.replace('_',' ') print g title= g.encode('utf8') filename = 'reps%04d.tex' % j writeres(title,'','',filename) j = j+1 return j </pre> Similary, add this to tex code<texcode>\startluacodefunction listtitles(title) require("python") pg = python.globals() wikiversity = python.import("wikidbxml_queryTxn") r = wikiversity.querycategory(title) local j = 0 local res = r[j] or {} while res do local d = string.format("\%s\\par",string.gsub(tostring(res),'_',' ')) tex.sprint(tex.ctxcatcodes,d) j = j+1 res = r[j] endend\stopluacode  \startluacodefunction simplereports(title) require("python") pg = python.globals() wikiversity = python.import("wikidbxml_queryTxn") r = wikiversity.simplereports(title) local j = tonumber(r) for v = 0,j-1 do local d = string.format("\\input reps\%04d ",v) tex.sprint(tex.ctxcatcodes,d) end print( j )end\stopluacode</texcode>
def writeres(title,preamble,postamble,filename):  res = getArtitleByTitle(title=title) res = res.replace('&',r'\&')and test it with
open(filename,'wb').write( '\n'.join((preamble,res,postamble)) )
 
pass
 
if __name__ == '__main__':
 
preamble = r"""\usetypescriptfile[type-gentium]
\usetypescript[gentium]
\setupbodyfont[gentium,10pt]
\setuppapersize[A5][A5]
\setuplayout[height=middle,topspace=1cm,header={2\lineheight},footer=0pt,backspace=1cm,margin=1cm, width=middle]
\starttext"""
 
postamble = r"""\stoptext"""
 
 
title="Primary mathematics/Numbers"
filename = 'res.tex'
writeres(title,preamble,postamble,filename)
</pre>
 
And in the end mkiv wrapper:
<texcode>
\usetypescriptfile[type-gentium]
\usetypescript[gentium]
\setupbodyfont[gentium,10pt]
\setuppapersize[A5][A5]
\setuplayout[height=middle,topspace=1cm,header={2\lineheight},footer=0pt,backspace=1cm,margin=1cm, width=middle]
 
 
\startluacode
function testdbxml(title,preamble,postamble,filename)
require("python")
pg = python.globals()
wikiversity = python.import("wikidbxml_queryTxn")
wikiversity.writeres(title,preamble,postamble,filename)
end
\stopluacode
 
\def\testdbxml[#1]{%
\getparameters[dbxml][#1]%
\ctxlua{testdbxml("\csname dbxmltitle\endcsname","\csname dbxmlpreamble\endcsname",
"\csname dbxmlpostamble\endcsname","\csname dbxmlfilename\endcsname")}%
\input \csname dbxmlfilename\endcsname %
}
 
 
 
\starttext
{\testdbxml[title={Primary mathematics/Numbersbfb Query for 'geometr':}, preamble=\ctxlua{listtitles("geometr")},% postamble={}, filename=\ctxlua{testres.texsimplereports("geometr")}]%
\stoptext
</texcode>
Here here the result: <table class="wikitable"> <tr><td></td> <td>[[Image:Dbxml-1(query results are stored in reps0001.png]]</td></tr><tr><td>[[Image:Dbxml-2tex ,reps0002.png]]</td> <td>[[Image:Dbxml-3tex ,.png]]</td></tr></table>.and so on.)

Navigation menu