@@ -92,6 +92,7 @@ local function walk(sourcedir, targetdir)
9292
9393 -- Process all items in the directory
9494 for file in lfs .dir (sourcedir ) do
95+
9596 if file == " ." or file == " .." then
9697 -- Ignore these two special ones
9798 elseif lfs .attributes (sourcedir .. file , " mode" ) == " directory" then
@@ -113,8 +114,12 @@ local function walk(sourcedir, targetdir)
113114 -- extract all code examples
114115 local matches = extractor :match (text ) or {}
115116
116- -- write code examples to separate files
117+ -- storage
117118 local setup_code = " "
119+ local preamble = " "
120+ local document = " "
121+
122+ -- write code examples to separate files
118123 for n , e in ipairs (matches ) do
119124 local options = e [1 ]
120125 local content = e [2 ]
@@ -133,6 +138,7 @@ local function walk(sourcedir, targetdir)
133138 -- Skip those that say "code only" or "setup code"
134139 if not options [" code only" ] and not options [" setup code" ] then
135140 local newname = name .. " -" .. n .. " .tex"
141+ --[[
136142 local examplefile = io.open(targetdir .. newname, "w")
137143
138144 examplefile:write"\\documentclass{standalone}\n"
@@ -153,10 +159,47 @@ local function walk(sourcedir, targetdir)
153159 examplefile:write"\\end{document}\n"
154160
155161 examplefile:close()
162+ --]]
163+ preamble = preamble .. (options [" preamble" ] and (options [" preamble" ] .. " \n " ) or " " )
164+ document = document .. " \\ BEGINBOXTEST{" .. name .. " -" .. n .. " }\n "
165+ local pre = options [" pre" ]
166+ if pre then
167+ pre = pre :gsub (" ##" , " #" )
168+ document = document .. pre .. " \n "
169+ end
170+ if options [" render instead" ] then
171+ document = document .. options [" render instead" ] .. " \n "
172+ else
173+ document = document .. strip (content ) .. " \n "
174+ end
175+ document = document .. (options [" post" ] and (options [" post" ] .. " \n " ) or " " )
176+ document = document .. " \\ ENDBOXTEST\n\n "
156177 end
157178
158179 :: continue::
159180 end
181+
182+ document = strip (document )
183+ if document ~= " " then
184+ local examplefile = io.open (targetdir .. name .. " .lvt" , " w" )
185+ examplefile :write " \\ documentclass{minimal}\n "
186+ examplefile :write " \\ input{pgf-regression-test}\n "
187+ examplefile :write " \\ RequirePackage{fp,pgf,tikz,xcolor}\n "
188+ if preamble ~= " " then
189+ examplefile :write " \n "
190+ examplefile :write (preamble )
191+ examplefile :write " \n "
192+ end
193+ examplefile :write " \\ begin{document}\n\n "
194+ if setup_code ~= " " then
195+ examplefile :write (setup_code )
196+ examplefile :write " \n "
197+ end
198+ examplefile :write (document )
199+ examplefile :write " \n "
200+ examplefile :write " \\ END\n "
201+ examplefile :close ()
202+ end
160203 end
161204 end
162205end
0 commit comments