PhD

The LaTeX sources of my Ph.D. thesis
git clone https://esimon.eu/repos/PhD.git
Log | Files | Refs | README | LICENSE

layout.lua (2725B)


      1 -- This script set up the two geometry withmarginpar and withoutmarginpar.
      2 -- The page layout somewhat respect the Van de Graaf canon except that the textblock width is not a simple fraction of the page width.
      3 -- However the textblock does have the same proportion as the page, with the margin respecting the 1:2 ratio (with twoside)
      4 -- Since a large marginpar is used, it is included in the textblock width, its width being a parameter.
      5 require("math")
      6 
      7 local layout = {}
      8 
      9 local function format(value)
     10 	return tostring(math.floor(value+0.5)) .. "sp"
     11 end
     12 
     13 local function set_key(config, key, value)
     14 	if value ~= nil then
     15 		value = "=" .. format(value)
     16 	else
     17 		value = ""
     18 	end
     19 	table.insert(config, key .. value)
     20 end
     21 
     22 function layout.set(parameters)
     23 	-- Parameters:
     24 	--     twoside: whether to distinguish outer and inner margins
     25 	--     top: size of the top margin from which other margins are computed
     26 	--     mpwidth: width of the marginpar column
     27 	--     mpsep: space between the marginpar column and normal text
     28 	--     debug: whether to display the construction frame
     29 	local top = tex.sp(parameters.top)
     30 
     31 	local common_config = {}
     32 	set_key(common_config, "a4paper")
     33 	if parameters.debug then
     34 		set_key(common_config, "showframe")
     35 	end
     36 	set_key(common_config, "top", top)
     37 	set_key(common_config, "bottom", top * 2)
     38 	if parameters.twoside then
     39 		set_key(common_config, "inner", top / math.sqrt(2))
     40 		set_key(common_config, "outer", top * math.sqrt(2))
     41 	else
     42 		set_key(common_config, "inner", top * 3 / 2 / math.sqrt(2))
     43 		set_key(common_config, "outer", top * 3 / 2 / math.sqrt(2))
     44 	end
     45 	set_key(common_config, "includehead")
     46 
     47 	local without_margin_config = {unpack(common_config)}
     48 	set_key(without_margin_config, "nomarginpar")
     49 	-- Set a tiny marginpar to avoid spurious overfull \hbox
     50 	set_key(without_margin_config, "marginpar", tex.sp("0.4pt"))
     51 	if parameters.twoside then
     52 		set_key(without_margin_config, "twoside")
     53 	end
     54 
     55 	local with_margin_config = {unpack(common_config)}
     56 	set_key(with_margin_config, "includemp")
     57 	set_key(with_margin_config, "asymmetric")
     58 	set_key(with_margin_config, "marginpar", tex.sp(parameters.mpwidth))
     59 	set_key(with_margin_config, "marginparsep", tex.sp(parameters.mpsep))
     60 
     61 	tex.print([[\RequirePackage[]] .. table.concat(with_margin_config, ",") .. [[]{geometry}]])
     62 	if parameters.twoside then
     63 		tex.print([[\setlength\evensidemargin{]] .. format(top * math.sqrt(2) - tex.sp("1in")) .. [[}]])
     64 		tex.print([[\setlength\oddsidemargin{]] .. format(top / math.sqrt(2) - tex.sp("1in")) .. [[}]])
     65 	end
     66 	tex.print([[\savegeometry{withmarginpar}]])
     67 
     68 	tex.print([[\geometry{]] .. table.concat(without_margin_config, ",") .. [[}]])
     69 	tex.print([[\savegeometry{withoutmarginpar}]])
     70 end
     71 
     72 return layout