let doc_settings_of_ts_blks (doc_settings : t_doc_settings) (lvl : int) (blks : Doc_types.ts_blks) : t_doc_settings =
if not doc_settings.allow_custom_numbering then doc_settings else
let rec aux (blk_list : Doc_types.tu_blk list) : t_doc_settings =
match blk_list with
|[] -> doc_settings
|hd ::tl ->
match hd with
|Cu_blk_itm (blk_itm : tr_blk_itm) -> (
match blk_itm.fld_blk_itm_lbl with
|Cu_lbl_custom (Cs_lbl_custom s) -> (
match s with
|"1" | "a" | "i" ->
let inc : int =
match s, doc_settings.auto_numbering 1 0, doc_settings.auto_numbering 2 0 with
|"a","a",_ -> 1
|"a",_,"a" -> 2
|"1","1",_ -> 1
|"1",_,"1" -> 2
|"i","i",_ -> 1
|"i",_,"i" -> 2
|_,_,_ -> 0
in
let new_auto_numbering (l : int) (n : int) : string =
let new_n = if l=lvl then n+1 else n in
doc_settings.auto_numbering (l - lvl + inc) new_n
in
{
doc_width = doc_settings.doc_width;
left_margin = doc_settings.left_margin;
title_indent = doc_settings.title_indent;
author_indent = doc_settings.author_indent;
abstract_indent = doc_settings.abstract_indent;
refs_indent = doc_settings.refs_indent;
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 = doc_settings.expand_tag;
auto_numbering = new_auto_numbering;
allow_custom_numbering = doc_settings.allow_custom_numbering;
}
|_ -> doc_settings
)
|_ -> doc_settings
)
|_ -> aux tl
in
match blks with
|Cs_blks blk_list -> aux blk_list