[Solved] Printing labels into file to support editor

joz Asks: Printing labels into file to support editor
I am using the following command to define a custom counter for different things I refer later in the document.

Code:
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:

  1. Move the labels out of the command and write them directly behind it ( so goal{g:reach-himalaya} would become goallabel{g:reach-himalaya}). But this did not work, as the label now pointed to the last section instead of my goal.
  2. 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.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.