def tidy(self):
try:<EOL><INDENT>self.tags.sort(lambda x, y: cmp(len(x), len(y)))<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>for t in self.tasks:<EOL><INDENT>t.tidy()<EOL><DEDENT><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>for p in self.projects:<EOL><INDENT>p.tidy()<EOL><DEDENT><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>if self.content:<EOL><INDENT>if self.parent:<EOL><INDENT>self.content = ("<STR_LIT:\n>").join(self.to_string(<EOL>indentLevel=<NUM_LIT:0>).split("<STR_LIT:\n>")[<NUM_LIT:1>:])<EOL><DEDENT>else:<EOL><INDENT>regex = re.compile(r'<STR_LIT>')<EOL>while "<STR_LIT>" in self.content:<EOL><INDENT>self.content = regex.sub("<STR_LIT:\n>", self.content)<EOL><DEDENT><DEDENT><DEDENT>if not self.parent:<EOL><INDENT>self.content = self.to_string(<EOL>indentLevel=<NUM_LIT:0>, title=False)<EOL><DEDENT>return None<EOL>
*Tidy this taskpapaer object so that sub-objects appear in this order: title, tags, notes, tasks, projects*

        **Return:**
            - ``None``

        **Usage:**

           When a taskpaper document is opened it is tidied by default. To tidy the document object (or project or task) use the command:

            .. code-block:: python

                doc.tidy()