aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-09-17 17:35:19 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-09-17 17:35:19 +0200
commit1df61d671706436c17e23bc9dcdc3bbd0f14a167 (patch)
tree0e507ff303210a54eef3417d6a4451f943037fa6
parentca5fb75953ae2a73d2d41ceff59e2688b11cbf2b (diff)
labels/refs working inside requirements.tex
-rwxr-xr-xscripts/reqs2tex.py28
-rw-r--r--scripts/tex.py17
2 files changed, 32 insertions, 13 deletions
diff --git a/scripts/reqs2tex.py b/scripts/reqs2tex.py
index 8c2236a..700d05f 100755
--- a/scripts/reqs2tex.py
+++ b/scripts/reqs2tex.py
@@ -107,19 +107,25 @@ def fmt_aux(data):
return "\n".join(out)
def fmt_tex(data):
- out = []
+ out = ""
for item in data:
- out.append(
- tex.cmd('subsection', item[KEY.ID]) +\
- tex.cmd('label', label2ref(item[KEY.LABEL])) +\
- tex.cmd('par') +\
- tex.env('description',
- tex.cmd('item', ['Priority']) + item[KEY.PRIORITY].title() +\
- tex.cmd('item', ['Requirement']) + item[KEY.DESCRIPTION] +\
- (tex.cmd('item', ['Definition of done']) + item[KEY.DONE] if item[KEY.DONE] is not None else "")
- )
+ out += tex.join(
+ tex.cmd('subsection', item[KEY.ID]),
+ tex.withatletter(
+ tex.cmd('cref@constructprefix', 'requirement', r'\cref@result'),
+ tex.pedef('@currentlabel', item[KEY.ID]),
+ tex.pedef('@currentlabelname', item[KEY.ID]),
+ tex.pedef('cref@currentlabel', tex.group(['requirement'], [''], [r'\cref@result']) + item[KEY.ID]),
+ ),
+ tex.cmd('label', ['requirement'], label2ref(item[KEY.LABEL])),
+ tex.cmd('par'),
+ tex.env('description', tex.join(
+ tex.cmd('item', ['Priority']) + item[KEY.PRIORITY].title(),
+ tex.cmd('item', ['Requirement']) + item[KEY.DESCRIPTION],
+ (tex.cmd('item', ['Definition of done']) + item[KEY.DONE] if item[KEY.DONE] is not None else ""),
+ ))
)
- return "".join(out)
+ return out
def main(input_file):
data = {}
diff --git a/scripts/tex.py b/scripts/tex.py
index 59c6895..eebf8ec 100644
--- a/scripts/tex.py
+++ b/scripts/tex.py
@@ -9,6 +9,9 @@ def group(*args):
out += "{" + arg + "}"
return out
+def join(*things):
+ return "".join(things)
+
def string(content):
return r"\string" + content
@@ -18,11 +21,14 @@ def cmd(*args):
if len(args) == 0: args = [""]
return f"\\{name}" + group(*args)
+def pedef(*args):
+ return r"\protected@edef" + cmd(*args)
+
def csdef(*args):
return r"\def" + cmd(*args)
-def auxout(content):
- return r"\write\@auxout" + group(content)
+def auxout(*content):
+ return r"\write\@auxout" + group(join(*content))
def scmd(*args):
return string(cmd(*args))
@@ -47,3 +53,10 @@ def esc(plain):
def tabrule(*cells):
return "&".join(cells) + "\\\\"
+def withatletter(*content):
+ return join(
+ cmd('makeatletter'),
+ *content,
+ cmd('makeatother'),
+ )
+