From c9d4ba22a8b6d0d5fb1062701eda8b1af554d422 Mon Sep 17 00:00:00 2001
From: Loek Le Blansch <loek@pipeframe.xyz>
Date: Sat, 14 Sep 2024 20:41:10 +0200
Subject: WIP requirements

---
 requirements.tex | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 requirements.tex

(limited to 'requirements.tex')

diff --git a/requirements.tex b/requirements.tex
new file mode 100644
index 0000000..39e5831
--- /dev/null
+++ b/requirements.tex
@@ -0,0 +1,11 @@
+\documentclass{projdoc}
+\input{meta.tex}
+\input{reqs.tex}
+
+\title{Requirements}
+
+\begin{document}
+
+
+\end{document}
+
-- 
cgit v1.2.3


From b31ebef3db3765eef8e0492897e870a9fa4cd32b Mon Sep 17 00:00:00 2001
From: Loek Le Blansch <loek@pipeframe.xyz>
Date: Mon, 16 Sep 2024 18:48:23 +0200
Subject: fix cross-reference links to external file

---
 example.tex         |  4 ++--
 projdoc.cls         |  1 +
 readme.md           |  6 ++++++
 requirements.tex    |  1 -
 scripts/reqs2tex.py | 13 +++++--------
 5 files changed, 14 insertions(+), 11 deletions(-)

(limited to 'requirements.tex')

diff --git a/example.tex b/example.tex
index ee1377a..e0d21c0 100644
--- a/example.tex
+++ b/example.tex
@@ -3,7 +3,7 @@
 % with the [draft] option. this replaces all images with placeholders.
 \input{meta.tex}
 
-\input{reqs.aux}
+\externaldocument{reqs}[./requirements.pdf]
 
 \title{Example Document}
 
@@ -174,7 +174,7 @@ the glossary that is automatically printed after \codeinline{\end{document}}.
 \subsubsection{Requirements}
 
 Requirements are referenced like \codeinline{\label}s:
-e.g.~\cref{req:audio:handle:id,req:audio:async-api:id}.
+e.g.~\cref{req:audio:handle,req:audio:async-api}.
 
 \end{document}
 
diff --git a/projdoc.cls b/projdoc.cls
index c11fe61..8a592e3 100644
--- a/projdoc.cls
+++ b/projdoc.cls
@@ -40,6 +40,7 @@
 \RequirePackage{tabularx}
 \RequirePackage{booktabs}
 \RequirePackage{needspace}
+\RequirePackage{xr-hyper}
 \RequirePackage{hyperref}
 \RequirePackage{microtype}
 \RequirePackage{xcolor}
diff --git a/readme.md b/readme.md
index 818d445..7b58cfd 100644
--- a/readme.md
+++ b/readme.md
@@ -18,6 +18,12 @@ A `latexmkrc` file is provided for copmilation with latexmk. The documents
 should also compile under [Visual Studio Code][vscode] using the [LaTeX
 Workshop extension][latexworkshop], as well as [VimTeX][vimtex].
 
+## TODO
+
+- Requirement cross-references are broken (they print both the label and the
+  path to the other document, should be label only). Interesting:
+  `\creflabelformat` and `\@templabel` (inside #2 of `\creflabelformat`).
+
 [vscode]: https://code.visualstudio.com
 [latexworkshop]: https://marketplace.visualstudio.com/items?itemName=James-Yu.latex-workshop
 [vimtex]: https://github.com/lervag/vimtex
diff --git a/requirements.tex b/requirements.tex
index 39e5831..1b51220 100644
--- a/requirements.tex
+++ b/requirements.tex
@@ -6,6 +6,5 @@
 
 \begin{document}
 
-
 \end{document}
 
diff --git a/scripts/reqs2tex.py b/scripts/reqs2tex.py
index c5ab3dd..667eeb6 100755
--- a/scripts/reqs2tex.py
+++ b/scripts/reqs2tex.py
@@ -69,18 +69,15 @@ def convert(data):
   return reqs
 
 def req2aux(req):
-  # TODO: this is a dead-end solution, newlabel only works for in-document anchors, not external links
+  ref = tex.label2ref(req['label'])
   out = [
-    tex.scmd('newlabel', f"req:{req['label']}:id", tex.group(req['id'], req['id'], '', './requirements.pdf', '')),
-    tex.scmd('newlabel', f"req:{req['label']}:id@cref", tex.group(f"[requirement][][]{req['id']}", '')),
+    tex.cmd('newlabel', f"{ref}", tex.group(req['id'], req['id'], 'ggg', 'hhh', 'iii')),
+    tex.cmd('newlabel', f"{ref}@cref", tex.group(f"[requirement][aaa][bbb]{req['id']}", '[ccc][ddd][eee]fff')),
   ]
-  return "\n".join([tex.auxout(line) for line in out])
+  return "\n".join(out)
 
 def fmt_aux(data):
-  out = ""
-  out += tex.cmd('makeatletter')
-  out += "\n".join([req2aux(req) for req in data])
-  out += tex.cmd('makeatother')
+  out = "\n".join([req2aux(req) for req in data])
   return out
 
 def fmt_tex(data):
-- 
cgit v1.2.3


From 2e49e0e0db184295eb08e930a3ccdf10e80e40fe Mon Sep 17 00:00:00 2001
From: Loek Le Blansch <loek@pipeframe.xyz>
Date: Mon, 16 Sep 2024 19:07:50 +0200
Subject: implement simple requirements dump

---
 glossary.bib        |  5 +++++
 projdoc.cls         | 25 +++++++++++++++----------
 requirements.tex    | 12 +++++++++++-
 scripts/reqs2tex.py | 32 +++++++++++++++++++-------------
 scripts/tex.py      |  8 +++++++-
 5 files changed, 57 insertions(+), 25 deletions(-)

(limited to 'requirements.tex')

diff --git a/glossary.bib b/glossary.bib
index 4d02e4a..437db86 100644
--- a/glossary.bib
+++ b/glossary.bib
@@ -28,3 +28,8 @@
 	description = {Graphics library developed by \hbox{Microsoft}},
 }
 
+@acronym{api,
+	short = {API},
+	long = {Application Programming Interface},
+}
+
diff --git a/projdoc.cls b/projdoc.cls
index 8a592e3..fe8c8bc 100644
--- a/projdoc.cls
+++ b/projdoc.cls
@@ -121,16 +121,23 @@
 	itemsep=\dimexpr\style@itemsep-\style@parsep\relax,
 	parsep=\style@parsep,
 }
-\def\projdoc@setdescriptionstyle{%
+\def\projdoc@description@before{%
 	\renewcommand\makelabel[1]{%
 		{\bfseries ##1}:%
 	}%
 }
-\setdescription{
-	before={\projdoc@setdescriptionstyle},
-	leftmargin=3em,
-	labelindent=3ex,
+\newlength\projdoc@description@leftmargin%
+\projdoc@description@leftmargin=3em%
+\newlength\projdoc@description@labelindent%
+\projdoc@description@labelindent=3ex%
+\def\projdoc@setdescriptionstyle{%
+	\setdescription{
+		before={\projdoc@description@before},
+		leftmargin=\projdoc@description@leftmargin,
+		labelindent=\projdoc@description@labelindent,
+	}%
 }
+\projdoc@setdescriptionstyle%
 \makeatother
 
 % create a label using \customlabel[<creftype>]{<refname>}{<reftext>} that displays
@@ -230,11 +237,9 @@
 	}{}%
 	% glossary
 	\ifbool{projdoc@used@gls}{%
-		\setdescription{
-			before={\projdoc@setdescriptionstyle},
-			leftmargin=2ex,
-			labelindent=0pt,
-		}%
+		\projdoc@description@leftmargin=2ex%
+		\projdoc@description@labelindent=0pt%
+		\projdoc@setdescriptionstyle%
 		\section*{Glossary}%
 		\begin{multicols}{2}%
 			\renewcommand{\glossarysection}[2][]{}%
diff --git a/requirements.tex b/requirements.tex
index 1b51220..dee529d 100644
--- a/requirements.tex
+++ b/requirements.tex
@@ -1,10 +1,20 @@
 \documentclass{projdoc}
 \input{meta.tex}
-\input{reqs.tex}
+
+\makeatletter
+\projdoc@description@leftmargin=2ex
+\projdoc@description@labelindent=0pt
+\projdoc@setdescriptionstyle
+\makeatother
 
 \title{Requirements}
 
 \begin{document}
 
+\section{Requirements}
+\begin{multicols}{2}
+\input{reqs.tex}
+\end{multicols}
+
 \end{document}
 
diff --git a/scripts/reqs2tex.py b/scripts/reqs2tex.py
index 667eeb6..3bf0501 100755
--- a/scripts/reqs2tex.py
+++ b/scripts/reqs2tex.py
@@ -68,22 +68,28 @@ def convert(data):
 
   return reqs
 
-def req2aux(req):
-  ref = tex.label2ref(req['label'])
-  out = [
-    tex.cmd('newlabel', f"{ref}", tex.group(req['id'], req['id'], 'ggg', 'hhh', 'iii')),
-    tex.cmd('newlabel', f"{ref}@cref", tex.group(f"[requirement][aaa][bbb]{req['id']}", '[ccc][ddd][eee]fff')),
-  ]
-  return "\n".join(out)
-
 def fmt_aux(data):
-  out = "\n".join([req2aux(req) for req in data])
-  return out
+  out = []
+  for req in data:
+    ref = tex.label2ref(req['label'])
+    out += [
+      tex.cmd('newlabel', f"{ref}", tex.group(req['id'], req['id'], 'ggg', 'hhh', 'iii')),
+      tex.cmd('newlabel', f"{ref}@cref", tex.group(f"[requirement][aaa][bbb]{req['id']}", '[ccc][ddd][eee]fff')),
+    ]
+  return "\n".join(out)
 
 def fmt_tex(data):
-  return "\n".join([
-    tex.cmd('relax')
-  ])
+  out = []
+  for req in data:
+    out.append(
+      tex.cmd('subsection', req['id']) + "\n\n" +\
+      tex.env('description',
+        tex.cmd('item', ['Priority']) + req['priority'].title() +\
+        tex.cmd('item', ['Requirement']) + req['description'] +\
+        (tex.cmd('item', ['Definition of done']) + req['done'] if req['type'] == 'user' else "")
+      )
+    )
+  return "\n\n".join(out)
 
 def main(input_file):
   data = {}
diff --git a/scripts/tex.py b/scripts/tex.py
index 2fd51d8..2509a87 100644
--- a/scripts/tex.py
+++ b/scripts/tex.py
@@ -1,7 +1,13 @@
 # utility function for converting latex code
 
 def group(*args):
-  return "".join("{" + arg + "}" for arg in args)
+  out = ""
+  for arg in args:
+    if isinstance(arg, list):
+      out += "[" + arg[0] + "]"
+    if isinstance(arg, str):
+      out += "{" + arg + "}"
+  return out
 
 def string(content):
   return r"\string" + content
-- 
cgit v1.2.3


From 976a8d260fd138161317aac14df5311ef0ef07ca Mon Sep 17 00:00:00 2001
From: Loek Le Blansch <loek@pipeframe.xyz>
Date: Mon, 16 Sep 2024 19:08:37 +0200
Subject: add table of contents to requirements

---
 requirements.tex | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'requirements.tex')

diff --git a/requirements.tex b/requirements.tex
index dee529d..2936272 100644
--- a/requirements.tex
+++ b/requirements.tex
@@ -10,6 +10,8 @@
 \title{Requirements}
 
 \begin{document}
+\tablestables
+\newpage
 
 \section{Requirements}
 \begin{multicols}{2}
-- 
cgit v1.2.3

