def read_title_file(titles_opt, chapters, sec_list):
    "Helper function to read and process a file with titles\n\n    Read the file containing titles and process them according to the number of jupyter-book chapters and sections.\n    len(sec_list) should be the same as len(chapters), and its elements can be empty lists\n    :param str titles_opt: 'auto' or file containing titles\n    :param list[str] chapters: DocOnce texts consisting in Jupyter-book chapters\n    :param list[list[str]] sec_list: DocOnce texts consisting in Jupyter-book sections.\n    :return: tuple with chapter and section titles\n    :rtype: (list[str], list[list[str]])\n    "
    chapter_titles = []
    sec_title_list = ([[]] * len(chapters))
    if (titles_opt != 'auto'):
        chapter_titles = ([''] * len(chapters))
        input_titles = read_to_list(titles_opt)
        for c in range(len(chapters)):
            chapter_titles[c] = (input_titles.pop(0) if len(input_titles) else '')
            section = []
            for _ in range(len(sec_list[c])):
                section.append((input_titles.pop(0) if len(input_titles) else ''))
            sec_title_list[c] = section
        if len(input_titles):
            errwarn('*** warning : number of titles is larger than chapters and sections detected. These titles will be ignored')
    return (chapter_titles, sec_title_list)
Helper function to read and process a file with titles

Read the file containing titles and process them according to the number of jupyter-book chapters and sections.
len(sec_list) should be the same as len(chapters), and its elements can be empty lists
:param str titles_opt: 'auto' or file containing titles
:param list[str] chapters: DocOnce texts consisting in Jupyter-book chapters
:param list[list[str]] sec_list: DocOnce texts consisting in Jupyter-book sections.
:return: tuple with chapter and section titles
:rtype: (list[str], list[list[str]])
def read_title_file(titles_opt, chapters, sec_list):
    "Helper function to read and process a file with titles\n\n    Read the file containing titles and process them according to the number of jupyter-book chapters and sections.\n    len(sec_list) should be the same as len(chapters), and its elements can be empty lists\n    :param str titles_opt: 'auto' or file containing titles\n    :param list[str] chapters: DocOnce texts consisting in Jupyter-book chapters\n    :param list[list[str]] sec_list: DocOnce texts consisting in Jupyter-book sections.\n    :return: tuple with chapter and section titles\n    :rtype: (list[str], list[list[str]])\n    "
    chapter_titles = []
    sec_title_list = ([[]] * len(chapters))
    if (titles_opt != 'auto'):
        chapter_titles = ([] * len(chapters))
        input_titles = read_to_list(titles_opt)
        for c in range(len(chapters)):
            chapter_titles[c] = (input_titles.pop(0) if len(input_titles) else )
            section = []
            for _ in range(len(sec_list[c])):
                section.append((input_titles.pop(0) if len(input_titles) else ))
            sec_title_list[c] = section
        if len(input_titles):
            errwarn('*** warning : number of titles is larger than chapters and sections detected. These titles will be ignored')
    return (chapter_titles, sec_title_list)