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:
8
sks/color/color.k
Normal file
8
sks/color/color.k
Normal file
@@ -0,0 +1,8 @@
|
||||
@@@argtype color |
|
||||
a color in the form <red> <green> <blue>.
|
||||
:pattern 'float' 'float' 'float'
|
||||
:python_cast (lambda s : [float(e) for e in s.strip().split()])
|
||||
@@@
|
||||
|
||||
@@color.k rgb :text : Color description as required by the target from @c <r>,<g>,<b> @ input @@
|
||||
@@color :: @eval color.Color(K) eval@ @@
|
||||
37
sks/color/color.py
Normal file
37
sks/color/color.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import re
|
||||
import klammer_base
|
||||
import kutil
|
||||
|
||||
class Color(klammer_base.Klammer_base):
|
||||
def __init__(self, K):
|
||||
kutil.msg()
|
||||
super().__init__(K)
|
||||
match = re.compile(r'([0-9.]+)\s*,\s*([0-9.]+)\s*,\s*([0-9.]+)', re.S).match(self.rgb)
|
||||
if not match:
|
||||
raise fehler.KlammertextError(
|
||||
'Error in color format: "{}". '.format(K.rgb)
|
||||
+ 'Should be "<r>,<g>,<b>", where the components are [0,1].')
|
||||
self.r, self.g, self.b = [float(c) for c in match.groups()]
|
||||
|
||||
def html(self):
|
||||
result = 'rgb({},{},{})'.format(*[int(round(float(e*255))) for e in [self.r, self.g, self.b]])
|
||||
#result = f"rgb({self.r},{self.g},{self.b}"
|
||||
if self.text:
|
||||
result = f'<span style="color:{result}">{self.text}</span>'
|
||||
return result
|
||||
|
||||
def tex(self):
|
||||
result = '\\color[rgb]{{{},{},{}}}'.format(self.r, self.g, self.b)
|
||||
if self.text:
|
||||
result = '{{{} {}}}'.format(result, self.text)
|
||||
return result
|
||||
|
||||
def hex_color(name, hex):
|
||||
def c(h):
|
||||
return float(eval('0x' + h)) / 255.0
|
||||
r = c(hex[:2])
|
||||
g = c(hex[2:4])
|
||||
b = c(hex[4:])
|
||||
return '\\definecolor{{{}}}{{rgb}}{{{:.3f},{:.3f},{:.3f}}}'.format(
|
||||
name, r, g, b)
|
||||
|
||||
16
sks/color/sty/color.sty
Normal file
16
sks/color/sty/color.sty
Normal file
@@ -0,0 +1,16 @@
|
||||
\usepackage[table]{xcolor}
|
||||
|
||||
\definecolor{Gray}{gray}{.85}
|
||||
\definecolor{LightGray}{gray}{.95}
|
||||
\definecolor{White}{gray}{1}
|
||||
\definecolor{Red}{rgb}{1,0,0}
|
||||
\definecolor{Darkred}{rgb}{.5,0,0}
|
||||
\definecolor{Lightred}{rgb}{0.855,0.812,0.812}
|
||||
\definecolor{Metalightred}{rgb}{0.598,0.568,0.568}
|
||||
\definecolor{RoyalBlue}{rgb}{0,0,0.5}
|
||||
\definecolor{Pink}{rgb}{1,.8,.8}
|
||||
\definecolor{Green}{rgb}{.8, 1, .8}
|
||||
\definecolor{Bluu}{rgb}{.6,.7,.8}
|
||||
\definecolor{Middlegray}{gray}{.5}
|
||||
|
||||
\definecolor{LinkBlue}{rgb}{0.1,0.2,0.5}
|
||||
Reference in New Issue
Block a user