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}
\expandafter\newcommand\csname #1\endcsname[1]{\noindent%
\refstepcounter{#1}\textbf{#2\arabic{#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:
- Move the labels out of the command and write them directly behind it ( so \goal{g:reach-himalaya} would become \goal\label{g:reach-himalaya}). But this did not work, as the label now pointed to the last section instead of my goal.
- Create a .tex file, where i print all the labels I generate again. This file is then included with \input inside a false if block. This way, the IDE picks up the labels, but the generation still works. I couldn't get this to work, as it did not let me correctly print the commands into the file
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.
.cwlentry for each of your new 'counters'. For example,\goal{label}#lif you have\customcounter{goal}{G}. Read this answer and the TeXstudio user manual if you need an intro to cwl. – Troy Aug 14 '18 at 14:37