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:
113
sks/block/block.k
Normal file
113
sks/block/block.k
Normal file
@@ -0,0 +1,113 @@
|
||||
@@sp.k : Non-breaking space character @@
|
||||
@@sp.html :: &^#160; @@
|
||||
@@sp.tex :: ~ @@
|
||||
|
||||
@@footnote.k s : Footnote (TBD) @@
|
||||
@@footnote :: [*s*] @@
|
||||
|
||||
@@indent.k s :w.int 3 :linebreak.bool false : Indented block @@
|
||||
@@indent :: @eval block.Indent(K) eval@ @@
|
||||
|
||||
@@quote.k s :w.int 1 :source : Quotation block @@
|
||||
|
||||
@@quote.html ::
|
||||
<div class="quote">
|
||||
*s*
|
||||
</div>
|
||||
@@
|
||||
|
||||
@@quote.tex ::
|
||||
ANDY: QUOTE: *s*
|
||||
#[
|
||||
\hspace*{@{justify.length_mul("|margin|", 1, 'latex')}@}
|
||||
\begin{minipage}{\textwidth- @{justify.length_mul("|margin|", 2, 'latex')}@ }
|
||||
\raggedright
|
||||
|text|
|
||||
@? """|source|""" |?
|
||||
\vspace*{6pt}
|
||||
{\begin{spacing}{1.1}\footnotesize\raggedleft |source| \end{spacing}}
|
||||
?@
|
||||
\end{minipage}
|
||||
]#
|
||||
@@
|
||||
|
||||
@@quote.txt ::
|
||||
@eval block.block_indent(K) eval@
|
||||
@@
|
||||
|
||||
@@note.k s :label Note :color 1.0,1.0,0.9 :bordercolor 0.2,0.2,0.2 :level.int 0 :width
|
||||
: Rectangular block for a special note @@
|
||||
|
||||
@@note :: @eval block.Note(K) eval@ @@
|
||||
|
||||
@@center.k s : Center text @@
|
||||
|
||||
@@center.tex ::
|
||||
\begin{center}
|
||||
*s*
|
||||
\end{center}
|
||||
@@
|
||||
|
||||
@@center.html ::
|
||||
<div class="center">
|
||||
*s*
|
||||
</div>
|
||||
@@
|
||||
|
||||
@@right.k s : Right-justified text @@
|
||||
|
||||
@@right.html ::
|
||||
<b>TBD</b> *s*
|
||||
@@
|
||||
|
||||
@@right.tex ::
|
||||
\begin{flushright}
|
||||
*s*
|
||||
\end{flushright}
|
||||
@@
|
||||
|
||||
@@nl.k : Newline character @@
|
||||
@@nl.html :: <br> @@
|
||||
@@nl.tex :: \newline @@
|
||||
@@nl.txt :: \n @@
|
||||
|
||||
@@tnl.k : Table newline (deprecated; check) @@
|
||||
@@tnl.html :: <br> @@
|
||||
@@tnl.tex :: \\\\ @@
|
||||
@@tnl.txt :: \n @@
|
||||
|
||||
@@newpage.k : Start new page @@
|
||||
@@newpage.html :: @@
|
||||
@@newpage.tex :: \newpage @@
|
||||
@@newpage.txt :: @@
|
||||
|
||||
@@extendpage.k linecount : Extenad current page @@
|
||||
@@extendpage.html :: @@
|
||||
@@extendpage.tex :: \enlargethispage{*linecount*\baselineskip} @@
|
||||
@@extendpage.txt :: @@
|
||||
|
||||
@@vspace.k length : Vertical space @@
|
||||
@@vspace.tex :: \vspace*{*length*} @@
|
||||
|
||||
@@qa.k question | answer : Question and answer formatting @@
|
||||
@@qa ::
|
||||
@b Q: @ *question*
|
||||
|
||||
@b A: @ *answer*
|
||||
@@
|
||||
|
||||
@@@argtype coords | x and y coordinates :pattern 'float'\s+'float' @@@
|
||||
|
||||
@@block.k : to.coords | content :width.float .5 :point.coords 0.0 0.0
|
||||
: Absolute positioning of text block @@
|
||||
|
||||
@@block :: @eval block.Block(K) eval@ @@
|
||||
|
||||
@@lines.k s : Maintain line breaks @@
|
||||
@@lines :: @eval block.Lines(K) eval@ @@
|
||||
|
||||
@@twocolumns.tex s :
|
||||
\begin{multicols}{2}
|
||||
*s*
|
||||
\end{multicols}
|
||||
@@
|
||||
114
sks/block/block.py
Normal file
114
sks/block/block.py
Normal file
@@ -0,0 +1,114 @@
|
||||
import re
|
||||
import textwrap
|
||||
import pprint
|
||||
|
||||
import klammer_base
|
||||
import kutil
|
||||
import latex_util
|
||||
|
||||
class Indent(klammer_base.Klammer_base):
|
||||
def __init__(self, K):
|
||||
super().__init__(K)
|
||||
self.s = kutil.escape(self.s)
|
||||
|
||||
def html(self):
|
||||
return "FIX: INDENT " + self.s
|
||||
|
||||
def tex(self):
|
||||
tab = f"\\hspace*{{{self.w}ex}}"
|
||||
result = ""
|
||||
|
||||
if self.linebreak:
|
||||
for e in self.s.split("\n"):
|
||||
result += f"{tab}{e}\\\\\n"
|
||||
result = result[:-3]
|
||||
result = re.sub(r"\t", r"\\t", result)
|
||||
else:
|
||||
result = tab + latex_util.minipage(
|
||||
"\\raggedright " + self.s, f"\\textwidth - {self.w}ex", center=False, vmargin="4pt")
|
||||
#print(result)
|
||||
return result
|
||||
|
||||
def txt(self):
|
||||
indent = " " * self.w
|
||||
result = self.s
|
||||
result = re.sub("KK0022", '"', result)
|
||||
result = indent + f"\n{indent}".join(textwrap.wrap(result, width=70, break_on_hyphens=False))
|
||||
return f"@lit\n{result}\nlit@"
|
||||
|
||||
class Note(klammer_base.Klammer_base):
|
||||
def __init__(self, K):
|
||||
super().__init__(K)
|
||||
|
||||
def html(self):
|
||||
color = ",".join([f"{float(e)*100}%" for e in self.color.split(",")])
|
||||
result = f'''<div class="box" style="background-color: rgb({color}); border-color: rgb({self.bordercolor}) ;">
|
||||
<b>{self.label}:</b> {self.s}
|
||||
</div>'''
|
||||
return result
|
||||
|
||||
def tex(self):
|
||||
if self.width:
|
||||
width = r'{}\\textwidth'.format(self.width)
|
||||
else:
|
||||
#width = r'\\textwidth - 16pt - {}\\leftmargin'.format(self.level)
|
||||
width = r'\\linewidth - \\leftmargin + 2pt'
|
||||
|
||||
result = '''
|
||||
\\par\\begingroup
|
||||
COLOR\\setlength{\\fboxsep}{8pt}
|
||||
\\fcolorbox{bordercolor}{localcolor}{
|
||||
\\parbox{WIDTH}{\\raggedright\\setlength{\\parskip}{8pt}
|
||||
\\textbf{LABEL:} TEXT
|
||||
}}\\endgroup\\par
|
||||
'''
|
||||
result = re.sub('LABEL', self.label, result)
|
||||
result = re.sub('TEXT', re.sub(r'\\', r'\\\\', self.s), result)
|
||||
result = re.sub('COLOR', r'\\definecolor{{localcolor}}{{rgb}}{{{}}}\nCOLOR'.format(self.color), result)
|
||||
result = re.sub('COLOR', r'\\definecolor{{bordercolor}}{{rgb}}{{{}}}\n'.format(self.bordercolor), result)
|
||||
result = re.sub('WIDTH', width, result)
|
||||
print(result)
|
||||
return result
|
||||
|
||||
|
||||
class Block(klammer_base.Klammer_base):
|
||||
def __init__(self, K):
|
||||
super().__init__(K)
|
||||
#self.show()
|
||||
|
||||
def html(self):
|
||||
return ""
|
||||
|
||||
def tex(self):
|
||||
to_x, to_y = [float(e) for e in self.to.split()]
|
||||
pt_x, pt_y = [float(e) for e in self.point.split()]
|
||||
result = f"""
|
||||
\\begin{{textblock}}{{{self.width}}}[{pt_x},{pt_y}]({to_x},{to_y})
|
||||
\\vspace*{{-1\\parskip}}
|
||||
{self.content.strip()}
|
||||
\\end{{textblock}}
|
||||
"""
|
||||
return result
|
||||
|
||||
|
||||
class Lines(klammer_base.Klammer_base):
|
||||
def __init__(self, K):
|
||||
super().__init__(K)
|
||||
self.s = kutil.escape(self.s)
|
||||
self.lines = self.s.split("\n")
|
||||
|
||||
def html(self):
|
||||
result = ""
|
||||
for line in self.lines:
|
||||
result += line + "<br>\n"
|
||||
return result
|
||||
|
||||
def tex(self):
|
||||
return "\\\\\n".join(self.lines) + "\n"
|
||||
result = ""
|
||||
for line in self.lines:
|
||||
if line:
|
||||
line += r" \\"
|
||||
result += line + "\n"
|
||||
result = re.sub(r"\\\\\n\n", "\n\n", result)
|
||||
return result
|
||||
26
sks/block/css/block.css
Normal file
26
sks/block/css/block.css
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
p {
|
||||
margin: .5rem 0 .5rem 0;
|
||||
}
|
||||
|
||||
.quote {
|
||||
margin-left: 2em;
|
||||
}
|
||||
|
||||
.box {
|
||||
border: solid black 1px;
|
||||
padding: 0.5em 1em;
|
||||
clear: both;
|
||||
margin: 1.0em 0;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.centered {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
.indent {
|
||||
margin-left: 2rem;
|
||||
}
|
||||
1
sks/block/css/list.txt
Normal file
1
sks/block/css/list.txt
Normal file
@@ -0,0 +1 @@
|
||||
block.css
|
||||
30
sks/block/js/justify.js
Normal file
30
sks/block/js/justify.js
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
function adjust_footnotes() {
|
||||
return;
|
||||
const nodes = document.querySelectorAll(".footnote")
|
||||
+ document.querySelectorAll(".footnotetext");
|
||||
nodes.forEach(function (node) {
|
||||
const left = node.parentElement.position().left;
|
||||
const c = document.getElementById("text");
|
||||
const half_width = c.width() / 2.0;
|
||||
const mid = c.position().left + half_width;
|
||||
const max_width = 400;
|
||||
if (left > mid) {
|
||||
node.style.right = "0em";
|
||||
node.style.left = "auto";
|
||||
} else {
|
||||
node.style.left = "0em";
|
||||
node.style.right = "auto";
|
||||
}
|
||||
node.setAttribute("width", Math.min(max_width, half_width));
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
window.onload = function() {
|
||||
// This means "no animation", not "don't show the tooltip."
|
||||
console.log("tooltip: " + document.tooltip, document.getAttribute("tooltip"));
|
||||
//document.tooltip.setAttribute("hide", false);
|
||||
//document.tooltip.setAttribute("show", false);
|
||||
};
|
||||
*/
|
||||
20
sks/block/sty/block.sty
Normal file
20
sks/block/sty/block.sty
Normal file
@@ -0,0 +1,20 @@
|
||||
%\usepackage{quoting}
|
||||
%\quotingsetup{vskip=0pt}
|
||||
\usepackage{float}
|
||||
\usepackage{multicol}
|
||||
|
||||
%\usepackage[absolute,showboxes]{textpos}
|
||||
\usepackage[absolute]{textpos}
|
||||
\setlength{\TPHorizModule}{\paperheight}
|
||||
\setlength{\TPVertModule}{\paperwidth}
|
||||
|
||||
%\setlength{\TPVertModule}{1\paperheight}
|
||||
\textblockorigin{0in}{0in}
|
||||
|
||||
\newlength{\fwboxwidth}
|
||||
\newcommand{\fwboxn}[1]{\setlength{\fwboxwidth}{#1}}
|
||||
\newcommand{\fwboxs}[1]{\setlength{\fwboxwidth}{\widthof{#1}}}
|
||||
\newcommand{\fwbox}[1]{\makebox[\fwboxwidth][l]{#1}}
|
||||
|
||||
% No space if top of page:
|
||||
\newcommand{\topspace}[1]{\ifdim\pagetotal=0pt\else\vspace*{#1}\fi}
|
||||
Reference in New Issue
Block a user