let txt_of_tr_doc (options : t_txt_options) (doc : tr_doc) : string = let doc_settings : t_doc_settings = doc_settings_of_tr_doc doc in let left_margin : int = match options.margin with |Some (m : int) -> m |None -> let margin_labels : string list = margin_labels_of_tr_doc doc_settings doc in Txt_utils.left_margin_of_margin_labels margin_labels in let doc_width : int = match options.width with |Some (w : int) -> w |None -> if 68 + left_margin > 80 then 80 else 68 + left_margin in let auto_numbering : int -> int -> string = auto_numbering_of_string options.numbering in let allow_custom_numbering : bool = options.allow_custom_numbering in let expand_tag : ts_tag -> (string * string) option = match options.tags with |None -> doc_settings.expand_tag |Some path -> Tags.expander_of_file path in let new_doc_settings : t_doc_settings = { doc_width = doc_width; left_margin = left_margin; title_indent = left_margin; author_indent = left_margin; abstract_indent = left_margin; refs_indent = left_margin; tab_length = doc_settings.tab_length; abstract_hdr = doc_settings.abstract_hdr; refs_hdr = doc_settings.refs_hdr; endnotes_hdr = doc_settings.endnotes_hdr; ch_prefix = doc_settings.ch_prefix; sec_prefix = doc_settings.sec_prefix; app_prefix = doc_settings.app_prefix; par_prefix = doc_settings.par_prefix; expand_tag = expand_tag; auto_numbering = auto_numbering; allow_custom_numbering = allow_custom_numbering; } in let _ : unit = IO.quiet.contents <- options.quiet in String.concat "\n" (lines_of_tr_doc new_doc_settings doc)