def _preamble(layout='layered'):
    """Return preamble and begin/end document."""
    if layout == 'layered':
        layout_lib = 'layered'
    elif layout == 'spring':
        layout_lib = 'force'
    else:
        raise ValueError(
            'Unknown which library contains layout: {s}'.format(s=layout))
    document = (
        '\documentclass{{standalone}}\n'
        '\usepackage{{amsmath}}\n'
        '\n'
        '\usepackage{{tikz}}\n'
        '\usetikzlibrary{{graphs,graphs.standard,'
        'graphdrawing,quotes,shapes}}\n'
        '\usegdlibrary{{ {layout_lib} }}\n').format(
            layout_lib=layout_lib)
    return document