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:
55
sks/font/font.py
Normal file
55
sks/font/font.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import re
|
||||
import klammer_base
|
||||
|
||||
class Subsuper(klammer_base.Klammer_base):
|
||||
def __init__(self, K, position):
|
||||
super().__init__(K)
|
||||
self.position = position
|
||||
"""
|
||||
print("Subsuper:", self.args)
|
||||
|
||||
parts = self.args.strip().split()
|
||||
if len(parts) != 2:
|
||||
raise Exception(f"Two arguments required, but argument is: {self.args.strip()}")
|
||||
self.base, self.script = parts
|
||||
"""
|
||||
|
||||
def html(self):
|
||||
return f"{self.base}<{self.position}>{self.script}</sub>"
|
||||
|
||||
def tex(self):
|
||||
if self.position == "sub":
|
||||
return f"${self.base}_{self.script}$"
|
||||
else:
|
||||
return f"${self.base}^{self.script}$"
|
||||
|
||||
def html_fontify(text, font_symbol, font_size):
|
||||
cls = {"r" : "",
|
||||
"i" :"ritalic",
|
||||
"b" : "bold",
|
||||
"s" : "sansserif",
|
||||
"t" : "monospace",
|
||||
"c" : "code"}[font_symbol]
|
||||
result = text
|
||||
if cls:
|
||||
if font_symbol == "c":
|
||||
result = re.sub(" ", " ", result)
|
||||
cls = f'class="cls"'
|
||||
sty = ""
|
||||
if font_size != 1:
|
||||
sty = f'style="font-size: {float(font_size) * 100}%"'
|
||||
attr = (cls + " " + sty).strip()
|
||||
if attr:
|
||||
result = f'<span {attr}>{result}</span>'
|
||||
return result
|
||||
|
||||
|
||||
def tex_fontify(text, font_symbol, font_size):
|
||||
command = {"r" : "\\rmfamily",
|
||||
"i" :"\\it",
|
||||
"b" : "\\bfseries",
|
||||
"s" : "\\sffamily",
|
||||
"t" : "\\ttfamily",
|
||||
"c" : "\\ttfamily"}[font_symbol]
|
||||
result = f"{{{command}\\scalefont{{{font_size}}}{{{text}}}}}"
|
||||
return result
|
||||
Reference in New Issue
Block a user