Files
klammertext/sks/block/block.k
T
ack e4f1307aa9 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)
2026-09-07 22:37:05 +02:00

217 lines
5.5 KiB
Plaintext

#[
A paragraph is a document-structural object, like a section or a table of
contents, and making paragraphs is a service @document provides: inside a
@document, blank-line-separated text becomes paragraphs (the LaTeX
convention) and @par need not be written. @par is the explicit form, for
a text FRAGMENT rendered without a @document, where nothing infers them.
Written inside a @document it is harmless: html sees a <p>, which the
paragraph pass recognizes as a block and leaves alone, and \par in
vertical mode is a no-op.
]#
# Paragraph
@@par.k s : A paragraph of text. @@
@@par.html :: <p>*s*</p> @@
@@par.tex :: \par *s* \par @@
# In plain text a paragraph is delimited by blank lines, which
# phases.justify_blocks then fills; #/2 inserts them without depending on
# the definition body's own whitespace surviving extraction.
@@par.txt :: #/2*s*#/2 @@
# Non-breaking space
@@sp.k : Non-breaking space character @@
@@sp.html :: &^#160; @@
@@sp.tex :: ~ @@
# Indented block
@@indent.k s :left.int 8 :right.int -1 :ragged.bool false :
Indented block. The *left* and *right* values are the number of characters for
indentation (as roughtly defined by "ex"). By default, *right* is set to the
*left* value (with -1 as the sentinel).
@@
@@indent.html,tex,txt :: @eval block.Indent(K) eval@ @@
# Right justification
@@right.k s :margin 0 :top_margin 2 : Right-justified text @@
@@right.html ::
<div style="text-align: right; margin: *top_margin*ex *margin*ex 2ex 0;">*s*</div>
@@
@@right.tex ::
{\setlength{\topsep}{0pt}\setlength{\partopsep}{0pt}\setlength{\parskip}{*top_margin*ex}
\begin{flushright}
\raggedleft\rightskip=*margin*ex
*s*
\end{flushright}}
@@
@@right.txt ::
# str.rjust takes a ONE-character fill, so the padding is built by hand:
# the non-breaking space is a marker now, not a character.
@eval import textwrap, phases;
"\n".join([phases.txt_nbsp_marker() * (*Target_txt_width* - len(line)) + line
for line in textwrap.wrap("""*s*""", *Target_txt_width*)]) @
@@
# Quote with attribution
@@quote.k text | attribution : A block quote with attribution. @@
@@quote.html,tex ::
@indent *text* :left 8 @
@right *attribution* :margin 8
:top_margin @cond @eval "*K_target*" == "html" @ | -1 | 1 cond@ @
@@
# Highlighted note in text
@@note.k s :label Note :color 1.0,1.0,0.9 :border_color 0.2,0.2,0.2 :level.int 0 :width.float 0.5
: Rectangular block for an editorial note @@
@@note.html,tex :: @eval block.Note(K) @ @@
# Center
@@center.k s : Center text @@
@@center.tex ::
\begin{center}
*s*
\end{center}
@@
@@center.html ::
<p>
<div class="center">
*s*
</div>
</p>
@@
# Newline
@@nl.k : Newline character @@
@@nl.html :: <br/> @@
@@nl.tex :: @eval phases.tex_nl_marker() @ @@
@@nl.txt :: @eval phases.txt_nl_marker() @ @@
# New page
@@newpage.k : Start new page @@
@@newpage.html :: @@
@@newpage.tex :: \newpage @@
@@newpage.txt :: @@
# Extend page
@@extendpage.k linecount : Extenad current page @@
@@extendpage.html :: @@
@@extendpage.tex :: \enlargethispage{*linecount*\baselineskip} @@
@@extendpage.txt :: @@
# Vertical space
@@vspace.k lines.float : Vertical space, in multiples of the current line height @@
@@vspace.tex :: \vspace{*lines*\baselineskip} @@
@@vspace.html :: <div style="height: *lines*lh"></div> @@
@@vspace.txt :: @eval phases.txt_vspace_marker() * round(*lines*) @ @@
# Vertical fill to end of page
@@vfill.k :
Fill the vertical space so that any following text is flush with the bottom
of the page (in HTML, the bottom of the window; once the content is taller
than the window the space collapses, as on a full LaTeX page). Several
vfills divide the space equally, like LaTeX's \vfill glue. In plain text,
only makes some vertical space. @@
@@vfill.tex :: \vfill @@
# An empty glue div; block.css gives it flex-grow 1 and makes the text
# column a flex column only in documents that use it (the :has() rule).
@@vfill.html :: <div class="vfill"></div> @@
@@vfill.txt :: @vspace 3 @ @@
# Questions and answers
@@qa.k question | answer : Question and answer formatting @@
@@qa.html,tex,txt ::
@b Q: @ *question*
@b A: @ *answer*
@@
# Absolute positioning
@@@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.tex :: @eval block.Block(K) eval@ @@
# Preserved line endings
@@lines.k s : Maintain line breaks @@
@@lines.html,tex,txt :: @eval block.Lines(K) eval@ @@
# Multiple columns of text
@@multicolumn.k s :n 2 :gap 3 : Format *s* in *n* columns (default: 2). The *gap* is in "ex" units. @@
@@multicolumn.tex ::
{\setlength{\columnsep}{*gap*ex}
\setlength{\multicolsep}{\parskip}
\begin{multicols}{*n*}
*s*
\end{multicols}}
@@
@@multicolumn.html ::
<p>
<div style="column-count: *n*; column-gap: *gap*ex; text-align: justify;">
*s*
</div>
</p>
@@
# Text justified left and right on one line
@@left_right.k parts.rest(2) :
Pairs of text left- and right- justified. First, left lines are written with a
bar (|) between each line. Then, two bars (||), and the right lines with a bar
betwen them.
@@
@@left_right.html,tex :: @eval block.Left_right(K) @ @@
# Footnote
@@footnote.k s : Footnote @@
@@footnote.html :: <kt-footnote>*s*</kt-footnote> @@
@@footnote.tex :: \unskip\footnote{*s*} @@
@@footnote.txt :: __ #- @eval phases.txt_footnote_marker() @ *s* @eval phases.txt_footnote_marker() @ #- __ @@
# This doesn't work, either, so it isn't the @eval:
# @@footnote.txt :: __ #- marker *s* marker #- __ @@