Initial commit: Klammertext source distribution

Curated source subset assembled by klammertext-dev's doc/make_dist.sh: the Klammermachine (mac), the Standard Klammer Set (sks), the commands (com), editor plugins and install guides (doc), a test subset (tst), and lib/bin placeholders. Builds with 'make -C com'.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-18 18:48:23 +02:00
commit 2ba7ceee7a
272 changed files with 27634 additions and 0 deletions

1
sks/section/css/list.txt Normal file
View File

@@ -0,0 +1 @@
section.css

View File

@@ -0,0 +1,83 @@
:root {
--tab: 1.5em;
--toc-bottom: .1em;
}
kt-part {
display: block;
padding-top: 1.5rem;
margin-top: 0px;
font-family: var(--sans-serif);
font-size: 1.5rem;
}
kt-chapter {
display: block;
padding-top: 1.5rem;
margin-top: 0px;
font-family: var(--sans-serif);
font-size: 1.5rem;
}
h1 {
padding-top: 1.5rem;
margin-top: 0;
}
h2, h3, h4, h5 {
padding-top: 0.5rem;
margin-bottom: .5rem;
padding-bottom: 0rem;
}
.sectiontitle {
}
.sectionnumber {
padding-right: .5rem;
}
.level {
font: .9em var(--sans-serif);
}
.level a:link, .level a:visited {
color: black;
}
.level_number {
padding-right: .5em;
}
.level1 {
margin-left: 0;
margin-bottom: var(--toc-bottom);
}
.level2 {
margin-left: calc(1 * var(--tab));
margin-bottom: var(--toc-bottom);
}
.level3 {
margin-left: calc(2 * var(--tab));
margin-bottom: var(--toc-bottom);
}
.level4 {
margin-left: calc(3 * var(--tab));
margin-bottom: var(--toc-bottom);
}
.level5 {
margin-left: calc(4 * var(--tab));
margin-bottom: var(--toc-bottom);
}
.level6 {
margin-left: calc(5 * var(--tab));
margin-bottom: var(--toc-bottom);
}

54
sks/section/section.k Normal file
View File

@@ -0,0 +1,54 @@
# Book-specific component headings (others possible to correspond to
# the front and back matter of a book):
@@preface.k :id :name Preface : Preface text @@
@@preface :: @eval section.Section(K, "preface") eval@ @@
# Numbered section headings:
@@part.k title :id :name Part : Part heading @@
@@part :: @eval section.Section(K, 0) eval@ @@
@@s1.k title :id :n : Top level division, numbered @@
@@s1 :: @eval section.Section(K, 1) eval@ @@
@@s2.k title :id :n : Second level division, numbered @@
@@s2 :: @eval section.Section(K, 2) eval@ @@
@@s3.k title :id :n : Third level division, numbered @@
@@s3 :: @eval section.Section(K, 3) eval@ @@
@@s4.k title :id :n : Fourth level division, numbered @@
@@s4 :: @eval section.Section(K, 4) eval@ @@
@@s5.k title :id :n : Fifth level division, numbered @@
@@s5 :: @eval section.Section(K, 5) eval@ @@
@@s6.k title :id :n : Sixth level division, numbered @@
@@s6 :: @eval section.Section(K, 6) eval@ @@
@@s7.k title :id :n : Seventh level division, numbered @@
@@s7 :: @eval section.Section(K, 7) eval@ @@
# Unnumbered section headings:
@@h1.k title :id :n : Top level division, unnumbered @@
@@h1 :: @eval section.Section(K, 1, numbered=False) eval@ @@
@@h2.k title :id : Second level division, unnumbered @@
@@h2 :: @eval section.Section(K, 2, numbered=False) eval@ @@
@@h3.k title :id : Third level division, unnumbered @@
@@h3 :: @eval section.Section(K, 3, numbered=False) eval@ @@
@@h4.k title :id : Fourth level division, unnumbered @@
@@h4 :: @eval section.Section(K, 4, numbered=False) eval@ @@
@@h5.k title :id : Fifth level division, unnumbered @@
@@h5 :: @eval section.Section(K, 5, numbered=False) eval@ @@
@@h6.k title :id : Sixth level division, unnumbered @@
@@h6 :: @eval section.Section(K, 6, numbered=False) eval@ @@
@@h7.k title :id : Seventh level division, unnumbered @@
@@h7 :: @eval section.Section(K, 7, numbered=False) eval@ @@

76
sks/section/section.py Normal file
View File

@@ -0,0 +1,76 @@
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
def txt(self):
return self.title

View File

