aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-09-18 13:40:39 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-09-18 13:40:39 +0200
commit6b034454f35819999cc26cfe472d537bf1eb3fbf (patch)
treef3ac5a79ed3daa13aaee8d9dbe06e112ffad03d4
parentde6821389604dc5254b285a1ca13b19ffb1905b5 (diff)
fix requirement cross-references
-rw-r--r--example.tex2
-rw-r--r--projdoc.cls83
-rw-r--r--readme.md6
-rwxr-xr-xscripts/reqs2tex.py16
4 files changed, 88 insertions, 19 deletions
diff --git a/example.tex b/example.tex
index e0d21c0..24c525b 100644
--- a/example.tex
+++ b/example.tex
@@ -3,8 +3,6 @@
% with the [draft] option. this replaces all images with placeholders.
\input{meta.tex}
-\externaldocument{reqs}[./requirements.pdf]
-
\title{Example Document}
\begin{document}
diff --git a/projdoc.cls b/projdoc.cls
index fe8c8bc..23f3ea9 100644
--- a/projdoc.cls
+++ b/projdoc.cls
@@ -145,13 +145,13 @@
% \cref{<refname>} is used
\makeatletter
\NewDocumentCommand{\customlabel}{omm}{%
- \begingroup
- \cref@constructprefix{#1}{\cref@result}%
- \protected@edef\@currentlabel{#3}%
- \protected@edef\@currentlabelname{#3}%
- \protected@edef\cref@currentlabel{[#1][][\cref@result]#3}
- \label[#1]{#2}%
- \endgroup
+ \begingroup
+ \cref@constructprefix{#1}{\cref@result}%
+ \protected@edef\@currentlabel{#3}%
+ \protected@edef\@currentlabelname{#3}%
+ \protected@edef\cref@currentlabel{[#1][][\cref@result]#3}
+ \label[#1]{#2}%
+ \endgroup
}
\makeatother
@@ -215,6 +215,9 @@
selection={recorded and deps and see},
]
+% requirements
+\externaldocument{reqs}[./requirements.pdf]
+
% default document header/trailer
\makeatletter
\def\projdoc@header{
@@ -293,8 +296,8 @@
\def\UrlRight{\hbox{\,}}%
}
\DefineVerbatimEnvironment{blockcode}{Verbatim}{
- tabsize=2,
- obeytabs,
+ tabsize=2,
+ obeytabs,
}
% scale down image if it exceeds page margins
@@ -321,3 +324,65 @@
\crefname{test}{test}{tests}
\Crefname{test}{Test}{Tests}
+% fix cleveref showing filename to external cross-reference
+% see <https://tex.stackexchange.com/a/708445/211562>
+% edited from cleveref source
+\makeatletter
+\def\cref@getref#1#2{%
+ \expandafter\let\expandafter#2\csname r@#1@cref\endcsname%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter#2%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@firstoffive#2}}%
+\def\cpageref@getref#1#2{%
+ \expandafter\let\expandafter#2\csname r@#1@cref\endcsname%
+ \expandafter\expandafter\expandafter\def%
+ \expandafter\expandafter\expandafter#2%
+ \expandafter\expandafter\expandafter{%
+ \expandafter\@secondoffive#2}}%
+\AtBeginDocument{%
+ \def\label@noarg#1{%
+ \cref@old@label{#1}%
+ \@bsphack%
+ \edef\@tempa{{page}{\the\c@page}}%
+ \setcounter{page}{1}%
+ \edef\@tempb{\thepage}%
+ \expandafter\setcounter\@tempa%
+ \cref@constructprefix{page}{\cref@result}%
+ \protected@write\@auxout{}{%
+ \string\newlabel{#1@cref}{%
+ {\cref@currentlabel}%
+ {[\@tempb][\arabic{page}][\cref@result]\thepage}%
+ {}%
+ {}%
+ {}%
+ }%
+ }%
+ \@esphack%
+ }%
+ \def\label@optarg[#1]#2{%
+ \cref@old@label{#2}%
+ \@bsphack%
+ \edef\@tempa{{page}{\the\c@page}}%
+ \setcounter{page}{1}%
+ \edef\@tempb{\thepage}%
+ \expandafter\setcounter\@tempa%
+ \cref@constructprefix{page}{\cref@result}%
+ \protected@edef\cref@currentlabel{%
+ \expandafter\cref@override@label@type%
+ \cref@currentlabel\@nil{#1}%
+ }%
+ \protected@write\@auxout{}{%
+ \string\newlabel{#2@cref}{%
+ {\cref@currentlabel}%
+ {[\@tempb][\arabic{page}][\cref@result]\thepage}%
+ {}%
+ {}%
+ {}%
+ }%
+ }%
+ \@esphack%
+ }%
+}
+\makeatother
+
diff --git a/readme.md b/readme.md
index 7b58cfd..818d445 100644
--- a/readme.md
+++ b/readme.md
@@ -18,12 +18,6 @@ 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/scripts/reqs2tex.py b/scripts/reqs2tex.py
index 700d05f..8a6976a 100755
--- a/scripts/reqs2tex.py
+++ b/scripts/reqs2tex.py
@@ -101,8 +101,20 @@ def fmt_aux(data):
for item in data:
ref = label2ref(item[KEY.LABEL])
out += [
- tex.cmd('newlabel', f"{ref}", tex.group(item[KEY.ID], item[KEY.ID], 'ggg', 'hhh', 'iii')),
- tex.cmd('newlabel', f"{ref}@cref", tex.group(f"[requirement][aaa][bbb]{item[KEY.ID]}", '[ccc][ddd][eee]fff')),
+ tex.cmd('newlabel', f"{ref}", tex.group(
+ item[KEY.ID],
+ '',
+ '',
+ ref,
+ '',
+ )),
+ tex.cmd('newlabel', f"{ref}@cref", tex.group(
+ f"[requirement][][]{item[KEY.ID]}",
+ '[][][]',
+ '',
+ '',
+ './requirements.pdf',
+ )),
]
return "\n".join(out)