A named group of optional parameters, declared once and used by several
klammers, so a writer learns one vocabulary instead of a spelling per
klammer. The "o" target is a pseudo-target beside "k": "k" declares a
klammer's interface and documents it, "o" declares an option interface and
documents it, and neither produces output for any target.
@@caption_args.o :caption :number.bool true :caption_side.side
: Arguments that define a caption for a block element @@
@@code.k :filename @hpos_args :hpos left @ @caption_args :caption_side top @
| text.literal : A source file displayed verbatim @@
A set is used only in the parameter list of a ".k" declaration -- the one
place a klammer's interface is declared once for all of its targets -- and
is resolved as that list is read. Names and types come from the set; a
default may be overridden where it is used. A klammer application in a
parameter list is now a definition-time error.
The SKS gains the sets caption_args and hpos_args (:hpos and :offset), and
@table, @image, @image_grid, @reference and @show gain .k declarations. A
distance is no longer written as a position: :hpos 4em is rejected, and the
same layout is :hpos left :offset 4em. Code listings are numbered by
default, like tables and figures.
New engine sources mac/option_set{,_registry}.{h,cpp}; tst/ ships two more
suites, option_set_test.sh and signature_test.sh (twelve in all).
(from dev 34e536cb0329)
120 lines
3.7 KiB
Python
120 lines
3.7 KiB
Python
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 latex_util.block(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'
|
|
|
|
# The \par on each side comes from latex_util.block() below: an
|
|
# \fcolorbox is box material and must sit in vertical mode.
|
|
result = '''
|
|
\\begingroup
|
|
COLOR\\setlength{\\fboxsep}{8pt}
|
|
\\fcolorbox{bordercolor}{localcolor}{
|
|
\\parbox{WIDTH}{\\raggedright\\setlength{\\parskip}{8pt}
|
|
\\textbf{LABEL:} TEXT
|
|
}}\\endgroup
|
|
'''
|
|
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 latex_util.block(result)
|
|
|
|
|
|
class Block(klammer_base.Klammer_base):
|
|
def __init__(self, K):
|
|
super().__init__(K)
|
|
#self.show()
|
|
|
|
def html(self):
|
|
return ""
|
|
|
|
def tex(self):
|
|
# NOT latex_util.block(): a textblock is absolutely positioned and
|
|
# does not participate in the normal flow, so breaking the paragraph
|
|
# around it would move the surrounding text.
|
|
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
|