Plugin API¶
Plugins bundle opinionated HTML post-processors and asset helpers so you can extend TeXSmith without patching the core read → IR → write pipeline.
texsmith.plugins exposes a namespace package populated by the MkDocs hook in
docs/hooks/mkdocs_hooks.py, re-exporting the maintained plugin modules under
texsmith.adapters.plugins.
Loading plugins¶
import texsmith.plugins.snippet # noqa: F401
from texsmith import Document, convert_documents
bundle = convert_documents([Document.from_markdown(Path("intro.md"))])
Authoring your own plugin¶
- Create a module (e.g.,
texsmith.plugins.acme) exposing a Markdown extension and/or the HTML rewriting helpers your documents need. - Declare entry points or instruct consumers to
import texsmith.plugins.acmebefore rendering. - Optionally provide a MkDocs plugin/hook so documentation builds load your plugin automatically.
Keep plugin modules small and focused.
Reference¶
Compatibility layer exposing plugin integrations to documentation.
TeXSmith consolidated its plugin utilities under
texsmith.adapters.plugins. mkdocstrings still references the historical
texsmith.plugins namespace, so we re-export the maintained modules here to
keep the public import path available.
Plugin rendering fenced snippet blocks into standalone PDF assets.
SnippetBlock
dataclass
¶
SnippetBlock(
content: str | None,
front_matter: dict[str, Any],
sources: list[Path],
layout: tuple[int, int] | None,
preview_dogear: bool,
preview_fold_size: float | None,
template_id: str | None,
cwd: Path | None,
caption: str | None,
label: str | None,
figure_width: str | None,
template_overrides: dict[str, Any],
digest: str,
bibliography_files: list[Path],
promote_title: bool,
drop_title: bool,
suppress_title_metadata: bool,
)
Parsed representation of a snippet fence.
asset_filename ¶
asset_filename(digest: str, suffix: str) -> str
Return the deterministic filename for a snippet artefact.
Source code in src/texsmith/adapters/plugins/snippet.py
470 471 472 | |
ensure_snippet_assets ¶
ensure_snippet_assets(
block: SnippetBlock,
*,
output_dir: Path,
source_path: Path | str | None = None,
emitter: DiagnosticEmitter | None = None,
) -> _SnippetAssets
Render snippet assets into the provided directory when missing.
Source code in src/texsmith/adapters/plugins/snippet.py
1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 | |
render_snippet_latex ¶
render_snippet_latex(
html: str, context: RenderContextLike
) -> str
Render a preserved .snippet HTML element to a LATEX figure string.
Single entry point used by the LATEX writer: it unwraps the stored snippet markup, parses the fence (resolving file inclusions against the document via the render context), compiles the preview assets, registers the artefact and emits the figure. Keeps all snippet-HTML handling inside this plugin instead of leaking BeautifulSoup and the block internals into the writer.
Source code in src/texsmith/adapters/plugins/snippet.py
1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 | |
rewrite_html_snippets ¶
rewrite_html_snippets(
html: str,
resolver: Callable[[SnippetBlock], tuple[str, str]],
*,
source_path: Path | str | None = None,
) -> str
Replace snippet fences in an HTML fragment with linked previews.
Source code in src/texsmith/adapters/plugins/snippet.py
1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 | |