X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fmaster-project%2Freport.git;a=blobdiff_plain;f=pret-trans.lua;h=a0ae9c2c73747ae99650e63d6f87f19b6d14c591;hp=ac1b525946364600d9bff3616f14ec6539921cd8;hb=313351372e8c609c2875902d9c9a2b89f7c97032;hpb=cb736fa056825e66c2831a01843cfcaf4bf9b4b8 diff --git a/pret-trans.lua b/pret-trans.lua index ac1b525..a0ae9c2 100644 --- a/pret-trans.lua +++ b/pret-trans.lua @@ -9,19 +9,20 @@ local utf = unicode.utf8 -vis = buffers.newvisualizer("trans") +local vis = buffers.newvisualizer("trans") local commands = {} -- A command to create a horizontal rule. -commands.rule = "\\blackrule[height=0.5pt,depth=0pt,width=.45\\textwidth]" --- Pretty printer to use for the stuff before and after the line -commands.before_pret = "lam" -commands.after_pret = "lam" +commands.rule = "\\HLine[width=.40 * \\the\\textwidth]" +-- Typing environment to use for the stuff before and after the line. Will be +-- prefixed with \start and \stop automatically. +commands.beforeenv = "unboxedlambda" +commands.afterenv = "unboxedlambda" -- Frame commands to use for the left (before + line + after) and right -- (conditions) parts. Should include an opening {, which will be closed -- automatically. -commands.leftframe = "\\framed[offset=0mm,location=middle,strut=no,align=right,frame=off,width=.5\\textwidth]{\\sans" -commands.rightframe = "\\framed[offset=0mm,location=middle,strut=no,align=right,frame=off,width=.5\\textwidth]{" +commands.leftframe = "\\framed[offset=0mm,location=middle,strut=no,align=right,frame=off,width=.48\\textwidth]{" +commands.rightframe = "\\framed[offset=0mm,location=middle,strut=no,align=right,frame=off,width=.48\\textwidth]{" -- A table to keep the lines in this buffer, so we can process them all at -- once at the end. @@ -91,7 +92,11 @@ function vis.end_of_display() break end end - + + if not len then + error("No horizontal separator found in:\n" .. table.concat(lines, "\n")) + end + -- Split the input in three parts. Stuff before the line, stuff -- after the line, stuff to the right of the line. before, after, rights = {}, {}, {} @@ -121,17 +126,29 @@ function vis.end_of_display() -- Real output starts here -- + -- Let all the lambda pretty printing in this buffer use shared subscript + -- detection + tex.sprint("\\directlua{buffers.visualizers.handlers.lam.begin_of_block()}") + -- Ensure the left and right frames end up next to each other. tex.sprint("\\dontleavehmode") -- Open and fill the left frame tex.sprint(commands.leftframe) - prettyprint('lam', before) + tex.sprint("\\start" .. commands.beforeenv) + + tex.sprint(table.concat(before, "\n")) + + tex.sprint("\\stop" .. commands.beforeenv) tex.sprint(commands.rule) - prettyprint('lam', after) + tex.sprint("\\start" .. commands.afterenv) + + tex.sprint(table.concat(after, "\n")) + + tex.sprint("\\stop" .. commands.afterenv) -- Close the left frame tex.sprint("}") @@ -158,6 +175,8 @@ function vis.end_of_display() -- Close the right frame tex.sprint("}") + + tex.sprint("\\directlua{buffers.visualizers.handlers.lam.end_of_block()}") -- Clean up lines = {}