Characters that killed a render, what may sit next to a klammer, and ref/

A character written in the ^...^ mnemonic form -- ^oe^, ^zz^, ^hello^ --
used to kill ktext outright: no message, no output, and an exit status
that looked like a crash because it was one.  Only the forms that happen
to spell hexadecimal digits escaped, and they were right by luck rather
than by reading.  Any caret form that names no character is now a located
error that quotes what was written.

A klammer may now sit inside square brackets and braces as it already
could inside parentheses, and may be followed by the punctuation that
ends a sentence: [@i word@], {@b word@}, @i word@'s.  The rule is a fixed
list of characters, because none of them can occur inside a klammer name
and so none of them is ambiguous next to a delimiter.  A letter still
cannot: "x@" is the named closing delimiter, so a letter before "@" has
two readings and no rule can separate them.

The abbreviations an author writes -- the hyphen form @i-word, a klammer
glued to its neighbouring punctuation -- are now recognised as author
conveniences only.  They are not applied to @@ definitions or @@@ system
commands, which are written by someone who needs no such shorthand and
whose forms are already whole.

Also fixed, each of them silent: an exported shell function in the
environment broke every @eval in the document; a line break written with
@nl was destroyed when it passed through a klammer that generates a
table, printing as \textbackslash{}newline in the finished PDF; and
"kdesc --coverage" shortened its file column by comparing the spelling of
a path rather than the path, so a klammer set reached by a symbolic link
showed a full path where its neighbours showed a short one.

New in the distribution: ref/, a small klammerset that describes the
Klammermachine's own tables in Klammertext.  It currently provides the
character tables -- the diacritics and the extended Latin letters -- as
klammers that render to any target, so the documentation of what can be
written cannot drift from what the machine accepts.  It is early, and
will grow.

The Klammertext taxonomy now has a section on targets, describes the
@@@klammerset system command alongside the other three, and states the
precedence of "^" -- what a caret means before a letter, a digit, a
punctuation character, and a quote, in one ordered list.

(from dev 6594c7ff8c1f)
This commit is contained in:
ack committed 2026-09-07 22:37:05 +02:00
1 parent b80e823ab3
commit e4f1307aa9
53 files changed
+2014 -350

No files matched your search

+33 -12
View File
@@ -870,30 +870,51 @@ class Table(klammer_base.Klammer_base):
# txt target
def txt_column_widths(self):
def ws(lst, ext=0):
result = [len(e) for e in lst]
if ext > 0:
result += ["~"] * (ext - (len(lst)))
return result
row_count = max(ws(self.rows))
widths = ws(self.rows[0], row_count)
for row in self.rows[1:]:
widths = list(max(widths, ws(row, row_count)))
"""The visible width of the widest cell in each column.
Measured with txt_util.visible_length, not len: a cell holding a
quoted character carries a KTESC marker, fourteen characters wide
and one glyph, so len() sizes the column to a width the reader
never sees -- and then the f-string below, padding the same
unresolved text, adds nothing because it is already "wider" than
the column. The cell came out unpadded and three columns wide in
a column sized sixteen.
"""
widths = [0] * self.row_size
for row in self.rows:
# ELEMENT-WISE, which max() of two lists is not: it compares
# them lexicographically and returns the whole larger list, so
# a later row wider in a later column was discarded entirely
# if it was narrower in an earlier one.
widths = [max(w, txt_util.visible_length(cell))
for w, cell in zip(widths, row)]
return widths
def txt(self):
def hpos(p):
return {'l':'<', 'c':'^', 'r':'>'}[p]
def if_empty(char):
return "~" if len(char) == 0 else char
return txt_util.NBSP if len(char) == 0 else char
# Padded by hand rather than by an f-string width: the format spec
# counts characters, and a cell's markers are many characters and
# few columns. visible_length is what the reader will see.
def pad(cell, width, align):
cell = if_empty(cell)
space = max(0, width - txt_util.visible_length(cell))
if align == '>':
return txt_util.NBSP * space + cell
if align == '^':
left = space // 2
return txt_util.NBSP * left + cell + txt_util.NBSP * (space - left)
return cell + txt_util.NBSP * space
widths = self.txt_column_widths()
pos = [hpos(p) for p in self.cell_hpos]
result = ""
indent = "~" * int(self.Target_txt_indent)
indent = txt_util.NBSP * int(self.Target_txt_indent)
colsep = " "
for row in self.rows:
result += indent + colsep.join(
[f"{if_empty(elt):{pos}{width}}" for elt, width, pos in
[pad(elt, width, align) for elt, width, align in
list(zip(row, widths, pos))])
result += "\n"
result = txt_util.add_caption(