pygacity.generate.block module

LaTeX compound block class for pygacity

class pygacity.generate.block.LatexBlock(block_specs: dict)[source]

Bases: object

A LaTeX block with support for external source files, substitutions, and embedded pythontex code.

copy_referenced_configs(output_dir: str)[source]

Copies any referenced configuration files to the specified output directory.

Parameters:

output_dir (str) – the directory to copy configuration files to

Returns:

list of paths to the copied configuration files

Return type:

list of str

classmethod from_specs(block_specs: dict) list[LatexBlock][source]

Factory that returns a list of LatexBlocks. Handles the old-style ‘enumerate’ shorthand: if block_specs has an ‘enumerate’ key whose value is a list, each item is treated as a question block with question_number assigned sequentially starting from 1.

load() LatexBlock[source]

Loads the block’s text contents from source files if specified, processes substitutions to identify keys, and recursively loads child blocks.

Returns:

the loaded block instance

Return type:

LatexCompoundBlock

resources_root: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pygacity/envs/latest/lib/python3.12/site-packages/pygacity/resources')

The root path for pygacity resources

substitute(super_substitutions: dict = {}, match_all: bool = True)[source]

Applies substitutions to the block’s text contents and recursively to its children.

Parameters:
  • super_substitutions (dict, optional) – substitutions from parent blocks

  • match_all (bool, optional) – if True, raises KeyError if any substitution key has no associated value

substitution_delimiters: tuple = ('<<<', '>>>')

The delimiters for substitution keys in LaTeX text

templates_dir: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pygacity/envs/latest/lib/python3.12/site-packages/pygacity/resources/templates')

The directory containing LaTeX template files

pygacity.generate.block.path_resolver(filename: str, search_paths: list[Path] = [], ext: str = '') Path[source]

Resolves a filename to a Path object, checking the local directory first, then searching the provided search paths. If the file is not found, raises a FileNotFoundError.

Parameters:
  • filename (str) – the name of the file to locate

  • search_paths (list of Path, optional) – list of directories to search if the file is not found locally

  • ext (str, optional) – file extension to append if not already present

Returns:

the resolved Path object for the file

Return type:

Path