Repository: executablebooks/jupyter-book
File: jupyter_book/commands/__init__.py (Python)

Code before:
        allowed_keys = tuple(builder_dict.keys())
        _error(f"Value for --builder must be one of {allowed_keys}. Got '{builder}'")
    sphinx_builder = builder_dict[builder]

    # Table of contents
    if toc is None:
        if PATH_BOOK.joinpath("_toc.yml").exists():
            toc = PATH_BOOK.joinpath("_toc.yml")
        else:
            _error(
                "Couldn't find a Table of Contents file. To auto-generate "
                f"one, run\n\n\tjupyter-book toc {path_book}"
            )
    book_config["globaltoc_path"] = str(toc)

    # Configuration file
    path_config = config
    if path_config is None:
        # Check if there's a `_config.yml` file in the source directory
        if PATH_BOOK.joinpath("_config.yml").exists():
            path_config = str(PATH_BOOK.joinpath("_config.yml"))

    if path_config:
        if not Path(path_config).exists():
            raise ValueError(f"Config file path given, but not found: {path_config}")
        config_yaml = yaml.safe_load(Path(path_config).read_text())

    # Builder-specific overrides
    if builder == "pdfhtml":
        book_config["html_theme_options"] = {"single_page": True}

    latex_config = None
    if builder == "pdflatex":
        if "latex" in config_yaml.keys():
            latex_config = config_yaml.pop("latex")
        if "title" in config_yaml.keys():
            # Note: a latex_documents specified title takes precendence
            # over a top level title
            if (
                latex_config is not None
                and "latex_documents" in latex_config.keys()
                and "title" not in latex_config["latex_documents"].keys()
            ):
                latex_config["latex_documents"]["title"] = config_yaml["title"]
            else:
                latex_config = {"latex_documents": {"title": config_yaml["title"]}}

    BUILD_PATH = path_output if path_output is not None else PATH_BOOK
    BUILD_PATH = Path(BUILD_PATH).joinpath("_build")
    if builder in ["html", "pdfhtml", "linkcheck"]:
        OUTPUT_PATH = BUILD_PATH.joinpath("html")

Review comment (suggestion):
Unless I've missed something, it seems like the only reason `_config.yml` (or whatever book-specific configuration is supplied by the user via the `--config` flag) is read is to build the `latex_config`. I haven't traced this all the way through, but might this result in ordering issues for the latex-specific config vals (since both `path_config`, and `latex_config` are passed into `build_sphinx`)? I guess it's necessary because the `--builder` flag dictates whether the latex config values are relevant.

Code after:
        _error(f"Value for --builder must be one of {allowed_keys}. Got '{builder}'")
    sphinx_builder = builder_dict[builder]

    # Table of contents
    if toc is None:
        if PATH_BOOK.joinpath("_toc.yml").exists():
            toc = PATH_BOOK.joinpath("_toc.yml")
        else:
            _error(
                "Couldn't find a Table of Contents file. To auto-generate "
                f"one, run\n\n\tjupyter-book toc {path_book}"
            )
    book_config["globaltoc_path"] = str(toc)

    # Configuration file
    path_config = config
    if path_config is None:
        # Check if there's a `_config.yml` file in the source directory
        if PATH_BOOK.joinpath("_config.yml").exists():
            path_config = str(PATH_BOOK.joinpath("_config.yml"))

    if path_config:
        if not Path(path_config).exists():
            raise ValueError(f"Config file path given, but not found: {path_config}")

    # Builder-specific overrides
    if builder == "pdfhtml":
        book_config["html_theme_options"] = {"single_page": True}

    BUILD_PATH = path_output if path_output is not None else PATH_BOOK
    BUILD_PATH = Path(BUILD_PATH).joinpath("_build")
    if builder in ["html", "pdfhtml", "linkcheck"]:
        OUTPUT_PATH = BUILD_PATH.joinpath("html")
    elif builder in ["latex", "pdflatex"]:
        OUTPUT_PATH = BUILD_PATH.joinpath("latex")

    # Now call the Sphinx commands to build
    exc = build_sphinx(
        PATH_BOOK,
        OUTPUT_PATH,
        noconfig=True,
        path_config=path_config,
        confoverrides=book_config,
        builder=sphinx_builder,
        warningiserror=warningiserror,
    )

    if exc:
        if builder == "linkcheck":
            _error(
                "The link checker either didn't finish or found broken links.\n"