2026-07-18 18:48:23 +02:00
|
|
|
import re, glob
|
|
|
|
|
import kutil
|
|
|
|
|
import font
|
|
|
|
|
|
|
|
|
|
def tex_style():
|
|
|
|
|
result = ""
|
|
|
|
|
for basename, filename in kutil.sks_files_of_type("sty"):
|
|
|
|
|
with open(filename) as fp:
|
|
|
|
|
src = fp.read()
|
|
|
|
|
result += f"% {basename}.sty\n{src.strip()}\n\n"
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
# \usepackage{quoting}
|
|
|
|
|
|
|
|
|
|
def environment(name, body, required=None, optional=None):
|
|
|
|
|
req = f"{{{required}}}" if required else ""
|
|
|
|
|
opt = f"[{optional}]" if optional else ""
|
|
|
|
|
result = f"""\\begin{{{name}}}{opt}{req}
|
|
|
|
|
{body}
|
|
|
|
|
\\end{{{name}}}
|
|
|
|
|
"""
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def page(title, subtitle, leading, pointsize, ragged_right, body):
|
|
|
|
|
title = f"\\textsf{{\\Large {title}}}" if title else ""
|
|
|
|
|
subtitle = f"\\vspace*{{4pt}}\\textsf{{\\large {subtitle}}}" if subtitle else ""
|
|
|
|
|
#leading = f"\\renewcommand{{\\baselinestretch}}{{{leading}}}"
|
|
|
|
|
leading = f"\\setstretch{{{leading}}}"
|
|
|
|
|
raggedright = "\\raggedright" if ragged_right else ""
|
|
|
|
|
if title or subtitle:
|
|
|
|
|
title = f"\\begin{{center}}{title} \\\\ {subtitle}\\end{{center}}\n\n"
|
|
|
|
|
result = f"""\\documentclass[a4paper,{pointsize}]{{article}}
|
|
|
|
|
{tex_style()}
|
|
|
|
|
{leading}
|
|
|
|
|
{raggedright}
|
|
|
|
|
\\begin{{document}}
|
|
|
|
|
\\thispagestyle{{empty}}
|
|
|
|
|
"""
|
|
|
|
|
result += title + body + "\n\\end{document}\n"
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
TARGET_ID = 0
|
|
|
|
|
|
|
|
|
|
#def add_caption(element, label, numbered, caption_text, center, side, width, side_center, vmargin, caption_margin):
|
|
|
|
|
|
|
|
|
|
def minipage(content, width="\\textwidth", vertical="c", center=True, vmargin="", outline=False):
|
|
|
|
|
vertical = f"[{vertical}]" if vertical else ""
|
|
|
|
|
center = "\n\\centering" if center else ""
|
|
|
|
|
vmargin = f"\n\\vspace*{{{vmargin}}}" if vmargin else ""
|
|
|
|
|
result = f"""\\begin{{minipage}}{vertical}{{{width}}}{center}{vmargin}
|
|
|
|
|
{content}{vmargin}
|
|
|
|
|
\\end{{minipage}}"""
|
|
|
|
|
if outline:
|
|
|
|
|
result = f"\\fbox{{{result}}}"
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def caption_wrapper(element, hpos, bottom_margin=.67):
|
|
|
|
|
vmargin = f"{bottom_margin}\\baselineskip"
|
|
|
|
|
result = element
|
|
|
|
|
if hpos == "center":
|
|
|
|
|
result = minipage(element, vmargin=vmargin)
|
|
|
|
|
elif hpos == "left":
|
|
|
|
|
result = minipage("\\hfill" + element, vmargin=vmargin)
|
|
|
|
|
elif hpos == "right":
|
|
|
|
|
result = minipage(element + "\\hfill", vmargin=vmargin)
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def make_caption_text(number, label, text, font_symbol, font_size):
|
|
|
|
|
caption = None
|
|
|
|
|
if number:
|
|
|
|
|
caption = kutil.caption_marker(label, text)
|
|
|
|
|
elif text:
|
|
|
|
|
# caption = text # f"{{\\small \\it \\par {caption_text}}}"
|
|
|
|
|
caption = text
|
|
|
|
|
|
Typed arguments, calculated tables, spans, closed-world fonts, top-level fnt/ and env/
Sync with klammertext-dev through b90b0e09:
- Argument types end to end: :python_cast values are applied (Python
@eval receives real bools/numbers/lists), argument values are
validated against their argtype patterns with the argtype's
description as the error message, argtypes can declare :default
(overridable per declaration), and parameterized type families are
supported: rest(N) casts a rest argument to an N-dimensional list
(bar-count = dimension).
- Unified indexed_range syntax (selector with parenthesized subsets,
composable mnemonic names) for table lines and spans.
- Table klammer: caption fonts fixed in both targets, :column_width /
:leading / :colsep wired, :colspan and :rowspan render (HTML
attributes; \multicolumn / \multirow), calculated cell values (:calc)
with prefix operators, display-precision semantics, :calc_format and
:decimal period|comma.
- Fonts: closed-world resolution on the Klammertext font store
(infrastructure in mac/font_store; no Google Fonts links or fetch).
Default fonts live in the top-level fnt/; additional fonts install
into KLAMMERTEXT_FONTS directories via kdesc --font (list, samples,
preview, install — classification by font metadata). CSS font family
names are quoted (digit-initial families were silently lost).
- Environment files moved from mac/env/ to the top-level env/; shell
profiles source env/runtime.env. Dead per-host variants removed.
- Container: fnt/ ships in the image; curl removed (no network use).
2026-07-22 18:17:43 +02:00
|
|
|
if caption is None:
|
|
|
|
|
return ""
|
2026-07-18 18:48:23 +02:00
|
|
|
caption = font.tex_fontify(caption, font_symbol, font_size)
|
|
|
|
|
return caption
|
|
|
|
|
|
|
|
|
|
def add_caption(element, caption_label, number, caption_text, latex_width,
|
|
|
|
|
hpos="center", side="bottom", font_symbol="i", font_size=.9):
|
|
|
|
|
top_margin = .75 if "includegraphics" in element else .5
|
|
|
|
|
caption = make_caption_text(number, caption_label, caption_text, font_symbol, font_size)
|
|
|
|
|
if caption:
|
|
|
|
|
if side in {"left", "right"}:
|
|
|
|
|
caption_margin_size = "12pt"
|
|
|
|
|
caption_margin = f"\\hspace{{{caption_margin_size}}}"
|
|
|
|
|
caption_width = f"\\textwidth - {latex_width} - {caption_margin_size}"
|
|
|
|
|
else:
|
|
|
|
|
#caption_margin = "\\vspace*{8pt}"
|
|
|
|
|
# caption_margin = "\\vstrut{.25\\baselineskip}\n"
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
if side == "left":
|
|
|
|
|
element = minipage(minipage(caption, caption_width, center=False) + #, vmargin=top_margin) +
|
|
|
|
|
caption_margin +
|
|
|
|
|
minipage(element, latex_width))
|
|
|
|
|
elif side == "right":
|
|
|
|
|
element = minipage(minipage(element, latex_width) +
|
|
|
|
|
caption_margin +
|
|
|
|
|
minipage(caption, caption_width, center=False))
|
|
|
|
|
elif side == "bottom":
|
|
|
|
|
element = minipage(element + "\n\\vstrut{1.33\\baselineskip}" + caption,
|
|
|
|
|
# minipage(element, vertical="t") +
|
|
|
|
|
# caption_margin + "\n" +
|
|
|
|
|
# minipage(caption),
|
|
|
|
|
latex_width, vertical="t")
|
|
|
|
|
elif side == "top":
|
Typed arguments, calculated tables, spans, closed-world fonts, top-level fnt/ and env/
Sync with klammertext-dev through b90b0e09:
- Argument types end to end: :python_cast values are applied (Python
@eval receives real bools/numbers/lists), argument values are
validated against their argtype patterns with the argtype's
description as the error message, argtypes can declare :default
(overridable per declaration), and parameterized type families are
supported: rest(N) casts a rest argument to an N-dimensional list
(bar-count = dimension).
- Unified indexed_range syntax (selector with parenthesized subsets,
composable mnemonic names) for table lines and spans.
- Table klammer: caption fonts fixed in both targets, :column_width /
:leading / :colsep wired, :colspan and :rowspan render (HTML
attributes; \multicolumn / \multirow), calculated cell values (:calc)
with prefix operators, display-precision semantics, :calc_format and
:decimal period|comma.
- Fonts: closed-world resolution on the Klammertext font store
(infrastructure in mac/font_store; no Google Fonts links or fetch).
Default fonts live in the top-level fnt/; additional fonts install
into KLAMMERTEXT_FONTS directories via kdesc --font (list, samples,
preview, install — classification by font metadata). CSS font family
names are quoted (digit-initial families were silently lost).
- Environment files moved from mac/env/ to the top-level env/; shell
profiles source env/runtime.env. Dead per-host variants removed.
- Container: fnt/ ships in the image; curl removed (no network use).
2026-07-22 18:17:43 +02:00
|
|
|
# A depth strut: the bottom-caption case uses \vstrut (height)
|
|
|
|
|
# above the caption; a top caption needs the mirror image,
|
|
|
|
|
# space below its line.
|
|
|
|
|
element = minipage(caption + "\\rule[-0.75\\baselineskip]{0pt}{0pt}\n" + element,
|
2026-07-18 18:48:23 +02:00
|
|
|
latex_width, vertical="t")
|
|
|
|
|
return caption_wrapper(element, hpos)
|