<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def command(engine, format, filepath=None, renderer=None, formatter=None):
 """Return args list for ``subprocess.Popen`` and name of the rendered file."""

    if formatter is not None and renderer is None:
        raise RequiredArgumentError('formatter given without renderer')

    if engine not in ENGINES:
        raise ValueError('unknown engine: %r' % engine)
    if format not in FORMATS:
        raise ValueError('unknown format: %r' % format)
    if renderer is not None and renderer not in RENDERERS:
        raise ValueError('unknown renderer: %r' % renderer)
    if formatter is not None and formatter not in FORMATTERS:
        raise ValueError('unknown formatter: %r' % formatter)

    format_arg = [s for s in (format, renderer, formatter) if s is not None]
    suffix = '.'.join(reversed(format_arg))
    format_arg = ':'.join(format_arg)

    cmd = [engine, '-T%s' % format_arg]
    rendered = None
    if filepath is not None:
        cmd.extend(['-O', filepath])
        rendered = '%s.%s' % (filepath, suffix)

    return cmd, rendered