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 !! '''
</pre>
* in <tt>source/texk/web2c/luatexdir/amlua51/liblua51loadlib.amc</tt>
<pre>
12c1269c69< liblua51_a_CPPFLAGS + void *lib = -DLUA_USE_POSIXdlopen(path, RTLD_NOW);
---
> liblua51_a_CPPFLAGS + void *lib = -DLUA_USE_LINUXdlopen(path, RTLD_NOW|RTLD_GLOBAL);
</pre>
* 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>
 
* in <source/texk/web2c/luatexdir/lua51/loadlib.c</tt>
<pre>
69c69
< void *lib = dlopen(path, RTLD_NOW);
---
> void *lib = dlopen(path, RTLD_NOW|RTLD_GLOBAL);
</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{%\ctxlua{testPIL c1.SetFillColor("#1","#2"42 )}%\startcombination[2*1]{\externalfigure[#1]}{\ss Orig c1.}{\externalfigure[#2]}{\ss Sepia}\stopcombination}SetGrid()
n = 20
x, y = array( 'd' ), array( 'd' )
\starttext for i in range( n ):\startTEXpage\SepiaImage{lena x.jpg}{lena-sepiaappend( 0.jpg}1*i )\stopTEXpage\stoptext</texcode> || y.append( 10*sin( x[[Image:Test-PILi]+0.png|330px]] |}2 ) )
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 = ROOT ==pg.run run(filename)This example shot how to literally embedendoriginal python source code .\stopluacode
\starttext\startTEXpage\ctxlua{test_ROOT("testsin.pdf")}\rotate[rotation=90]{|\externalfigure[testsin.pdf][width=5cm]}\stopTEXpage\stoptext</texcode> </td><td> [[Image:Testsin.jpg|-512px]] </td> |<texcode/tr>\startluacode</table>function test_ROOT(filename) require("We can do a bit better: separate python")code from lua code .<br/> pg = pythonSave this in <tt>test-ROOT1.globalspy</tt> (so it's also easy to test):<pre>from ROOT import TCanvas, TGraph ,TGraphErrors,TMultiGraphfrom ROOT import gROOTfrom math import sinfrom 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")
c1 = TCanvas( 'c1', 'A Simple Graph Example', 200, 10, 700, 500 )  c1.SetFillColor( 42 ) c1.SetGrid()  n = 20 x, y = array( 'd' ), array( 'd' )  for i in range( n ): x.append( 0.1*i ) y.append( 10*sin( x[i]+0.2 ) )  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' )#force drawing of canvas to generate the fit TPaveStats
c1.Update()
c1.Print(filename)
]])
run = pg.run
run(filename)
end
\stopluacode
</pre>Here file 'data' is a 110 lines file with 24 floats values space separated,ie <br/><tt> 20.6000 19.4000 19.4000 18.3000 17.8000 16.1000 16.7000 21.1000 23.3000 26.1000 26.1000 27.2000 27.8000 28.3000 28.3000 27.2000 25.6000 22.8000 21.7000 21.7000 21.7000 21.7000 21.7000 21.7000 </tt>.<br/>Now a tex file, with a simple layer in lua as interface for python:{||-|<texcode>\startluacodefunction test_ROOT(filename) require("python") test = python.import('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 = ConTeXt mkIV examples=Here I will collect some tex snippets,just to show some ideas. == Scipy ==Watch how python code from lua code <tt> z = x*np.exp(-x**2-y**2) <br/tt>Save this is translated in lua code <tt>test-ROOT1 z = x.__mul__( np.exp( (x.__pow__(2).__add__(y.__pow__(2))).py__neg__() ) )</tt> (so it's also easy to test) :<pre>from ROOT import TCanvas, TGraph ,TGraphErrors,TMultiGraphfrom ROOT import gROOTfrom math import sinfrom array import array
def run(filename):
c1 = TCanvas("c1","multigraph",200,10,700,500)
c1.SetGrid()
# draw a frame to define the range mg = TMultiGraph() # create first graph n = 24; x = array('d',range(24)) data = file('data').readlines() for line in data: line = line.strip() y = array('d',[float(d) for d in line.split()]) gr {| class= TGraph(n,x,y) gr.Fit("pol6","qwikitable") mg.Add(gr)  mg.Draw("ap")  #force drawing of canvas to generate the fit TPaveStats c1.Update() c1.Print(filename) </pre>Here file 'data' is a 110 lines file with 24 floats values space separated,ie <br/><tt> 20.6000 19.4000 19.4000 18.3000 17.8000 16.1000 16.7000 21.1000 23.3000 26.1000 26.1000 27.2000 27.8000 28.3000 28.3000 27.2000 25.6000 22.8000 21.7000 21.7000 21.7000 21.7000 21.7000 21.7000 </tt>.<br/>Now a tex file, with a simple layer in lua as interface for python:{|
|-
|<texcode>
\startluacode
function test_ROOTtestSCIPY(filenamefigname,dpi)
require("python")
test pg = python.globals() python.apply = python.eval('apply') or {} np = python.import("numpy") mlab = python.import("matplotlib.mlab") griddata = mlab.griddata plt = python.import("matplotlib.pyplot") ma = np.ma random = python.import("numpy.random") uniform = random.uniform  -- make up some randomly distributed data npts = 200 x = uniform(-2,2,npts) y = uniform(-2,2,npts) -- z = x*np.exp(-x**2-y**2) z = x.__mul__( np.exp( (x.__pow__(2).__add__(y.__pow__(2))).__neg__() ) ) -- define grid. xi = np.linspace(-2.1,2.1,100) yi = np.linspace(-2.1,2.1,100) -- grid the data. zi = griddata(x,y,z,xi,yi) -- contour the gridded data, plotting dots -- at the randomly spaced data points. -- we put this in python globals space -- CS = plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k') pg.xi = xi ; pg.yi = yi ; pg.zi = zi args = python.eval("[xi,yi,zi,15]") kv = python.eval("{'linewidth': 0.5 ,'colors' :'k'}") CS = python.apply(plt.contour, args,kv) -- pg.jet = plt.cm.jet args = python.eval("[xi,yi,zi,15]") kv = python.eval("{'cmap': jet}") CS = python.apply(plt.contourf, args,kv) -- draw colorbar plt.colorbar() -- plot data points. pg.x = x; pg.y = y args = python.eval("[x,y]") kv = python.eval("{'marker': 'o', 'c':'b','s':5}") CS = python.apply(plt.scatter, args,kv) plt.xlim(-2,2) plt.ylim(-2,2) plt.title(string.format('griddata test(%i points)',npts)) --plt.savefig(figname, dpi, 'white') -ROOT1- pg.figname = figname ; pg.dpi = dpi args = python.eval("[figname]") kv = python.eval("{'dpi': dpi ,'facecolor' :'white'}") 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|</tttexcode>:<pre>\startluacodefunction testPIL(imageorig,imagesepia) require("python") PIL_Image = python.import sys("PIL.Image") PIL_ImageOps = python.import fontforge("PIL.ImageOps") python.execute([[def make_linear_ramp(white): ramp = [] r, g, b = white for i in range(255): ramp.extend((r*i/255, g*i/255, b*i/255)) return ramp]]) -- make sepia ramp (tweak color as necessary) sepia = python.eval("make_linear_ramp((255, 240, 192))") class simpledraw im = PIL_Image.open(imageorig) -- convert to grayscale if not(im.mode == "L") then im = im.convert(object"L") end -- optional:apply contrast enhancement here, e.g. im = PIL_ImageOps.autocontrast(im)
def __init__(self,font_file):-- apply sepia palette self.font = fontforge im.openputpalette(font_filesepia)
def getcurve(self,letter):-- convert back to RGB so we can save it as JPEG self.glname = letter res = dict() try : glyph_letter = [ g -- for g in self.font.glyphs() if g.glyphname == self.glname][0] except Exception alternatively,e : res['err'] = str(esave it in PNG or similar) return res cnt im = glyph_letterim.layers[1][0] res['is_quadratic'] = cnt.is_quadratic res['closed'] = cnt.closed res['points'] = [convert(p.x,p.y,"%iRGB" %p.on_curve) for p in cnt ] res['design_size'] = self.font.design_size res['em'] = self.font.em return res
im.save(imagesepia)
end
\stopluacode
\def getmpostoutline\SepiaImage#1#2{%\ctxlua{testPIL(self"#1",letter"#2"):}% res = self.getcurve(letter) path = '..'.join( \startcombination[str((p[02*1],p{\externalfigure[#1])) for p in res['points'] if p}{\ss Orig.}{\externalfigure[#2] == '1'] )}{\ss Sepia}\stopcombination return path}
def getmpostpoints(self,letter):
res = self.getcurve(letter)
path = [str((p[0],p[1])) for p in res['points'] if p[2] == '1']
return path
def getmpostpointsSugar(self,letter):\starttext\startTEXpage res = self\SepiaImage{lena.jpg}{lena-sepia.getcurve(letter) jpg} path = 'drawdot '.join( \stopTEXpage\stoptext</texcode> || ["%s;" %str((p[0],p[1])) for p in res['points'] if p[2Image:Test-PIL.png|330px] == '1'] ) return 'drawdot ' +path|}
if __name__ == ImageMagick =='__main__'ImageMagick® '' ([http: s = simpledraw("koeieletters//www.imagemagick.org/script/index.pfb"php here]) res = s''is a software suite to create, edit, and compose bitmap images.getmpostpointsSugarIt can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.'C') print resThere are at least two python bindings, and this time I consider<[http:/pre>/www.procoders.net/?p=39 PythonMagickWand] which is a binding "ala" ctypes way .
Note the <tt>'__main__'</tt> check, so we can test this class from python. <br/>Next lua layer, which in this case Code is embed in a tex file:simple
<texcode>
\usetypescriptfile[type-gentium]
\usetypescript[gentium]
\setupbodyfont[gentium,10pt]
\setuppapersize[A5][A5]
\setuplayout[height=middle,topspace=1cm,header={2\lineheight},footer=0pt,backspace=1cm,margin=1cm, width=middle]
 
 
\startluacode
function testFontforgetestimagemagick(fontfilebox,lettert) local w local h local d local f local res = 118.11023622047244094488 -- 300 dpi local opacity = 25 local sigma = 15 local x = 10 local y = 10   require("python") testoutlines pg = python.globals() PythonMagickWand = python.import("test-fontforgePythonMagickWand") s w = testoutlines math.simpledrawfloor(fontfile(tex.wd[box] / 65536 ) g = s/ 72.27 * 2.getmpostoutline(letter54 * res ) p h = s math.getmpostpointsSugarfloor(((letter) tex.sprintht[box] / 65536) + (tex.ctxcatcodes,"\\startMPcode"dp[box] / 65536)) tex/ 72.sprint(tex27 *2.ctxcatcodes,"pickup pencircle scaled 1pt;"54 *res ) tex.sprint(tex.ctxcatcodes, f = string.format("draw %s .. cycle;png",gt)   wand = PythonMagickWand.NewMagickWand() tex background = PythonMagickWand.sprintNewPixelWand(tex0) -- PythonMagickWand.ctxcatcodesMagickNewImage(wand,w,h,"pickup pencircle scaled 8pt;"background) tex PythonMagickWand.sprintMagickNewImage(texwand,w,h,background)  PythonMagickWand.ctxcatcodesMagickSetImageResolution(wand,res,stringres) PythonMagickWand.formatMagickSetImageUnits("%s"wand,pPythonMagickWand.PixelsPerCentimeterResolution) PythonMagickWand.MagickShadowImage(wand,opacity,sigma,x,y) tex PythonMagickWand.sprintMagickWriteImage(wand ,f)   print(tex.ctxcatcodesw,h,"\\stopMPcode"f)
end
\stopluacode
  \def\Outlinetestimagemagick[#1]{%\getparameters[testimagemagick][#1]%\ctxlua{testFontforgetestimagemagick("\testfontfile"csname imagemagickbox\endcsname, "\testlettercsname 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\Outline[letter={C}, fontfile={lmmono10-regular.otf}]%\Outline[letter={o}, fontfile={lmmono10-regular.otf}]%\Outline[letter={n}, fontfile={lmmono10-regular.otf}]%\Outline[letter={T}, fontfile={lmmono10-regular.otf}]%\Outline[letter={e}, fontfile={lmmono10-regular.otf}]startShadowtext%\Outline[letter={X}, fontfile={lmmono10-regular.otf}]%input tufte\Outline[letter={t}, fontfile={lmmono10-regular.otf}]stopShadowtext%
\stopTEXpage
\stoptext
</texcode>
And here is the result:
Here we use <tt>tex.sprint(tex.ctxcatcodes,"\\stopMPcode")</tt> to inject tex code (actually Metapost code) into TeX parser .<br/><tt>\Outline</tt> is the TeX layer: of course one can write <tt>\Outline</tt> and <tt>testFontforge</tt> in a different manner to avoid use of tex.sprint(..) <br/>And this is the result: <br/>[[Image:Test-fontforgeimagemagick.png|900px]]
...ok,it's not correct (why?), but it looks funny :) == Ghostscript Fontforge ==There are essentially 2 kind of In this example, we will use Metapost to draw a bezier curve of ghostscript a glyph (''Note:* convert an existing eps / ps file in pdf ;* use starting from Metapost 1.200 it is now possible to get the actual path drawing routines from a program in postscript that take an inputfont glyph, do something and make so this example is only to show how to translate a ps output ( e.g. a barcode/label generator path in metapost''). For the first case, we consider an implementation of eps2pdf, being ps2pdf virtually the same .<br/>Actually there is not We will use 3-layer approach:# a python binding of ghostscriptlayer that export a class, so we build # a simple wrapper lua layer to manage objects of this classusing ctypes module# 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 ctypes
import sys
import fontforge
class gssimpledraw(object):
def __init__(self,font_file): self.font = fontforge.open(font_file)
def getcurve(self,letter): self.ierrors glname = letter res_Array = [] res = dict() try : #glyph_letter = [ g for g in self.ierrors['e_unknownerror'] font.glyphs() if g.glyphname == -1 self.ierrorsglname]['e_dictfull'0] g = -2 self.ierrorsfont['e_dictstackoverflow'letter] = -3 self.ierrors except Exception ,e : res['e_dictstackunderflowerr'] = -4str(e) self res_Array.ierrors['e_execstackoverflow'] append(res) return res_Array layer_idx = -50; for layer_name in g.layers: self layer = g.ierrorslayers['e_interrupt'layer_name] for contour_idx in range(len(layer)): res = -6dict() self.ierrors contour = layer['e_invalidaccess'contour_idx] contour_name = -7contour.name self.ierrors res['e_invalidexitname'] = -8contour.name self.ierrors res['e_invalidfileaccessis_quadratic'] = -9contour.is_quadratic self.ierrors res['e_invalidfontclosed'] = -10contour.closed self.ierrors res['e_invalidrestorepoints'] = -11[(p.x,p.y,"%i" %p.on_curve) for p in contour ] self.ierrors res['e_ioerrordesign_size'] = -12 self.ierrorsfont.design_size res['e_limitcheckem'] = -13self.font.em res_Array.append(res) return res_Array   def drawmpostpath(self,letter): res_Array = self.ierrors[getcurve(letter) state = 0 paths = 'e_nocurrentpoint'] for res in res_Array: temp = -14'' self.ierrors for p in res['e_rangecheckpoints'] = -15: self.ierrors if p[2]=='e_stackoverflow1'] : if state == -161 : self.ierrors[ temp = temp + 'e_stackunderflow-- (%s,%s)'%(p[0] ,p[1] ) ; state = -171; continue else: self temp = temp + '..ierrors(%s,%s)' %(p[0] ,p['e_syntaxerror'1] ) ; state = -181; continue self if state == 1 : temp = temp + ' ..ierrorscontrols (%s,%s)' %(p[0],p['e_timeout'1] ) ; state = -192; continue self.ierrors[ if state == 2 : temp = temp + 'e_typecheckand (%s,%s) '%(p[0],p[1] ) ; state = -200; continue self.ierrors if res['e_undefinedclosed'] : if state == -211 : self.ierrors[ temp = 'e_undefinedfilenamedraw '+ temp[2:] = + " --22cycle;\n" else: self.ierrors[ temp = 'e_undefinedresultdraw '+ temp[2:] + " .. cycle;\n" else: temp = -23 self.ierrors['e_unmatchedmarkdraw '+ temp[2:] + ";\n" paths = -24paths + temp return paths    def drawmpostpoints(self,letter): res_Array = self.ierrors[getcurve(letter) dots = 'e_VMerror'] for res in res_Array: temp = -25 self.ierrors['e_configurationerror\n'] = -26 self.ierrorsjoin( ['e_undefinedresource'"drawdot %s;" %str((p[0] = -27 self.ierrors,p['e_unregistered'1] = -28 self.ierrors)) for p in res['e_invalidcontextpoints'] = -29 self.ierrorsif p['e_invalidid'2] = -30 self.ierrors[= 'e_Fatal1'] ) + "\n" dots = -100dots + temp return dots    self.ierrors[if __name__ == 'e_Quit__main__'] : s = simpledraw("lmmono10-101regular.otf") self #res = s.ierrors[getmpostpointsSugar('e_InterpreterExitC'] = -102) #print res self #print s.ierrors[getmpostoutline('e_RemapColorC'] = -103) self print s.ierrors[getcurve('e_ExecStackUnderflowe'] = -104) self print s.ierrors[drawmpostpath('e_VMreclaime'] = -105) self print s.ierrors[drawmpostpoints('e_NeedInpute'] = -106) </pre>  self.ierrors[Note the <tt>'e_Info__main__'] = -110</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>
self.libgspath \setupcolors[state= '/opt/luatex/luatex-lunatic/lib/libgs.so'start]
self.OutFile = ''
self.InFile = ''
self\startluacodefunction testFontforge(fontfile,letter) require("python") testoutlines = python.import("test-fontforge") s = testoutlines.simpledraw(fontfile) g = s.drawmpostpath(letter) p = s.args 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
def appendargs(self,arg):
if arg.find('-sOutputFile')>= 0: return
if arg.find('-c quit')>= 0: return
self.args.append(arg)
\def\Outline[#1]{%
\getparameters[test][#1]%
\ctxlua{testFontforge("\testfontfile", "\testletter")}%
}
def rawappendargs(self\starttext\startTEXpage\Outline[letter={C},arg):fontfile={lmmono10-regular.otf}]% self\Outline[letter={o}, fontfile={lmmono10-regular.argsotf}]%\Outline[letter={n}, fontfile={lmmono10-regular.append(arg)otf}]%\Outline[letter={T}, fontfile={lmmono10-regular.otf}]%\Outline[letter={e}, fontfile={lmmono10-regular.otf}]%\Outline[letter={X}, fontfile={lmmono10-regular.otf}]%\Outline[letter={t}, fontfile={lmmono10-regular.otf}]%\stopTEXpage\stoptext</texcode>
Here we use <tt>tex.sprint(tex.ctxcatcodes,"\\stopMPcode")</tt> to inject tex code (actually Metapost code) into TeX parser .<br/>
<tt>\Outline</tt> is the TeX layer: of course one can write <tt>\Outline</tt> and <tt>testFontforge</tt> in a different manner to avoid use of tex.sprint(..) <br/>
And this is the result: <br/>
[[Image:Test-fontforge.png|900px]]
== Ghostscript ==
There are essentially 2 kind of use of ghostscript :
* convert an existing eps / ps file in pdf ;
* use a program in postscript that take an input, do something and make a ps output ( e.g. a barcode/label generator ).
def run(self): libgs = ctypesFor the first case, we consider an implementation of eps2pdf, being ps2pdf virtually the same .CDLL(self.libgspath)<br/>Actually there is not a python binding of ghostscript, so we build a simple wrapper exit_status = using ctypesmodule <tt>testgs.c_int() code = ctypes.c_int(1) code1 = ctypes.c_int() instance = ctypes.c_void_p(None) exit_code = ctypes.c_int()py</tt> :
<pre>
import ctypes
import sys
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) > 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)
code1.value = libgs.gsapi_exitclass gs(instanceobject):
if code.value == 0 or code.value == def __init__(self.ierrors['e_Quit']): code.value = code1.value
if code self.ierrors = dict() self.ierrors['e_unknownerror'] = -1 self.value ierrors['e_dictfull'] =-2 self.ierrors['e_dictstackoverflow'] = -3 self.ierrors['e_Quite_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 code self.value ierrors['e_limitcheck'] = 0 -13 self.ierrors['e_nocurrentpoint'] = -14 libgs self.gsapi_delete_instance(instance)ierrors['e_rangecheck'] = -15 self.ierrors['e_stackoverflow'] = -16 exit_statusself.value ierrors['e_stackunderflow'] = 0-17 self.ierrors['e_syntaxerror'] = -18if __name__ self.ierrors['e_timeout'] =-19 self.ierrors['e_typecheck'] = -20 self.ierrors['__main__e_undefined':] = -21 pyctyps self.ierrors['e_undefinedfilename'] = gs()-22 pyctyps self.appendargs(ierrors['e_undefinedresult'] = -q23 self.ierrors['e_unmatchedmark')] = -24 pyctyps self.appendargs(ierrors['e_VMerror'] = -dNOPAUSE25 self.ierrors[')e_configurationerror'] = -26 pyctyps self.appendargs(ierrors['e_undefinedresource'] = -dEPSCrop27 self.ierrors[')e_unregistered'] = -28 pyctyps self.appendargs(ierrors['e_invalidcontext'] = -sDEVICE29 self.ierrors['e_invalidid'] =pdfwrite-30 self.ierrors[')e_Fatal'] = -100 pyctyps self.InFile ierrors['e_Quit'] = -101 self.ierrors['teste_InterpreterExit'] = -102 self.epsierrors['e_RemapColor'] = -103 pyctyps self.OutFile ierrors['e_ExecStackUnderflow'] = -104 self.ierrors['teste_VMreclaim'] = -105 self.pdfierrors['e_NeedInput'] = -106 pyctyps self.run()ierrors['e_Info'] = -110
< self.libgspath = '/pre>opt/luatex/luatex-lunatic/lib/libgs.so'
The tex code<texcode>\startluacodefunction testgs(epsin,pdfout) require("python") gsmodule = python self.import("testgs") ghost OutFile = gsmodule.gs() ghost.appendargs('-q') ghost self.appendargs('-dNOPAUSE') ghost.appendargs(InFile = '-dEPSCrop') ghost.appendargs('-sDEVICE=pdfwrite') ghost.InFile = epsin ghost.OutFile = pdfout ghost.run()end\stopluacode
\def\epstopdf#1#2{\ctxlua{testgs("#1","#2")}}\def\EPSfigure[#1]{%lazy way to load eps\epstopdf{#1.eps}{#1 self.pdf}%\externalfigureargs = [#1.pdf]%}
\starttext \startTEXpage \startcombination[2*1] def appendargs(self,arg):{\EPSfigure[tiger]}{\ss tiger if arg.eps}find('-sOutputFile')>= 0: return{\EPSfigure[golfer]}{\ss golfer if arg.eps}\stopcombination\stopTEXpage\stoptext</texcodefind('-c quit')>and the result = 0:<br/>return[[Image:Testgs self.args.png|900px]]append(arg)
Another example:<br/>
here we use a library to generate barcodes [http://www.terryburton.co.uk/barcodewriter (see here)] .
<texcode>
\startluacode
function epstopdf(epsin,pdfout)
require("python")
gsmodule = python.import("testgs")
ghost = gsmodule.gs()
ghost.appendargs('-q')
ghost.appendargs('-dNOPAUSE')
ghost.appendargs('-dEPSCrop')
ghost.appendargs('-sDEVICE=pdfwrite')
ghost.InFile = epsin
ghost.OutFile = pdfout
ghost.run()
end
function barcode def rawappendargs(textself,type,options,savefilearg): require("python") gsmodule = python self.args.importappend("testgs"arg)
barcode_string = string.format("%%!\n100 100 moveto (%s) (%s) %s barcode showpage" ,text,options,type)
psfile = string.format("%s.ps",savefile)
epsfile = string.format("%s.eps",savefile)
pdffile = string.format("%s.pdf",savefile)
temp = io.open def run(psfile,'w'self) temp:write(tostring(barcode_string),"\n") temp:flush() io.close(temp) ghost libgs = gsmodulectypes.gsCDLL() ghostself.rawappendargs('-q'libgspath) ghost.rawappendargs('-dNOPAUSE') ghost.rawappendargs('-sDEVICE=epswrite') ghost.rawappendargs(string.format('-sOutputFile=%s',epsfile)) ghost.rawappendargs('barcode.ps') ghost.InFile= psfile ghost.run()end\stopluacode
\def\epstopdf#1#2{\ctxlua{epstopdf exit_status = ctypes.c_int("#1","#2")}}\def\EPSfigure[# code = ctypes.c_int(1]{%lazy way to load eps)\epstopdf{#1 code1 = ctypes.eps}{#1c_int() instance = ctypes.pdf}%c_void_p(None)\externalfigure[#1 exit_code = ctypes.pdf]%}c_int()
\def\PutBarcode[#1]{%
\getparameters[bc][#1]%
\ctxlua{barcode("\csname bctext\endcsname","\csname bctype\endcsname","\csname bcoptions\endcsname","\csname bcsavefile\endcsname" )}%
\expanded{\EPSfigure[\csname bcsavefile\endcsname]}%
}
\starttext\startTEXpage\startcombination[2*2]{\PutBarcode[text code.value ={CODE 39}libgs.gsapi_new_instance(ctypes.byref(instance),typeNone) if code.value ={code39},options={includecheck includetext},savefile={TEMP1}]}{\ss code39}0 :{\PutBarcode[text={CONTEXT} libgs.gsapi_set_stdio(instance,type={code93}None,options={includecheck includetext}None,savefile={TEMP2}]}{\ss code93}None){\PutBarcode[text={977147396801} self.args.insert(0,type'') # if len(self.OutFile) > 0: self.args.append('-sOutputFile={ean13},options%s' %self.OutFile) if len(self.InFile) > 0: self.args.append("%s" %self.InFile) self.args.append('-c quit') arguments ={includetext},savefileself.args # argc ={TEMP3}]}{\ss ean13}ctypes.c_int(len(arguments)){\PutBarcode[text argv ={0123456789},type(ctypes.c_char_p * argc.value)(*arguments) code.value ={interleaved2of5}libgs.gsapi_init_with_args(instance,options={includecheck includetext}argc,savefile={TEMP4}]}{\ss interleaved2of5}argv)\stopcombination\stopTEXpage\stoptext</texcode> code1.value = libgs.gsapi_exit(instance)
if code.value == 0 or code.value == self.ierrors[[Image'e_Quit']:Test-ghostscript-barcode code.value = code1.png|900px]]value
if code.value == Graphviz == self.ierrors[http'e_Quit']://www.graphviz.org Graphviz] is a Graph Visualization Software .<br/>Standard distribution comes with several binding (lua and python among others) so it's not difficult to integrate in luatex lunatic code.<br/>In this example, we draw a graph of the nodes of <context>\TeX</context><pre>\def\StudyBox#1{%\startluacoderequire "python"gv = python.import("gv")g value = gv.digraph("G")gv.setv(g,'rankdir','LR')0
nodes = nodes or {} libgs.gsapi_delete_instance(instance)
local nd exit_status.value = {};local kd = {};0
local k if __name__ = 0;= '__main__':local function nodesprint pyctyps = gs(head,n) while head do pyctyps.appendargs('-q') local id = head pyctyps.id local oldn = nappendargs('-dNOPAUSE') ndlbl = string pyctyps.formatappendargs("nd_\%03d",k'-dEPSCrop') texio pyctyps.write_nlappendargs(string'-sDEVICE=pdfwrite') pyctyps.format("idInFile =\%s, ndlbl'test.eps' pyctyps.OutFile =\%s",id,ndlbl)'test.pdf' pyctyps.run(</pre>
if id == node.id("vlist") thenThe tex code<texcode> k = k + 1\startluacode nd[n] = gv.nodefunction testgs(gepsin,ndlblpdfout) res = gv.setv require(nd[n],"shape","recordpython") res gsmodule = gvpython.setvimport(nd[n],"labeltestgs",tostring(k) .. " " .. "vlist" .. "\|id:" . ghost = gsmodule. tostringgs(head.id) .. "\|subtype:" . ghost. tostringappendargs(head.subtype'-q') .. "\|attr:" .. string.gsub(tostring(head ghost.attr),"appendargs([><])","\\\%1"'-dNOPAUSE') .. "\|width:" ghost.. tostringappendargs(head.width'-dEPSCrop') .. "\|depth:" ghost.. tostringappendargs(head.depth) .. "\|height:" .. tostring(head.height'-sDEVICE=pdfwrite') .. "\|dir:" .. tostring(head.dir) .. "\|shift:" .. tostring(head.shift) . ghost. InFile = epsin "\|glue_order:" .. tostring(head.glue_order) . ghost. OutFile = pdfout "\|glue_sign:" ghost.. tostringrun(head.glue_sign) .. "\|glue_set:" .. tostring(head.glue_set) .. "\|list:" .. string.gsub(tostring(head.list),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. end "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) endstopluacode
if id == node.id\def\epstopdf#1#2{\ctxlua{testgs("rule#1","#2") then}} k = k + \def\EPSfigure[#1]{%lazy way to load eps nd[n] = gv\epstopdf{#1.eps}{#1.node(g,ndlbl)pdf}% res = gv\externalfigure[#1.setv(nd[npdf],"shape","record")%} \starttext\startTEXpage res = gv.setv(nd\startcombination[n2*1],"label",tostring(k) .. " " .. "rule" {\EPSfigure[tiger]}{\ss tiger.eps}{\EPSfigure[golfer]}{\ss golfer. eps}\stopcombination "\|id:" .. tostring(head.id) .. stopTEXpage "\stoptext</texcode>and the result :<br/>[[Image:Testgs.png|subtype900px]] Another example:" .<br/>here we use a library to generate barcodes [http://www.terryburton.co. tostringuk/barcodewriter (headsee here)] .subtype<texcode>\startluacodefunction epstopdf(epsin,pdfout) .. require("\|attr:python" ) gsmodule = python.import("testgs") ghost = gsmodule. stringgs() ghost.gsubappendargs(tostring'-q') ghost.appendargs(head'-dNOPAUSE') ghost.attrappendargs('-dEPSCrop')," ghost.appendargs([><])","\\\%1"'-sDEVICE=pdfwrite') ghost.InFile = epsin ghost. OutFile = pdfout "\|width:" . ghost. tostringrun(head.width) .. "\|depth:" .. tostringend function barcode(head.depthtext,type,options,savefile) .. require("\|height:python" ) gsmodule = python.. tostringimport(head.height"testgs")   barcode_string = string.. format("%%!\|dir:" .. tostringn100 100 moveto (%s) (head.dir%s) .. %s barcode showpage"\|next:,text,options,type)  psfile = string.format(" %s.. ps",savefile) epsfile = string.gsubformat(tostring(head"%s.nexteps",savefile)," pdffile = string.format([><])","\\\%1s.pdf",savefile)   temp = io.. open(psfile,'w') "\|prev temp:" .. string.gsubwrite(tostring(head.prev),"([><]barcode_string)","\\\%1n") temp:flush() end io.close(temp) if id = ghost = nodegsmodule.idgs("ins") then k = k + 1 ghost.rawappendargs('-q') nd[n] = gv ghost.noderawappendargs(g,ndlbl'-dNOPAUSE') res ghost.rawappendargs('-sDEVICE= gvepswrite') ghost.rawappendargs(string.setvformat(nd[n]'-sOutputFile=%s',"shape","record"epsfile)) res = gv ghost.setvrawappendargs(nd[n],"label",tostring(k'barcode.ps') ghost.InFile= psfile ghost. " " .. "ins" .. run()end "\|id:stopluacode \def\epstopdf#1#2{\ctxlua{epstopdf("#1","#2" .. tostring(head.id) .. }} "\|subtype:" def\EPSfigure[#1]{%lazy way to load eps\epstopdf{#1.eps}{#1. tostring(head.subtype) .pdf}%\externalfigure[#1. pdf]%}  "\|attr:" .. string.gsub(tostring(head.attr),"(def\PutBarcode[><#1])","\\\{%1") .. "\|cost:" .. tostringgetparameters[bc][#1]%\ctxlua{barcode(head.cost) .. "\|depth:csname bctext\endcsname"," .. tostring(head.depth) .. \csname bctype\endcsname","\|height:csname bcoptions\endcsname" .. tostring(head.height) .. ,"\|spec:csname bcsavefile\endcsname" .. string.gsub(tostring(head.spec),"(}%\expanded{\EPSfigure[><])","\\csname bcsavefile\endcsname]}%1") .. "} \starttext\startTEXpage\|list:" .. string.gsub(tostring(head.list),"(startcombination[><2*2])"{\PutBarcode[text={CODE 39},type={code39},options={includecheck includetext},"savefile={TEMP1}]}{\ss code39}{\PutBarcode[text={CONTEXT},type={code93},options={includecheck includetext},savefile={TEMP2}]}{\%1") .. ss code93} "{\|next:" .. string.gsub(tostring(head.next)PutBarcode[text={977147396801},type={ean13},options={includetext},"([><savefile={TEMP3}])"}{\ss ean13}{\PutBarcode[text={0123456789},type={interleaved2of5},options={includecheck includetext},"savefile={TEMP4}]}{\ss interleaved2of5}\stopcombination\%1") .. stopTEXpage "\|prevstoptext</texcode> [[Image:" Test-ghostscript-barcode.png|900px]] == Graphviz == [http://www. stringgraphviz.org Graphviz] is a Graph Visualization Software .gsub<br/>Standard distribution comes with several binding (tostring(headlua and python among others) so it's not difficult to integrate in luatex lunatic .prev)<br/>In this example,"([we draw a graph of the nodes of <context>\TeX</context><])","pre>\def\StudyBox#1{%\%1startluacoderequire "python"gv = python.import("gv")) end if id g == nodegv.iddigraph("markG") then k = k + 1 nd[n] = gv.nodesetv(g,ndlbl'rankdir','LR') res nodes = nodes or {} local nd = {};local kd = {}; local k = gv.setv0;local function nodesprint(nd[head,n],"shape","record") res while head do local id = head.id local oldn = n ndlbl = gvstring.setvformat(nd[n],"labelnd_\%03d",tostring(k) texio.write_nl(string. format(" id=\%s, ndlbl=\%s" ,id,ndlbl))  if id == node.. id("markvlist" .. ) then k = k + 1 "\|id:" nd[n] = gv.. tostringnode(head.idg,ndlbl) .. "\|subtype:" res = gv.. tostringsetv(head.subtype) .. nd[n],"\|attr:shape","record" ) res = gv.. string.gsubsetv(tostring(head.attr)nd[n],"label",tostring([><]k).. ","\\\%1.. "vlist") .. "\|classid:" .. tostring(head.classid) .. "\|marksubtype:" .. tostring(head.marksubtype) .. "\|nextattr:" .. string.gsub(tostring(head.nextattr),"([><])","\\\%1") .. "\|prevwidth:" .. string.gsub(tostring(head.prevwidth),.. "\|depth:".. tostring([><]head.depth)",.. "\\\%1|height:")) end if id == node.id. tostring("adjust"head.height) then.. k = k + 1 nd[n] = gv "\|dir:" ..nodetostring(g,ndlblhead.dir) res = gv.setv(nd[n],. "shape","record\|shift:".. tostring(head.shift).. res = gv.setv(nd[n], "label\|glue_order:",.. tostring(khead.glue_order) .. " " .. "adjust" .. "\|idglue_sign:" .. tostring(head.idglue_sign) .. "\|subtypeglue_set:" .. tostring(head.subtypeglue_set) .. "\|attrlist:" .. string.gsub(tostring(head.attrlist),"([><])","\\\%1") .. "\|listprev:" .. string.gsub(tostring(head.listprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. ) end  "\|next:" if id == node.. string.gsubid(tostring(head.next),"([><]rule")","\\\%1")) end if id == node.id("disc") then then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") res = gv.setv(nd[n],"label",tostring(k) .. " " .. "disc" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|pre:" .. string.gsub(tostring(head.pre),"([><])","\\\%1") .. "\|post:" .. string.gsub(tostring(head.post),"([><])","\\\%1") .. "\|replace:" .. string.gsub(tostring(head.replace),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if id == node.id("whatsit") then k = k + 1 nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record") if head.subtype == node.subtype("write") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:write" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|stream:" .. tostring(head.stream) .. "\|data:" .. tostring(head.data) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if head.subtype == node.subtype("close") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:close" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|stream:" .. tostring(head.stream) .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if head.subtype == node.subtype("special") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:special" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|data:" .. tostring(head.data) .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if head.subtype == node.subtype("local_par") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:local_par" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|pen_inter:" .. tostring(head.pen_inter) .. "\|pen_broken:" .. tostring(head.pen_broken) .. "\|dir:" .. tostring(head.dir) .. "\|box_left:" .. tostring(head.box_left) .. "\|box_left_width:" .. tostring(head.box_left_width) .. "\|box_right:" .. tostring(head.box_right) .. "\|box_right_width:" .. tostring(head.box_right_width) .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if head.subtype == node.subtype("dir") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:dir" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|dir:" .. tostring(head.dir) .. "\|level:" .. tostring(head.level) .. "\|dvi_ptr:" .. tostring(head.dvi_ptr) .. "\|dvi_h:" .. tostring(head.dvi_h) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1")) end if head.subtype == node.subtype("pdf_literal") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_literalrule" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|modewidth:" .. tostring(head.modewidth) .. "\|datadepth:" .. tostring(head.datadepth) .. "\|height:" .. tostring(head.height) .. "\|dir:" .. tostring(head.dir) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end if headid == node.subtype id("ins") then k =k + 1 nd[n] = gv.node(g,ndlbl) res = gv.subtypesetv(nd[n],"shape"pdf_refobj,"record") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_refobjins" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|objnumcost:" .. tostring(head.objnumcost) .. "\|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") .. "\|widthdepth:" .. tostring(head.widthdepth) ..
"\|height:" .. tostring(head.height) ..
"\|depthspec:" .. string.gsub(tostring(head.depthspec),"([><])","\\\%1") .. "\|objnumlist:" .. string.gsub(tostring(head.objnumlist),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end if headid == node.subtype id("mark") then k =k + 1 nd[n] = gv.node(g,ndlbl) res = gv.subtypesetv(nd[n],"shape"pdf_refximage,"record") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_refximagemark" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthclass:" .. tostring(head.widthclass) .. "\|heightmark:" .. tostring(head.height) .. "\|depth:" .. tostring(head.depth) .. "\|objnum:" .. tostring(head.objnummark) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end if headid == node.subtype id("adjust") then k =k + 1 nd[n] = gv.node(g,ndlbl) res = gv.subtypesetv(nd[n],"pdf_annotshape","record") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_annotadjust" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthlist:" .. string.gsub(tostring(head.widthlist) .. ,"\|height:" .. tostring(head.height[><]) .. ","\|depth:" .. tostring(head.depth) .. "\|objnum:" .. tostring(head.objnum) .. "\|data:%1" .. tostring(head.data) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1")) end if headid == node.subtype id("disc") then k =k + 1 nd[n] = gv.node(g,ndlbl) res = gv.subtypesetv(nd[n],"shape","pdf_start_linkrecord") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_start_linkdisc" ..
"\|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") .. "\|objnumnext:" .. string.gsub(tostring(head.objnumnext),"([><])","\\\%1") .. "\|link_attrprev:" .. string.gsub(tostring(head.link_attrprev),"([><])","\\\%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) .. "\|actionsubtype:" .. tostring(head.actionsubtype) .. "\|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_end_linkclose") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_end_linkclose" ..
"\|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("pdf_destspecial") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_destspecial" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthdata:" .. tostring(head.width) .. "\|height:" .. tostring(head.height) .. "\|depth:" .. tostring(head.depth) .. "\|named_id:" .. tostring(head.named_id) .. "\|dest_id:" .. tostring(head.dest_id) .. "\|dest_type:" .. tostring(head.dest_type) .. "\|xyz_zoom:" .. tostring(head.xyz_zoom) .. "\|objnum:" .. tostring(head.objnumdata) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_threadlocal_par") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_threadlocal_par" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthpen_inter:" .. tostring(head.widthpen_inter) .. "\|heightpen_broken:" .. tostring(head.heightpen_broken) .. "\|depthdir:" .. tostring(head.depthdir) .. "\|named_idbox_left:" .. tostring(head.named_idbox_left) .. "\|thread_idbox_left_width:" .. tostring(head.thread_idbox_left_width) .. "\|thread_attrbox_right:" .. tostring(head.thread_attrbox_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_start_threaddir") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_start_threaddir" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthdir:" .. tostring(head.widthdir) .. "\|heightlevel:" .. tostring(head.heightlevel) .. "\|depthdvi_ptr:" .. tostring(head.depthdvi_ptr) .. "\|named_iddvi_h:" .. tostring(head.named_iddvi_h) .. "\|thread_id:" .. tostring(head.thread_id) .. "\|thread_attr:" .. tostring(head.thread_attr) .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_end_threadpdf_literal") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_end_threadpdf_literal" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|prevmode:" .. tostring(head.mode) .. "\|data:" .. tostring(head.data) .. "\|next:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_save_pospdf_refobj") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_save_pospdf_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_thread_datapdf_refxform") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_thread_datapdf_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_link_datapdf_refximage") 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:openpdf_refximage" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|streamwidth:" .. tostring(head.streamwidth) .. "\|nameheight:" .. tostring(head.nameheight) .. "\|areadepth:" .. tostring(head.areadepth) .. "\|extobjnum:" .. tostring(head.extobjnum) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if head.subtype == node.subtype("late_luapdf_annot") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:late_luapdf_annot" ..
"\|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) ..
"\|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_start_link") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:fakepdf_start_link" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|width:" .. tostring(head.width) ..
"\|height:" .. tostring(head.height) ..
"\|depth:" .. tostring(head.depth) ..
"\|objnum:" .. tostring(head.objnum) ..
"\|link_attr:" .. tostring(head.link_attr) ..
"\|action:" .. tostring(head.action) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_colorstackpdf_end_link") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_colorstackpdf_end_link" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|stack:" .. tostring(head.stack) .. "\|cmd:" .. tostring(head.cmd) .. "\|data:" .. tostring(head.data) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1")) end if head.subtype == node.subtype("pdf_savepdf_dest") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_savepdf_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("cancel_boundarypdf_thread") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:cancel_boundarypdf_thread" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|width:" .. tostring(head.width) ..
"\|height:" .. tostring(head.height) ..
"\|depth:" .. tostring(head.depth) ..
"\|named_id:" .. tostring(head.named_id) ..
"\|thread_id:" .. tostring(head.thread_id) ..
"\|thread_attr:" .. tostring(head.thread_attr) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("close_luapdf_start_thread") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:close_luapdf_start_thread" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|regwidth:" .. tostring(head.regwidth) .. "\|height:" .. tostring(head.height) .. "\|depth:" .. tostring(head.depth) .. "\|named_id:" .. tostring(head.named_id) .. "\|thread_id:" .. tostring(head.thread_id) .. "\|thread_attr:" .. tostring(head.thread_attr) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("pdf_setmatrixpdf_end_thread") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_setmatrixpdf_end_thread" ..
"\|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_save_pos") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_restorepdf_save_pos" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if head.subtype == node.subtype("user_definedpdf_thread_data") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:user_definedpdf_thread_data" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|user_id:" .. tostring(head.user_id) .. "\|type:" .. tostring(head.type) .. "\|value:" .. tostring(head.value) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
end if id head.subtype == node.idsubtype("mathpdf_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) .. " " .. "mathwhatsit:pdf_link_data" ..
"\|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("glueopen") 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:open" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|specstream:" .. string.gsub(tostring(head.specstream),.. "\|name:" .. tostring([><]head.name)",.. "\\\%1|area:".. tostring(head.area) .. "\|leaderext:" .. tostring(head.leaderext) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end if id head.subtype == node.idsubtype("kernlate_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) .. " " .. "kernwhatsit:late_lua" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|kernreg:" .. tostring(head.kernreg) .. "\|prevdata:" .. tostring(head.data) .. "\|name:" .. tostring(head.name) .. "\|next:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("penaltyfake") 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:fake" ..
"\|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("unsetpdf_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) .. " " .. "unsetwhatsit:pdf_colorstack" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthstack:" .. tostring(head.widthstack) .. "\|depthcmd:" .. tostring(head.depthcmd) .. "\|heightdata:" .. tostring(head.heightdata) .. "\|dir:" .. tostring(head.dir) .. "\|shrink:" .. tostring(head.shrink) .. "\|glue_order:" .. tostring(head.glue_order) .. "\|glue_sign:" .. tostring(head.glue_sign) .. "\|stretch:" .. tostring(head.stretch) .. "\|span:" .. tostring(head.span) .. "\|listnext:" .. string.gsub(tostring(head.listnext),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("stylepdf_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) .. " " .. "stylewhatsit:pdf_save" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|style:" .. tostring(head.style) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end if id head.subtype == node.idsubtype("choicecancel_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) .. " " .. "choicewhatsit:cancel_boundary" ..
"\|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("noadclose_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) .. " " .. "noadwhatsit:close_lua" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleusreg:" .. tostring(head.nucleusreg) .. "\|subprev:" .. string.gsub(tostring(head.subprev),"([><])","\\\%1") .. "\|supnext:" .. string.gsub(tostring(head.supnext),"([><])","\\\%1") ) end if head.subtype == node.subtype("pdf_setmatrix") then res = gv.setv(nd[n],"label",tostring(k) .. " " .."whatsit:pdf_setmatrix" .. "\|nextid:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.nextattr),"([><])","\\\%1") .. "\|data:" .. tostring(head.data) .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id head.subtype == node.idsubtype("oppdf_restore") then k res = k + 1 gv.setv(nd[n] = gv,"label",tostring(k) .. " " .."whatsit:pdf_restore" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.nodegsub(tostring(ghead.attr),ndlbl"([><]) res = gv","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.setvprev),"(nd[n><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"shape([><])","record\\\%1")) end if head.subtype == node.subtype("user_defined") then res = gv.setv(nd[n],"label",tostring(k) .. " " .. "opwhatsit: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("binmath") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "binmath" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleussurround:" .. tostring(head.nucleussurround) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("relglue") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "relglue" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleusspec:" .. string.gsub(tostring(head.nucleusspec),"([><]) .. ","\\|sub:\%1" .. tostring(head.sub) .. "\|supleader:" .. tostring(head.supleader) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("openkern") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "openkern" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleuskern:" .. tostring(head.nucleuskern) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("closepenalty") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "closepenalty" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleuspenalty:" .. tostring(head.nucleuspenalty) .. "\|sub:" .. tostring(head.sub) .. "\|sup:" .. tostring(head.sup) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("punctunset") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "punctunset" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|nucleuswidth:" .. tostring(head.nucleuswidth) .. "\|subdepth:" .. tostring(head.subdepth) .. "\|supheight:" .. tostring(head.supheight) .. "\|dir:" .. tostring(head.dir) .. "\|shrink:" .. tostring(head.shrink) .. "\|glue_order:" .. tostring(head.glue_order) .. "\|glue_sign:" .. tostring(head.glue_sign) .. "\|stretch:" .. tostring(head.stretch) .. "\|span:" .. tostring(head.span) .. "\|list:" .. string.gsub(tostring(head.list),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id == node.id("style") 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) .. " " .. "style" .. "\|id:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|style:" .. tostring(head.style) .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id == node.id("innerchoice") 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) .. " " .. "innerchoice" ..
"\|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("radicalnoad") 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) .. " " .. "radicalnoad" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|sub:" .. tostring(head.sub) ..
"\|sup:" .. tostring(head.sup) ..
"\|left:" .. tostring(head.left) ..
"\|degree:" .. tostring(head.degree) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("fractionop") 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) .. " " .. "fractionop" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthnucleus:" .. tostring(head.widthnucleus) .. "\|numsub:" .. tostring(head.numsub) .. "\|denomsup:" .. tostring(head.denom) .. "\|left:" .. tostring(head.left) .. "\|right:" .. tostring(head.rightsup) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("underbin") 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) .. " " .. "underbin" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("overrel") 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) .. " " .. "overrel" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("accentopen") 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) .. " " .. "accentopen" ..
"\|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("vcenterclose") 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) .. " " .. "vcenterclose" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("fencepunct") 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) .. " " .. "fencepunct" ..
"\|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_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_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("sub_boxradical") 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_boxradical" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|listnucleus:" .. stringtostring(head.nucleus) .. "\|sub:" ..gsubtostring(head.sub) .. "\|sup:" .. tostring(head.listsup),.. "\|left:".. tostring([><]head.left)",.. "\\\%1|degree:".. tostring(head.degree) .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if id == node.id("sub_mlistfraction") 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_mlistfraction" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|listwidth:" .. stringtostring(head.width) .. "\|num:" ..gsubtostring(head.num) .. "\|denom:" .. tostring(head.listdenom),.. "\|left:".. tostring([><]head.left)",.. "\\\%1|right:".. tostring(head.right) .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if id == node.id("math_text_charunder") 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_charunder" ..
"\|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("delimover") 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) .. " " .. "delimover" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|small_famnucleus:" .. tostring(head.small_famnucleus) .. "\|small_charsub:" .. tostring(head.small_charsub) .. "\|large_famsup:" .. tostring(head.large_fam) .. "\|large_char:" .. tostring(head.large_charsup) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("margin_kernaccent") 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_kernaccent" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|widthnucleus:" .. tostring(head.widthnucleus) .. "\|glyphsub:" .. tostring(head.glyphsub) .. "\|sup:" .. tostring(head.sup) .. "\|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("glyphvcenter") 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) .. " " .. "glyphvcenter" ..
"\|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_recordfence") 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_recordfence" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..
"\|delim:" .. tostring(head.delim) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("pseudo_filemath_char") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "pseudo_filemath_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("pseudo_linesub_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) .. " " .. "pseudo_linesub_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("page_insertsub_mlist") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "page_insertsub_mlist" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|heightattr:" .. string.gsub(tostring(head.heightattr),"([><])","\\\%1") .. "\|last_ins_ptrlist:" .. string.gsub(tostring(head.last_ins_ptrlist),"([><]) .. ","\\|best_ins_ptr:\%1" .. tostring(head.best_ins_ptr) .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1") .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("split_insertmath_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) .. " " .. "split_insertmath_text_char" ..
"\|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:%1" .. tostring(head.best_ins_ptr) .. "\|broken_ptrfam:" .. tostring(head.broken_ptrfam) .. "\|broken_inschar:" .. tostring(head.broken_inschar) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("expr_stackdelim") 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_stackdelim" ..
"\|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("nested_listmargin_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) .. " " .. "nested_listmargin_kern" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") .. "\|width:" .. tostring(head.width) .. "\|glyph:" .. tostring(head.glyph) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("spanglyph") 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) .. " " .. "spanglyph" ..
"\|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("attributealign_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) .. " " .. "attributealign_record" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|number:" .. tostring(head.number) ..
"\|value:" .. tostring(head.value) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("glue_specpseudo_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) .. " " .. "glue_specpseudo_file" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|widthnext:" .. string.gsub(tostring(head.widthnext) .. ,"([><])","\|stretch:\\%1" )) end if id == node.id("pseudo_line") then k = k + 1 nd[n] = gv. tostringnode(head.stretchg,ndlbl) res = gv.. setv(nd[n],"shape","\|shrink:record" ) res = gv.. tostringsetv(head.shrink) .. nd[n],"\|stretch_order:label" .. ,tostring(head.stretch_orderk) .. "\|shrink_order:" .. tostring(head.shrink_order) "pseudo_line" .. "\|ref_countid:" .. tostring(head.ref_countid) .. "\|nextsubtype:" .. string.gsub(tostring(head.next),"([><])","\\\%1"subtype) .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1"))
end
if id == node.id("attribute_listpage_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) .. " " .. "attribute_listpage_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("actionsplit_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) .. " " .. "actionsplit_insert" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|action_typeheight:" .. tostring(head.action_typeheight) .. "\|named_idlast_ins_ptr:" .. tostring(head.named_idlast_ins_ptr) .. "\|action_idbest_ins_ptr:" .. tostring(head.action_idbest_ins_ptr) .. "\|filebroken_ptr:" .. tostring(head.filebroken_ptr) .. "\|new_windowbroken_ins:" .. tostring(head.new_windowbroken_ins) .. "\|data:" .. tostring(head.data) .. "\|ref_count:" .. tostring(head.ref_count) .. "\|prevnext:" .. string.gsub(tostring(head.prevnext),"([><])","\\\%1") .. "\|nextprev:" .. string.gsub(tostring(head.nextprev),"([><])","\\\%1"))
end
if id == node.id("tempexpr_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) .. " " .. "tempexpr_stack" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("align_stacknested_list") then
k = k + 1
nd[n] = gv.node(g,ndlbl) res = gv.setv(nd[n],"shape","record")
res = gv.setv(nd[n],"label",tostring(k) .. " " .. "align_stacknested_list" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("movement_stackspan") 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_stackspan" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("if_stackattribute") 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_stackattribute" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|number:" .. tostring(head.number) ..
"\|value:" .. tostring(head.value) ..
"\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1") ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("unhyphenatedglue_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) .. " " .. "unhyphenatedglue_spec" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|width:" .. tostring(head.width) .. "\|stretch:" .. tostring(head.stretch) .. "\|shrink:" .. tostring(head.shrink) .. "\|stretch_order:" .. tostring(head.stretch_order) .. "\|shrink_order:" .. tostring(head.shrink_order) .. "\|ref_count:" .. tostring(head.ref_count) .. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("hyphenatedattribute_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) .. " " .. "hyphenatedattribute_list" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1") .. "\|prev:" .. string.gsub(tostring(head.prev),"([><])","\\\%1"))
end
if id == node.id("deltaaction") 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) .. " " .. "deltaaction" ..
"\|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("passivetemp") 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) .. " " .. "passivetemp" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("shapealign_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) .. " " .. "shapealign_stack" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
if id == node.id("hlistmovement_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) .. " " .. "hlistmovement_stack" ..
"\|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("fakeif_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) .. " " .. "fakeif_stack" ..
"\|id:" .. tostring(head.id) ..
"\|subtype:" .. tostring(head.subtype) ..
"\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
kd if id == node.id("unhyphenated") 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]).. " " .. "unhyphenated" .. if "\|id == node:" .. tostring(head.id) .. "\|subtype:" .. tostring(head.subtype) .. "\|next:" .. string.gsub(tostring('hlist'head.next) or ,"([><])","\\\%1")) end if id == node.id('vlist'"hyphenated") then %% If we want to connect nested k = k + 1 nd[n] = gv.node(h|vg,ndlbl)list %% %%e res = gv.edgesetv(nd[n-1],nd[n]"shape","record") %% res = gv.setv(end[n],'arrowhead'"label",'diamond'tostring(k).. " " .. "hyphenated" .. nodesprint "\|id:" .. tostring(head.list,id) .. "\|subtype:" .. tostring( n or 0) +1head.subtype).. end head = "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1"))
end
end if id == node.id("delta") then k = k + 1local head nd[n] = texgv.box[#1]nodesprintnode(headg,0ndlbl)r res = gv.layoutsetv(gnd[n],"shape","dotrecord")r res = gv.rendersetv(gnd[n],'pdf'"label",stringtostring(k) .. " " .. "delta" .. "\|id:" ..formattostring('box\%dhead.pdf',#1)id).. "\stopluacode%%}|subtype:" .. tostring(head.subtype) .. "\starttext|next:" .. string.gsub(tostring(head.next),"([><])","\startTEXpage\setbox0=\hbox{\TeX}%1")) end\hbox to 29cm{\strut\hss\copy0\hss} if id == node.id("passive") then\StudyBox{0}% k = k + 1\externalfigure nd[box0n] = gv.node(g,ndlbl) res = gv.pdfsetv(nd[n],"shape","record") res = gv.setv(nd[width=29cmn],"label",tostring(k) .. " " .. "passive" .. "\stopTEXpage|id:" .. tostring(head.id) .. "\stoptext|subtype:" .. tostring(head.subtype) .. </pre>[[Image "\|next:Graphviz" .png|900px]. string.gsub(tostring(head.next),"([><])","\\\%1")) end if id == R =node.id("shape") then k =k + 1R is a language and environment for statistical computing and graphics nd[http://wwwn] = gv.r-projectnode(g,ndlbl) res = gv.org setv(see herend[n],"shape","record") res = gv.setv(nd[n] ,"label",tostring(k) .. " " .. "shape" .. <br/>RPy is a very simple, yet robust, Python interface to the R Programming Language [http "\|id://rpy" .sourceforge.net tostring(see herehead.id)] . <br/>. As example, let's try to plot a discrete distribution of probability for a set of pseudorandom number "\|subtype:" .. tostring(around 100000 sampleshead.subtype) .. "\|next:" .. string.gsub(tostring(head.next),"([><pre>])","\\\%1"))import rpy2.robjects as robjects endimport rpy2 if id == node.rinterface as rinterface class densityid(object"hlist"):then k = k + 1 def __init__ nd[n] = gv.node(selfg,samplesndlbl) res = gv.setv(nd[n],outpdf"shape",w"record") res = gv.setv(nd[n],h"label",kerneltostring(k).. " " .. "hlist" .. "\|id:" .. tostring(head.id) .. self "\|subtype:" .. tostring(head.subtype) ..samples = samples self "\|attr:" .. string.gsub(tostring(head.attr),"([><])","\\\%1") ..outpdf= outpdf self "\|width:" .. tostring(head.width) ..kernel = kernel self "\|depth:" .. tostring(head.depth) ..width=w self "\|height:" .. tostring(head.height=h) .. "\|dir:" .. tostring(head.dir) .. "\|shift:" .. tostring(head.shift) .. def run "\|glue_order:" .. tostring(selfhead.glue_order).. "\|glue_sign:" .. tostring(head.glue_sign) .. r = robjects "\|glue_set:" .. tostring(head.glue_set) ..r data = [int "\|list:" .. string.gsub(tostring(khead.striplist),"([><])","\\\%1") for k in file.. "\|prev:" .. string.gsub(tostring(selfhead.samplesprev),"([><])",'r'"\\\%1").readlines. "\|next:" .. string.gsub(tostring(head.next),"([><])","\\\%1")) end x if id == robjectsnode.IntVectorid(data"fake")then r k = k + 1 nd[n] = gv.pdfnode(fileg,ndlbl) res =selfgv.outpdfsetv(nd[n],"shape",width"record") res =selfgv.widthsetv(nd[n],"label",height=selftostring(k) .. " " .. "fake" .. "\|id:" .. tostring(head.heightid).. z = r "\|subtype:" ..densitytostring(x,kernel=selfhead.kernelsubtype).. #r "\|next:" .. string.gsub(tostring(head.plotnext),"(z[0><])",z"\\\%1")) end kd[k] = nd[n] e1 = gv.edge(kd[k-1],xlabkd[k]) if id ==node.id('hlist',ylab) or id ==node.id('vlist',xlim) then %% If we want to connect nested (h|v)list %% %%e =robjectsgv.IntVectoredge(nd[0,2**16n-1]),nd[n]) r %%gv.plotsetv(z[0],z[1]e,xlab='arrowhead',ylab='diamond') r['dev nodesprint(head.off']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.)