What I'm trying to do
I want to create a custom cross-referencing tag which a reader can click on and view the line of text I am referencing. However, I want the numbering of the tags to be automated so I can add and subtract items from my text without manually renumbering something.
To achieve this, I am currently kludging together an expl3 \prop_ which behaves similarly to the Python dict or C-like map which are quite common. I set and call my custom tags inside commands and spit out a test. BUT, it seems like my \prop_item increments my counter in a manner I don't expect.
MWE
\documentclass{article}
\usepackage{hyperref}
\usepackage{xparse}
% Define a dict-like object where I can store the label and my associated text.
\ExplSyntaxOn
\prop_new:N \g_prop_dict
\NewDocumentCommand{\dictappend}{mm}{%
\prop_gput:Nnn\g_prop_dict{#1}{#2}
}
\NewDocumentCommand{\CGet}{m}{%
\prop_item:Nn\g_prop_dict{#1}
}
\ExplSyntaxOff
% First counter
\newcounter{articlejournal}
\setcounter{articlejournal}{1}
\newcommand{\countAJ}[1]{%
\dictappend{#1}{AJ\thearticlejournal}
\phantomsection\label{#1}{\textbf{AJ\thearticlejournal}}
\stepcounter{articlejournal}
}%
% Secound counter
\newcounter{articleconference}
\setcounter{articleconference}{1}
\newcommand{\countAC}[1]{%
\dictappend{#1}{AC\thearticleconference}
\phantomsection\label{#1}{\textbf{AC\thearticleconference}}
\stepcounter{articleconference}
}%
% Command to retrieve the value and format it correctly.
\newcommand{\myref}[1]{\hyperref[#1]{\textbf{\CGet{#1}}}}
\begin{document}
\countAJ{foo} - is test 1
\countAJ{bar} - is test 2
\countAC{baz} - this is a different one
Here I reference \myref{bar} and \myref{foo}, and here I want \myref{baz}.
I expect these to look like AJ2, AJ1, and AC1, respectively.
\end{document}
Making Input Variables Immutable
It seems like my \dictappend{#1}{A*\thearticle***} formatted lines are not passing immutable values with \the like I would expect. Is that not how it works?
What I Don't Want or Does not Work
- I have tried using parts from this post, but no configuration helped that I tried. This is odd, because @egreg 's answer seems like it should work when I apply it to
\dictappend{#1}{\edef\newstring{AJ\thearticlejournal}}, yet this just makes my string disappear. - Making a 2-argument label definition a la this question is not acceptable here. I want to be able to insert a new entry into a big list without re-numbering things manually. My use-case requires self-reference.
- Since I have multiple counters I want to reference with
\myref, using\theto access the count does not have the effect I need as cited here. Using\thealone, the best I could manage was injection of the counter value only. - Similarly, working with
\refstepcountersimilar to this example only returns the value instead of the text.
The Ask
Why are my variables incrementing during this operation? How can I fix this such that they do not change after each dict entry is defined?

\prop_gput:Nnxin\dictappend. – gusbrs Mar 14 '23 at 20:56\dictappend{#1}{A*\thearticle***}just storesA*\thearticle***you want anxorevariant to expand the argument – David Carlisle Mar 14 '23 at 20:59xto work like gusbrs mentioned, but using the nestedein the arg-spec:Nnein the_gputappears to fail. – WesH Mar 14 '23 at 21:09evariant of that one isn't predefined but you can always define such variants, just a representative sample are predefined, morexthaneas theetype is newer – David Carlisle Mar 14 '23 at 21:12