Find the tex article in the current directory that can be considered
    a root. We do this by searching contents for ``'\documentclass'``.

    Parameters
    ----------
    base_dir : str
        Directory to search for LaTeX documents, relative to the current
        working directory.

    Returns
    -------
    tex_path : str
        Path to the root tex document relative to the current
        working directory.

def find_root_tex_document(base_dir="."):
    """Find the tex article in the current directory that can be considered
    a root. We do this by searching contents for ``'\documentclass'``.

    Parameters
    ----------
    base_dir : str
        Directory to search for LaTeX documents, relative to the current
        working directory.

    Returns
    -------
    tex_path : str
        Path to the root tex document relative to the current
        working directory.
    """
    log = logging.getLogger(__name__)
    for tex_path in iter_tex_documents(base_dir=base_dir):
        with codecs.open(tex_path, 'r', encoding='utf-8') as f:
            text = f.read()
            if len(docclass_pattern.findall(text)) > 0:
                log.debug("Found root tex {0}".format(tex_path))
                return tex_path
    log.warning("Could not find a root .tex file")
    raise RootNotFound