Open main menu

Changes

=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 !! '''
* in <tt>source/texk/web2c/Makefile.in</tt>:
<pre>
101c10198c98< @MINGW32_FALSE@am__append_15 am__append_14 = -DLUA_USE_POSIX
---
> @MINGW32_FALSE@am__append_15 am__append_14 = -DLUA_USE_LINUX1575c15751674c1674< $(CXXLINK) $(luatex_OBJECTS) $(luatex_LDADD) $(LIBS)
---
> $(CXXLINK) $(luatex_OBJECTS) $(luatex_LDADD) $(LIBS) -Wl,-E -uluaL_openlibs -fvisibility=hidden -fvisibility-inlines-hidden -ldl -lreadline -lhistory -lncurses
</pre>
 
So, first compile as usual
=Python packages=
These are python packages that are not in standard libraries ; "✔" means that I have made only small lua wrapper .<br/>
Only for PythonImagingLibrary (PIL) I have made a <context>{\x \Context}</context> example.* numpy * ,scipy * matplot ✔[[#Scipy| here]]
* odfpy ✔
* PIL, python imaging library ✔[[#Python_Imaging_Library_.28PIL.29| here]]
For these, I stille still have to decide what todo.
* TO FIX ; pygegl (I like its syntax, but need too much and it's easy only in python)
* 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
[[Image:Test-ode.png|900px]]
 
 
(other examples follows...)
==ROOT (CERN) ==
For more infos, see [http://root.cern.ch here] ([http://root.cern.ch/cgi-bin/print_hit_bold.pl/root/HowtoPyROOT.html?python#first_hit here] for python stuffs).
Under Linux installation is not difficult at all, so but in this case I choose to not create a luatex-lunatic apart, as done above for sagemath.<br/>See an example [[#ROOT| here]] .
= ConTeXt mkIV examples=This example shot how to literally embedHere I will collect some tex snippets,just to show some ideasoriginal python source code .
== Python Imaging Library (PIL) ==<table><tr>{| class="wikitable" |-|<td><texcode>
\startluacode
function testPILtest_ROOT(imageorig,imagesepiafilename)
require("python")
PIL_Image pg = python.importglobals("PIL.Image") PIL_ImageOps = python.import("PIL.ImageOps")
python.execute([[
def make_linear_ramprun(whitefilename): 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, 240from ROOT import TCanvas, 192))") im = PIL_Image.open(imageorig) -- convert to grayscale if not(im.mode == "L") then im = im.convert("L")TGraph endfrom ROOT import gROOT from math import sin -- optional: apply contrast enhancement here, e.g. im = PIL_ImageOps.autocontrast(im)from array import array
-- 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 = imgROOT.convertReset("RGB")
im.savec1 = TCanvas(imagesepia'c1', 'A Simple Graph Example', 200, 10, 700, 500 )end\stopluacode
\def\SepiaImage#1#2{% c1.SetFillColor( 42 )\ctxlua{testPIL c1.SetGrid("#1")  n = 20 x, y = array( 'd' ),"#2"array( 'd' )  for i in range( n )}%:\startcombination[2 x.append( 0.1*1]i ){\externalfigure y.append( 10*sin( x[#1i]}{\ss Orig+0.}{\externalfigure[#2]}{\ss Sepia}\stopcombination}) )
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' )
gr.GetYaxis().SetTitle( 'Y title' )
gr.Draw( 'ACP' )
c1.Update()
c1.Print(filename)
]])
run = pg.run
run(filename)
end
\stopluacode
\starttext
\startTEXpage
\SepiaImagectxlua{lenatest_ROOT("testsin.jpgpdf")}\rotate[rotation=90]{lena-sepia\externalfigure[testsin.jpgpdf][width=5cm]}
\stopTEXpage
\stoptext
</texcode> || </td><td> [[Image:Test-PILTestsin.pngjpg|330px512px]] </td> |}</tr></table>
== ROOT ==This example shot how to literally embedoriginal We can do a bit better: separate python source code from lua code .<br/> {||Save this in <tt>test-ROOT1.py</tt> (so it's also easy to test) :|<texcodepre>\startluacodefrom ROOT import TCanvas, TGraph ,TGraphErrors,TMultiGraphfunction test_ROOT(filename)from ROOT import gROOT require("python")from math import sin pg = python.globals()from array import array
python.execute([[
def run(filename):
from ROOT import c1 = TCanvas("c1", TGraph from ROOT import gROOT from math import sin"multigraph",200,10,700,500) from array import arrayc1.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("pol6","q")
mg.Add(gr)
gROOTmg.ResetDraw("ap")
#force drawing of canvas to generate the fit TPaveStats c1 = TCanvas.Update( ') c1', 'A Simple Graph Example', 200, 10, 700, 500 .Print(filename)
c1.SetFillColor( 42 ) c1.SetGrid()</pre>  n = 20 x, y = array( Here file 'ddata' )is a 110 lines file with 24 floats values space separated, array( 'd' )  for i in range( n ): xie <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.append( 02000 25.1*i ) y6000 22.append( 10*sin( x[i]+08000 21.2 ) )  gr = TGraph( n, x, y ) gr7000 21.SetLineColor( 2 ) gr7000 21.SetLineWidth( 4 ) gr7000 21.SetMarkerColor( 4 ) gr7000 21.SetMarkerStyle( 7000 21 ).7000 </tt>.<br/> gr.SetTitle( 'Now a tex file, with a simple graph' )layer in lua as interface for python: gr.GetXaxis().SetTitle( 'X title' ){| gr.GetYaxis().SetTitle( 'Y title' )|- gr.Draw( 'ACP' )|<texcode> c1.Update()\startluacode c1.Printfunction test_ROOT(filename)]] require("python") run test = pgpython.runimport('test-ROOT1') test.run(filename)
end
\stopluacode
\starttext
\startTEXpage
\ctxlua{test_ROOT("testsindata.pdf")}\rotate[rotation=90]{\externalfigure[testsindata.pdf][width=5cm]}
\stopTEXpage
\stoptext
</texcode>
| [[Image:TestsinTest-ROOT1.jpg|512px300px]]
|}
We can do a bit better: separate python code from lua code .<br/>Save this in <tt>test-ROOT1.py</tt> (so it's also easy to test) := ConTeXt mkIV examples=<pre>from ROOT import TCanvasHere I will collect some tex snippets, TGraph ,TGraphErrors,TMultiGraphfrom ROOT import gROOTfrom math import sinfrom array import arrayjust to show some ideas.
def run== Scipy ==Watch how python code <tt> z = x*np.exp(filename-x**2-y**2):</tt> c1 is translated in lua code <tt> z = TCanvasx.__mul__( np.exp("c1","multigraph",200,10,700,500(x.__pow__(2).__add__(y.__pow__(2))) c1.SetGrid__neg__()) )</tt>
# 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("pol6","q")
mg.Add(gr)
mg{| class="wikitable" |-|<texcode>\startluacodefunction testSCIPY(figname,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.Drawimport("apmatplotlib.pyplot") ma = np.ma random = python.import("numpy.random") uniform = random.uniform
#force drawing of canvas to generate the fit TPaveStats -- make up some randomly distributed data npts = 200 x = uniform(-2,2,npts) y = uniform(-2,2,npts) c1 -- z = x*np.Updateexp(-x**2-y**2) c1 z = x.Print__mul__(filenamenp.exp( (x.__pow__(2).__add__(y.__pow__(2))).__neg__() ) ) -- define grid. </pre>Here file 'data' is a 110 lines file with 24 floats values space separated xi = np.linspace(-2.1,2.1,100)ie <br/><tt> 20 yi = np.6000 19linspace(-2.4000 191,2.4000 181,100) -- grid the data.3000 17 zi = griddata(x,y,z,xi,yi) -- contour the gridded data, plotting dots -- at the randomly spaced data points.8000 16 -- we put this in python globals space -- CS = plt.contour(xi,yi,zi,15,linewidths=0.1000 165,colors='k') pg.7000 21xi = xi ; pg.1000 23yi = yi ; pg.3000 26zi = zi args = python.1000 26eval("[xi,yi,zi,15]") kv = python.1000 27eval("{'linewidth': 0.2000 275 ,'colors' :'k'}") CS = python.8000 28apply(plt.3000 28contour, args,kv) -- pg.3000 27jet = plt.2000 25cm.6000 22jet args = python.8000 21eval("[xi,yi,zi,15]") kv = python.7000 21eval("{'cmap': jet}") CS = python.7000 21apply(plt.7000 21contourf, args,kv) -- draw colorbar plt.7000 21colorbar() -- plot data points.7000 21 pg.7000 </tt>x = x; pg.<br/>y = y Now a tex file args = python.eval("[x, with a simple layer in lua as interface for y]") kv = python.eval("{'marker': 'o', 'c':'b','s':5}"){| CS = python.apply(plt.scatter, args,kv)| plt.xlim(-2,2)|<texcode> plt.ylim(-2,2)\startluacode plt.title(string.format('griddata test (%i points)',npts))function test_ROOT --plt.savefig(filenamefigname, dpi, 'white') require-- pg.figname = figname ; pg.dpi = dpi args = python.eval("python[figname]") test kv = python.importeval("{'dpi': dpi ,'facecolor' :'test-ROOT1white'}") testCS = python.runapply(filenameplt.savefig, args,kv)
end
\stopluacode
 
 
\def\testSCIPY[#1]{%
\getparameters[scipy][#1]%
\ctxlua{testSCIPY("\csname scipyfigname\endcsname",
"\csname scipydpi\endcsname")}%
\externalfigure[\csname scipyfigname\endcsname]%
}
\starttext
\startTEXpage
\ctxluatestSCIPY[figname={test_ROOT("datatest-scipy-1.pdf")}\rotate[rotation,dpi=90]{\externalfigure[data.pdf150}]}
\stopTEXpage
\stoptext
</texcode> || [[Image:Test-ROOT1scipy.jpgpng|300px600px]]
|}
== Fontforge Python Imaging Library (PIL) ==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{| class="wikitable" |-fontforge.py</tt>:|<pretexcode>import sysimport fontforge \startluacodeclass simpledrawfunction testPIL(objectimageorig,imagesepia):  def __init__ require(self,font_file"python"): self.font PIL_Image = fontforgepython.openimport(font_file"PIL.Image" def getcurve PIL_ImageOps = python.import(self,letter"PIL.ImageOps"): self python.glname = letterexecute([[ res = dictdef make_linear_ramp(white) try : glyph_letter ramp = [ ] r, g , b = white for g i in self.font.glyphsrange(255) if g.glyphname == self.glname][0]: except Exception ramp.extend((r*i/255, g*i/255,e : res['err'] = str(eb*i/255)) return resramp cnt= glyph_letter.layers[1][0]) res['is_quadratic'] -- make sepia ramp (tweak color as necessary) sepia = cntpython.is_quadraticeval("make_linear_ramp((255, 240, 192))") res['closed'] im = cntPIL_Image.closedopen(imageorig) -- convert to grayscale res['points'] = [ if not(pim.x,p.y,mode == "%iL" %p.on_curve) for p in cnt ] then res['design_size'] im = selfim.convert("L") end -- optional: apply contrast enhancement here, e.fontg.design_size res['em'] im = selfPIL_ImageOps.font.em return resautocontrast(im)
-- apply sepia palette
im.putpalette(sepia)
def getmpostoutline-- convert back to RGB so we can save it as JPEG -- (selfalternatively,lettersave it in PNG or similar): res im = selfim.getcurveconvert(letter"RGB") path = '..'.join( [str((p[0],p[1])) for p in res['points'] if p[2] == '1'] ) return path
def getmpostpoints(self,letter): res = selfim.getcurve(letter) path = [str(save(p[0],p[1])) for p in res['points'] if p[2] == '1'] return path  def getmpostpointsSugar(self,letter): res = self.getcurve(letter) path = 'drawdot '.join( ["%s;" %str((p[0],p[1])) for p in res['points'] if p[2] == '1'] ) return 'drawdot ' +path   if __name__ == '__main__': s = simpledraw("koeieletters.pfb") res = s.getmpostpointsSugar('C') print res</pre> Note the <tt>'__main__'</tt> check, so we can test this class from python. <br/>Next lua layer, which in this case is embed in a tex file:<texcode>\startluacodefunction testFontforge(fontfile,letter) require("python") testoutlines = python.import("test-fontforge") s = testoutlines.simpledraw(fontfile) g = s.getmpostoutline(letter) p = s.getmpostpointsSugar(letter) tex.sprint(tex.ctxcatcodes,"\\startMPcode") tex.sprint(tex.ctxcatcodes,"pickup pencircle scaled 1pt;") tex.sprint(tex.ctxcatcodes,string.format("draw %s .. cycle;",g) ) tex.sprint(tex.ctxcatcodes,"pickup pencircle scaled 8pt;") tex.sprint(tex.ctxcatcodes,string.format("%s",p) ) tex.sprint(tex.ctxcatcodes,"\\stopMPcode"imagesepia)end\stopluacode
\def\SepiaImage#1#2{%
\ctxlua{testPIL("#1","#2")}%
\startcombination[2*1]
{\externalfigure[#1]}{\ss Orig.}
{\externalfigure[#2]}{\ss Sepia}
\stopcombination
}
\def\Outline[#1]{%
\getparameters[test][#1]%
\ctxlua{testFontforge("\testfontfile", "\testletter")}%
}
\starttext
\startTEXpage
\Outline[letter=SepiaImage{C}, fontfile={lmmono10-regular.otf}]%\Outline[letter={o}, fontfile={lmmono10-regularlena.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={tjpg}, fontfile={lmmono10lena-regularsepia.otfjpg}]%
\stopTEXpage
\stoptext
</texcode>|| [[Image:Test-PIL.png|330px]] |}  
Here we use <tt>tex.sprint== ImageMagick ==''ImageMagick® '' (tex[http://www.ctxcatcodes,"\\stopMPcode")</tt> to inject tex code (actually Metapost code) into TeX parser imagemagick.<brorg/><tt>\Outline<script/tt> index.php here]) ''is the TeX layer: of course one a software suite to create, edit, and compose bitmap images. It can read, convert and write <tt>\Outline</tt> and <tt>testFontforge</tt> images in a different manner to avoid use variety of tex.sprintformats (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.) <br/>And ''There are at least two python bindings, and this is the result: <br/>time I consider[[Imagehttp:Test-fontforge//www.procoders.png|900px]net/?p=39 PythonMagickWand]which is a binding "ala" ctypes way .
...okCode is simple<texcode>\usetypescriptfile[type-gentium]\usetypescript[gentium]\setupbodyfont[gentium,it's not correct (why?)10pt]\setuppapersize[A5][A5]\setuplayout[height=middle, but it looks funny :)topspace=1cm,header={2\lineheight},footer=0pt,backspace=1cm,margin=1cm, width=middle]
== 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 ).
For the first case\startluacodefunction testimagemagick(box, we consider an implementation of eps2pdf, being ps2pdf virtually the same t) local w local h local d local f local res = 118.<br/>11023622047244094488 -- 300 dpiActually there is not a python binding of ghostscript, so we build a simple wrapper local opacity = 25 local sigma = 15 local x = 10using ctypes module. local y = 10
<pre> require("python") pg = python.globals() PythonMagickWand = python.import ctypes("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 ) import sys f = string.format("%s.png",t)
wand = PythonMagickWand.NewMagickWand()
background = PythonMagickWand.NewPixelWand(0)
-- PythonMagickWand.MagickNewImage(wand,w,h,background)
PythonMagickWand.MagickNewImage(wand,w,h,background)
class gs PythonMagickWand.MagickSetImageResolution(objectwand,res,res) PythonMagickWand.MagickSetImageUnits(wand,PythonMagickWand.PixelsPerCentimeterResolution) PythonMagickWand.MagickShadowImage(wand,opacity,sigma,x,y) PythonMagickWand.MagickWriteImage(wand ,f):
def __init__ print(selfw,h,f):end\stopluacode
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
self.libgspath = '/opt/luatex/luatex-lunatic/lib/libgs.so'
self.OutFile = ''
self.InFile = ''
\def\testimagemagick[#1]{%\getparameters[imagemagick][#1]%\ctxlua{testimagemagick(\csname imagemagickbox\endcsname,"\csname imagemagickfilename\endcsname")}%} \newcount\shdw\long\def\startShadowtext#1\stopShadowtext{%\bgroup%\setbox0=\vbox{#1}%\testimagemagick[box=0,filename={shd-\the\shdw}]%%%\defineoverlay[backg][{\externalfigure[shd-\the\shdw.png]}]%\framed[background=backg,frame=off,offset=4pt]{\box0}%%%\framed{\box0}\global\advance\shdw by 1%\egroup%} \starttext\startTEXpage%\startShadowtext%\input tufte\stopShadowtext%\stopTEXpage\stoptext</texcode>And here is the result: [[Image:Test-imagemagick.png]] == 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 sysimport fontforge  class simpledraw(object):  def __init__(self,font_file): self.font = fontforge.open(font_file)  def getcurve(self,letter): self.args 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 appendargs(self,arg):
if arg.find('-sOutputFile')>= 0: return
if arg.find('-c quit')>= 0: return
self.args.append(arg)
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 rawappendargs(self,arg):
self.args.append(arg)
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
def run(self):
libgs = ctypes.CDLL(self.libgspath)
exit_status = ctypes.c_int()
code = ctypes.c_int(1)
code1 = ctypes.c_int()
instance = ctypes.c_void_p(None)
exit_code = ctypes.c_int()
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('e')
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 = (ctypes.c_char_p * argc.value)(*arguments) code.value = libgs.gsapi_init_with_args(instance, argc, argv)
code1Note the <tt>'__main__'</tt> check, so we can test this class from python.value = libgs.gsapi_exit(instance)<br/>Next lua layer, which in this case is embed in a tex file:<texcode>
if code.value == 0 or code.value =\setupcolors[state= self.ierrors['e_Quit'start]: code.value = code1.value
if code.value == self.ierrors['e_Quit']:
code.value = 0
libgs\startluacodefunction testFontforge(fontfile,letter) require("python") testoutlines = python.gsapi_delete_instanceimport(instance"test-fontforge") s = testoutlines.simpledraw(fontfile) exit_status g = s.value drawmpostpath(letter) p = 0s.drawmpostpoints(letter) --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;") tex.sprint(tex.ctxcatcodes,string.format("\%s",p) ) tex.sprint(tex.ctxcatcodes,"\\stopMPcode")end\stopluacode
if __name__ == '__main__':
pyctyps = gs()
pyctyps.appendargs('-q')
pyctyps.appendargs('-dNOPAUSE')
pyctyps.appendargs('-dEPSCrop')
pyctyps.appendargs('-sDEVICE=pdfwrite')
pyctyps.InFile = 'test.eps'
pyctyps.OutFile = 'test.pdf'
pyctyps.run()
</pre>\def\Outline[#1]{%\getparameters[test][#1]%\ctxlua{testFontforge("\testfontfile", "\testletter")}%}
The tex code\starttext<texcode>\startTEXpage\startluacodefunction testgs(epsinOutline[letter={C},pdfout) require("python") gsmodule fontfile= python.import("testgs") ghost = gsmodule.gs() ghost.appendargs('{lmmono10-q') ghostregular.appendargs('-dNOPAUSE')otf}]% ghost.appendargs('-dEPSCrop') ghost.appendargs('-sDEVICE\Outline[letter=pdfwrite') ghost.InFile {o}, fontfile= epsin ghost{lmmono10-regular.OutFile = pdfout ghost.run()endotf}]%\stopluacode \def\epstopdf#1#2Outline[letter={\ctxluan}, fontfile={testgs("#1","#2")}lmmono10-regular.otf}\def\EPSfigure[#1]{%lazy way to load eps\epstopdfOutline[letter={#1.epsT}, fontfile={#1lmmono10-regular.pdfotf}]%\externalfigureOutline[#1letter={e}, fontfile={lmmono10-regular.pdfotf}]%} \starttext\startTEXpage\startcombinationOutline[2*1]letter={\EPSfigure[tiger]X}, fontfile={\ss tigerlmmono10-regular.epsotf}]%{\EPSfigureOutline[golfer]letter={t}, fontfile={\ss golferlmmono10-regular.epsotf}\stopcombination]%
\stopTEXpage
\stoptext
</texcode>
and the result :<br/>
[[Image:Testgs.png|900px]]
Another example:Here we use <br/tt>here we use a library to generate barcodes [http://wwwtex.terryburtonsprint(tex.co.ukctxcatcodes,"\\stopMPcode")</barcodewriter tt> to inject tex code (see hereactually Metapost code)] into TeX parser .<br/><texcodett>\Outline</tt> is the TeX layer: of course one can write <tt>\startluacodefunction epstopdf(epsin,pdfout) require("python") gsmodule = pythonOutline</tt> and <tt>testFontforge</tt> in a different manner to avoid use of tex.importsprint("testgs") ghost = gsmodule.gs() ghost.appendargs('-q')<br/> ghost.appendargs('-dNOPAUSE')And this is the result: <br/> ghost.appendargs('[[Image:Test-dEPSCrop') ghostfontforge.appendargs('-sDEVICE=pdfwrite') ghost.InFile = epsin ghost.OutFile = pdfout ghost.run()endpng|900px]]
function barcode(text,type,options== 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,savefile) requiredo something and make a ps output ("python"e.g. a barcode/label generator ) gsmodule = python.import("testgs")
barcode_string = string.format("%%!\n100 100 moveto (%s) (%s) %s barcode showpage" For the first case,textwe consider an implementation of eps2pdf,optionsbeing ps2pdf virtually the same .<br/>Actually there is not a python binding of ghostscript,type)so we build a simple wrapper using ctypes module <tt>testgs.py</tt> :
psfile = string.format("%s.ps",savefile)<pre> epsfile = string.format("%s.eps",savefile)import ctypes pdffile = string.format("%s.pdf",savefile)import sys
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{epstopdfclass gs("#1","#2"object)}}\def\EPSfigure[#1]{%lazy way to load eps\epstopdf{#1.eps}{#1.pdf}%\externalfigure[#1.pdf]%}:
\ def\PutBarcode[#1]{%\getparameters[bc][#1]%\ctxlua{barcode__init__("\csname bctext\endcsname","\csname bctype\endcsname","\csname bcoptions\endcsname","\csname bcsavefile\endcsname" self)}%\expanded{\EPSfigure[\csname bcsavefile\endcsname]}%}:
\starttext self.ierrors = dict()\startTEXpage self.ierrors['e_unknownerror'] = -1 \startcombination self.ierrors['e_dictfull'] = -2*2 self.ierrors['e_dictstackoverflow']= -3{\PutBarcode self.ierrors[text'e_dictstackunderflow'] ={CODE 39},type-4 self.ierrors['e_execstackoverflow'] ={code39},options-5 self.ierrors['e_interrupt'] ={includecheck includetext},savefile-6 self.ierrors['e_invalidaccess'] ={TEMP1}-7 self.ierrors['e_invalidexit']}{\ss code39}= -8{\PutBarcode self.ierrors[text'e_invalidfileaccess'] ={CONTEXT},type-9 self.ierrors['e_invalidfont'] ={code93},options-10 self.ierrors['e_invalidrestore'] ={includecheck includetext},savefile-11 self.ierrors['e_ioerror'] ={TEMP2}-12 self.ierrors['e_limitcheck']}{\ss code93}= -13{\PutBarcode self.ierrors[text'e_nocurrentpoint'] ={977147396801},type-14 self.ierrors['e_rangecheck'] ={ean13},options-15 self.ierrors['e_stackoverflow'] ={includetext},savefile-16 self.ierrors['e_stackunderflow'] ={TEMP3}-17 self.ierrors['e_syntaxerror']}{\ss ean13}= -18{\PutBarcode self.ierrors[text'e_timeout'] ={0123456789},type-19 self.ierrors['e_typecheck'] ={interleaved2of5},options-20 self.ierrors['e_undefined'] ={includecheck includetext},savefile-21 self.ierrors['e_undefinedfilename'] ={TEMP4}-22 self.ierrors['e_undefinedresult']}{\ss interleaved2of5}= -23\stopcombination self.ierrors['e_unmatchedmark'] = -24\stopTEXpage self.ierrors['e_VMerror'] = -25\stoptext self.ierrors['e_configurationerror'] = -26</texcode> self.ierrors['e_undefinedresource'] = -27 self.ierrors['e_unregistered'] = -28 self.ierrors['e_invalidcontext'] = -29 self.ierrors[Image:Test'e_invalidid'] = -ghostscript30 self.ierrors['e_Fatal'] = -barcode100 self.png|900pxierrors['e_Quit']= -101 self.ierrors['e_InterpreterExit']= -102 self.ierrors['e_RemapColor'] = -103 self.ierrors['e_ExecStackUnderflow'] =-104 self.ierrors['e_VMreclaim'] = Graphviz -105 self.ierrors['e_NeedInput'] =-106 self.ierrors['e_Info'] = -110[http: self.libgspath = '/opt/www.graphviz.org Graphviz] is a Graph Visualization Software .<brluatex/>Standard distribution comes with several binding (lua and python among others) so it's not difficult to integrate in luatex -lunatic .<br/>In this example, we draw a graph of the nodes of <context>\TeX<lib/context>libgs.so'<pre>\def\StudyBox#1{% self.OutFile = ''\startluacode self.InFile = ''require "python"gv self.args = python.import[]  def appendargs("gv"self,arg):g = gv if arg.digraphfind("G"'-sOutputFile')>= 0: returngv if arg.setvfind(g,'rankdir','LR-c quit')>= 0: return self.args.append(arg)nodes = nodes or {} local nd = {}; def rawappendargs(self,arg):local kd = {}; self.args.append(arg)
local k = 0;
local function nodesprint(head,n)
while head do
local id = head.id
local oldn = n
ndlbl = string.format("nd_\%03d",k)
texio.write_nl(string.format("id=\%s, ndlbl=\%s",id,ndlbl))
if id == node.id("vlist") 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) .. " " ..
"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"))
end
if id = def run(self): libgs = nodectypes.idCDLL("rule"self.libgspath) then k = k + 1 nd[n] exit_status = gvctypes.nodec_int(g,ndlbl) res code = gvctypes.setvc_int(1) code1 = ctypes.c_int(nd[n],"shape","record") instance res = gvctypes.setvc_void_p(nd[n],"label",tostring(kNone) exit_code = ctypes.. " " .. "rule" .. c_int()   "\|id:" code.value = libgs. tostringgsapi_new_instance(headctypes.idbyref(instance), None) if code.value == 0 : libgs. "\|subtype:" gsapi_set_stdio(instance, None, None, None) self.args. tostringinsert(0,'') # if len(headself.subtypeOutFile) .. > 0: "\|attr:" . self. stringargs.gsubappend(tostring'-sOutputFile=%s' %self.OutFile) if len(headself.attrInFile),"> 0: self.args.append([><])",%s"\\\%1"self.InFile) self.args. append('-c quit') "\|width:" arguments = self.args # argc = ctypes.. tostringc_int(len(head.widtharguments)) .. "\|depth:" argv = (ctypes.c_char_p * argc. tostringvalue)(head.depth*arguments) code.value = libgs. gsapi_init_with_args(instance, argc, argv) "\|height:" code1.value = libgs. tostringgsapi_exit(headinstance)  if code.height) value == 0 or code.value == self. ierrors['e_Quit']: "\|dir:" code.value = code1. tostring(headvalue  if code.dir) value == self.ierrors['e_Quit']: code. value = 0 "\|next:" libgs.. string.gsubgsapi_delete_instance(tostring(headinstance)  exit_status.next),"value = 0 if __name__ == '__main__': pyctyps = gs([><])","\\\%1" pyctyps.appendargs('-q') pyctyps.appendargs('-dNOPAUSE') pyctyps. appendargs('-dEPSCrop') "\|prev:" pyctyps.appendargs('-sDEVICE=pdfwrite') pyctyps.InFile = 'test.eps' pyctyps.OutFile = 'test. stringpdf' pyctyps.gsubrun(tostring(head.prev),"([ </preThe tex code<]texcode>\startluacodefunction testgs(epsin,pdfout) require(","\\\%1python")) end if id = gsmodule = nodepython.idimport("instestgs") then k ghost = k + 1 nd[n] = gvgsmodule.nodegs(g,ndlbl) res = gv ghost.appendargs('-q') ghost.appendargs('-dNOPAUSE') ghost.setvappendargs(nd[n],"shape","record"'-dEPSCrop') res = gv ghost.setvappendargs(nd[n],"label",tostring(k'-sDEVICE=pdfwrite') ghost.InFile = epsin ghost. " " .. "ins" .. OutFile = pdfout "\|id:" . ghost. tostringrun(head.id) .. end\stopluacode \def\epstopdf#1#2{\ctxlua{testgs("\|subtype:#1","#2" .. tostring(head.subtype) .. }} "\|attr:" .. string.gsub(tostring(head.attr),"([><])","def\EPSfigure[#1]{%lazy way to load eps\\\%epstopdf{#1") .eps}{#1. pdf}% "\|cost:" .. tostring(head.cost) .externalfigure[#1. pdf]%} \starttext "\|depth:" .. tostring(head.depth) .. startTEXpage "\|height:" .. tostring(head.height) startcombination[2*1]{\EPSfigure[tiger]}{\ss tiger.eps}{\EPSfigure[golfer]}{\ss golfer. eps}\stopcombination\stopTEXpage "\|specstoptext</texcode>and the result :" <br/>[[Image:Testgs.png|900px]] Another example:<br/>here we use a library to generate barcodes [http://www.terryburton. stringco.gsubuk/barcodewriter (tostring(headsee here)] .spec),"([<texcode><]\startluacodefunction epstopdf(epsin,pdfout) require(","\\\%1python") gsmodule = python.. import("\|list:testgs" ) ghost = gsmodule.gs() ghost. stringappendargs('-q') ghost.gsubappendargs(tostring'-dNOPAUSE') ghost.appendargs(head'-dEPSCrop') ghost.list),"appendargs([><])","\\\%1"'-sDEVICE=pdfwrite') ghost.InFile = epsin ghost. OutFile = pdfout "\|next:" ghost.. string.gsubrun()end function barcode(tostring(head.nexttext,type,options,savefile)," require([><])","\\\%1python") gsmodule = python.. import("\|prev:testgs" .. )   barcode_string = string.gsubformat(tostring"%%!\n100 100 moveto (head.prev%s),"([><]%s)%s barcode showpage","\\\text,options,type)  psfile = string.format("%1s.ps"),savefile) end if id epsfile == nodestring.idformat("mark%s.eps",savefile) then k pdffile = k + 1string.format("%s.pdf",savefile)  nd[n] temp = gvio.nodeopen(gpsfile,ndlbl'w') res = gv.setv temp:write(tostring(nd[n]barcode_string),"shape","record\n") res temp:flush() io.close(temp) ghost = gvgsmodule.setvgs(nd[n],"label",tostring) ghost.rawappendargs(k'-q') ghost.rawappendargs('-dNOPAUSE') ghost. " " rawappendargs('-sDEVICE=epswrite') ghost.rawappendargs(string. "mark" format('-sOutputFile=%s',epsfile)) ghost.rawappendargs('barcode. ps') "\|id:" ghost.InFile= psfile ghost. tostringrun(head.id) .. "end\|subtype:stopluacode \def\epstopdf#1#2{\ctxlua{epstopdf("#1","#2" .. tostring(head.subtype) }}\def\EPSfigure[#1]{%lazy way to load eps\epstopdf{#1.eps}{#1. pdf}% "\|attr:" .. stringexternalfigure[#1.gsub(tostring(head.attr),"([><pdf])","%} \def\\%PutBarcode[#1") .. ]{%\getparameters[bc][#1]% \ctxlua{barcode("\|class:csname bctext\endcsname" .. tostring(head.class) .. ,"\|mark:" .. tostring(head.mark) .. csname bctype\endcsname","\|next:" .. string.gsub(tostring(head.next),"([><])csname bcoptions\endcsname","\csname bcsavefile\\%1endcsname") .. }% "\|prev:" .. string.gsub(tostring(head.prev),"(expanded{\EPSfigure[><])","\\csname bcsavefile\endcsname]}%1")) end}  if id == node.id("adjust") then\starttext k = k + 1\startTEXpage nd\startcombination[n2*2] = gv.node(g{\PutBarcode[text={CODE 39},ndlbl) res type= gv.setv(nd[n]{code39},"shape"options={includecheck includetext},"record")savefile={TEMP1}]}{\ss code39} res {\PutBarcode[text= gv.setv(nd{CONTEXT},type={code93},options={includecheck includetext},savefile={TEMP2}]}{\ss code93}{\PutBarcode[ntext={977147396801},type={ean13},options={includetext},savefile={TEMP3}]}{\ss ean13}{\PutBarcode[text={0123456789},"label"type={interleaved2of5},tostring(k) .. " " .. "adjust" .. options={includecheck includetext},savefile={TEMP4}]}{\ss interleaved2of5}\stopcombination\stopTEXpage "\|idstoptext</texcode> [[Image:" Test-ghostscript-barcode.png|900px]] == Graphviz == [http://www. tostring(head.id) graphviz.org Graphviz] is a Graph Visualization Software . <br/> "\|subtype:" .. tostringStandard distribution comes with several binding (head.subtypelua and python among others) so it's not difficult to integrate in luatex lunatic .. <br/> "In this example, we draw a graph of the nodes of <context>\|attr:" .. string.gsub(tostring(head.attr),"([TeX</context><])","\pre>\def\StudyBox#1{%1\startluacoderequire ") python"gv = python.. import("\|list:gv" )g = gv.. string.gsubdigraph(tostring(head.list"G"),"([><])","\\\%1") .. "\|prev:" gv.. string.gsubsetv(tostring(head.prev)g,"'rankdir','LR') nodes = nodes or {} local nd = {};local kd = {}; local k = 0;local function nodesprint([><])"head,"\\\%1"n) .. while head do local id = head.id local oldn = n ndlbl = string.format("nd_\|next:%03d" ,k) texio.. write_nl(string.gsubformat(tostring(head.next)"id=\%s,"([><])","\\ndlbl=\%1s",id,ndlbl)) end if id == node.id("discvlist") 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) .. " " .. "discvlist" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|prewidth:" .. string.gsub(tostringtostring(head.pre),"([><])","\\\%1"width) .. "\|postdepth:" .. string.gsub(tostring(head.postdepth),.. "\|height:" .. tostring([><])","\\\%1"head.height) .. "\|replacedir:" .. string.gsub(tostring(head.replacedir),.. "([><]\|shift:" .. tostring(head.shift)",.. "\\\%1|glue_order:".. tostring(head.glue_order) .. "\|nextglue_sign:" .. string.gsub(tostring(head.next),"([><]glue_sign)",.. "\\\%1|glue_set:".. tostring(head.glue_set) .. "\|prevlist:" .. string.gsub(tostring(head.prevlist),"([><])","\\\%1")).. end if id == node "\|prev:" .. string.gsub(tostring(head.idprev),"([><])"whatsit,") then k = k + \\\%1") .. nd[n] = gv "\|next:" .. string.nodegsub(tostring(ghead.next),ndlbl) res = gv.setv"(nd[n><],"shape)","record\\\%1")) end  if head.subtype id == node.subtypeid("writerule") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"labelshape",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(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_refximage" .. "\|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_annot") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_annot" .. "\|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) .. "\|data:" .. tostring(head.data) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"record")) end if head.subtype == node.subtype("pdf_start_link") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_start_linkrule" .. "\|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.depthdir) .. "\|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("ins") 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_linkins" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|prevcost:" .. tostring(head.cost) .. "\|depth:" .. tostring(head.depth) .. "\|height:" .. tostring(head.height) .. "\|spec:" .. string.gsub(tostring(head.spec),"([><])","\\\%1") .. "\|list:" .. string.gsub(tostring(head.prevlist),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if headid == node.subtype id("mark") then k =k + 1 nd[n] = gv.node(g,ndlbl) res = gv.subtypesetv(nd[n],"shape","pdf_destrecord") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_destmark" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthclass:" .. tostring(head.widthclass) .. "\|heightmark:" .. tostring(head.heightmark) .. "\|depthnext:" .. string.gsub(tostring(head.depthnext),"([><])","\\\%1") .. "\|named_idprev:" .. string.gsub(tostring(head.named_idprev),"([><])","\\\%1")) end if id == node.id("adjust") 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) .. " " .. "adjust" .. "\|dest_idid:" .. tostring(head.dest_idid) .. "\|dest_typesubtype:" .. tostring(head.dest_typesubtype) .. "\|xyz_zoomattr:" .. string.gsub(tostring(head.xyz_zoomattr),"([><])","\\\%1") .. "\|objnumlist:" .. string.gsub(tostring(head.objnumlist),"([><])","\\\%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_threadshape","record") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_threaddisc" ..
"\|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") .. "\|thread_idprev:" .. string.gsub(tostring(head.thread_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) .. "\|thread_attrsubtype:" .. tostring(head.thread_attrsubtype) .. "\|prevattr:" .. string.gsub(tostring(head.prevattr),"([><])","\\\%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("pdf_start_threadclose") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_start_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_end_threadspecial") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_end_threadspecial" ..
"\|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("pdf_save_poslocal_par") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_save_poslocal_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_thread_datadir") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_thread_datadir" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if head.subtype == node.subtype("pdf_link_data") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_link_data" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if head.subtype == node.subtype("open") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:open" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|streamdir:" .. tostring(head.streamdir) .. "\|namelevel:" .. tostring(head.namelevel) .. "\|areadvi_ptr:" .. tostring(head.areadvi_ptr) .. "\|extdvi_h:" .. tostring(head.extdvi_h) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if head.subtype == node.subtype("late_luapdf_literal") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:late_luapdf_literal" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|regmode:" .. tostring(head.regmode) ..
"\|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("fakepdf_refobj") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:fakepdf_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_colorstackpdf_refxform") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_colorstackpdf_refxform" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|stackwidth:" .. tostring(head.stackwidth) .. "\|cmdheight:" .. tostring(head.cmdheight) .. "\|datadepth:" .. tostring(head.datadepth) .. "\|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_savepdf_refximage") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_savepdf_refximage" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|prevwidth:" .. tostring(head.width) .. "\|height:" .. tostring(head.height) .. "\|depth:" .. tostring(head.depth) .. "\|objnum:" .. tostring(head.objnum) .. "\|next:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if head.subtype == node.subtype("cancel_boundarypdf_annot") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:cancel_boundarypdf_annot" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|prevwidth:" .. tostring(head.width) .. "\|height:" .. tostring(head.height) .. "\|depth:" .. tostring(head.depth) .. "\|objnum:" .. tostring(head.objnum) .. "\|data:" .. tostring(head.data) .. "\|next:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if head.subtype == node.subtype("close_luapdf_start_link") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:close_luapdf_start_link" ..
"\|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) .. "\|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("pdf_setmatrixpdf_end_link") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_setmatrixpdf_end_link" ..
"\|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("pdf_restorepdf_dest") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_restorepdf_dest" ..
"\|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) .. "\|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("user_definedpdf_thread") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:user_definedpdf_thread" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|user_idwidth:" .. tostring(head.user_idwidth) .. "\|typeheight:" .. tostring(head.typeheight) .. "\|valuedepth:" .. tostring(head.valuedepth) .. "\|nextnamed_id:" .. tostring(head.named_id) .. "\|thread_id:" .. tostring(head.thread_id) .. "\|thread_attr:" .. tostring(head.thread_attr) .. "\|prev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
end if id head.subtype == node.idsubtype("mathpdf_start_thread") then k res = k + 1 gv.setv(nd[n] = gv,"label",tostring(k) .. " " .."whatsit:pdf_start_thread" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.nodeattr),"(g[><])",ndlbl"\\\%1") .. "\|width:" .. tostring(head.width) res = gv.setv. "\|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),"(nd[n><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"shape([><])","record\\\%1")) end if head.subtype == node.subtype("pdf_end_thread") then res = gv.setv(nd[n],"label",tostring(k) .. " " .. "mathwhatsit:pdf_end_thread" ..
"\|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_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) .. " " .. "gluewhatsit:pdf_save_pos" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|specprev:" .. string.gsub(tostring(head.specprev),"([><])","\\\%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_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) .. " " .. "kernwhatsit:pdf_thread_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("penaltypdf_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) .. " " .. "penaltywhatsit:pdf_link_data" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|penalty:" .. tostring(head.penalty) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end if id head.subtype == node.idsubtype("unsetopen") then k res = k + 1 gv.setv(nd[n] = gv,"label",tostring(k) .. " " .."whatsit:open" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.nodeattr),"(g[><])",ndlbl"\\\%1") .. "\|stream:" .. tostring(head.stream) .. "\|name:" .. tostring(head.name) .. "\|area:" .. tostring(head.area) res = gv.setv. "\|ext:" .. tostring(head.ext) .. "\|next:" .. string.gsub(tostring(head.next),"(nd[n><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"shape([><])","record\\\%1")) end if head.subtype == node.subtype("late_lua") then res = gv.setv(nd[n],"label",tostring(k) .. " " .. "unsetwhatsit:late_lua" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthreg:" .. tostring(head.widthreg) .. "\|depthdata:" .. tostring(head.depthdata) .. "\|heightname:" .. tostring(head.heightname) .. "\|dirnext:" .. string.gsub(tostring(head.dirnext),"([><]) .. ","\\|shrink:\%1" .. tostring(head.shrink) .. "\|glue_orderprev:" .. string.gsub(tostring(head.glue_orderprev) .. ,"([><])","\|glue_sign:\\%1" )) end if head.subtype == node. tostringsubtype(head.glue_sign"fake") then res = gv.. setv(nd[n],"\|stretch:label" .. ,tostring(head.stretchk) .. "\|span:" .. tostring(head.span) "whatsit:fake" .. "\|listid:" .. string.gsub(tostring(head.list),"([><])","\\\%1"id) .. "\|prevsubtype:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end if id head.subtype == node.idsubtype("stylepdf_colorstack") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "stylewhatsit:pdf_colorstack" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|stylestack:" .. tostring(head.stylestack) .. "\|prevcmd:" .. tostring(head.cmd) .. "\|data:" .. tostring(head.data) .. "\|next:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("choicepdf_save") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "choicewhatsit:pdf_save" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|display:" .. tostring(head.display) .. "\|text:" .. tostring(head.text) .. "\|script:" .. tostring(head.script) .. "\|scriptscript:" .. tostring(head.scriptscript) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("noadcancel_boundary") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "noadwhatsit:cancel_boundary" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleus:" .. tostring(head.nucleus) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("opclose_lua") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "opwhatsit:close_lua" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleusreg:" .. tostring(head.nucleusreg) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("binpdf_setmatrix") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "binwhatsit:pdf_setmatrix" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleusdata:" .. tostring(head.nucleusdata) .. "\|subprev:" .. string.gsub(tostring(head.subprev),"([><])","\\\%1") .. "\|supnext:" .. string.gsub(tostring(head.supnext),"([><])","\\\%1") ) end if head.subtype == node.subtype("pdf_restore") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_restore" .. "\|nextid:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.nextattr),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")).. end if id == node "\|next:" .. string.gsub(tostring(head.idnext),"([><])","rel\\\%1") then) k = k + 1end nd[n] if head.subtype == gv.node(g,ndlbl) res = gv.setvsubtype(nd[n],"shape","recorduser_defined")then res = gv.setv(nd[n],"label",tostring(k) .. " " .. "relwhatsit:user_defined" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleususer_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("openmath") 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) .. " " .. "openmath" ..
"\|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("closeglue") 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) .. " " .. "closeglue" ..
"\|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("punctkern") 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) .. " " .. "punctkern" ..
"\|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("innerpenalty") 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) .. " " .. "innerpenalty" ..
"\|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("radicalunset") 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) .. " " .. "radicalunset" ..
"\|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) .. "\|leftdir:" .. tostring(head.leftdir) .. "\|degreeshrink:" .. tostring(head.degreeshrink) .. "\|nextglue_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("fractionstyle") 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) .. " " .. "fractionstyle" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthstyle:" .. tostring(head.widthstyle) .. "\|num:" .. tostring(head.num) .. "\|denom:" .. tostring(head.denom) .. "\|left:" .. tostring(head.left) .. "\|right:" .. tostring(head.right) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("underchoice") 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) .. " " .. "underchoice" ..
"\|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) .. "\|scriptscript:" .. tostring(head.scriptscript) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("overnoad") 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) .. " " .. "overnoad" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("accentop") 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) .. " " .. "accentop" ..
"\|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("vcenterbin") 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) .. " " .. "vcenterbin" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("fencerel") 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) .. " " .. "fencerel" ..
"\|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_charopen") 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_charopen" ..
"\|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_boxclose") 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_boxclose" ..
"\|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_mlistpunct") 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_mlistpunct" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|listnucleus:" .. string.gsub(tostring(head.listnucleus),.. "\|sub:".. tostring([><]head.sub)",.. "\\\%1|sup:".. tostring(head.sup) .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if id == node.id("math_text_charinner") 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_charinner" ..
"\|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("delimradical") 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) .. " " .. "delimradical" ..
"\|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_famsup) .. "\|large_charleft:" .. tostring(head.large_charleft) .. "\|degree:" .. tostring(head.degree) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("margin_kernfraction") 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_kernfraction" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|width:" .. tostring(head.width) ..
"\|glyphnum:" .. tostring(head.glyphnum) .. "\|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("glyphunder") 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) .. " " .. "glyphunder" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|charnucleus:" .. tostring(head.charnucleus) .. "\|fontsub:" .. tostring(head.fontsub) .. "\|langsup:" .. tostring(head.langsup) .. "\|left:" .. tostring(head.left) .. "\|right:" .. tostring(head.right) .. "\|uchyph:" .. tostring(head.uchyph) .. "\|componentsnext:" .. string.gsub(tostring(head.componentsnext),"([><])","\\\%1") .. "\|xoffset:" .. tostring(head.xoffset) .. "\|yoffset:" .. tostring(head.yoffset) .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("align_recordover") 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_recordover" ..
"\|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_fileaccent") 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_fileaccent" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|nucleus:" .. tostring(head.nucleus) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|accent:" .. tostring(head.accent) .. "\|bot_accent:" .. tostring(head.bot_accent) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("pseudo_linevcenter") 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_linevcenter" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|nextattr:" .. string.gsub(tostring(head.nextattr),"([><])","\\\%1")) end if id == node.id("page_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) .. " " .. "page_insert" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|heightnucleus:" .. tostring(head.heightnucleus) .. "\|last_ins_ptrsub:" .. tostring(head.last_ins_ptrsub) .. "\|best_ins_ptrsup:" .. tostring(head.best_ins_ptrsup) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("split_insertfence") 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_insertfence" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|heightattr:" .. string.gsub(tostring(head.heightattr) .. "\|last_ins_ptr:," .. tostring(head.last_ins_ptr[><]) .. ","\|best_ins_ptr:" .. tostring(head.best_ins_ptr) .. "\|broken_ptr:\%1" .. tostring(head.broken_ptr) .. "\|broken_insdelim:" .. tostring(head.broken_insdelim) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("expr_stackmath_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_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_listsub_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) .. " " .. "nested_listsub_box" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|list:" .. string.gsub(tostring(head.list),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("spansub_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) .. " " .. "spansub_mlist" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|nextattr:" .. string.gsub(tostring(head.nextattr),"([><])","\\\%1")) end if id == node.id("attribute") 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" .. "\|idlist:" .. string.gsub(tostring(head.idlist) .. ,"\|subtype:" .. tostring(head.subtype[><]) .. ","\|number:" .. tostring(head.number) .. "\|value:\%1" .. tostring(head.value) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("glue_specmath_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) .. " " .. "glue_specmath_text_char" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|widthattr:" .. string.gsub(tostring(head.widthattr) .. ,"\|stretch:" .. tostring(head.stretch[><]) .. ","\|shrink:" .. tostring(head.shrink) .. "\|stretch_order:\%1" .. tostring(head.stretch_order) .. "\|shrink_orderfam:" .. tostring(head.shrink_orderfam) .. "\|ref_countchar:" .. tostring(head.ref_countchar) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("attribute_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) .. " " .. "attribute_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("actionmargin_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) .. " " .. "actionmargin_kern" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|action_typeattr:" .. string.gsub(tostring(head.action_typeattr) .. ,"\|named_id:" .. tostring(head.named_id[><]) .. ","\|action_id:" .. tostring(head.action_id) .. "\|file:" .. tostring(head.file) .. "\|new_window:%1" .. tostring(head.new_window) .. "\|datawidth:" .. tostring(head.datawidth) .. "\|ref_countglyph:" .. tostring(head.ref_countglyph) .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if id == node.id("tempglyph") 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) .. " " .. "tempglyph" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. 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.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_stackalign_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) .. " " .. "align_stackalign_record" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("movement_stackpseudo_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) .. " " .. "movement_stackpseudo_file" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("if_stackpseudo_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) .. " " .. "if_stackpseudo_line" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("unhyphenatedpage_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) .. " " .. "unhyphenatedpage_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("hyphenatedsplit_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) .. " " .. "hyphenatedsplit_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("deltaexpr_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) .. " " .. "deltaexpr_stack" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("passivenested_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) .. " " .. "passivenested_list" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("shapespan") 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) .. " " .. "shapespan" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("hlistattribute") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "hlistattribute" ..
"\|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_setnumber:" .. tostring(head.glue_setnumber) .. "\|listvalue:" .. string.gsub(tostring(head.list),"([><])","\\\%1"value) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("fakeglue_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) .. " " .. "fakeglue_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
kd if id == node.id("attribute_list") 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]).. " " .. "attribute_list" .. if "\|id == node:" ..idtostring('hlist') or id == nodehead.id('vlist') then.. %% If we want to connect nested "\|subtype:" .. tostring(h|vhead.subtype)list.. %% %%e = gv "\|next:" .. string.gsub(tostring(head.edgenext),"(nd[n-1><])",nd[n]"\\\%1").. %%gv "\|prev:" .. string.setvgsub(e,'arrowhead','diamond') nodesprinttostring(head.listprev),"( n or 0[><]) +","\\\%1")) end head = head.next
end
if id == node.id("action") 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) .. " " .. "action" .. "\|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("temp") 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) .. " " .. "temp" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id == node.id("align_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) .. " " .. "align_stack" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id == node.id("movement_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_stack" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id == node.id("if_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) .. " " .. "if_stack" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id == node.id("unhyphenated") 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) .. " " .. "unhyphenated" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id == node.id("hyphenated") 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) .. " " .. "hyphenated" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id == node.id("delta") 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) .. " " .. "delta" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id == node.id("passive") 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) .. " " .. "passive" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id == node.id("shape") 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) .. " " .. "shape" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id == node.id("hlist") 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) .. " " .. "hlist" .. "\|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("fake") 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) .. " " .. "fake" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end kd[k] = nd[n] e1 = gv.edge(kd[k-1],kd[k]) if id == node.id('hlist') or id == node.id('vlist') then %% If we want to connect nested (h|v)list %% %%e = gv.edge(nd[n-1],nd[n]) %%gv.setv(e,'arrowhead','diamond') nodesprint(head.list,( n or 0) +1) end head = head.next endend 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:Graphviz.png|900px]] == R ==R is a language and environment for statistical computing and graphics [http://www.r-project.org (see here)] . <br/>RPy is a very simple, yet robust, Python interface to the R Programming Language [http://rpy.sourceforge.net (see here)] . <br/>As example, let's try to plot a discrete distribution of probability for a set of pseudorandom number (around 100000 samples) .<pre>import rpy2.robjects as robjectsimport rpy2.rinterface as rinterface class density(object):  def __init__(self,samples,outpdf,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 = [int(k.strip()) for k in file(self.samples,'r').readlines()] x = robjects.IntVector(data) r.pdf(file=self.outpdf,width=self.width,height=self.height) z = r.density(x,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']()  if __name__ == '__main__' :
dens = density('u-random-int','test-001.pdf',10,7,'o')
dens.run()</pre>   <texcode>\startluacodefunction testR(samples,outpdf,w,h,kernel) require("python") testR = python.import("test-R") dens = testR.density(samples,outpdf,w,h,kernel) dens.run()end\stopluacode \def\plotdenstiy[#1]{%\getparameters[R][#1]%\expanded{\ctxlua{testR("\Rsamples","\Routpdf",\Rwidth,\Rheight,"\Rkernel")}}%} \setupbodyfont[sans,10pt]\starttext\startTEXpage\plotdenstiy[samples={u-random-int},outpdf={test-001.pdf},width={10},height={7},kernel={o}]\setupcombinations[location=top]\startcombination[1*2]{\vbox{\hsize=400bpThis is a density plot of around {\tt 100 000} random numbers between $0$ and $2^{16}-1$ generated from {\tt \hbox{/dev/urandom}}}}{}{\externalfigure[test-001.pdf][width={400bp}]}{}\stopcombination\stopTEXpage\stoptext</texcode> And here is the plot <br/> [[Image:Test-R.png]] == dbxml ==From site [http://www.oracle.com/database/berkeley-db/xml/index.html (see here)] : ''Oracle Berkeley DB XML is an open source, embeddable XML database with XQuery-based access to documents stored in containers and indexed based on their content. Oracle Berkeley DB XML is built on top of Oracle Berkeley DB and inherits its rich features and attributes. Like Oracle Berkeley DB, it runs in process with the application with no need for human administration. Oracle Berkeley DB XML adds a document parser, XML indexer and XQuery engine on top of Oracle Berkeley DB to enable the fastest, most efficient retrieval of data.'' As test, we can use a dump from wikiversity [http://en.wikiversity.org/wiki/Getting_stats_out_of_Wikiversity_XML_dumps (see here)] .  === Build the cointainer ===First we build the container 'Data.dbxml' in the directory "wikienv" (that must exists) :<pre>"""---"""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>
\startluacode
function testR(samples,outpdf,w,h,kernel)
require("python")
testR = python.import("test-R")
dens = testR.density(samples,outpdf,w,h,kernel)
dens.run()
end
\stopluacode
 
\def\plotdenstiy[#1]{%
\getparameters[R][#1]%
\expanded{\ctxlua{testR("\Rsamples","\Routpdf",\Rwidth,\Rheight,"\Rkernel")}}%
}
 
\setupbodyfont[sans,10pt]
\starttext
\startTEXpage\plotdenstiy[samples={u-random-int},outpdf={test-001.pdf},width={10},height={7},kernel={o}]\setupcombinations[location=top]\startcombination[1*2]{\vbox{\hsize=400bpThis is a density plot of around {\tt 100 000} random numbers bfb Query for between $0$ and $2^{16'geometr':}-1$ generated from {\tt \hbox{/dev/urandom}}}}ctxlua{listtitles("geometr")}%{\externalfigure[test-001.pdf][width={400bp}]}ctxlua{simplereports("geometr")}\stopcombination\stopTEXpage%
\stoptext
</texcode>
And here is the plot <br/> [[Image:Test-R(query results are stored in reps0001.png]]tex ,reps0002.tex ,..and so on.)