2026-07-18 18:48:23 +02:00
|
|
|
import kutil
|
|
|
|
|
import klammer_base
|
|
|
|
|
|
|
|
|
|
NUMBER_VAR = "___NUM___"
|
|
|
|
|
|
|
|
|
|
class Section(klammer_base.Klammer_base):
|
|
|
|
|
label_number = 0
|
|
|
|
|
count = 7
|
|
|
|
|
indices = [0] * count
|
|
|
|
|
def __init__(self, K, level, numbered=True):
|
|
|
|
|
super().__init__(K)
|
|
|
|
|
# Add front and back matter elements as special cases:
|
|
|
|
|
if level == "preface":
|
|
|
|
|
self.preface = True
|
|
|
|
|
self.level = 0
|
|
|
|
|
self.title = None
|
|
|
|
|
else:
|
|
|
|
|
self.preface = False
|
|
|
|
|
self.level = level
|
|
|
|
|
self.numbered = numbered
|
|
|
|
|
self.part = 1
|
|
|
|
|
|
|
|
|
|
def html(self):
|
|
|
|
|
tags = "kt-part kt-chapter h1 h2 h3 h4 h5 h6 h7".split()
|
|
|
|
|
display_names = "Part Chapter".split()
|
|
|
|
|
id = f' id="{self.id}"' if self.id else ""
|
|
|
|
|
# number_class = " numbered" if self.numbered else ""
|
|
|
|
|
number_class = "" # The variable is sufficient?
|
|
|
|
|
title = self.title
|
|
|
|
|
tag = tags[self.level]
|
|
|
|
|
if self.numbered:
|
|
|
|
|
"""
|
|
|
|
|
Section.indices[self.level] += 1
|
|
|
|
|
for i in range(self.level + 1, Section.count):
|
|
|
|
|
Section.indices[i] = 0
|
|
|
|
|
level_number = ".".join([str(e) for e in Section.indices])
|
|
|
|
|
title = f'<span class="sectionnumber">{level_number}</span> {title}'
|
|
|
|
|
"""
|
|
|
|
|
title = f'<span class="sectionnumber">{NUMBER_VAR}</span> {self.title if self.title else ""}'
|
|
|
|
|
if self.level < 1: # < 2 for "Chapter"
|
|
|
|
|
#title = f"{tag} {Section.indices[self.level]} {title}"
|
|
|
|
|
title = f"{display_names[self.level]} {title if title else ''}"
|
|
|
|
|
|
|
|
|
|
result = f'<{tag}{id}{number_class}>{title}</{tag}>\n\n'
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def tex(self):
|
|
|
|
|
# names = "part chapter section subsection subsubsection paragraph subparagraph subsubparagraph subsubsubparagraph".split()
|
|
|
|
|
names = "part sA sB sC sD sE".split()
|
|
|
|
|
|
|
|
|
|
#self.show()
|
|
|
|
|
if self.id:
|
|
|
|
|
id = self.id
|
|
|
|
|
else:
|
|
|
|
|
id = f"-s{Section.label_number}"
|
|
|
|
|
Section.label_number += 1
|
|
|
|
|
|
|
|
|
|
result = ''
|
|
|
|
|
if self.__dict__.get("n") and self.n:
|
|
|
|
|
result += f'\\setcounter{{chapter}}{{{int(self.n)-1}}}\n'
|
|
|
|
|
#if self.id:
|
|
|
|
|
# result +=
|
|
|
|
|
#if self.level == 1:
|
|
|
|
|
#result += '\\newpage\n\n'
|
|
|
|
|
# result += '\\vspace*{24pt}'
|
|
|
|
|
suffix = "" if self.numbered else "*"
|
|
|
|
|
result += f'\\{names[self.level]}{suffix}{{{self.title}}}'
|
|
|
|
|
result += f'\n\\hypertarget{{{id}}}{{}}'
|
|
|
|
|
|
|
|
|
|
# result = kutil.protect_klammertext_special_characters(result)
|
|
|
|
|
|
|
|
|
|
result = f"%__sectionlink__{id}__{self.title}__" + "\n" + result
|
|
|
|
|
return result
|
|
|
|
|
|
Target coverage: a klammer states the targets it serves
kdesc gains --coverage, which reports for every klammer the set of targets it
can render to, and — the point of it — which klammers' coverage cannot be
derived and must therefore be declared. Three rules: coverage is DERIVED
where the definitions determine it (a general body of klammer calls covers
the intersection of what those klammers cover, by a greatest fixpoint after
loading), DECLARED where the engine cannot interpret what decides it (an
@eval body, whose targets are undecidable), and UNKNOWN where nothing is
written — which never means "deliberately unavailable".
Two new spellings in a definition's name. A comma-separated target list,
"@@table.html,tex :: ...", gives one body several targets; it is surface
syntax, expanded at registration, and each member goes through the
redefinition rules on its own. And "@@date.* :: ..." writes the general
target out, asserting that the klammer works for EVERY target including ones
not yet defined — a stronger claim than a list of the targets defined today,
and the one target declaration that could be mechanically falsified.
The Standard Klammer Set was swept accordingly: it now has no general
definitions at all, every klammer names the targets it serves, six use ".*",
and tex and pdf are at zero undecided.
kdesc's flags are reorganised on two rules: a flag reached for often gets a
single letter (-k klammers, -t targets, -c characters, -i input), a more
specialised topic a multi-letter name (--argtypes, --katoms, --rewrite,
--optionsets, --coverage, --klammerset, --font); and -v says how much to show
about PROCESSING, never what the RESULT contains — so the katom regex column
is "--katoms full" and the coverage detail "--coverage all". NOTE: "-k" now
lists klammers (optionally filtered by a name/description search); the katom
table moved to "--katoms".
Fixes carried along: an option written with no value crashed the command with
SIGSEGV instead of reporting the mistake; two required positional arguments
never parsed; kdesc and kdiag printed an error and exited 0; and definition
diagnostics counted registrations rather than what was written, so one line
could be reported as two definitions and then printed twice.
Four new test suites: target_list, coverage, command_option, kdesc.
(from dev 46f54080bd9a)
2026-08-12 17:20:23 +02:00
|
|
|
# Need to implement the procedural numbering for the txt target
|
|
|
|
|
# def txt(self):
|
|
|
|
|
# return self.title
|