from typing import Dict
from typing import Any


def merge(d1: Dict, d2: Dict) -> Dict:
    """Merge two raw datasets into one.

    Parameters
    ----------
    d1 : Dict
    d2 : Dict

    Returns
    -------
    Dict
    """
    if d1["formula_id2latex"] is None:
        formula_id2latex: Dict[str, Any] = {}
    else:
        formula_id2latex = d1["formula_id2latex"].copy()
    formula_id2latex.update(d2["formula_id2latex"])
    handwriting_datasets = d1["handwriting_datasets"]
    for dataset in d2["handwriting_datasets"]:
        handwriting_datasets.append(dataset)
    return {
        "formula_id2latex": formula_id2latex,
        "handwriting_datasets": handwriting_datasets,
    }