From 9c83d108049c6187f1e53e632ebd1e0e3f9196b5 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 26 Aug 2009 09:58:38 +0200 Subject: [PATCH] Make pret-haskell work also for inline \types. Somehow, \type sets the catcodes different than \starttyping, causing \obs and other escape codes produced by pret-haskell to not work. Now, pret-haskell sets the right catcodes for each print, so this is no longer a problem. --- pret-haskell.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pret-haskell.lua b/pret-haskell.lua index bf74fe0..f1dc31b 100644 --- a/pret-haskell.lua +++ b/pret-haskell.lua @@ -9,24 +9,40 @@ local utf = unicode.utf8 local visualizer = buffers.newvisualizer('haskell') +-- Print a string or table of strings with the catcodes set to the default +-- context ones. Use this function to print a string that contains context +-- macro's that should be interpreted. Does not insert any automatic +-- linebreaking. +local function ctxsprint(str) + tex.sprint(ctxcatcodes, str) +end + +-- Print a string or table of strings almost literal. Each character in the +-- string will be printed with the "character" catcode, causing it to show up +-- literal in the output. Only the space character is printed with the "space" +-- catcode. +local function texwrite(str) + tex.write(str) +end + function visualizer.flush_line(str,nested) while str ~= '' do if utf.match(str, '^ ') then - tex.sprint('\\obs ') + ctxsprint('\\obs ') -- Eat the first character str = utf.sub(str, 2) else local text, rest = utf.match(str, "^%-%-(.-)%-%-(.*)") if text then - tex.sprint('\\strikethrough{') + ctxsprint('\\strikethrough{') -- Recursively call ourselves to handle spaces gracefully. visualizer.flush_line(text) - tex.sprint('}') + ctxsprint('}') -- Eat the processed characters str = rest else -- Write the first character - tex.write(utf.sub(str, 1, 1)) + texwrite(utf.sub(str, 1, 1)) -- Eat the first character str = utf.sub(str, 2) end -- 2.30.2