@@ -0,0 +1,143 @@
% Header and footer definitions for the SKS @document klammer.
%
% Three page style sets, one per document structure:
%
% plain structure: No headers. Centered page number in footer.
% article structure: No headers. Centered page number in footer.
% First page has no header (same as regular pages).
% book structure: Verso header: chapter number + title.
% Recto header: section number + title.
% Page number in outer header margin.
% No footer. Chapter-opening pages get centered
% page number in footer and no header.
%
% Special styles used across structures:
% \pagestyle{empty} — title pages, copyright pages, part pages, blank pages
%
% The style names use a "sks" prefix to avoid clashing with LaTeX's
% built-in page style names:
% \pagestyle{sksplain}, \pagestyle{sksarticle}, \pagestyle{sksbook}
%
% titlesec's pagestyles option (loaded by titles.sty) provides \newpagestyle,
% \sethead, \setfoot, and the automatic marks \chaptertitle, \sectiontitle,
% \subsectiontitle.
\usepackage{ifthen}
% --- Font for header/footer text ---
\newcommand{\hdrfont}[1]{{\sffamily\scalefont{.9}{#1}}}
% --- Running head content ---
%
% These commands produce the running head text, using titlesec's automatic
% mark variables. They suppress output when the counter is zero (before
% the first heading of that level has appeared).
%
% The \sect dispatch from titles.sty shifts heading levels between book
% and article classes: in book class, \sA expands to \chapter and the
% top-level counter is \thechapter; in article class, \sA expands to
% \section and the top-level counter is \thesection. The running head
% commands follow the same shift.
\ifthenelse{\equal{\documentisbook}{true}}{%
\newcommand{\runningchapter}{%
\ifthenelse{\equal{0}{\thechapter}}{}{\hdrfont{\thechapter~~\chaptertitle}}}
\newcommand{\runningsection}{%
\ifthenelse{\equal{0}{\thesection}}{}{\hdrfont{\thesection~~\sectiontitle}}}
}{%
\newcommand{\runningchapter}{%
\ifthenelse{\equal{0}{\thesection}}{}{\hdrfont{\thesection~~\sectiontitle}}}
\newcommand{\runningsection}{%
\ifthenelse{\equal{0}{\thesubsection}}{}{\hdrfont{\thesubsection~~\subsectiontitle}}}
}
% --- Plain structure ---
%
% No headers, centered page number in footer, no rules.
\newpagestyle{sksplain}{%
\ifdefined\documentbottom
\setfoot{\hdrfont{\documentbottom}}{}{\hdrfont{\thepage}}%
\else
\setfoot{}{\hdrfont{\thepage}}{}%
\fi
}
% --- Article structure ---
%
% Same as plain: no headers, centered page number in footer, no rules.
% Defined as a separate style so that it can be extended independently
% (e.g., adding author/title running heads for longer articles).
\newpagestyle{sksarticle}{%
\ifdefined\documentbottom
\setfoot{\hdrfont{\documentbottom}}{}{\hdrfont{\thepage}}%
\else
\setfoot{}{\hdrfont{\thepage}}{}%
\fi
}
% --- Book structure ---
%
% Twoside layout with running heads and page numbers in the outer margin.
% Verso (even): chapter title in header.
% Recto (odd): section title in header.
% No footer on regular pages.
\newpagestyle{sksbook}{%
\sethead[\hdrfont{\thepage}]%
[]%
[\runningchapter]%
{\runningsection}%
{}%
{\hdrfont{\thepage}}%
\ifdefined\documentbottom
\setfoot[\hdrfont{\documentbottom}]%
[]%
[]%
{}%
{}%
{\hdrfont{\documentbottom}}%
\fi
}
% --- Book opening style ---
%
% \chapter internally calls \thispagestyle{plain}, so we must override
% LaTeX's built-in plain style for book structure. For plain and article
% structures, the override is harmless (plain is not used as the main
% page style, and this matches the centered-page-number convention).
\ifthenelse{\equal{\documentisbook}{true}}{%
\renewpagestyle{plain}{%
\ifdefined\documentbottom
\setfoot{\hdrfont{\documentbottom}}{}{\hdrfont{\thepage}}%
\else
\setfoot{}{}{\hdrfont{\thepage}}%
\fi
}
}{%
\renewpagestyle{plain}{%
\ifdefined\documentbottom
\setfoot{\hdrfont{\documentbottom}}{}{\hdrfont{\thepage}}%
\else
\setfoot{}{\hdrfont{\thepage}}{}%
\fi
}
}
% --- Noheader (compatibility) ---
%
% Used by toc.sty for TOC chapter entries. No running heads, centered
% page number in footer.
\newpagestyle{noheader}{%
\ifdefined\documentbottom
\setfoot{\hdrfont{\documentbottom}}{}{\hdrfont{\thepage}}%
\else
\setfoot{}{\hdrfont{\thepage}}{}%
\fi
}
\write0{Headers and page styles defined}

3
sks/section/sty/list.txt Normal file
View File

@@ -0,0 +1,3 @@
titles.sty
headerfooter.sty
toc.sty

View File

@@ -0,0 +1,11 @@
\usepackage{titles}
\usepackage{headerfooter}
\usepackage{toc}
%% \usepackage{etoolbox}
%% \makeatletter
%% %\patchcmd{\chapter}{\if@openright\cleardoublepage\else\newpage\fi}{}{}{}
%% %\patchcmd{\chapter}{\newpage}{}{}{}
%% %\patchcmd{\chapter}{\if@openright\clearpage\else\newpage\fi}{}{}{}
%% \patchcmd{\chapter}{\clearpage}{}{}{}
%% \makeatother

123
sks/section/sty/titles.sty Normal file
View File

@@ -0,0 +1,123 @@
% Section heading formatting for the SKS @document klammer.
%
% The \sect command dispatches between book and article document classes.
% Section klammers (@s1-@s7) emit \sA-\sE, which expand to the appropriate
% LaTeX sectioning command based on \documentisbook. The \defineheading
% utility eliminates duplication across heading levels.
\usepackage[bf,sf,big,raggedright,compact,newlinetospace,explicit,pagestyles,clearempty]{titlesec}
\usepackage{etoolbox}
\usepackage{ifthen}
% --- Structure dispatch ---
% Select first or second argument based on document class:
\newcommand{\sect}[2]{\ifthenelse{\equal{\documentisbook}{true}}{#1}{#2}}
% Sectioning commands, shifted by structure:
\newcommand{\sA}{\sect{\chapter}{\section}}
\newcommand{\sB}{\sect{\section}{\subsection}}
\newcommand{\sC}{\sect{\subsection}{\subsubsection}}
\newcommand{\sD}{\sect{\subsubsection}{\paragraph}}
\newcommand{\sE}{\sect{\paragraph}{\subparagraph}}
% Counters, shifted by structure:
\newcommand{\snA}{\sect{\thechapter}{\thesection}}
\newcommand{\snB}{\sect{\thesection}{\thesubsection}}
\newcommand{\snC}{\sect{\thesubsection}{\thesubsubsection}}
\newcommand{\snD}{\sect{\thesubsubsection}{\theparagraph}}
\newcommand{\snE}{\sect{\theparagraph}{\thesubparagraph}}
% Font sizes, shifted by structure:
\newcommand{\fsect}[2]{\ifthenelse{\equal{\documentisbook}{true}}{\sfont{#1}}{\sfont{#2}}}
\newcommand{\fA}{\fsect{1.6}{1.2}}
\newcommand{\fB}{\fsect{1.2}{1.1}}
\newcommand{\fC}{\fsect{1.1}{1.1}}
\newcommand{\fD}{\fsect{1.1}{1.1}}
\newcommand{\fE}{\fsect{1.1}{1.1}}
% --- Shared heading parameters ---
\newlength{\beforeheading}\setlength{\beforeheading}{4pt}
\newlength{\afterheading}\setlength{\afterheading}{-4pt}
\newcommand{\numsep}{8pt}
% Outdent section numbers into the left margin:
\newlength{\sectionoutdent}
\newcommand{\numleft}[1]{%
\ifthenelse{\equal{#1}{}}%
{}%
{\setlength{\sectionoutdent}{0pt-\widthof{#1}-8pt}%
\hspace*{\sectionoutdent}}}
% --- Heading definition utility ---
% Define titleformat and titlespacing for a heading level.
% #1 = LaTeX sectioning command (e.g., \section, \chapter)
% #2 = font command (e.g., \fA)
% #3 = counter (e.g., \thesection, \thechapter)
\newcommand{\defineheading}[3]{%
\titlespacing*{name=#1}{0pt}{\beforeheading}{\afterheading}%
\titleformat{name=#1}[block]%
{#2\numleft{#3}}%
{#2#3}%
{\numsep}%
{##1}%
\titlespacing*{name=#1,numberless}{0pt}{\beforeheading}{\afterheading}%
\titleformat{name=#1,numberless}[block]%
{#2}%
{}%
{0pt}%
{##1}%
}
% --- Heading definitions ---
%
% Register \titleformat for the actual LaTeX sectioning commands, not for
% \sA-\sE. When \sA{title} is used in the document, TeX expands \sA to
% \section or \chapter, and titlesec intercepts that command. Formatting
% registered for \sA would never be reached.
% In book structure, chapters start on recto (odd) pages. titlesec
% replaces \chapter's internals and ignores the book class's openright
% default, using \clearpage instead of \cleardoublepage. The
% \chapterbreak hook restores recto-start behavior.
\ifthenelse{\equal{\documentisbook}{true}}{%
\newcommand{\chapterbreak}{\cleardoublepage}
\titleclass{\chapter}{top}
\defineheading{\chapter}{\fA}{\thechapter}
\defineheading{\section}{\fB}{\thesection}
\defineheading{\subsection}{\fC}{\thesubsection}
\defineheading{\subsubsection}{\fD}{\thesubsubsection}
\defineheading{\paragraph}{\fE}{\theparagraph}
}{%
\defineheading{\section}{\fA}{\thesection}
\defineheading{\subsection}{\fB}{\thesubsection}
\defineheading{\subsubsection}{\fC}{\thesubsubsection}
\defineheading{\paragraph}{\fD}{\theparagraph}
\defineheading{\subparagraph}{\fE}{\thesubparagraph}
}
% --- Counter resets ---
\makeatletter
\@addtoreset{paragraph}{section}
\@addtoreset{paragraph}{subsection}
\@addtoreset{paragraph}{subsubsection}
\@addtoreset{subparagraph}{section}
\@addtoreset{subparagraph}{subsection}
\@addtoreset{subparagraph}{subsubsection}
\@addtoreset{subparagraph}{paragraph}
\makeatother
\setcounter{secnumdepth}{6}
\setcounter{tocdepth}{6}
% --- Part ---
\newcounter{partnumber}
\stepcounter{partnumber}
\newcommand{\partspace}{\hspace*{64pt}}
\newcommand{\partindent}[1]{\partspace\large\bfseries #1}

83
sks/section/sty/toc.sty Normal file
View File

@@ -0,0 +1,83 @@
\newlength{\tocindent}
\setlength{\tocindent}{8pt}
\newlength{\tocchaptermargin}
\setlength{\tocchaptermargin}{-72pt}
\newlength{\tocsectionmargin}
\setlength{\tocsectionmargin}{\tocchaptermargin + \tocindent}
\newlength{\tocsubsectionmargin}
\setlength{\tocsubsectionmargin}{\tocsectionmargin + \tocindent}
\newlength{\tocsubsubsectionmargin}
\setlength{\tocsubsubsectionmargin}{\tocsubsectionmargin + \tocindent}
\newlength{\tocparagraphmargin}
\setlength{\tocparagraphmargin}{\tocsubsubsectionmargin + \tocindent}
\newlength{\tocsubparagraphmargin}
\setlength{\tocsubparagraphmargin}{\tocparagraphmargin + \tocindent}
\newlength{\tocdotspacing}
\setlength{\tocdotspacing}{6pt}
% Compensate for outdenting of section titles:
% This has no effect:
\renewcommand{\contentsname}{\sfont{1.4}\hspace*{1em}Contents}
\newcommand{\afternumberspace}{~~}
\newcommand{\numberlabel}{\parbox[b]{64pt}
{\raggedleft\hspace*{8pt}\small\thecontentslabel}}
\renewcommand{\numberlabel}{\hspace*{-1\hoffset}\thecontentslabel\afternumberspace}
\newcommand{\pagenumber}{\parbox{\widthof{888}{\contentspage}}}
\newcommand{\tocpage}{~\titlerule*[\tocdotspacing]{.}
\makebox[\widthof{\thecontentspage}][r]{\small\thecontentspage}}
\newcommand{\interline}{\vspace*{-6pt}}
\titlecontents{chapter}[\tocchaptermargin]
{\vspace{6pt}\thispagestyle{noheader}}
{\numberlabel}
{\hspace*{-12pt}}
{\tocpage}
[\interline]
\titlecontents{section}[\tocsectionmargin]
{\ifthenelse{\equal{\documentisbook}{true}}{}{\vspace{6pt}}}
{\numberlabel}
{\hspace*{-18pt}}
{\tocpage}
[\interline]
\titlecontents{subsection}[\tocsubsectionmargin]
{}
{\numberlabel}
{\hspace*{-24pt}}
{\tocpage}
[\interline]
\titlecontents{subsubsection}[\tocsubsubsectionmargin]
{}
{\numberlabel}
{\hspace*{-30pt}}
{\tocpage}
[\interline]
\titlecontents{paragraph}[\tocparagraphmargin]
{}
{\numberlabel}
{\hspace*{-36pt}}
{\tocpage}
[\interline]
\titlecontents{subparagraph}[\tocsubparagraphmargin]
{}
{\numberlabel}
{\hspace*{-42pt}}
{\tocpage}
[\interline]