Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add external converter to image generation signatures #891

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions pretext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,6 @@ def build(
default=False,
help="Generate all possible asset formats rather than just the defaults for the specified target.",
)
@click.option(
"--non-pymupdf",
is_flag=True,
default=False,
help="Used to revert to non-pymupdf (legacy) method for generating svg and png.",
)
@click.pass_context
@nice_errors
def generate(
Expand All @@ -639,7 +633,6 @@ def generate(
all_formats: bool,
only_changed: bool,
xmlid: Optional[str],
non_pymupdf: bool,
) -> None:
"""
Generate specified (or all) assets for the default target (first target in "project.ptx"). Asset "generation" is typically
Expand Down Expand Up @@ -676,7 +669,6 @@ def generate(
all_formats=all_formats,
only_changed=only_changed, # Unless requested, generate all assets, so don't check the cache.
xmlid=xmlid,
non_pymupdf=non_pymupdf,
)
log.info("Finished generating assets.\n")
except ValidationError as e:
Expand Down
7 changes: 4 additions & 3 deletions pretext/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ def build(
extra_xsl=custom_xsl,
out_file=out_file,
dest_dir=self.output_dir_abspath().as_posix(),
# rs_query_methods=None,
)
try:
codechat.map_path_to_xml_id(
Expand Down Expand Up @@ -808,15 +809,13 @@ def generate_assets(
all_formats: bool = False,
only_changed: bool = True,
xmlid: t.Optional[str] = None,
non_pymupdf: bool = False,
) -> None:
"""
Generates assets for the current target. Options:
- requested_asset_types: optional list of which assets to generate (latex-image, sagemath, asymptote, etc). Default will generate all asset types found in target.
- all_formats: boolean to decide whether the output format of the assets will be just those that the target format uses (default/False) or all possible output formats for that asset (True).
- only_changed: boolean. When True (default), function will only generate assets that have changed since last generation. When False, all assets will be built (hash table will be ignored).
- xmlid: optional string to specify the root of the subtree of the xml document to generate assets within.
- non_pymupdf: temporary boolean to revert to legacy alternative image generation without pymupdf (and use old external programs).
"""
# Two "ensure" functions call generate to get just a single asset. Every generation step other than webwork must have webwork generated, so unless we are "ensuring" webwork, we will need to call ensure webwork. Note if this function was called with just webwork, then we would move down and actually build webwork.
if requested_asset_types != ["webwork"]:
Expand Down Expand Up @@ -1008,7 +1007,7 @@ def generate_assets(
dest_dir=self.generated_dir_abspath() / "latex-image",
outformat=outformat,
method=self.latex_engine,
pyMuPDF=not (non_pymupdf),
ext_converter=None,
)
successful_assets.append(("latex-image", id))
except Exception as e:
Expand All @@ -1026,6 +1025,7 @@ def generate_assets(
dest_dir=self.generated_dir_abspath() / "asymptote",
outformat=outformat,
method=self.asy_method,
ext_converter=None,
)
successful_assets.append(("asymptote", id))
except Exception as e:
Expand All @@ -1042,6 +1042,7 @@ def generate_assets(
xmlid_root=id,
dest_dir=self.generated_dir_abspath() / "sageplot",
outformat=outformat,
ext_converter=None,
)
successful_assets.append(("sageplot", id))
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions pretext/project/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class Executables(pxml.BaseXmlModel, tag="executables"):
latex: str = pxml.attr(default="latex")
pdflatex: str = pxml.attr(default="pdflatex")
xelatex: str = pxml.attr(default="xelatex")
pdfsvg: str = pxml.attr(default="pdf2svg")
pdfsvg: t.Optional[str] = pxml.attr(default="pdf2svg")
# If not specified, use a local executable if it exists; if it doesn't exist, choose `None`, which allows the generation logic to use the server instead.
asy: t.Optional[str] = pxml.attr(default=shutil.which("asy"))
# The same applies to Sage.
sage: t.Optional[str] = pxml.attr(default=shutil.which("sage"))
mermaid: str = pxml.attr(default="mmdc")
pdfpng: str = pxml.attr(default="convert")
pdfpng: t.Optional[str] = pxml.attr(default="convert")
pdfeps: str = pxml.attr(default="pdftops")
node: str = pxml.attr(default="node")
liblouis: str = pxml.attr(default="file2brl")
Expand Down
Loading