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=Here I will collect some tex snippets,just to show some ideas. == Scipy ==Watch how python code <tt> z = x*np.exp(-x**2-y**2) </tt>is translated in lua code <tt> z = x.__mul__( np.exp( (x.__pow__(2).__add__(y.__pow__(2))).__neg__() ) )</tt>
This example shot how to literally embed
original python source code .
{| class="wikitable" <table>|-<tr>|<td><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
\def\SepiaImage#1#2{%\ctxlua{testPIL("#1","#2")}%\startcombination[2*1]{\externalfigure[#1]}{\ss Orig.}{\externalfigure[#2]}{\ss Sepia}\stopcombination}  \starttext
\startTEXpage
\SepiaImagectxlua{lenatest_ROOT("data.jpgpdf")}\rotate[rotation=90]{lena-sepia\externalfigure[data.jpgpdf]}
\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
python-- make up some randomly distributed data npts = 200 x = uniform(-2,2,npts) y = uniform(-2,2,npts) -- z = x*np.executeexp([[-x**2-y**2)def run z = x.__mul__( np.exp( (x.__pow__(2).__add__(y.__pow__(2))).__neg__(filename):) ) -- define grid. from ROOT import TCanvas xi = np.linspace(-2.1,2.1, TGraph100) from ROOT import gROOT yi = np.linspace(-2.1,2.1,100) -- grid the data. from math import sin zi = griddata(x,y,z,xi,yi) from array import array -- contour the gridded data, plotting dots -- at the randomly spaced data points. -- we put this in python globals space gROOT -- CS = plt.Resetcontour(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]") c1 kv = TCanvaspython.eval( "{'c1linewidth': 0.5 , 'A Simple Graph Examplecolors':'k'}") CS = python.apply(plt.contour, args, 200kv) -- pg.jet = plt.cm.jet args = python.eval("[xi, 10yi, 700zi, 500 15]") kv = python.eval("{'cmap': jet}") c1 CS = python.SetFillColorapply( 42 plt.contourf, args,kv) c1 -- draw colorbar plt.SetGridcolorbar() -- plot data points. n pg.x = x; pg.y = 20y args = python.eval("[x, y ]") kv = arraypython.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( 'dgriddata test (%i points)' ,npts)) --plt.savefig(figname, dpi, array'white') -- pg.figname = figname ; pg.dpi = dpi args = python.eval("[figname]") kv = python.eval( "{'dpi'd: dpi ,' facecolor' :'white'}") CS = python.apply(plt.savefig, args,kv)end\stopluacode
for i in range( n ):
x.append( 0.1*i )
y.append( 10*sin( x[i]+0.2 ) )
gr = TGraph( n, x, y )\def\testSCIPY[#1]{% gr.SetLineColor( 2 )\getparameters[scipy][#1]% gr.SetLineWidth\ctxlua{testSCIPY( 4 )"\csname scipyfigname\endcsname", gr.SetMarkerColor( 4 "\csname scipydpi\endcsname")}% 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)]\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/>Save this in <tt>test-ROOT1.py</tt> == Python Imaging Library (so it's also easy to testPIL) :<pre>from ROOT import TCanvas, TGraph ,TGraphErrors,TMultiGraphfrom ROOT import gROOTfrom math import sinfrom array import array==
def run{| class="wikitable" |-|<texcode>\startluacodefunction testPIL(filenameimageorig,imagesepia): c1 = TCanvas require("c1python",) PIL_Image = python.import("multigraphPIL.Image",200,10,700,500) c1 PIL_ImageOps = python.SetGridimport("PIL.ImageOps") python.execute([[ # draw a frame to define the range mg = TMultiGraphdef make_linear_ramp(white): # create first graphramp = [] n r, g, b = 24;white x = array('d',for i in range(24)255): data = file ramp.extend(('data'r*i/255, g*i/255, b*i/255).readlines() for line in data:return ramp]]) line = line.strip -- make sepia ramp (tweak color as necessary) y sepia = arraypython.eval("make_linear_ramp('d'(255, 240,[float(d192))") for d in line im = PIL_Image.splitopen(imageorig)]) gr -- convert to grayscale if not(im.mode == TGraph(n,x,y"L") then grim = im.Fitconvert("pol6L") end -- optional: apply contrast enhancement here,"q")e.g. 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.Update-- (alternatively, save it in PNG or similar) c1im = im.Printconvert(filename"RGB")
</pre>Here file 'data' is a 110 lines file with 24 floats values space separated,ie <br/><tt> 20 im.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>\startluacodefunction test_ROOT(filename) require("python") test = python.import('test-ROOT1') test.runsave(filenameimagesepia)end
\stopluacode
 
\def\SepiaImage#1#2{%
\ctxlua{testPIL("#1","#2")}%
\startcombination[2*1]
{\externalfigure[#1]}{\ss Orig.}
{\externalfigure[#2]}{\ss Sepia}
\stopcombination
}
 
\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 .
class simpledraw(object):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]
def __init__(self,font_file):
self.font = fontforge.open(font_file)
def getcurve\startluacodefunction testimagemagick(selfbox,lettert): self.glname = letter local w res = dict() try : glyph_letter = [ g for g in self.font.glyphs() if g.glyphname == self.glname][0] local h except Exception ,e : local d res['err'] = str(e) local f return local res cnt= glyph_letter118.layers[1][0]11023622047244094488 -- 300 dpi res['is_quadratic'] local opacity = cnt.is_quadratic25 res['closed'] local sigma = cnt.closed15 res['points'] = [(p. local x,p.y,"%i" %p.on_curve) for p in cnt ] res['design_size'] = self.font.design_size10 res['em'] local y = self.font.em return res10
require("python")
pg = python.globals()
PythonMagickWand = python.import("PythonMagickWand")
w = math.floor((tex.wd[box] / 65536 ) / 72.27 * 2.54 * res )
h = math.floor(((tex.ht[box] / 65536) + (tex.dp[box] / 65536)) / 72.27 *2.54 *res )
f = string.format("%s.png",t)
def getmpostoutline wand = PythonMagickWand.NewMagickWand(self,letter): res background = selfPythonMagickWand.getcurveNewPixelWand(letter0) path = ' -- PythonMagickWand.MagickNewImage(wand,w,h,background) PythonMagickWand.'.joinMagickNewImage( [str((p[0]wand,w,h,p[1]background)) for p in res['points'] if p[2] == '1'] ) return path
def getmpostpoints PythonMagickWand.MagickSetImageResolution(selfwand,letterres,res): res = self PythonMagickWand.getcurveMagickSetImageUnits(letterwand,PythonMagickWand.PixelsPerCentimeterResolution) path = [str PythonMagickWand.MagickShadowImage(wand,opacity,sigma,x,y) PythonMagickWand.MagickWriteImage(p[0]wand ,p[1])f) for p in res['points'] if p[2] == '1'] return path
def getmpostpointsSugar print(selfw,letter): res = self.getcurve(letterh,f) path = 'drawdot '.join( ["%s;" %str((p[0],p[1])) for p in res['points'] if p[2] == '1'] )end return 'drawdot ' +path\stopluacode
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>:There are essentially 2 kind of use of ghostscript :<pre>* convert an existing eps / ps file in pdf ;import sys* use a program in postscript that take an input, do something and make a ps output ( e.g. a barcode/label generator ).import fontforge
For the first case, we consider an implementation of eps2pdf, being ps2pdf virtually the same .<br/>
Actually there is not a python binding of ghostscript, so we build a simple wrapper
using ctypes module.
<pre>class simpledraw(object):import ctypesimport sys def __init__(self,font_file): self.font = fontforge.open(font_file)  def getcurve(self,letter): self.glname = letter 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   def drawmpostpath(self,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 drawmpostpoints(self,letter): res_Array = self.getcurve(letter) dots = '' for res in res_Array: temp = '\n'.join( ["drawdot %s;" %str((p[0],p[1])) for p in res['points'] if p[2] == '1'] ) + "\n" dots = dots + temp return dots
class gs(object):
def __init__if __name__ == '__main__': s = simpledraw("lmmono10-regular.otf") #res = s.getmpostpointsSugar('C') #print res #print s.getmpostoutline('C') print s.getcurve('e') print s.drawmpostpath('e') print s.drawmpostpoints(self'e'):
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</pre>
self.libgspath = Note the <tt>'__main__'</opt/luatex/luatex-lunatictt> check, so we can test this class from python. <br/lib/libgs.so'>Next lua layer, which in this case is embed in a tex file:<texcode>
self.OutFile \setupcolors[state= '' self.InFile = ''start]
self.args = []
\startluacode function testFontforge(fontfile,letter) def appendargsrequire(self,arg"python"): if arg testoutlines = python.findimport('"test-sOutputFile'fontforge")> s = 0: returntestoutlines.simpledraw(fontfile) g = s.drawmpostpath(letter) if arg p = s.finddrawmpostpoints('letter) -c quit'-print( string.format("\%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;")>= 0: return self tex.sprint(tex.ctxcatcodes,string.argsformat("\%s",p) ) tex.appendsprint(argtex.ctxcatcodes,"\\stopMPcode")end\stopluacode
\def rawappendargs\Outline[#1]{%\getparameters[test][#1]%\ctxlua{testFontforge(self"\testfontfile",arg"\testletter"):}% self.args.append(arg)}
\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}]%
\Outline[letter={X}, fontfile={lmmono10-regular.otf}]%
\Outline[letter={t}, fontfile={lmmono10-regular.otf}]%
\stopTEXpage
\stoptext
</texcode>
 
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-fontforge.png|900px]]
== Ghostscript ==
There 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 ( e.g. a barcode/label generator ).
def run(self): libgs = ctypesFor the first case, we consider an implementation of eps2pdf, being ps2pdf virtually the same .CDLL(self.libgspath)<br/>Actually there is not a python binding of ghostscript, so we build a simple wrapper exit_status = using ctypesmodule <tt>testgs.c_int() code = ctypes.c_int(1) code1 = ctypes.c_int() instance = ctypes.c_void_p(None) exit_code = ctypes.c_int()py</tt> :
code.value = libgs.gsapi_new_instance(ctypes.byref(instance), None) if code.value == 0 : libgs.gsapi_set_stdio(instance, None, None, None) self.args.insert(0,'') # if len(self.OutFile) <pre> 0: self.args.append('-sOutputFile=%s' %self.OutFile) if len(self.InFile) > 0: self.args.append("%s" %self.InFile) self.args.append('-c quit') arguments = self.args # argc = ctypes.c_int(len(arguments)) argv = (import ctypes.c_char_p * argc.value)(*arguments) code.value = libgs.gsapi_init_with_args(instance, argc, argv)import sys
code1.value = libgs.gsapi_exit(instance)
if code.value == 0 or code.value == self.ierrors['e_Quit']class gs(object): code.value = code1.value
if code.value == def __init__(self.ierrors['e_Quit']): code.value = 0
libgs self.gsapi_delete_instanceierrors = dict(instance) self.ierrors['e_unknownerror'] = -1 exit_statusself.value ierrors['e_dictfull'] = 0-2 self.ierrors['e_dictstackoverflow'] = -3if __name__ self.ierrors['e_dictstackunderflow'] =-4 self.ierrors['e_execstackoverflow'] = -5 self.ierrors['__main__e_interrupt':] = -6 pyctyps self.ierrors['e_invalidaccess'] = gs()-7 pyctyps self.appendargs(ierrors['e_invalidexit'] = -q8 self.ierrors[')e_invalidfileaccess'] = -9 pyctyps self.appendargs(ierrors['e_invalidfont'] = -dNOPAUSE10 self.ierrors['e_invalidrestore')] = -11 pyctyps self.appendargs(ierrors['e_ioerror'] = -dEPSCrop12 self.ierrors[')e_limitcheck'] = -13 pyctyps self.appendargs(ierrors['e_nocurrentpoint'] = -sDEVICE14 self.ierrors['e_rangecheck'] =pdfwrite-15 self.ierrors['e_stackoverflow')] = -16 pyctyps self.InFile ierrors['e_stackunderflow'] = -17 self.ierrors['teste_syntaxerror'] = -18 self.epsierrors['e_timeout'] = -19 pyctyps self.OutFile ierrors['e_typecheck'] = -20 self.ierrors['e_undefined'test] = -21 self.pdfierrors['e_undefinedfilename'] = -22 pyctyps self.run()ierrors['e_undefinedresult'] = -23 self.ierrors['e_unmatchedmark'] = -24</pre> self.ierrors['e_VMerror'] = -25 self.ierrors['e_configurationerror'] = -26The tex code self.ierrors['e_undefinedresource'] = -27<texcode> self.ierrors['e_unregistered'] = -28\startluacode self.ierrors['e_invalidcontext'] = -29function testgs(epsin,pdfout) self.ierrors['e_invalidid'] = -30 require("python") gsmodule = python self.import("testgs") ghost ierrors['e_Fatal'] = gsmodule.gs()-100 ghost self.appendargs(ierrors['e_Quit'] = -q')101 ghost self.appendargs(ierrors['e_InterpreterExit'] = -dNOPAUSE')102 ghost self.appendargs(ierrors['e_RemapColor'] = -dEPSCrop')103 ghost self.appendargs(ierrors['e_ExecStackUnderflow'] = -sDEVICE=pdfwrite')104 ghost self.InFile ierrors['e_VMreclaim'] = epsin-105 ghost self.OutFile ierrors['e_NeedInput'] = pdfout-106 ghost self.run()end\stopluacodeierrors['e_Info'] = -110
\def\epstopdf#1#2{\ctxlua{testgs("#1","#2")}}\def\EPSfigure[#1]{%lazy way to load eps\epstopdf{#1 self.eps}{#1libgspath = '/opt/luatex/luatex-lunatic/lib/libgs.pdf}%\externalfigure[#1.pdf]%}so'
\starttext\startTEXpage\startcombination[2*1]{\EPSfigure[tiger]}{\ss tiger.eps}{\EPSfigure[golfer]}{\ss golfer self.eps}\stopcombination\stopTEXpage\stoptext</texcode>and the result :<br/>OutFile = ''[[Image:Testgs self.png|900px]]InFile = ''
Another example:<br/>here we use a library to generate barcodes self.args = [http://www.terryburton.co.uk/barcodewriter (see here)] .<texcode>\startluacodefunction epstopdf(epsin,pdfout) require("python") gsmodule = python.import("testgs") ghost = gsmodule.gs() ghost.appendargs('-q') ghost.appendargs('-dNOPAUSE') ghost.appendargs('-dEPSCrop') ghost.appendargs('-sDEVICE=pdfwrite') ghost.InFile = epsin ghost.OutFile = pdfout ghost.run()end
function barcode def appendargs(textself,type,options,savefilearg): require if arg.find("python"'-sOutputFile')>= 0: return gsmodule if arg.find('-c quit')>= python0: return self.args.importappend("testgs"arg)
barcode_string = string.format("%%!\n100 100 moveto (%s) (%s) %s barcode showpage" ,text,options,type)
psfile = string.format def rawappendargs("%s.ps"self,savefilearg): epsfile = string self.format("%sargs.eps",savefile) pdffile = string.formatappend("%s.pdf",savefilearg)
temp = io.open(psfile,'w')
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.rawappendargs('barcode.ps')
ghost.InFile= psfile
ghost.run()
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 or {}libgs.gsapi_exit(instance)
local nd if code.value = {};= 0 or code.value == self.ierrors['e_Quit']:local kd code.value = {};code1.value
local k = 0;local function nodesprint(head,n) while head do local id = head if code.id local oldn value = n ndlbl = stringself.format("nd_\%03d",k)ierrors['e_Quit']: texio code.write_nl(string.format("idvalue =\%s, ndlbl=\%s",id,ndlbl))0
if id == node libgs.idgsapi_delete_instance("vlist"instance) then k = k + 1 nd[n] = gv exit_status.node(g,ndlbl) res value = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "vlist" .. "\|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) .. "\|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),"([><])","\\\%1")) end0
if id __name__ == node'__main__': pyctyps = gs() pyctyps.idappendargs("rule"'-q') then k = k + 1 nd[n] = gv pyctyps.nodeappendargs(g,ndlbl'-dNOPAUSE') res = gv pyctyps.appendargs('-dEPSCrop') pyctyps.setvappendargs(nd[n],"shape","record"'-sDEVICE=pdfwrite') res pyctyps.InFile = 'test.eps' pyctyps.OutFile = gv'test.pdf' pyctyps.setvrun(nd[n]) </pre> The tex code<texcode>\startluacodefunction testgs(epsin,pdfout) require("labelpython",tostring(k) gsmodule = python.. import(" testgs" ) ghost = gsmodule.gs() ghost. "rule" appendargs('-q') ghost.appendargs('-dNOPAUSE') ghost. appendargs('-dEPSCrop') "\|id:" . ghost. tostringappendargs(head.id'-sDEVICE=pdfwrite') ghost.InFile = epsin ghost. OutFile = pdfout ghost.run()end "\|subtype:stopluacode \def\epstopdf#1#2{\ctxlua{testgs("#1","#2" .. tostring(head.subtype) .. }} "\|attr:" .. string.gsub(tostring(head.attr),"([><def\EPSfigure[#1])","\\{%lazy way to load eps\%epstopdf{#1") .eps}{#1. pdf}% "\|width:" .. tostring(head.width) .externalfigure[#1. pdf]%} \starttext\startTEXpage "\|depth:" .. tostring(head.depth) .startcombination[2*1]{\EPSfigure[tiger]}{\ss tiger. eps} "{\EPSfigure[golfer]}{\|height:" .. tostring(head.height) .ss golfer. eps} "\stopcombination\stopTEXpage\stoptext</texcode>and the result :<br/>[[Image:Testgs.png|dir900px]] Another example:<br/>here we use a library to generate barcodes [http:" //www.terryburton.co. tostringuk/barcodewriter (head.dirsee here) .] . <texcode>\startluacodefunction epstopdf(epsin,pdfout) require("\|next:python" ) gsmodule = python.import("testgs") ghost = gsmodule. stringgs() ghost.gsubappendargs(tostring'-q') ghost.appendargs(head'-dNOPAUSE') ghost.nextappendargs('-dEPSCrop')," ghost.appendargs([><])","\\\%1"'-sDEVICE=pdfwrite') ghost.InFile = epsin ghost. OutFile = pdfout "\|prev:" ghost.. string.gsubrun(tostring)end function barcode(head.prevtext,type,options,savefile)," require([><])","\\\%1python")) end if id == node gsmodule = python.idimport("instestgs") then k = k + 1 nd[n] barcode_string = gvstring.nodeformat(g,ndlbl)"%%!\n100 100 moveto (%s) (%s) %s barcode showpage" ,text,options,type)  res psfile = gvstring.setvformat(nd[n],"shape%s.ps","record"savefile) res epsfile = gvstring.setvformat(nd[n],"label%s.eps",tostring(ksavefile) pdffile = string.. format(" " .%s. pdf"ins" .,savefile)  temp = io. open(psfile,'w') "\|id:" .. temp:write(tostring(head.idbarcode_string) .. ,"\|subtypen") temp:" flush() io.. tostringclose(head.subtypetemp) ghost = gsmodule.gs() ghost. rawappendargs('-q') "\|attr:" ghost.rawappendargs('-dNOPAUSE') ghost. rawappendargs('-sDEVICE=epswrite') ghost.rawappendargs(string.gsubformat(tostring'-sOutputFile=%s',epsfile)) ghost.rawappendargs(head'barcode.attrps')," ghost.InFile= psfile ghost.run([><])","end\stopluacode \def\epstopdf#1#2{\%ctxlua{epstopdf("#1","#2") .. }} "\|cost:" .. tostring(head.cost) .. def\EPSfigure[#1]{%lazy way to load eps "\|depth:" .. tostring(head.depth) epstopdf{#1.eps}{#1. pdf}% "\|height:" .. tostring(head.height) .. externalfigure[#1.pdf]%} \def\PutBarcode[#1]{% "\|spec:" .. string.gsubgetparameters[bc][#1]%\ctxlua{barcode(tostring(head.spec)"\csname bctext\endcsname","([><])\csname bctype\endcsname","\csname bcoptions\endcsname","\csname bcsavefile\%1endcsname") .. }% "\|list:" .. string.gsub(tostring(head.list),"(expanded{\EPSfigure[><])","\\csname bcsavefile\endcsname]}%1") .. "} \starttext\startTEXpage\|next:" .. string.gsub(tostring(head.next),"(startcombination[><2*2])"{\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} "{\|prev:" .. string.gsub(tostring(head.prev)PutBarcode[text={977147396801},type={ean13},options={includetext},"([><savefile={TEMP3}])","}{\ss ean13}{\\%1")) end if id PutBarcode[text={0123456789},type={interleaved2of5},options= node.id("mark") then k {includecheck includetext},savefile= k + 1{TEMP4}]}{\ss interleaved2of5} nd[n\stopcombination\stopTEXpage\stoptext</texcode> [[Image:Test-ghostscript-barcode.png|900px]]  == Graphviz == gv[http://www.graphviz.org Graphviz] is a Graph Visualization Software .node<br/>Standard distribution comes with several binding (glua and python among others) so it's not difficult to integrate in luatex lunatic .<br/>In this example,ndlbl)we draw a graph of the nodes of <context>\TeX</context><pre>\def\StudyBox#1{%\startluacoderequire "python" res gv = gvpython.setvimport(nd[n],"shape",gv")g = gv.digraph("recordG") res = gv.setv(nd[n]g,"label"'rankdir',tostring(k'LR') .. " " .. "mark" .. "\|id:" .. tostringnodes = nodes or {} local nd = {};local kd = {}; local k = 0;local function nodesprint(head.id,n) while head do local id = head.id local oldn = n ndlbl = string. format("nd_\|subtype:%03d" ,k) texio.write_nl(string. tostringformat(head.subtype"id=\%s, ndlbl=\%s",id,ndlbl))   if id == node.. id("\|attr:vlist" ) then k = k + 1 nd[n] = gv.. string.gsubnode(tostring(head.attr)g,"([><ndlbl) res = gv.setv(nd[n]),"shape","\\\%1record") res = gv.. "\|class:setv(nd[n],"label" .. ,tostring(headk) ..class) " " .. "vlist" .. "\|markid:" .. tostring(head.markid) .. "\|nextsubtype:" .. string.gsub(tostring(head.next),"([><])","\\\%1"subtype) .. "\|prevattr:" .. string.gsub(tostring(head.prevattr),"([><])","\\\%1")).. end if id == node "\|width:" ..idtostring(head.width) .. "adjust\|depth:".. tostring(head.depth) then k = k + 1 nd[n] = gv.node. "\|height:" .. tostring(g,ndlblhead.height) res = gv.setv(nd[n],. "shape","record\|dir:".. tostring(head.dir) res = gv.setv(nd[n],. "label\|shift:",.. tostring(khead.shift) .. " \|glue_order:" .. "adjust" tostring(head.glue_order) .. "\|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("\|next:rule" ) then k = k + 1 nd[n] = gv.. string.gsubnode(tostring(head.nextg,ndlbl)," res = gv.setv(nd[><n]),"shape","\\\%1record")) end if id res == nodegv.idsetv("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 = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_refxform" .. "\|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) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if head.subtype == node.subtype("pdf_refximage") then res = gv.setv(ndnd[n],"label",tostring(k) .. " " .."whatsit:pdf_refximagerule" ..
"\|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_annot,"record") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_annotins" ..
"\|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),"([><]) .. ","\\\|data:%1" .. tostring(head.data) ..
"\|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_start_link,"record") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_start_linkmark" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthclass:" .. tostring(head.widthclass) .. "\|heightmark:" .. tostring(head.heightmark) .. "\|depth:" .. tostring(head.depth) .. "\|objnum:" .. tostring(head.objnum) .. "\|link_attr:" .. tostring(head.link_attr) .. "\|action:" .. tostring(head.action) .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1")) end if headid == node.subtype id("adjust") then k =k + 1 nd[n] = gv.node(g,ndlbl) res = gv.subtypesetv(nd[n],"shape","pdf_end_linkrecord") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_end_linkadjust" ..
"\|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 headid == node.subtype id("disc") then k =k + 1 nd[n] = gv.node(g,ndlbl) res = gv.subtypesetv(nd[n],"pdf_destshape","record") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_destdisc" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthpre:" .. string.gsub(tostring(head.widthpre),"([><])","\\\%1") .. "\|heightpost:" .. string.gsub(tostring(head.heightpost),"([><])","\\\%1") .. "\|depthreplace:" .. string.gsub(tostring(head.depthreplace),"([><])","\\\%1") .. "\|named_idnext:" .. string.gsub(tostring(head.named_idnext),"([><])","\\\%1") .. "\|dest_idprev:" .. string.gsub(tostring(head.dest_idprev),"([><])","\\\%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) .. "\|dest_typesubtype:" .. tostring(head.dest_typesubtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|xyz_zoomstream:" .. tostring(head.xyz_zoomstream) .. "\|objnumdata:" .. tostring(head.objnumdata) .. "\|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 = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "gluewhatsit:pdf_thread_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("kernpdf_link_data") 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:pdf_link_data" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|kern:" .. tostring(head.kern) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end if id head.subtype == node.idsubtype("penaltyopen") 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:open" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|penaltystream:" .. tostring(head.penaltystream) .. "\|name:" .. tostring(head.name) .. "\|area:" .. tostring(head.area) .. "\|ext:" .. tostring(head.ext) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if head.subtype == node.subtype("late_lua") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:late_lua" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|reg:" .. tostring(head.reg) .. "\|data:" .. tostring(head.data) .. "\|name:" .. tostring(head.name) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if head.subtype == node.subtype("fake") 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 id head.subtype == node.idsubtype("unsetpdf_colorstack") then k res = k + 1 gv.setv(nd[n] = gv,"label",tostring(k) .. " " .."whatsit:pdf_colorstack" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.nodeattr),"(g[><])",ndlbl"\\\%1") res = gv.setv. "\|stack:" .. tostring(head.stack) .. "\|cmd:" .. tostring(head.cmd) .. "\|data:" .. tostring(head.data) .. "\|next:" .. string.gsub(tostring(head.next),"(nd[n><])","shape\\\%1") .. "\|prev:".. string.gsub(tostring(head.prev),"record([><])","\\\%1")) end if head.subtype == node.subtype("pdf_save") then res = gv.setv(nd[n],"label",tostring(k) .. " " .. "unsetwhatsit:pdf_save" ..
"\|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("stylecancel_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) .. " " .. "stylewhatsit:cancel_boundary" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|style:" .. tostring(head.style) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end if id head.subtype == node.idsubtype("choiceclose_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) .. " " .. "choicewhatsit:close_lua" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|displayreg:" .. tostring(head.displayreg) .. "\|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("noadpdf_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) .. " " .. "noadwhatsit:pdf_setmatrix" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleusdata:" .. tostring(head.nucleusdata) .. "\|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("oppdf_restore") 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:pdf_restore" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleusprev:" .. 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.nucleususer_id) .. "\|subtype:" .. 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("binmath") 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) .. " " .. "binmath" ..
"\|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("relglue") 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) .. " " .. "relglue" ..
"\|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("openkern") 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) .. " " .. "openkern" ..
"\|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("closepenalty") 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) .. " " .. "closepenalty" ..
"\|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("punctunset") 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) .. " " .. "punctunset" ..
"\|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("innerstyle") 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) .. " " .. "innerstyle" ..
"\|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) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("radicalchoice") 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) .. " " .. "radicalchoice" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleusdisplay:" .. tostring(head.nucleusdisplay) .. "\|subtext:" .. tostring(head.subtext) .. "\|supscript:" .. tostring(head.supscript) .. "\|leftscriptscript:" .. tostring(head.left) .. "\|degree:" .. tostring(head.degreescriptscript) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("fractionnoad") 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) .. " " .. "fractionnoad" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthnucleus:" .. tostring(head.widthnucleus) .. "\|numsub:" .. tostring(head.numsub) .. "\|denomsup:" .. tostring(head.denom) .. "\|left:" .. tostring(head.left) .. "\|right:" .. tostring(head.rightsup) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("underop") 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) .. " " .. "underop" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("overbin") 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) .. " " .. "overbin" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("accentrel") 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) .. " " .. "accentrel" ..
"\|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("vcenteropen") 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) .. " " .. "vcenteropen" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("fenceclose") 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) .. " " .. "fenceclose" ..
"\|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_charpunct") 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_charpunct" ..
"\|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_boxinner") 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_boxinner" ..
"\|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_mlistradical") 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_mlistradical" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|listnucleus:" .. stringtostring(head.nucleus) .. "\|sub:" ..gsubtostring(head.sub) .. "\|sup:" .. tostring(head.listsup),.. "\|left:".. tostring([><]head.left)",.. "\\\%1|degree:".. tostring(head.degree) .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if id == node.id("math_text_charfraction") 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_charfraction" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|famwidth:" .. tostring(head.famwidth) .. "\|charnum:" .. tostring(head.charnum) .. "\|denom:" .. tostring(head.denom) .. "\|left:" .. tostring(head.left) .. "\|right:" .. tostring(head.right) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("delimunder") 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) .. " " .. "delimunder" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|small_famnucleus:" .. tostring(head.small_famnucleus) .. "\|small_charsub:" .. tostring(head.small_charsub) .. "\|large_famsup:" .. tostring(head.large_fam) .. "\|large_char:" .. tostring(head.large_charsup) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("margin_kernover") 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_kernover" ..
"\|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("glyphaccent") 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) .. " " .. "glyphaccent" ..
"\|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) .. "\|leftaccent:" .. tostring(head.leftaccent) .. "\|rightbot_accent:" .. tostring(head.rightbot_accent) .. "\|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_recordvcenter") 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_recordvcenter" ..
"\|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_filefence") 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_filefence" ..
"\|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("pseudo_linemath_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) .. " " .. "pseudo_linemath_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("page_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) .. " " .. "page_insertsub_box" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|heightattr:" .. string.gsub(tostring(head.heightattr),"([><])","\\\%1") .. "\|last_ins_ptrlist:" .. string.gsub(tostring(head.last_ins_ptrlist),"([><]) .. ","\\|best_ins_ptr:\%1" .. tostring(head.best_ins_ptr) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("split_insertsub_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) .. " " .. "split_insertsub_mlist" ..
"\|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_stackmath_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) .. " " .. "expr_stackmath_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("nested_listdelim") 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_listdelim" ..
"\|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("spanmargin_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) .. " " .. "spanmargin_kern" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|width:" .. tostring(head.width) .. "\|glyph:" .. tostring(head.glyph) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("attributeglyph") 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) .. " " .. "attributeglyph" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|numberattr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|char:" .. tostring(head.char) .. "\|font:" .. tostring(head.font) .. "\|lang:" .. tostring(head.lang) .. "\|left:" .. tostring(head.left) .. "\|right:" .. tostring(head.right) .. "\|uchyph:" .. tostring(head.uchyph) .. "\|components:" .. string.gsub(tostring(head.components),"([><])","\\\%1") .. "\|xoffset:" .. tostring(head.numberxoffset) .. "\|valueyoffset:" .. tostring(head.valueyoffset) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("glue_specalign_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) .. " " .. "glue_specalign_record" ..
"\|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("attribute_listpseudo_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) .. " " .. "attribute_listpseudo_file" ..
"\|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_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) .. " " .. "actionpseudo_line" ..
"\|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("temppage_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) .. " " .. "temppage_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("align_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) .. " " .. "align_stacksplit_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) .. "\|broken_ptr:" .. tostring(head.broken_ptr) .. "\|broken_ins:" .. tostring(head.broken_ins) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("movement_stackexpr_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) .. " " .. "movement_stackexpr_stack" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("if_stacknested_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) .. " " .. "if_stacknested_list" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("unhyphenatedspan") 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) .. " " .. "unhyphenatedspan" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("hyphenatedattribute") 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) .. " " .. "hyphenatedattribute" ..
"\|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("deltaglue_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) .. " " .. "deltaglue_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("passiveattribute_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) .. " " .. "passiveattribute_list" ..
"\|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("shapeaction") 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) .. " " .. "shapeaction" ..
"\|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("hlisttemp") 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) .. " " .. "hlisttemp" ..
"\|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) ..
"\|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),"([><])","\\\%1"))
end
if id == node.id("fakealign_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) .. " " .. "fakealign_stack" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
kd if id == node.id("movement_stack") then k = k + 1 nd[kn] = gv.node(g,ndlbl) res = gv.setv(nd[n] ,"shape","record") e1 res = gv.edgesetv(kdnd[k-1n],kd["label",tostring(k]).. " " .. "movement_stack" .. if "\|id == node:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring('hlist'head.next) or ,"([><])","\\\%1")) end if id == node.id('vlist'"if_stack") then %% If we want to connect nested k = k + 1 nd[n] = gv.node(h|vg,ndlbl)list %% %%e res = gv.edgesetv(nd[n-1],nd[n]"shape","record") %% res = gv.setv(end[n],'arrowhead'"label",'diamond'tostring(k).. " " .. "if_stack" .. 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("unhyphenated") 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",stringtostring(k) .. " " .. "unhyphenated" .. "\|id:" ..formattostring('box\%dhead.pdf',#1)id).. "\stopluacode%%}|subtype:" .. tostring(head.subtype) .. "\starttext|next:" .. string.gsub(tostring(head.next),"([><])","\startTEXpage\setbox0=\hbox{\TeX}%1")) end\hbox to 29cm{\strut\hss\copy0\hss} if id == node.id("hyphenated") 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) .. " " .. "hyphenated" .. "\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("delta") 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) .. " " .. "delta" .. <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) ..<pre>import rpy2 "\|next:" ..robjects as robjectsimport rpy2string.rinterface as rinterface class densitygsub(tostring(objecthead.next):  def __init__,"(self[><])",samples,outpdf,w,h,kernel"\\\%1")): self end if id == node.samples = samplesid("passive") then self.outpdfk = outpdfk + 1 self.kernel nd[n] = kernel selfgv.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"passive" .. "\|id:" .. tostring(head.id)) for k in file.. "\|subtype:" .. tostring(selfhead.samples,'r'subtype).readlines. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) x end if id == robjectsnode.IntVectorid(data"shape")then k = k + 1 r nd[n] = gv.pdfnode(fileg,ndlbl) res =selfgv.outpdfsetv(nd[n],width"shape","record") res =selfgv.widthsetv(nd[n],"label",height=selftostring(k) .. " " .. "shape" .. "\|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("hlist") then k = k + 1 nd[1n],xlab=''gv.node(g,ylabndlbl) res ='',xlim=robjectsgv.IntVectorsetv(nd[0n],"shape",2**16-1])"record") r res = gv.plotsetv(znd[0n],z[1]"label",xlab='',ylab=''tostring(k).. " " .. "hlist" .. r['dev "\|id:" ..off']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").. dens "\|width:" .run. tostring(head.width).. </pre>   <texcode> "\startluacodefunction testR|depth:" .. tostring(samples,outpdf,w,h,kernelhead.depth).. require( "python\|height:".. tostring(head.height).. testR = python "\|dir:" ..importtostring(head.dir) .. "test-R\|shift:".. tostring(head.shift) .. dens = testR "\|glue_order:" ..densitytostring(samples,outpdf,w,h,kernelhead.glue_order).. dens "\|glue_sign:" .run. tostring(head.glue_sign).. end "\stopluacode|glue_set:" .. tostring(head.glue_set) .. "\def\plotdenstiy|list:" .. string.gsub(tostring(head.list),"([#1><]{)","\\\%1") .. "\getparameters|prev:" .. string.gsub(tostring(head.prev),"([R><][#)","\\\%1]%") .. "\expanded{\ctxlua{testR|next:" .. string.gsub(tostring(head.next),"\Rsamples([><])","\Routpdf",\Rwidth,\Rheight,%1")) end if id == node.id("\Rkernelfake")}}%then} k = k + 1 nd[n] = gv.node(g,ndlbl)\setupbodyfont res = gv.setv(nd[sansn],"shape",10pt"record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "fake" .. "\starttext|id:" .. tostring(head.id) .. "\startTEXpage|subtype:" .. tostring(head.subtype) .. "\plotdenstiy[samples={u-random-int},outpdf={test-001|next:" .. string.gsub(tostring(head.pdf}next),width={10}"([><])",height={7},kernel={o}]"\\\%1")) end\setupcombinations kd[locationk] =topnd[n]\startcombination e1 = gv.edge(kd[k-1*2],kd[k]){\vbox{\hsize if id == node.id('hlist') or id ==400bpnode.id('vlist') thenThis is a density plot of around {\tt 100 000} random numbers between $0$ and $2^{16}-1$ generated from {\tt \hbox{/dev/urandom}}}}{} %% If we want to connect nested (h|v)list %% {\externalfigure %%e = gv.edge(nd[testn-001.pdf1],nd[width={400bp}n]}{})\stopcombination %%gv.setv(e,'arrowhead','diamond') nodesprint(head.list,( n or 0) +1) end\stopTEXpage head = head.next\stoptext end</texcode>end
And here is the plot <br/>local head = tex.box[#1]nodesprint(head,0)r = gv.layout(g,"dot")r = gv.render(g,'pdf',string.format('box\%d.pdf',#1))\stopluacode%%}
\starttext\startTEXpage\setbox0=\hbox{\TeX}\hbox to 29cm{\strut\hss\copy0\hss}\StudyBox{0}%\externalfigure[box0.pdf][width=29cm]\stopTEXpage\stoptext</pre>[[Image:Test-RGraphviz.png|900px]]
== dbxml R ==Oracle Berkeley DB XML R is a language and environment for statistical computing and graphics [http://www.oracler-project.org (see here)] .com<br/database>RPy is a very simple, yet robust, Python interface to the R Programming Language [http:/berkeley-db/xml/indexrpy.sourceforge.html net (see here)] is an open source. <br/>As example, embeddable XML database with XQuery-based access let's try to documents stored in containers and indexed based on their content. Oracle Berkeley DB XML is built on top plot a discrete distribution of Oracle Berkeley DB and inherits its rich features and attributes. Like Oracle Berkeley DB, it runs in process with the application with no need probability for human administration. Oracle Berkeley DB XML adds a document parser, XML indexer and XQuery engine on top set of Oracle Berkeley DB to enable the fastest, most efficient retrieval of datapseudorandom number (around 100000 samples) .<pre>import rpy2.robjects as robjectsimport rpy2.rinterface as rinterface
As testclass density(object):  def __init__(self,samples,outpdf, we can use a dump from wikiversity w,h,kernel): self.samples = samples self.outpdf= outpdf self.kernel = kernel self.width=w self.height=h  def run(self): r = robjects.r data = [http://enint(k.strip()) for k in file(self.samples,'r').readlines()] x = robjects.IntVector(data) r.pdf(file=self.outpdf,width=self.width,height=self.wikiversityheight) z = r.org/wiki/Getting_stats_out_of_Wikiversity_XML_dumps density(see herex,kernel=self.kernel) #r.plot(z[0] ,z[1],xlab='',ylab='',xlim=robjects.IntVector([0,2**16-1])) r.plot(z[0],z[1],xlab='',ylab='') r['dev.off']()
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)if __name__ == '__main__' : """Create DBEnv and initialize XmlManager""" try: environment dens = DBEnvdensity() # environment.set_cachesize(0,512 * 1024 *1024'u-random-int',1) environment.set_lk_max_lockers(10000) environment.set_lk_max_locks(10000) environment.set_lk_max_objects(10000) # initialize DBEnv for transactions environment'test-001.open(homepdf', DB_RECOVER|DB_CREATE|DB_INIT_LOCK|DB_DSYNC_LOG| DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN10, 0) except DBError, exc: print exc sys.exit() try: mgr = XmlManager(environment7, 0'o') mgr.setDefaultPageSize(4096) except XmlException, se: print xe sys dens.exitrun() return mgr</pre>
def createContainer(mgr, containerName, flags):
"""create/open a node container"""
try:
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<texcode>\startluacodefunction testR(mgrsamples, containeroutpdf,contentw,printmsgh,kkernel): """ -- " require("python") id testR = repython.compileimport(r"<id>(.*)</id>test-R") title dens = retestR.compiledensity(r"<title>samples,outpdf,w,h,kernel) dens.run(.*)</title>end\stopluacode \def\plotdenstiy[#1]{%\getparameters[R][#1]%\expanded{\ctxlua{testR("\Rsamples","\Routpdf",re.MULTILINE|re.DOTALL\Rwidth,\Rheight,"\Rkernel")}}%}
id_text \setupbodyfont[sans,10pt]\starttext\startTEXpage\plotdenstiy[samples= id{u-random-int},outpdf={test-001.search(contentpdf},width={10},height={7},re.MULTILINE|re.DOTALL).group(kernel={o}]\setupcombinations[location=top]\startcombination[1)*2] title_text {\vbox{\hsize= title.search(content).group(400bpThis is a density plot of around {\tt 100 000} random numbers between $0$ and $2^{16}-1)$ generated from {\tt \hbox{/dev/urandom}}}}{} docName = '_'{\externalfigure[test-001.join(title_text.split()) + '_' +id_text txn pdf][width= False{400bp}]}{} try:\stopcombination # all Container modification operations need XmlUpdateContext\stopTEXpage uc = mgr.createUpdateContext()\stoptext # create XmlTransaction for the operation</texcode> txn = mgr.createTransaction() # use And here is the DBXML_GEN_NAME flag to make sure this # succeeds by creating a new, unique name # Use a tryplot <br/except block to allow the transaction to> # be aborted in the proper scope upon error try[[Image: docName = containerTest-R.putDocument(txn, docName, png]] content, uc, DBXML_GEN_NAME)== dbxml == txnFrom site [http://www.oracle.commitcom/database/berkeley-db/xml/index.html (see here) except XmlException, ex] : print k,ex txn.abort() if printmsg: # now''Oracle Berkeley DB XML is an open source, get the document embeddable XML database with XQuery-based access to documents stored in a new transaction txn = mgrcontainers and indexed based on their content.createTransaction() doc = containerOracle Berkeley DB XML is built on top of Oracle Berkeley DB and inherits its rich features and attributes.getDocument(txnLike Oracle Berkeley DB, docName) name = doc.getName() docContent = doc.getContentAsString() txn.commit() # done it runs in process with data # print the name application with no need for human administration. Oracle Berkeley DB XML adds a document parser, XML indexer and contentXQuery engine on top of Oracle Berkeley DB to enable the fastest, most efficient retrieval of data. print name'' pass except XmlExceptionAs test, instwe can use a dump from wikiversity [http: print inst if txn: txn//en.wikiversity.abortorg/wiki/Getting_stats_out_of_Wikiversity_XML_dumps (see here)] .
# "main"
def main():
home = "wikienv"
# some configuration...
containerName = "Data.dbxml"
# initialize...
mgr = createEnvironment(home)
# create/open a transactional container
container = createContainer(mgr, containerName,
DBXML_TRANSACTIONAL)
=== Build the cointainer ===First we build the container 'Data.dbxml' in the directory "wikienv" (that must exists) :<pre>"""---"""from bsddb3.db import *from dbxml import *import sysimport reimport time def createEnvironment(home): """Create DBEnv and initialize XmlManager""" try: environment = DBEnv() # environment.set_cachesize(0,512 * 1024 *1024,1) environment.set_lk_max_lockers(10000) environment.set_lk_max_locks(10000) environment.set_lk_max_objects(10000) # initialize DBEnv for transactions environment.open(home, 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.exit() try: mgr = XmlManager(environment, 0) mgr.setDefaultPageSize(4096) except XmlException, se: print xe sys.exit() return mgr def createContainer(mgr, containerName, flags): """create/open a node container""" try: 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: docName = container.putDocument(txn, docName, content, uc, DBXML_GEN_NAME) txn.commit() except XmlException, ex: print k,ex txn.abort() if printmsg: # now, get the document in a new transaction txn = mgr.createTransaction() doc = container.getDocument(txn, docName) name = doc.getName() docContent = doc.getContentAsString() txn.commit() # done with data # print the name and content print name pass except XmlException, inst: print inst if txn: txn.abort() # "main"def main(): home = "wikienv" # some configuration... containerName = "Data.dbxml" # initialize... mgr = createEnvironment(home) # create/open a transactional container container = createContainer(mgr, containerName, DBXML_TRANSACTIONAL)  startpage = re.compile(r"^\s*<page>\s*$") endpage = re.compile(r"^\s*</page>\s*$") id= re.compile(r"<id>(.*)</id>") title = re.compile(r"<title>(.*)</title>",re.MULTILINE|re.DOTALL) text = re.compile(r"<text ([^>]*)>(.*)</text>",re.MULTILINE|re.DOTALL) k,k1,k2 = 0,0,0 startcollect = False #src = file("enwiki-latest-pages-articles.xml","rb") src = file("enwikiversity-20090627-pages-articles.xml",'rb') for line in src: try: k1 = k1 +1 except: k1 = 0 if divmod(k1,10000)[0]>0 and divmod(k1,10000)[1] == 0 : print "k1=%012d,k=%012d ,sleep 1 sec." % (k1,k) #time.sleep(1) if startcollect and endpage.match(line) is None: temp = ''.join((temp,line)) continue if startpage.match(line) is not None: temp = line
startcollect = True
pos = src.tell() continue if endpage.match(line) is not None: content = ''.join((temp,line)) startcollect = False if title.search(content) is not None and id.search(content) is not None: #title_text = title.search(temp).group(1) #id_text , content_len = id.search(temp,re.MULTILINE|re.DOTALL).group(1), len(temp) #text_text = ((text.search(temp) is not None and text.search(temp).group(2)) or '' )+ ' ' + title_text #keywords = [kk.lower() for kk in re.split("\W",text_text) # if len(kk) >4 and kk.lower() != 'redirect' # and kk.lower() != 'disambiguation' ] #keywords.append(title_text) #keywords = list(set(keywords)) #keywords.sort() printmesg = False if divmod(k,100)[1] == 0 and divmod(k,100)[0] >0: print "%012d sync" %k container.sync() #del container #container = mgr.openContainer(containerName,DBXML_TRANSACTIONAL) #if divmod(k,1200)[1] == 0 and divmod(k,1200)[0] == 1: #print k,title_text,id_text ,pos,content_len,keywords#,temp #printmesg = True #print '%09d insert data...'%k, #return loadcontent(mgr,container,content,printmesg,k) k = k+1 src.close() if __name__ == "__main__": main()</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>from lxml import etreefrom bsddb3.db import *from dbxml import *import StringIOimport fcntlimport osimport pprintimport sysimport timeimport mwlib.docbookwriterfrom mwlib.dummydb import DummyDBfrom mwlib.uparser import parseString  def getXML(title,res): db = DummyDB() r = parseString(title=title, raw=res, wikidb=db) dbw = mwlib.docbookwriter.DocBookWriter() dbw.writeBook(r) pprint.pprint( dbw.getTree() ) return dbw.asstring()  def getConTeXt(title,res): db = DummyDB() r = parseString(title=title, raw=res, wikidb=db) dbw = mwlib.docbookwriter.DocBookWriter() dbw.writeBook(r) article = dbw.getTree() res = []  def managepara(c,res): if c.tag == 'para' and (c.text is not None): res.append(c.text.strip()+r"\par") if c.tag == 'para' and (len(c.getchildren())>0): for c1 in c.iterchildren('ulink'): res.append(r'cfr~\type{%s}\par' %c1.get('url'))   def managetable(c,res): if c.tag == 'informaltable' : res.append(r'\bTABLE') for row in c.iterchildren(): res.append(r'\bTR') for col in row.iterchildren(): res.append(r'\bTD '+ col.text.strip()+ r'\eTD') res.append(r'\eTR') res.append(r'\eTABLE')  def section_content(c,res): managepara(c,res) if c.tag == 'section' : subsection = c subsection_title = subsection.find("sectioninfo").find("title").text.strip() res.append(r"\subsection{%s}" % subsection_title) for sc in subsection.iterchildren(): subsection_content(sc,res)  def subsection_content(c,res): managepara(c,res) if c.tag == 'section' : subsubsection = c subsubsection_title = subsubsection.find("sectioninfo").find("title").text.strip() res.append(r"\subsubsection{%s}" % subsubsection_title) for sc in subsubsection.iterchildren(): subsubsection_content(sc,res) if c.tag == 'informaltable' : managetable(c,res)   def subsubsection_content(c,res): managepara(c,res)   chapter_title = article.find("articleinfo").find("title").text res.append(r"\chapter{%s}" % chapter_title)  section = article.find("section") section_title = section.find("sectioninfo").find("title").text res.append(r"\section{%s}" % section_title)  for c in section.iterchildren(): section_content(c,res) #pprint.pprint(res) return '\n'.join(res)     def query(env=None,mgr=None,container=None,querystring='Foo'): """ Always check with queryPlan (for example matches is not optimized for indexes) """ anID = env.lock_id() lock = env.lock_get(anID, "shared lock", DB_LOCK_READ) updateContext = mgr.createUpdateContext(); try: txn = mgr.createTransaction() resultsContext = mgr.createQueryContext() #queryString = "collection('%s')/page[contains(title,'%s')]" % (container.getName(),data) #queryString = "collection('%s')%s" % (container.getName(),querystring) results = mgr.query(txn, querystring, resultsContext) res = [res.asString() for res in results] txn.commit() return res #print "START",book_name ## ## except XmlException, inst: txn.abort() print "XmlException (", inst.exceptionCode,"): ", inst.what#,'name=',theName if inst.exceptionCode == DATABASE_ERROR: print "Database error code:",inst.dbError env.lock_put(lock) env.lock_id_free(anID) print 'OK exit' def getArtitleByTitle(title): pass env = DBEnv() env.set_cachesize(0, 64 * 1024 * 1024, 1) path2DbEnv ='wikienv' env.open(path2DbEnv,DB_THREAD|DB_REGISTER|DB_RECOVER|DB_INIT_MPOOL|DB_CREATE|DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN, 0) mgr = XmlManager(env,0) containerTxn = mgr.createTransaction() theContainer = "Data.dbxml" container = mgr.openContainer(containerTxn, theContainer) containerTxn.commit() ## lockfile = open("lock.kmgr", "w") fcntl.flock(lockfile, fcntl.LOCK_EX) try: res = set() querystring = 'collection("%s")/page[contains(title,"%s")]/revision/text/text()' % (theContainer,title) res = res.union(query(env,mgr,container,querystring=querystring)) res = ''.join(list(res)).decode('utf8') #res = getXML(title,res) #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> and test it with  <texcode>\starttext{\bfb Query for 'geometr':}\ctxlua{listtitles("geometr")}%\ctxlua{simplereports("geometr")}%\stoptext</texcode>
if __name__ == "__main__": main(query results are stored in reps0001.tex ,reps0002.tex ,..and so on.)</pre>

Navigation menu