satz 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
satz-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 waidring
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
satz-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,172 @@
1
+ Metadata-Version: 2.4
2
+ Name: satz
3
+ Version: 0.1.0
4
+ Summary: A LaTeX-like markup language with a Python backend that compiles documents to PDF.
5
+ Author: waidring
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/waidring/satz
8
+ Project-URL: Repository, https://github.com/waidring/satz
9
+ Project-URL: Issues, https://github.com/waidring/satz/issues
10
+ Keywords: typesetting,markup,pdf,latex,documents
11
+ Classifier: Development Status :: 2 - Pre-Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Text Processing :: Markup
16
+ Classifier: Topic :: Printing
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: reportlab>=4.0
21
+ Requires-Dist: matplotlib>=3.7
22
+ Requires-Dist: pillow
23
+ Dynamic: license-file
24
+
25
+ # satz — a LaTeX-like markup language with a Python backend
26
+
27
+ Markup commands are ordinary Python functions; the document is compiled by
28
+ Python, not TeX. *Satz* is German for typesetting — and for theorem.
29
+
30
+ > Early alpha: the syntax and the Python API will still change.
31
+
32
+ ## Install
33
+
34
+ pip install satz
35
+
36
+ This installs the dependencies (reportlab, matplotlib, pillow) and the `satz` command.
37
+
38
+ To work on satz itself, install from a clone instead (editable, so your changes
39
+ take effect at once):
40
+
41
+ git clone https://github.com/waidring/satz.git
42
+ cd satz
43
+ pip install -e .
44
+
45
+ ## Use
46
+
47
+ A sample document using every command is in the
48
+ [examples folder](https://github.com/waidring/satz/tree/main/examples) of the repository.
49
+
50
+ satz content.tex # -> content.pdf
51
+ satz content.tex --dump # show the structure from pass 1
52
+ satz --commands # list every command
53
+ python -m satz content.tex # same thing without the command on PATH
54
+
55
+ ## Syntax in one screen
56
+
57
+ ```
58
+ \geometry{a4, margin=25mm} % comment
59
+ \use{si} % load a package
60
+
61
+ \title{My Report}
62
+ \author{A. Author}
63
+
64
+ \section{Introduction} % \chapter, \section, \subsection
65
+
66
+ Plain text. A blank line starts a new paragraph. \bold{bold}, \italic{italic},
67
+ \mono{code}, \underline{under}, \color{red}{red}, \size{14pt}{big},
68
+ \letterspacing{1pt}{SPACED}, H\sub{2}O, 2\sup{nd}. Non-breaking space: Fig.~1.
69
+ Inline math $\omega_0 = \sqrt{k/m}$ and units \qty{9.81}{m/s^2}.
70
+
71
+ \equation{ m \ddot{x} + c \dot{x} + k x = F(t) } % numbered
72
+ $$ \int_0^\infty e^{-st} f(t) \, dt $$ % unnumbered
73
+
74
+ \table{
75
+ | Name | Value |
76
+ |:-----|------:|
77
+ | Mass | 1.2 |
78
+ }{Caption.}
79
+
80
+ \csvtable{data.csv}{Caption.}
81
+
82
+ \list{
83
+ - bullet item
84
+ - another one
85
+ }
86
+ \numlist{ ... } % same, numbered
87
+
88
+ \figure{plot.png}{Caption.}
89
+ \newpage
90
+ ```
91
+
92
+ Only these characters are special: `\ { } $ % ~` and, inside tables, `|`.
93
+ Write them literally as `\\ \{ \} \$ \% \~ \|`.
94
+
95
+ ## How it works
96
+
97
+ content.tex
98
+ | parser.py text -> nodes: commands, text, $math$, paragraph breaks
99
+ v
100
+ | build.py PASS 1: every command runs its Python function and
101
+ | commands.py adds blocks / returns styled text
102
+ v
103
+ Document plain data (document.py) -- see it with --dump
104
+ | render.py PASS 2: lay out and draw on a ReportLab canvas
105
+ | layout.py (line breaking, justification)
106
+ | mathrender.py (formulas as vector outlines via matplotlib)
107
+ v
108
+ content.pdf
109
+
110
+ | file | what it is |
111
+ |---|---|
112
+ | `satz/parser.py` | the only place that knows the syntax |
113
+ | `satz/inline.py` | styled text runs; how nested styles combine |
114
+ | `satz/commands.py` | command registry + all built-in commands |
115
+ | `satz/build.py` | pass 1 and the `ctx` object commands receive |
116
+ | `satz/document.py` | node types, page geometry, numbering |
117
+ | `satz/layout.py` | words, lines, greedy line breaking |
118
+ | `satz/mathrender.py` | math measuring and drawing |
119
+ | `satz/fonts.py` | font families (STIX, DejaVu, your own) |
120
+ | `satz/render.py` | pass 2, **STYLES** and **OPTIONS** |
121
+ | `satz/packages/` | packages loadable with `\use{}` (`si.py`) |
122
+ | `satz/cli.py` | the `satz` command |
123
+ | `examples/` | sample document using every command |
124
+
125
+ ## Writing a command
126
+
127
+ ```python
128
+ from satz import command, restyle, Run
129
+
130
+ @command("todo", "content", inline=True)
131
+ def todo(ctx, body):
132
+ return restyle([Run("TODO: ")] + body, color="red", bold=True)
133
+ ```
134
+
135
+ Save it as `mycommands.py` next to your document and write `\use{mycommands}`.
136
+ That is the whole mechanism.
137
+
138
+ * Argument types: `content` (formatted text → list of runs), `text` (plain
139
+ string), `raw` (verbatim, e.g. a table body). A trailing `?` makes an
140
+ argument optional: `@command("figure", "text", "content?")`.
141
+ * Inline commands return runs; block commands call `ctx.add(block)`.
142
+ * `ctx` gives you `ctx.doc`, `ctx.content(string)`, `ctx.path(file)`,
143
+ `ctx.length("3mm")` and `ctx.error("message")` (reported with the line
144
+ number).
145
+
146
+ `\use{name}` looks for `name.py` next to the document, then in
147
+ `satz/packages/`, then for an installed Python module.
148
+
149
+ ## Changing the look
150
+
151
+ `satz/render.py`:
152
+
153
+ ```python
154
+ STYLES["body"] = Style(size=11, leading=15, align="justify")
155
+ STYLES["section"] = Style(family="sans", size=13, bold=True, space_before=12)
156
+ OPTIONS["chapter_starts_new_page"] = False
157
+ ```
158
+
159
+ Fonts: `serif` (STIX, matches the math), `sans` and `mono` (DejaVu) ship
160
+ with matplotlib. Add your own with `satz.fonts.register_family(...)`.
161
+
162
+ ## Current limits
163
+
164
+ Greedy line breaking, no hyphenation, no floats (a figure that doesn't fit
165
+ moves to the next page and leaves a gap), raster images only, flat lists,
166
+ and math limited to matplotlib's mathtext (no matrices or aligned
167
+ environments). All of these are on the roadmap.
168
+
169
+ ## License
170
+
171
+ MIT — see [LICENSE](https://github.com/waidring/satz/blob/main/LICENSE). Free to use, modify and sell, including in
172
+ commercial and closed-source products, as long as the copyright notice is kept.
satz-0.1.0/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # satz — a LaTeX-like markup language with a Python backend
2
+
3
+ Markup commands are ordinary Python functions; the document is compiled by
4
+ Python, not TeX. *Satz* is German for typesetting — and for theorem.
5
+
6
+ > Early alpha: the syntax and the Python API will still change.
7
+
8
+ ## Install
9
+
10
+ pip install satz
11
+
12
+ This installs the dependencies (reportlab, matplotlib, pillow) and the `satz` command.
13
+
14
+ To work on satz itself, install from a clone instead (editable, so your changes
15
+ take effect at once):
16
+
17
+ git clone https://github.com/waidring/satz.git
18
+ cd satz
19
+ pip install -e .
20
+
21
+ ## Use
22
+
23
+ A sample document using every command is in the
24
+ [examples folder](https://github.com/waidring/satz/tree/main/examples) of the repository.
25
+
26
+ satz content.tex # -> content.pdf
27
+ satz content.tex --dump # show the structure from pass 1
28
+ satz --commands # list every command
29
+ python -m satz content.tex # same thing without the command on PATH
30
+
31
+ ## Syntax in one screen
32
+
33
+ ```
34
+ \geometry{a4, margin=25mm} % comment
35
+ \use{si} % load a package
36
+
37
+ \title{My Report}
38
+ \author{A. Author}
39
+
40
+ \section{Introduction} % \chapter, \section, \subsection
41
+
42
+ Plain text. A blank line starts a new paragraph. \bold{bold}, \italic{italic},
43
+ \mono{code}, \underline{under}, \color{red}{red}, \size{14pt}{big},
44
+ \letterspacing{1pt}{SPACED}, H\sub{2}O, 2\sup{nd}. Non-breaking space: Fig.~1.
45
+ Inline math $\omega_0 = \sqrt{k/m}$ and units \qty{9.81}{m/s^2}.
46
+
47
+ \equation{ m \ddot{x} + c \dot{x} + k x = F(t) } % numbered
48
+ $$ \int_0^\infty e^{-st} f(t) \, dt $$ % unnumbered
49
+
50
+ \table{
51
+ | Name | Value |
52
+ |:-----|------:|
53
+ | Mass | 1.2 |
54
+ }{Caption.}
55
+
56
+ \csvtable{data.csv}{Caption.}
57
+
58
+ \list{
59
+ - bullet item
60
+ - another one
61
+ }
62
+ \numlist{ ... } % same, numbered
63
+
64
+ \figure{plot.png}{Caption.}
65
+ \newpage
66
+ ```
67
+
68
+ Only these characters are special: `\ { } $ % ~` and, inside tables, `|`.
69
+ Write them literally as `\\ \{ \} \$ \% \~ \|`.
70
+
71
+ ## How it works
72
+
73
+ content.tex
74
+ | parser.py text -> nodes: commands, text, $math$, paragraph breaks
75
+ v
76
+ | build.py PASS 1: every command runs its Python function and
77
+ | commands.py adds blocks / returns styled text
78
+ v
79
+ Document plain data (document.py) -- see it with --dump
80
+ | render.py PASS 2: lay out and draw on a ReportLab canvas
81
+ | layout.py (line breaking, justification)
82
+ | mathrender.py (formulas as vector outlines via matplotlib)
83
+ v
84
+ content.pdf
85
+
86
+ | file | what it is |
87
+ |---|---|
88
+ | `satz/parser.py` | the only place that knows the syntax |
89
+ | `satz/inline.py` | styled text runs; how nested styles combine |
90
+ | `satz/commands.py` | command registry + all built-in commands |
91
+ | `satz/build.py` | pass 1 and the `ctx` object commands receive |
92
+ | `satz/document.py` | node types, page geometry, numbering |
93
+ | `satz/layout.py` | words, lines, greedy line breaking |
94
+ | `satz/mathrender.py` | math measuring and drawing |
95
+ | `satz/fonts.py` | font families (STIX, DejaVu, your own) |
96
+ | `satz/render.py` | pass 2, **STYLES** and **OPTIONS** |
97
+ | `satz/packages/` | packages loadable with `\use{}` (`si.py`) |
98
+ | `satz/cli.py` | the `satz` command |
99
+ | `examples/` | sample document using every command |
100
+
101
+ ## Writing a command
102
+
103
+ ```python
104
+ from satz import command, restyle, Run
105
+
106
+ @command("todo", "content", inline=True)
107
+ def todo(ctx, body):
108
+ return restyle([Run("TODO: ")] + body, color="red", bold=True)
109
+ ```
110
+
111
+ Save it as `mycommands.py` next to your document and write `\use{mycommands}`.
112
+ That is the whole mechanism.
113
+
114
+ * Argument types: `content` (formatted text → list of runs), `text` (plain
115
+ string), `raw` (verbatim, e.g. a table body). A trailing `?` makes an
116
+ argument optional: `@command("figure", "text", "content?")`.
117
+ * Inline commands return runs; block commands call `ctx.add(block)`.
118
+ * `ctx` gives you `ctx.doc`, `ctx.content(string)`, `ctx.path(file)`,
119
+ `ctx.length("3mm")` and `ctx.error("message")` (reported with the line
120
+ number).
121
+
122
+ `\use{name}` looks for `name.py` next to the document, then in
123
+ `satz/packages/`, then for an installed Python module.
124
+
125
+ ## Changing the look
126
+
127
+ `satz/render.py`:
128
+
129
+ ```python
130
+ STYLES["body"] = Style(size=11, leading=15, align="justify")
131
+ STYLES["section"] = Style(family="sans", size=13, bold=True, space_before=12)
132
+ OPTIONS["chapter_starts_new_page"] = False
133
+ ```
134
+
135
+ Fonts: `serif` (STIX, matches the math), `sans` and `mono` (DejaVu) ship
136
+ with matplotlib. Add your own with `satz.fonts.register_family(...)`.
137
+
138
+ ## Current limits
139
+
140
+ Greedy line breaking, no hyphenation, no floats (a figure that doesn't fit
141
+ moves to the next page and leaves a gap), raster images only, flat lists,
142
+ and math limited to matplotlib's mathtext (no matrices or aligned
143
+ environments). All of these are on the roadmap.
144
+
145
+ ## License
146
+
147
+ MIT — see [LICENSE](https://github.com/waidring/satz/blob/main/LICENSE). Free to use, modify and sell, including in
148
+ commercial and closed-source products, as long as the copyright notice is kept.
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "satz"
7
+ dynamic = ["version"]
8
+ description = "A LaTeX-like markup language with a Python backend that compiles documents to PDF."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.9"
13
+ authors = [{ name = "waidring" }]
14
+ keywords = ["typesetting", "markup", "pdf", "latex", "documents"]
15
+ dependencies = [
16
+ "reportlab>=4.0",
17
+ "matplotlib>=3.7",
18
+ "pillow",
19
+ ]
20
+ classifiers = [
21
+ "Development Status :: 2 - Pre-Alpha",
22
+ "Intended Audience :: Science/Research",
23
+ "Operating System :: OS Independent",
24
+ "Programming Language :: Python :: 3",
25
+ "Topic :: Text Processing :: Markup",
26
+ "Topic :: Printing",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/waidring/satz"
31
+ Repository = "https://github.com/waidring/satz"
32
+ Issues = "https://github.com/waidring/satz/issues"
33
+
34
+ [project.scripts]
35
+ satz = "satz.cli:main"
36
+
37
+ [tool.setuptools.dynamic]
38
+ version = { attr = "satz.__version__" }
39
+
40
+ [tool.setuptools.packages.find]
41
+ include = ["satz*"]
@@ -0,0 +1,24 @@
1
+ """satz - a small LaTeX-like markup language with a Python backend.
2
+
3
+ source text --(parser)--> nodes
4
+ --(pass 1: command functions)--> Document structure
5
+ --(pass 2: renderer)--> PDF
6
+
7
+ For package authors, everything needed is importable from here:
8
+
9
+ from satz import command, restyle, Run, text
10
+ """
11
+
12
+ from .build import Context, build
13
+ from .commands import COMMANDS, command
14
+ from .document import Document, Geometry
15
+ from .errors import CommandError, CompileError, ParseError
16
+ from .inline import InlineStyle, MathRun, Run, plain, restyle, text
17
+ from .parser import parse
18
+ from .render import OPTIONS, STYLES, Style, render
19
+
20
+ __all__ = ["build", "parse", "render", "command", "COMMANDS", "Context",
21
+ "Document", "Geometry", "Style", "STYLES", "OPTIONS",
22
+ "Run", "MathRun", "InlineStyle", "restyle", "text", "plain",
23
+ "CompileError", "ParseError", "CommandError"]
24
+ __version__ = "0.1.0"
@@ -0,0 +1,5 @@
1
+ """python -m satz content.tex"""
2
+
3
+ from .cli import main
4
+
5
+ raise SystemExit(main())
@@ -0,0 +1,146 @@
1
+ """PASS 1 - walk the parsed nodes and build the document structure.
2
+
3
+ Nothing is drawn here. Consecutive text, math and inline commands are
4
+ collected into paragraphs; block commands end the current paragraph.
5
+ """
6
+
7
+ import os
8
+ from typing import List
9
+
10
+ from . import mathrender
11
+ from .commands import COMMANDS, CommandSpec
12
+ from .document import Document, Equation, Paragraph, parse_length
13
+ from .errors import CommandError
14
+ from .inline import Inline, MathRun, Run, is_blank
15
+ from .parser import Command, Math, ParBreak, Text, parse, unescape
16
+
17
+
18
+ class Context:
19
+ """What a command function receives as its first argument."""
20
+
21
+ def __init__(self, doc: Document, base_dir: str):
22
+ self.doc = doc
23
+ self.base_dir = base_dir
24
+ self.line = 0 # line of the command being executed
25
+ self.arg_line = 0 # line where its first argument starts
26
+
27
+ # -- for command authors ---------------------------------------------
28
+ def add(self, block):
29
+ return self.doc.add(block)
30
+
31
+ def content(self, raw: str, line: int = None) -> List[Inline]:
32
+ """Parse a string as formatted inline content."""
33
+ return to_inlines(parse(raw, line or self.arg_line or self.line), self)
34
+
35
+ def path(self, p: str) -> str:
36
+ return p if os.path.isabs(p) else os.path.join(self.base_dir, p)
37
+
38
+ def length(self, s: str) -> float:
39
+ try:
40
+ return parse_length(s)
41
+ except ValueError:
42
+ self.error(f"not a length: {s!r} (examples: 12pt, 3mm, 0.5cm)")
43
+
44
+ def check_math(self, src: str, line: int = None):
45
+ try:
46
+ mathrender.measure(src, 10)
47
+ except mathrender.MathError as exc:
48
+ raise CommandError(str(exc), line or self.line) from None
49
+
50
+ def error(self, message: str, line: int = None):
51
+ raise CommandError(message, line or self.line)
52
+
53
+
54
+ def _lookup(node: Command) -> CommandSpec:
55
+ spec = COMMANDS.get(node.name)
56
+ if spec is None:
57
+ raise CommandError(f"unknown command \\{node.name} (run 'satz "
58
+ f"--commands' for the list)", node.line)
59
+ n = len(node.args)
60
+ if not spec.min_args <= n <= spec.max_args:
61
+ raise CommandError(f"\\{node.name} takes {spec.min_args}"
62
+ f"{'' if spec.min_args == spec.max_args else f'-{spec.max_args}'}"
63
+ f" argument(s), got {n}. Usage: {spec.signature()}", node.line)
64
+ return spec
65
+
66
+
67
+ def call(ctx: Context, node: Command):
68
+ spec = _lookup(node)
69
+ saved = ctx.line, ctx.arg_line
70
+ ctx.line = node.line
71
+ ctx.arg_line = node.arg_lines[0] if node.arg_lines else node.line
72
+ try:
73
+ args = []
74
+ for raw, kind, line in zip(node.args, spec.argtypes, node.arg_lines):
75
+ if kind == "content":
76
+ args.append(to_inlines(parse(raw, line), ctx))
77
+ elif kind == "text":
78
+ args.append(" ".join(unescape(raw).split()))
79
+ else:
80
+ args.append(raw)
81
+ ctx.line = node.line
82
+ result = spec.fn(ctx, *args)
83
+ finally:
84
+ ctx.line, ctx.arg_line = saved
85
+ if spec.inline:
86
+ if result is None:
87
+ return []
88
+ if isinstance(result, str):
89
+ return [Run(result)]
90
+ if isinstance(result, (Run, MathRun)):
91
+ return [result]
92
+ return list(result)
93
+ return None
94
+
95
+
96
+ def to_inlines(nodes, ctx: Context) -> List[Inline]:
97
+ out: List[Inline] = []
98
+ for node in nodes:
99
+ if isinstance(node, Text):
100
+ out.append(Run(node.text))
101
+ elif isinstance(node, ParBreak):
102
+ out.append(Run(" "))
103
+ elif isinstance(node, Math):
104
+ if node.display:
105
+ raise CommandError("display math $$...$$ cannot be used inside an argument",
106
+ node.line)
107
+ ctx.check_math(node.src, node.line)
108
+ out.append(MathRun(node.src, line=node.line))
109
+ elif isinstance(node, Command):
110
+ if not _lookup(node).inline:
111
+ raise CommandError(f"\\{node.name} is a block command and cannot be "
112
+ f"used inside an argument", node.line)
113
+ out.extend(call(ctx, node))
114
+ return out
115
+
116
+
117
+ def build(source: str, base_dir: str = ".", doc: Document = None) -> Document:
118
+ doc = doc if doc is not None else Document()
119
+ ctx = Context(doc, base_dir)
120
+ para: List[Inline] = []
121
+
122
+ def flush():
123
+ if para and not is_blank(para):
124
+ doc.add(Paragraph(list(para)))
125
+ para.clear()
126
+
127
+ for node in parse(source):
128
+ if isinstance(node, ParBreak):
129
+ flush()
130
+ elif isinstance(node, Text):
131
+ para.append(Run(node.text))
132
+ elif isinstance(node, Math):
133
+ ctx.check_math(node.src, node.line)
134
+ if node.display:
135
+ flush()
136
+ doc.add(Equation(node.src, None))
137
+ else:
138
+ para.append(MathRun(node.src, line=node.line))
139
+ elif isinstance(node, Command):
140
+ if _lookup(node).inline:
141
+ para.extend(call(ctx, node))
142
+ else:
143
+ flush()
144
+ call(ctx, node)
145
+ flush()
146
+ return doc
satz-0.1.0/satz/cli.py ADDED
@@ -0,0 +1,69 @@
1
+ """Command line interface - installed as the `satz` command.
2
+
3
+ satz content.tex
4
+ satz content.tex -o out.pdf
5
+ satz content.tex --dump # show the structure from pass 1
6
+ satz --commands # list all commands
7
+
8
+ Without installing: python -m satz content.tex
9
+ """
10
+
11
+ import argparse
12
+ import os
13
+ import sys
14
+
15
+ from . import COMMANDS, CompileError, __version__, build, render
16
+
17
+
18
+ def list_commands():
19
+ seen = {}
20
+ for name, spec in sorted(COMMANDS.items()):
21
+ seen.setdefault(id(spec), (spec, []))[1].append(name)
22
+ for spec, names in sorted(seen.values(), key=lambda v: v[0].name):
23
+ aliases = [n for n in names if n != spec.name]
24
+ kind = "inline" if spec.inline else "block "
25
+ extra = f" (also: {', '.join(chr(92) + a for a in aliases)})" if aliases else ""
26
+ print(f" {kind} {spec.signature()}{extra}")
27
+
28
+
29
+ def main(argv=None):
30
+ ap = argparse.ArgumentParser(prog="satz", description="compile satz markup to PDF")
31
+ ap.add_argument("--version", action="version", version=f"satz {__version__}")
32
+ ap.add_argument("source", nargs="?", help="input file")
33
+ ap.add_argument("-o", "--output", help="output PDF (default: same name .pdf)")
34
+ ap.add_argument("--dump", action="store_true", help="print the pass-1 structure and exit")
35
+ ap.add_argument("--commands", action="store_true", help="list all commands and exit")
36
+ args = ap.parse_args(argv)
37
+
38
+ if args.commands:
39
+ list_commands()
40
+ return 0
41
+ if not args.source:
42
+ ap.error("no source file given")
43
+
44
+ with open(args.source, encoding="utf-8") as fh:
45
+ source = fh.read()
46
+ base_dir = os.path.dirname(os.path.abspath(args.source))
47
+
48
+ try: # ---- pass 1
49
+ doc = build(source, base_dir=base_dir)
50
+ except CompileError as exc:
51
+ print(f"{args.source}:{exc.line or '?'}: error: {exc.message}", file=sys.stderr)
52
+ if exc.line:
53
+ lines = source.splitlines()
54
+ if 0 < exc.line <= len(lines):
55
+ print(f" {exc.line} | {lines[exc.line - 1]}", file=sys.stderr)
56
+ return 1
57
+
58
+ if args.dump:
59
+ print(doc.dump())
60
+ return 0
61
+
62
+ out = args.output or os.path.splitext(args.source)[0] + ".pdf"
63
+ render(doc, out) # ---- pass 2
64
+ print(f"{args.source} -> {out} ({len(doc.blocks)} blocks)")
65
+ return 0
66
+
67
+
68
+ if __name__ == "__main__":
69
+ raise SystemExit(main())