def construct_engine_options(ts_directives, tm_engine_options, synctex=True):
    """Construct a string of command line options.

    The options come from two different sources:

        - %!TEX TS-options directive in the file
        - Options specified in the preferences of the LaTeX bundle

    In any case ``nonstopmode`` is set as is ``file-line-error-style``.

    Arguments:

        ts_directives

            A dictionary containing typesetting directives. If it contains the
            key ``TS-options`` then this value will be used to construct the
            options.

        tm_engine_options

            A string containing the default typesetting options set inside
            TextMate. This string will be used to extend the options only if
            ts_directives does not contain typesetting options. Otherwise the
            settings specified in this item will be ignored.

        synctex

            Specifies if synctex should be used for typesetting or not.


    Returns: ``str``

    Examples:

        >>> print(construct_engine_options({}, '', True))
        -interaction=nonstopmode -file-line-error-style -synctex=1
        >>> print(construct_engine_options({'TS-options': '-draftmode'},
        ...                                 '', False))
        -interaction=nonstopmode -file-line-error-style -draftmode
        >>> print(construct_engine_options({'TS-options': '-draftmode'},
        ...                                 '-8bit', False))
        -interaction=nonstopmode -file-line-error-style -draftmode
        >>> print(construct_engine_options({}, '-8bit'))
        -interaction=nonstopmode -file-line-error-style -synctex=1 -8bit

    """
    options = "-interaction=nonstopmode -file-line-error-style{}".format(
        ' -synctex=1' if synctex else '')

    if 'TS-options' in ts_directives:
        options += ' {}'.format(ts_directives['TS-options'])
    else:
        options += ' {}'.format(tm_engine_options) if tm_engine_options else ''

    return options