1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
if not modules then modules = { } end modules ['s-mod-00'] = {
version = 1.000,
comment = "companion to mult-aux.mkiv",
author = "Wolfgang Schuster",
copyright = "Wolfgang Schuster",
license = "GNU General Public License"
}
thirddata = thirddata or { }
thirddata.correspondence = thirddata.correspondence or { }
local concat, toks, settings_to_array, settings_to_hash = table.concat, tex.toks, utilities.parsers.settings_to_array, utilities.parsers.settings_to_hash
local correspondence = thirddata.correspondence
local constants = interfaces.constants
local variables = interfaces.variables
local c_titlestyle = constants.titlestyle
local c_titlecolor = constants.titlecolor
local c_textcolor = constants.textcolor
local c_textstyle = constants.textstyle
local c_separator = constants.separator
local v_correspondence = variables.correspondence
local v_letter = variables.letter
local v_memo = variables.memo
local v_resume = variables.resume
local v_frames = variables.frames
local v_stop = variables.stop
local v_layer = variables.layer
local v_section = variables.section
local v_color = variables.color
local v_singlesided = variables.singlesided
local v_reset = variables.reset
local v_line = variables.line
local v_top = variables.top
local v_bottom = variables.bottom
local v_off = variables.off
local v_right = variables.right
local v_page = variables.page
local v_paper = variables.paper
local v_text = variables.text
local v_start = variables.start
local v_list = variables.list
-- list for the elements to be shown
correspondence.data = { }
function correspondence.elements_define(environment,name,list)
local index = concat({environment,name},":")
local list = settings_to_array(list)
correspondence.data[index] = list
end
function correspondence.elements_access(environment,name)
local index = concat({environment,name},":")
local list = correspondence.data[index]
local entries = ""
if list and list ~= "" then
entries = concat(list,",")
end
context(entries)
end
-- create synonyms for the default styles
local patterns = {
[v_letter] = { "letter-imp-%s.mkiv", "letter-imp-%s.tex", "letter-%s.mkiv", "letter-%s.tex" },
[v_memo] = { "memo-imp-%s.mkiv", "memo-imp-%s.tex", "memo-%s.mkiv", "memo-%s.tex" },
[v_resume] = { "resume-imp-%s.mkiv", "resume-imp-%s.tex", "resume-%s.mkiv", "resume-%s.tex" },
[v_frames] = { "frames-imp-%s.mkiv", "frames-imp-%s.tex", "frames-%s.mkiv", "frames-%s.tex" },
}
local function action(name,foundname)
context.startreadingfile()
context.pushendofline()
context.unprotect()
context.input(foundname)
context.protect()
context.popendofline()
context.stopreadingfile()
end
function correspondence.file(environment,name)
local environment = environment
local name = name
resolvers.uselibrary {
name = name,
patterns = patterns[environment],
action = action,
}
end
-- moved from TeX to Lua because it’s easier with the lists for the sections and layers
function correspondence.place(environment,settings)
local bodyfont = settings.bodyfont
local whitespace = settings.whitespace
local interlinespace = settings.interlinespace
local language = settings.language
local backgroundcolor = settings.backgroundcolor
context.unprotect()
context(toks.t_correspondence_before)
context.page()
-- page layout is controlled with the \setup…layout commands
context.setuplayout{ method = v_correspondence }
-- disable headers and footers
context.setupheader{ state = v_stop }
context.setupfooter{ state = v_stop }
-- required for the manual, manual changes for the elements can be done with the “style” key
if bodyfont ~= "" then
context.setupbodyfont{bodyfont}
end
-- can be moved to the section elements because it’s only usefull for the content
if whitespace ~= "" then
context.setupwhitespace{whitespace}
end
-- feature
if interlinespace ~= "" then
context.setupinterlinespace{interlinespace}
end
-- I prefer to set this with \setup…options
if language ~= "" then
context.mainlanguage{language}
end
-- colored background is behind all other layers
if backgroundcolor ~= "" then
context.setupbackgrounds({ v_paper },{ background = v_color, backgroundcolor = backgroundcolor })
end
-- layers
local layer = { }
for index, element in next, correspondence.data[concat({environment,v_layer},":")] or { } do
layer[index] = concat({environment,element},":")
end
local overlays = {
"correspondence:backgroundimage",
"correspondence:background",
concat(layer,","),
}
context.setupbackgrounds({ v_page },{ background = concat(overlays,",") })
-- letters are always singlesided because the layout controlled by the module
context.setuppagenumbering{ alternative = v_singlesided, location = "" }
context.setupsubpagenumber{ way = v_text, state = v_start }
context.resetsubpagenumber()
-- sections
for _, element in next, correspondence.data[concat({environment,v_section},":")] or { } do
context.correspondence_section_place({environment},{element})
end
context.page()
context.resetsubpagenumber()
-- make sure the normal layout is restored
context.setuplayout{v_reset}
context(toks.t_correspondence_after)
context.protect()
end
correspondence.letter = { }
local function reference_a(environment,value)
local environment = environment
local value = value
local style = nil
context.vbox( function()
style = concat({environment,value},":")
context.setevalue("currentcorrespondencestyle",style)
context.framed( { frame = v_off, location = v_bottom, align = v_right, offset = "0pt" }, function()
context.usecorrespondencestylestyleandcolor(c_titlestyle,c_titlecolor)
context.setupinterlinespace()
context.lettertext(value)
context.par()
end )
context.framed( { frame = v_off, location = v_top, align = v_right, offset = "0pt" }, function()
context.usecorrespondencestylestyleandcolor(c_textstyle,c_textcolor)
context.setupinterlinespace()
context.correspondenceparameter(value)
context.par()
end )
end )
end
function correspondence.letter.reference_a(environment,list)
local environment = environment
local list = settings_to_array(list)
local style = nil
if #list == 1 then
local value = list[1]
context.rightaligned( function() reference_a(environment,value) end )
else
context.maxaligned( function()
for index, value in next, list do
if value == "" or value == v_line then
-- ignore empty entries and the “line” keyword
else
if index ~= 1 then context.hfill() end
reference_a(environment,value)
end
end
end )
end
end
function correspondence.letter.reference_b(environment,list)
local environment = environment
local list = settings_to_array(list)
local style = nil
context.vtop( function()
for _, value in next, list do
if value == "" then
-- ignore empty entries in the list
elseif value == v_line then
context.blank{v_line}
else
context.hbox( function()
style = concat({environment,value},":")
context.setevalue("currentcorrespondencestyle",style)
context.begingroup()
context.usecorrespondencestylestyleandcolor(c_titlestyle,c_titlecolor)
context.lettertext(value)
context.correspondencestyleparameter(c_separator)
context.endgroup()
context.begingroup()
context.usecorrespondencestylestyleandcolor(c_textstyle,c_textcolor)
context.correspondenceparameter(value)
context.endgroup()
end )
end
end
end )
end
function correspondence.letter.reference_c(environment,list)
local environment = environment
local list = settings_to_array(list)
local style = nil
for _, value in next, list do
if value == "" or value == v_line then
-- ignore empty entries and the “line” keyword
else
style = concat({environment,value},":")
context.setvalue("currentcorrespondencestyle",style)
context.usecorrespondencestylestyleandcolor(c_textstyle,c_textcolor)
context.correspondenceparameter(value)
end
end
end
function correspondence.letter.reference_d(environment,list)
local environment = environment
local list = settings_to_array(list)
local style = nil
context.vtop( function()
context.starttabulate( { "|l|l|" }, { before = "", after = "" } )
for _, value in next, list do
if value == "" then
-- ignore empty entries in the list
elseif value == v_line then
context.TB()
else
style = concat({environment,value},":")
context.NC()
context.setvalue("currentcorrespondencestyle",style)
context.usecorrespondencestylestyleandcolor(c_titlestyle,c_titlecolor)
context.lettertext(value)
context.correspondencestyleparameter(c_separator)
context.NC()
context.setvalue("currentcorrespondencestyle",style)
context.usecorrespondencestylestyleandcolor(c_textstyle,c_textcolor)
context.correspondenceparameter(value)
context.NC()
context.NR()
end
end
context.stoptabulate()
end )
end
function correspondence.letter.reference_e(environment,list)
local environment = environment
local list = settings_to_array(list)
local style, settings = nil
context.leftaligned( function()
for _, value in next, list do
if value == "" or value == v_line then
-- ignore empty entries and the “line” keyword
else
context.unprotect()
context.correspondence_style_width( environment, value, function() reference_a(environment,value) end )
context.protect()
end
end
end )
end
function correspondence.description_split(list)
local format, items = nil, nil
if string.find(list,":") then
format, items = string.splitup(list,":")
if format ~= v_list then
items = list
end
else
items = list
end
-- the macros are empty be default, change this only when necessary
context.unprotect()
if format then context.setvalue("m_correspondence_description_format",format) end
if items then context.setvalue("m_correspondence_description_items" ,items ) end
context.protect()
end
|