From d27d7c0fc9106e9930a3c5906525accd78b80298 Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 8 Aug 2021 22:45:24 -0400 Subject: [PATCH] Add ability to filter doc making by section Builds on what we did before in order to filter by chapter and part. This now gives a us a good ability to QUICKLY iterate over problems in making the doc or in asymptote problem.s --- mathics/doc/common_doc.py | 28 ++++++++++++++++++++++------ mathics/doc/tex/doc2latex.py | 14 +++++++++++++- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/mathics/doc/common_doc.py b/mathics/doc/common_doc.py index 0c347432d..87ccedc24 100644 --- a/mathics/doc/common_doc.py +++ b/mathics/doc/common_doc.py @@ -695,7 +695,12 @@ def get_tests(self): return def latex( - self, doc_data: dict, quiet=False, filter_parts=None, filter_chapters=None + self, + doc_data: dict, + quiet=False, + filter_parts=None, + filter_chapters=None, + filter_sections=None, ) -> str: """Render self as a LaTeX string and return that. @@ -708,7 +713,12 @@ def latex( if filter_parts: if part.title not in filter_parts: continue - text = part.latex(doc_data, quiet, filter_chapters=filter_chapters) + text = part.latex( + doc_data, + quiet, + filter_chapters=filter_chapters, + filter_sections=filter_sections, + ) if part.is_appendix and not appendix: appendix = True text = "\n\\appendix\n" + text @@ -1139,7 +1149,9 @@ def __str__(self): "\n".join(str(chapter) for chapter in self.chapters), ) - def latex(self, doc_data: dict, quiet=False, filter_chapters=None) -> str: + def latex( + self, doc_data: dict, quiet=False, filter_chapters=None, filter_sections=None + ) -> str: """Render this Part object as LaTeX string and return that. `output` is not used here but passed along to the bottom-most @@ -1147,7 +1159,7 @@ def latex(self, doc_data: dict, quiet=False, filter_chapters=None) -> str: """ result = "\n\n\\part{%s}\n\n" % escape_latex(self.title) + ( "\n\n".join( - chapter.latex(doc_data, quiet) + chapter.latex(doc_data, quiet, filter_sections=filter_sections) for chapter in self.chapters if not filter_chapters or chapter.title in filter_chapters ) @@ -1176,7 +1188,7 @@ def __str__(self): def all_sections(self): return sorted(self.sections + self.guide_sections) - def latex(self, doc_data: dict, quiet=False) -> str: + def latex(self, doc_data: dict, quiet=False, filter_sections=None) -> str: """Render this Chapter object as LaTeX string and return that. `output` is not used here but passed along to the bottom-most @@ -1196,7 +1208,11 @@ def latex(self, doc_data: dict, quiet=False) -> str: ("\n\n\\chapter{%(title)s}\n\\chapterstart\n\n%(intro)s") % {"title": escape_latex(self.title), "intro": intro}, "\\chaptersections\n", - "\n\n".join(section.latex(doc_data, quiet) for section in self.sections), + "\n\n".join( + section.latex(doc_data, quiet) + for section in self.sections + if not filter_sections or section.title in filter_sections + ), "\n\\chapterend\n", ] return "".join(chapter_sections) diff --git a/mathics/doc/tex/doc2latex.py b/mathics/doc/tex/doc2latex.py index 081e9f515..948621cd4 100755 --- a/mathics/doc/tex/doc2latex.py +++ b/mathics/doc/tex/doc2latex.py @@ -86,7 +86,9 @@ def try_cmd(cmd_list: tuple, stdout_or_stderr: str) -> str: return versions -def write_latex(doc_data, quiet=False, filter_parts=None, filter_chapters=None): +def write_latex( + doc_data, quiet=False, filter_parts=None, filter_chapters=None, filter_sections=None +): documentation = MathicsMainDocumentation() if not quiet: print(f"Writing LaTeX document to {DOC_LATEX_FILE}") @@ -96,6 +98,7 @@ def write_latex(doc_data, quiet=False, filter_parts=None, filter_chapters=None): quiet=quiet, filter_parts=filter_parts, filter_chapters=filter_chapters, + filter_sections=filter_sections, ) content = content.encode("utf-8") doc.write(content) @@ -127,6 +130,14 @@ def main(): help="only test CHAPTER(s). " "You can list multiple chapters by adding a comma (and no space) in between chapter names.", ) + parser.add_argument( + "--sections", + "-s", + dest="sections", + metavar="SECTION", + help="only test SECTION(s). " + "You can list multiple chapters by adding a comma (and no space) in between chapter names.", + ) parser.add_argument( "--parts", "-p", @@ -149,6 +160,7 @@ def main(): quiet=args.quiet, filter_parts=args.parts, filter_chapters=args.chapters, + filter_sections=args.sections, )