 
 
 #===========================================================================================================
+#
+#-----------------------------------------------------------------------------------------------------------
+@create_texwritestream = ( layout_info, input ) ->
+  ### TAINT get state via return value of MKTS.create_mdreadstream ###
+  S =
+    options:              @options
+    layout_info:          layout_info
+    input:                input
+    # resend:               ( event ) => input.write event
+    resend:               input.XXX_resend
+  #.......................................................................................................
+  R = D.create_throughstream()
+  #.......................................................................................................
+  input
+    .pipe @MKTX.TEX.$fix_typography_for_tex               S
+    .pipe @MKTX.DOCUMENT.$begin                           S
+    .pipe @MKTX.DOCUMENT.$end                             S
+    .pipe @MKTX.MIXED.$raw                                S
+    .pipe @MKTX.MIXED.$footnote                           S
+    .pipe @MKTX.MIXED.$remove_footnote_extra_paragraphs   S
+    .pipe @MKTX.COMMAND.$do                               S
+    .pipe @MKTX.COMMAND.$expansion                        S
+    .pipe @MKTX.COMMAND.$new_page                         S
+    .pipe @MKTX.COMMAND.$comment                          S
+    # .pipe @MKTX.REGION.$correct_p_tags_before_regions     S
+    .pipe @MKTX.COMMAND.$multi_column                     S
+    .pipe @MKTX.REGION.$multi_column                      S
+    .pipe @MKTX.REGION.$single_column                     S
+    .pipe @MKTX.REGION.$keep_lines                        S
+    .pipe @MKTX.REGION.$code                              S
+    .pipe @MKTX.BLOCK.$heading                            S
+    .pipe @MKTX.BLOCK.$hr                                 S
+    .pipe @MKTX.BLOCK.$unordered_list                     S
+    .pipe @MKTX.INLINE.$code                              S
+    .pipe @MKTX.INLINE.$translate_i_and_b                 S
+    .pipe @MKTX.INLINE.$em_and_strong                     S
+    .pipe @MKTX.BLOCK.$paragraph                          S
+    .pipe @MKTX.CLEANUP.$remove_empty_texts               S
+    .pipe MKTS.$close_dangling_open_tags                  S
+    .pipe MKTS.$show_mktsmd_events                        S
+    .pipe MKTS.$write_mktscript                           S
+    .pipe @MKTX.$show_unhandled_tags                      S
+    .pipe @$filter_tex                                    S
+    .pipe MKTS.$show_illegal_chrs                         S
+    .pipe R
+  #.......................................................................................................
+  # input.resume()
+  return R
+
+#===========================================================================================================
 # PDF FROM MD
 #-----------------------------------------------------------------------------------------------------------
 @pdf_from_md = ( source_route, handler ) ->

  return R

#-----------------------------------------------------------------------------------------------------------
@MKTX.TEX.$fix_typography_for_tex = ( options ) =>
  return $ ( event, send ) =>
    if select event, '.', 'text'
      [ type, name, text, meta, ] = event
      meta[ 'raw' ] = text
      text          = @MKTX.TEX.fix_typography_for_tex text, options
      send [ type, name, text, meta, ]
    else
      send event

#===========================================================================================================
#
#-----------------------------------------------------------------------------------------------------------
@$filter_tex = ( S ) ->
  return $ ( event, send ) =>
    if select event, 'tex'                        then send event[ 1 ]
    else if select event, '.', [ 'text', 'raw', ] then send event[ 2 ]
