 @compile_options()
 
 #-----------------------------------------------------------------------------------------------------------
-@write_mkts_master = ( S, layout_info, handler ) ->
+@write_mkts_master = ( S, handler ) ->
   self = @
   step ( resume ) ->
     lines             = []
     write             = lines.push.bind lines
-    master_locator    = layout_info[ 'master-locator'  ]
-    content_locator   = layout_info[ 'content-locator' ]
-    help "writing #{master_locator}"
+    help "writing #{S.layout_info[ 'master-locator'  ]}"
     #-------------------------------------------------------------------------------------------------------
     write ""
-    write "% #{master_locator}"
+    write "% #{S.layout_info[ 'master-locator'  ]}"
     write "% do not edit this file"
     write "% generated from #{self.options[ 'locator' ]}"
     write "% on #{new Date()}"

  RPC_SERVER  = require './rpc-server'
  server      = await ( promisify RPC_SERVER.listen.bind RPC_SERVER )()
  process.on 'exit', -> server.close()
  self = @
  #---------------------------------------------------------------------------------------------------------
  f = => step ( resume ) ->
    # handler                ?= ->
    layout_info             = HELPERS.new_layout_info self.options, source_route
    yield self.write_mkts_master S, layout_info, resume
    source_locator          = layout_info[ 'source-locator'  ]
    content_locator         = layout_info[ 'content-locator' ]
    file_output             = njs_fs.createWriteStream content_locator
    #.......................................................................................................
    file_output.on 'close', =>
      HELPERS.write_pdf layout_info, ( error ) =>
        throw error if error?
        S.t1              = +new Date()
        dt_s              = ( S.t1 - S.t0 ) / 1000
        dt_s_txt          = dt_s.toFixed 3
        chrs_per_s_txt    = (   S.chr_count / dt_s ).toFixed 3
        events_per_s_txt  = ( S.event_count / dt_s ).toFixed 3
        chr_count_txt     = ƒ S.chr_count
        event_count_txt   = ƒ S.event_count
        help "#{TEXT.flush_right    chr_count_txt, 10}       chrs (approx.)"
        help "#{TEXT.flush_right  event_count_txt, 10}     events (approx.)"
        help "#{TEXT.flush_right         dt_s_txt, 14}          s"
        help "#{TEXT.flush_right   chrs_per_s_txt, 14}   chrs / s"
        help "#{TEXT.flush_right events_per_s_txt, 14} events / s"
        # debug '49984', S.aux
        # handler null if handler?
        process.exit 0
    #.......................................................................................................
    ### TAINT use method to produce new state ###
    S =
      options:              self.options
      layout_info:          layout_info
      paragraph_nr:         0
      configuration:        {}
    #.......................................................................................................
    ### TAINT should read MD source stream ###
    md_source               = njs_fs.readFileSync source_locator, encoding: 'utf-8'
    md_readstream           = MD_READER.create_md_read_tee S, md_source
    tex_writestream         = self.create_tex_write_tee S
    md_input                = md_readstream.tee[    'input'  ]
    md_output               = md_readstream.tee[    'output' ]
    tex_input               = tex_writestream.tee[  'input'  ]
    tex_output              = tex_writestream.tee[  'output' ]
    #.......................................................................................................
    # S.aux                   = yield AUX.fetch_aux_data S, resume
    S.resend                = md_readstream.tee[ 'S' ].resend
    #.......................................................................................................
    md_output
      .pipe tex_input
    tex_output
      # .pipe $ ( event, send ) =>
      #   debug '33376', rpr event
      #   send event
      #   if event?
      #     send event
      #   if end?
      #     end() # setTimeout end, 1000
      .pipe file_output
    #.......................................................................................................
    md_input.resume()
  #---------------------------------------------------------------------------------------------------------
  D.run f, @_handle_error


#===========================================================================================================

    # INCLUDES
    #.......................................................................................................
    write ""
    write "\\input{#{S.layout_info[ 'content-locator' ]}}"
    write ""
    #-------------------------------------------------------------------------------------------------------
    write "\\end{document}"
    #-------------------------------------------------------------------------------------------------------
    text = lines.join '\n'
    # whisper text
    njs_fs.writeFile S.layout_info[ 'master-locator'  ], text, handler


#===========================================================================================================
