def add_task(<EOL>self,<EOL>title,<EOL>tags=None):
self.refresh<EOL>task = title.strip()<EOL>if task[:<NUM_LIT:2>] != "<STR_LIT>":<EOL><INDENT>task = "<STR_LIT>" + task<EOL><DEDENT>if tags:<EOL><INDENT>if isinstance(tags, list):<EOL><INDENT>if "<STR_LIT:@>" not in tags[<NUM_LIT:0>]:<EOL><INDENT>tagString = ("<STR_LIT>").join(tags)<EOL>tagString = "<STR_LIT:@>" + tagString<EOL><DEDENT>else:<EOL><INDENT>tagString = ("<STR_LIT:U+0020>").join(tags)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>tagString = tags<EOL><DEDENT>tagString = tagString.strip()<EOL>task += "<STR_LIT:U+0020>" + tagString<EOL><DEDENT>newTask = self._get_object(<EOL>regex=re.compile(<EOL>r'<STR_LIT>', re.UNICODE),<EOL>objectType="<STR_LIT>",<EOL>content=task<EOL>)<EOL>oldContent = self.to_string(indentLevel=<NUM_LIT:1>)<EOL>newContent = self.to_string(<EOL>indentLevel=<NUM_LIT:1>, tasks=self.tasks + newTask)<EOL>if self.parent:<EOL><INDENT>doc = self.parent._update_document_tree(<EOL>oldContent=oldContent,<EOL>newContent=newContent<EOL>)<EOL><DEDENT>self.content = self.content.replace(self.to_string(indentLevel=<NUM_LIT:0>, title=False), self.to_string(<EOL>indentLevel=<NUM_LIT:0>, title=False, tasks=self.tasks + newTask))<EOL>doc = self<EOL>while doc.parent:<EOL><INDENT>doc = doc.parent<EOL><DEDENT>doc.refresh<EOL>if not self.parent:<EOL><INDENT>parent = self<EOL><DEDENT>else:<EOL><INDENT>parent = doc.get_project(self.title)<EOL><DEDENT>if not parent:<EOL><INDENT>parent = doc.get_task(self.title)<EOL><DEDENT>thisTask = parent.get_task(title)<EOL>self.refresh<EOL>return thisTask<EOL>
*Add a task to this taskpaper object*

        **Key Arguments:**
            - ``title`` -- the title for the task.
            - ``tags`` -- tag string (*'@one @two(data)'*) or list of tags (*['one', 'two(data)']*)

        **Return:**
            - ``task`` -- the new taskpaper task object

        **Usage:**

            To add a task to an object (document, project, or task) use:

            .. code-block:: python

                newTask = doc.add_task("this is a task I added", "@with @tags")