Skip to content

Commit

Permalink
Merge pull request #1535 from mathics/selective-doc-sections
Browse files Browse the repository at this point in the history
Add ability to filter doc making by section
  • Loading branch information
rocky authored Aug 9, 2021
2 parents af36515 + d27d7c0 commit 0b92840
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
28 changes: 22 additions & 6 deletions mathics/doc/common_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -1139,15 +1149,17 @@ 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
level in getting expected test results.
"""
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
)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion mathics/doc/tex/doc2latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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)
Expand Down Expand Up @@ -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",
Expand All @@ -149,6 +160,7 @@ def main():
quiet=args.quiet,
filter_parts=args.parts,
filter_chapters=args.chapters,
filter_sections=args.sections,
)


Expand Down

0 comments on commit 0b92840

Please sign in to comment.