'Returns a filtered list with copies of each command entry
in the document
Arguments:
how -- how it should be filtered, possible types are:
string - only commands, which equals this string
list of string - only commands which are in this list
function of command->bool - should return true iff the command
should be in the result
flags -- flags to filter the commands, which should for a be used over
over filtering the commands on your own (optimization/caching).
Possible flags are:
NO_BEGIN_END_COMMANDS - removes all begin and end commands
i.e.: exclude \begin{} and \end{} commands
ONLY_COMMANDS_WITH_ARGS - removes all commands without arguments
i.e.: allows \com{args} and \com{} but not \com
default flags are:
NO_BEGIN_END_COMMANDS | ONLY_COMMANDS_WITH_ARGS
Returns:
A list of all commands, which are preprocessed with the flags'

def filter_commands(self, how, flags=DEFAULT_FLAGS):

    if isinstance(how, strbase):
        def command_filter(c):
            return (c.command == how)
    elif (type(how) is list):
        def command_filter(c):
            return (c.command in how)
    elif callable(how):
        def command_filter(c):
            return how(c)
    else:
        raise Exception(('Unsupported    filter    type:    ' + str(type(how))))
    com = self._commands(flags)
    return tuple(filter(command_filter, com))
