Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
-- This file:
-- http://angg.twu.net/LATEX/istanbulall.lua
-- http://angg.twu.net/LATEX/istanbulall.lua.html
--  (find-angg        "LATEX/istanbulall.lua")
--
-- Extensions that should be available to all istanbul*.tex modules.
--
-- «.parseorg»			(to "parseorg")
-- «.parseorg-tests»		(to "parseorg-tests")
-- «.getorgblocks»		(to "getorgblocks")
-- «.getorgblocks-tests»	(to "getorgblocks-tests")
-- «.orgblocktotex»		(to "orgblocktotex")
-- «.orgblocktotex-tests»	(to "orgblocktotex-tests")
-- «.orgblocktotex-export»	(to "orgblocktotex-export")
-- «.html»			(to "html")
-- «.html-tests»		(to "html-tests")
-- «.ttchars»			(to "ttchars")
-- «.secnumbers»		(to "secnumbers")
-- «.secnumbers-test»		(to "secnumbers-test")
-- «.output»			(to "output")
-- «.Stack»			(to "Stack")
-- «.Stack-tests»		(to "Stack-tests")
-- «.ubs»			(to "ubs")
-- «.ubs-tests»			(to "ubs-tests")
-- «.syntree-tests»		(to "syntree-tests")



--   ___            
--  / _ \ _ __ __ _ 
-- | | | | '__/ _` |
-- | |_| | | | (_| |
--  \___/|_|  \__, |
--            |___/ 
--
-- «parseorg» (to ".parseorg")
-- (find-es "org" "parse-org-with-lua")
parseorg_utils = function (bigstr)
    require "lpeg"
    lpeg.test   = function (pat, str, ...) PP(pat:C():match(str, ...)) end
    local P     = lpeg.P
    local S     = lpeg.S
    local C     = lpeg.C
    local sp    = P" "^1
    local NL    = S"\n"
    local NonNL = 1 - NL
    --
    local Stars = (P"*"^1):Cg"stars"
    local Big   = sp*P(":big:"):Cg"big"
    local Todo  = sp*(P"DONE"+P"HALF"+P"TODO"+P"COMMENT"+P"TEXED"):Cg"todo"
    local Rest  = sp*(NonNL^0):Cg"rest"
    StarLine0   = (Stars*(Big+Todo)^0*Rest)
    StarLineT   = StarLine0:Ct()
    StarLine1   = StarLine0:C()
    --
    local Line   = NonNL^0 * NL 
    NonStarLine  = (-StarLine0) * Line
    NonStarLines = NonStarLine^0
    --
    -- local HashLine     = P"#"*Line
    -- local NonHashLine  = (-HashLine) * Line
    -- local NonHashLines = ((HashLine * NonHashLine:C())^0):Ct():Cf(table.concat)
    -- nonhashlines = function (str) return NonHashLines:match(str) end
    --
    Block1       = (StarLine0:C()*NL*NonStarLines)
    Block2       = (StarLine0:C()*NL*NonStarLines:C()):Ct()
    BlockT       = (StarLine0*NL*NonStarLines:Cg("body")):Ct()
    BlockTT      = (StarLine0*NL*NonStarLines:Cg("body")):Ct() / orgblocktotex
    -- Block        = (StarLine:C() * (NonStarLine^0):C()):Ct()
    -- Blocks       = (Block^0):Ct()
  end

--[==[
-- «parseorg-tests» (to ".parseorg-tests")
-- (find-es "org" "parse-org-with-lua")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "istanbulall.lua"
parseorg_utils()

StarLineT:test "* :big: TODO why a is b"
StarLineT:test "**      DONE why b is c"
StarLineT:test "**           foo"

StarLine1:test "* :big: TODO why a is b"

bigstr = ee_readfile "~/ORG/istanbul.org"    -- (find-angg "ORG/istanbul.org")
bigstr = ee_readfile "~/LATEX/istanbul1.org" -- (find-ist "1.org")
NonStarLines:test(bigstr)
(NonStarLines*StarLine1):test(bigstr)
(NonStarLines*Block1)   :test(bigstr)
(NonStarLines*Block2)   :test(bigstr)

--]==]


--             _                  _     _            _        
--   __ _  ___| |_ ___  _ __ __ _| |__ | | ___   ___| | _____ 
--  / _` |/ _ \ __/ _ \| '__/ _` | '_ \| |/ _ \ / __| |/ / __|
-- | (_| |  __/ || (_) | | | (_| | |_) | | (_) | (__|   <\__ \
--  \__, |\___|\__\___/|_|  \__, |_.__/|_|\___/ \___|_|\_\___/
--  |___/                   |___/                             
--
-- «getorgblocks» (to ".getorgblocks")
getorgblocks = function (bigstr)
    parseorg_utils()
    local pat = NonStarLines:C()*(BlockT^0):Ct()
    local pre, blocks = pat:match(bigstr)
    blocks[0] = pre
    blocks.m = function (pat)
        for i,b in ipairs(blocks) do
          if b.rest:match(pat) then return b end
        end
      end
    return blocks
  end

--[==[
-- «getorgblocks-tests» (to ".getorgblocks-tests")
-- (find-es "org" "parse-org-with-lua")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "istanbulall.lua"
bs = getorgblocks(ee_readfile "~/LATEX/istanbul1.org") -- (find-ist "1.org")
= #bs
= bs[0]
PP(bs[4])
PP(bs.m"^Eval")
for i,b in ipairs(bs) do print(b.stars.." "..b.rest) end

--]==]




--                  _     _            _    _        _            
--   ___  _ __ __ _| |__ | | ___   ___| | _| |_ ___ | |_ _____  __
--  / _ \| '__/ _` | '_ \| |/ _ \ / __| |/ / __/ _ \| __/ _ \ \/ /
-- | (_) | | | (_| | |_) | | (_) | (__|   <| || (_) | ||  __/>  < 
--  \___/|_|  \__, |_.__/|_|\___/ \___|_|\_\\__\___/ \__\___/_/\_\
--            |___/                                               
--
-- «orgblocktotex» (to ".orgblocktotex")
-- We use nonhashlines(body) for LaTeXed sections
-- We use toverbatim(body) for non-LaTeXed sections
nonhashlines = function (bigstr)
    local A = splitlines(bigstr)
    local B = {}
    for _,li in ipairs(A) do
      if not li:match"^#" then table.insert(B, li.."\n") end
    end
    return table.concat(B)
  end
toverbatim_fmt = "{\\myttchars\n%s\\begin{verbatim}\n%s\\end{verbatim}\n}\n\n"
toverbatim0 = function (bigstr)
    return format(toverbatim_fmt, "\\footnotesize\n", bigstr)
  end
toverbatim = function (bigstr)
    return toverbatim0(bigstr:gsub("^\n*", ""))
  end

sectionnames = {}
storesectionname = function (name)
    print(name)
    table.insert(sectionnames, name)
    return name
  end

orgblocktotext_section = function (title)
    local  secn = nplus()
    return storesectionname(secn..". "..title)
  end
orgblocktotext_subsection = function (title)
    local  secnn = nnplus()
    return storesectionname(secnn..". "..title)
  end

orgblocktotex_omit = function (b) end
orgblocktotex_omittitle = function (b)
    return "%\n% "..b.rest.."\n"..nonhashlines(b.body)
  end
orgblocktotex_texed = function (b)
    local f = (b.stars=="*") and orgblocktotext_section
                             or  orgblocktotext_subsection
    local body = nonhashlines(untabify8(b.body))
    return "\\newpage\n"..f(b.rest).."\n"..body
  end
orgblocktotex_verbatim = function (b)
    local f = (b.stars=="*") and orgblocktotext_section
                             or  orgblocktotext_subsection
    local body = toverbatim(nonhashlines(untabify8(b.body)))
    return "\\newpage\n"..f(b.rest).."\n"..body
  end
orgblocktotex = function (b)
    if     b.rest:match"^-"    then return orgblocktotex_omittitle(b)
    elseif b.todo == "COMMENT" then return orgblocktotex_omit(b)
    elseif b.todo == "TEXED"   then return orgblocktotex_texed(b)
    else                            return orgblocktotex_verbatim(b)
    end
  end

orgblockstotex = function (bs)
    local ts = {}
    for _,b in ipairs(bs) do
      ts[#ts+1] = orgblocktotex(b)
    end
    return table.concat(ts)
  end

texfooter = "\f\n"..[[
% Local Variables:
% coding: utf-8-unix
% mode: latex
% End:
]]


--[==[
-- «orgblocktotex-tests» (to ".orgblocktotex-tests")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "istanbulall.lua"
bs = getorgblocks(ee_readfile "~/LATEX/istanbul1.org") -- (find-ist "1.org")
b = bs.m"^Eval" 
PP(b)
= orgblocktotex(b)

bt = orgblockstotex(bs)
= bt

PP(bs.m"^Local")
b = bs.m"^Elephant"
PP(b)
= b.body
= nonhashlines(b.body)

b = bs.m"Why study CT"
PP(b)
= orgblocktotex(b)

-- «orgblocktotex-export» (to ".orgblocktotex-export")
-- (find-ist "1.tex" "update-body")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "istanbulall.lua"
bs = getorgblocks(ee_readfile "~/LATEX/istanbul1.org") -- (find-ist "1.org")
bt0 = orgblockstotex(bs)
bt = "\n\n"..bt0..texfooter
bt = "\n\n"..bt0
ee_writefile("~/LATEX/istanbul1body.tex", bt) -- (find-ist "1body.tex")
= bt

--]==]













--  _     _             _ 
-- | |__ | |_ _ __ ___ | |
-- | '_ \| __| '_ ` _ \| |
-- | | | | |_| | | | | | |
-- |_| |_|\__|_| |_| |_|_|
--                        
-- «html» (to ".html")
-- «html-tests» (to ".html-tests")
-- Moved to: (find-es "lua5" "utf8-to-html")





--  _   _       _                    
-- | |_| |_ ___| |__   __ _ _ __ ___ 
-- | __| __/ __| '_ \ / _` | '__/ __|
-- | |_| || (__| | | | (_| | |  \__ \
--  \__|\__\___|_| |_|\__,_|_|  |___/
--                                   
-- «ttchars» (to ".ttchars")
-- (find-ist "defs.tex" "ttchars")
--[==[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
bigstr = ee_readfile "~/LATEX/istanbuldefs.tex"
pat = "^\\catcode`(.-)=13 \\def(.-)(%b{})(.*)"
for _,li in ipairs(splitlines(bigstr)) do
  local c, cc, def, rest = li:match(pat)
  if c then
    local indef = def:sub(2,-2)
    print(format("  \\def%s{\\ttchar{$%s$}}", c, indef))
  end
end

--]==]



--                                      _                   
--  ___  ___  ___ _ __  _   _ _ __ ___ | |__   ___ _ __ ___ 
-- / __|/ _ \/ __| '_ \| | | | '_ ` _ \| '_ \ / _ \ '__/ __|
-- \__ \  __/ (__| | | | |_| | | | | | | |_) |  __/ |  \__ \
-- |___/\___|\___|_| |_|\__,_|_| |_| |_|_.__/ \___|_|  |___/
--                                                          
-- «secnumbers» (to ".secnumbers")
-- (find-blogme3 "anggdefs.lua" "section-numbers")
__secn = "0"
incrsecn = function (pat)
    local a, b = string.match(__secn, pat)
    if not a then                      -- not deep enough?
      repeat __secn = __secn .. ".1"   -- keep adding ".1"s
      until string.match(__secn, pat)  -- until deep enough
      return __secn                    -- and return this.
    end
    __secn = a .. (b+1)  -- else increase the right digit (drop the rest)
    return __secn        -- and return that.
  end
nplus = function () return incrsecn("^(%d-)(%d+)") end
nnplus = function () return incrsecn("^(%d+%.)(%d+)") end
nnnplus = function () return incrsecn("^(%d+%.%d+%.)(%d+)") end
nnnnplus = function () return incrsecn("^(%d+%.%d+%.%d+%.)(%d+)") end

--[==[
-- «secnumbers-test» (to ".secnumbers-test")
-- (find-es "org" "parse-org-with-lua")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "istanbulall.lua"
__secn = "0"
print(nplus(), nplus(), nnplus(), nnnnplus(), nnplus())
      -->  1        2        2.1     2.1.1.1       2.2

--]==]



--   ___        _               _   
--  / _ \ _   _| |_ _ __  _   _| |_ 
-- | | | | | | | __| '_ \| | | | __|
-- | |_| | |_| | |_| |_) | |_| | |_ 
--  \___/ \__,_|\__| .__/ \__,_|\__|
--                 |_|              
--
-- «output» (to ".output")
-- (find-es "luatex" "comments-in-tex.print")
-- (find-LATEX "2015logicandcats.lua" "output")
-- Moved to: (find-dn6 "output.lua")
--
-- Usage:
-- \catcode`\^^J=10                     % (find-es "luatex" "spurious-omega")
-- \directlua{output = mytexprint}
-- \directlua{output =  printboth}





--  ____  _             _    
-- / ___|| |_ __ _  ___| | __
-- \___ \| __/ _` |/ __| |/ /
--  ___) | || (_| | (__|   < 
-- |____/ \__\__,_|\___|_|\_\
--                           
-- «Stack» (to ".Stack")
-- «ubs» (to ".ubs")
-- Moved to: (find-dn5 "stacks.lua" "Stack")









--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "istanbulall.lua"

--]]


--
-- Local Variables:
-- coding: raw-text-unix
-- End: