TeX - LaTeX Asked by joz on May 31, 2021
I am using the following command to define a custom counter for different things I refer later in the document.
usepackage{cleveref}
newcommand{customcounter}[2]{%
newcounter{#1} setcounter{#1}{0} crefname{#1}{#2}{#2s}
expandafternewcommandcsname #1endcsname[1]{noindent%
refstepcounter{#1}textbf{#2arabic{#1}}label{##1}%
makeatletter
}
}
customcounter{goal}{G}
customcounter{functionalrequirement}{FR}
When referencing things, I normally get hints from my editor (visual studio code with tex workshop or TexStudio). But when using these labels defined this way, it does not pick up the labels.
I had two solutions to this:
Now my question is: How could I correctly implement any of these solutions? I think that 1 is a bit cleaner code-wise and less of a workaround. On the other hand solution 2 is also interesting, as it makes the usage of the commands easier.
I found a workaround, that is very similar to the first proposed solution. I pulled the label part out of the command definition. the code now looks like this:
usepackage{cleveref}
newcommand{customcounter}[2]{%
newcounter{#1} setcounter{#1}{0} crefname{#1}{#2}{#2s} crefformat{#1}{#2##2##1##3}
expandafternewcommandcsname #1endcsname[1]{noindent%
refstepcounter{#1}textbf{#2arabic{#1}}##1%
}
}
customcounter{goal}{G}
and can be used with:
goal{label{g:reach-himalaya}}
Answered by joz on May 31, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP