<commit_before>SILE.scratch.masters = {}
local _currentMaster

local function defineMaster (self, args)
  SU.required(args, "id", "defining master")
  SU.required(args, "frames", "defining master")
  SU.required(args, "firstContentFrame", "defining master")
  SILE.scratch.masters[args.id] = {frames = {}, firstContentFrame = nil}
  for k,spec in pairs(args.frames) do
    spec.id=k
    SILE.scratch.masters[args.id].frames[k] = SILE.newFrame(spec)
  end
  SILE.frames = {page = SILE.frames.page}

  SILE.scratch.masters[args.id].firstContentFrame = SILE.scratch.masters[args.id].frames[args.firstContentFrame]
end

local function defineMasters (self, list)
  if list then
    for i=1,#list do defineMaster(self, list[i]) end
  end
end

local function doswitch(frames)
  SILE.frames = {page = SILE.frames.page}
  for id,f in pairs(frames) do
    SILE.frames[id] =f
    f:invalidate()
  end
end

local function switchMasterOnePage (id)
  if not SILE.scratch.masters[id] then
    SU.error("Can't find master "..id)
  end
  SILE.documentState.thisPageTemplate = SILE.scratch.masters[id]
  doswitch(SILE.scratch.masters[id].frames)
  SILE.typesetter:chuck()
  SILE.typesetter:initFrame(SILE.scratch.masters[id].firstContentFrame)
end<commit_msg>If handed a frame, just use it.<commit_after>SILE.scratch.masters = {}
local _currentMaster

local function defineMaster (self, args)
  SU.required(args, "id", "defining master")
  SU.required(args, "frames", "defining master")
  SU.required(args, "firstContentFrame", "defining master")
  SILE.scratch.masters[args.id] = {frames = {}, firstContentFrame = nil}
  for k,spec in pairs(args.frames) do
    spec.id=k
    if spec.solve then
      SILE.scratch.masters[args.id].frames[k] = spec
    else
      SILE.scratch.masters[args.id].frames[k] = SILE.newFrame(spec)
    end
  end
  SILE.frames = {page = SILE.frames.page}

  SILE.scratch.masters[args.id].firstContentFrame = SILE.scratch.masters[args.id].frames[args.firstContentFrame]
end

local function defineMasters (self, list)
  if list then
    for i=1,#list do defineMaster(self, list[i]) end
  end
end

local function doswitch(frames)
  SILE.frames = {page = SILE.frames.page}
  for id,f in pairs(frames) do
    SILE.frames[id] =f
    f:invalidate()
  end
end

local function switchMasterOnePage (id)
  if not SILE.scratch.masters[id] then
    SU.error("Can't find master "..id)
  end
  SILE.documentState.thisPageTemplate = SILE.scratch.masters[id]
  doswitch(SILE.scratch.masters[id].frames)
  SILE.typesetter:chuck()
  SILE.typesetter:initFrame(SILE.scratch.masters[id].firstContentFrame)
end
{'fraction_non_alphanumeric': 0.1302504816955684, 'fraction_numerical': 0.0007707129094412332, 'mean_word_length': 4.465263157894737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5070154', 'n_tokens_mistral': 951, 'n_tokens_neox': 940, 'n_words': 192}