From d7e6ac590b10409100f1a20de1eca55f5911dbe1 Mon Sep 17 00:00:00 2001 From: Oscar Levin Date: Sun, 23 Nov 2025 18:43:21 -0700 Subject: [PATCH 1/2] add latex-source attribute for manifest --- CHANGELOG.md | 4 ++++ pretext/project/__init__.py | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5dfc6e6..127331a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ Instructions: Add a subsection under `[Unreleased]` for additions, fixes, change ## [Unreleased] +### Added + +- The `latex-source` attribute, set to anything except "no", on a target with format `pdf` will copy latex source files to output directory. + ## [2.32.0] - 2025-11-23 Includes updates to core through commit: [ce20f15](https://github.com/PreTeXtBook/pretext/commit/ce20f15d525f2d1e7a3c3fb8da3bb5fa9d16d3ee) diff --git a/pretext/project/__init__.py b/pretext/project/__init__.py index 6a7f00de..e8a4ca00 100644 --- a/pretext/project/__init__.py +++ b/pretext/project/__init__.py @@ -132,6 +132,18 @@ class Target(pxml.BaseXmlModel, tag="target", search_mode=SearchMode.UNORDERED): latex_engine: LatexEngine = pxml.attr( name="latex-engine", default=LatexEngine.XELATEX ) + # Flag to indicate whether to include LaTeX source files in the output directory when building a PDF target. + latex_source: t.Optional[str] = pxml.attr(name="latex-source", default=None) + + @field_validator("latex_source") + @classmethod + def latex_source_validator( + cls, v: t.Optional[str] + ) -> bool: + if v is None: + return False + return v.lower() != "no" + braille_mode: BrailleMode = pxml.attr( name="braille-mode", default=BrailleMode.EMBOSS ) @@ -769,6 +781,9 @@ def build( ) log.debug(e, exc_info=True) elif self.format == Format.PDF: + # Include latex source files if requested. + if self.latex_source: + latex = True core.pdf( xml=self.source_abspath(), pub_file=self.publication_abspath().as_posix(), @@ -777,7 +792,7 @@ def build( out_file=out_file, dest_dir=self.output_dir_abspath().as_posix(), method=self.latex_engine, - outputs="all" if latex else "pdf", + outputs="all" if latex else "pdf-only", ) elif self.format == Format.LATEX: core.pdf( From f0490ba395568b0b0acc80c4df0daa697e31335b Mon Sep 17 00:00:00 2001 From: Oscar Levin Date: Sun, 23 Nov 2025 18:58:12 -0700 Subject: [PATCH 2/2] format --- pretext/project/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pretext/project/__init__.py b/pretext/project/__init__.py index e8a4ca00..9c298622 100644 --- a/pretext/project/__init__.py +++ b/pretext/project/__init__.py @@ -137,9 +137,7 @@ class Target(pxml.BaseXmlModel, tag="target", search_mode=SearchMode.UNORDERED): @field_validator("latex_source") @classmethod - def latex_source_validator( - cls, v: t.Optional[str] - ) -> bool: + def latex_source_validator(cls, v: t.Optional[str]) -> bool: if v is None: return False return v.lower() != "no"