import re


def concatenate_multiple_sources_into_one(multiple_inputs, main_tex):
    """ Inserts content of \input element into the main latex content
    Ex : if the content is:

        some text
        \input{other_file}

        some more text

    And the content of 'other_file' is 'abcd'

    The the result will be:

        some text
        abcd

        some more text

    :param multiple_inputs  : dictionary mapping an input name to its file content
    :type multiple_inputs   : dict(str)
    :param main_tex         : current content of the main latex file
    :type main_tex          : str
    :return                 : main latex file with references to inputs replaced by inputs contents
    :rtype                  : str
    """

    def replace_input_ref_by_content(m):
        """ Returns content for a given input name

        :param m    : (implicit) matched group, name in \input macro
        :type m     : match object
        :return     : content of file referenced by \input{filename}
        :rtype      : str
        """
        return multiple_inputs[m.groups()[0]]

    return re.sub(r'\\input{(.*?)}', replace_input_ref_by_content, main_tex)