# Variables (in some cases) not working inside \href

Given this small document class file mycustomloc.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mycustomloc}[2019/03/06 My custom class]
\RequirePackage{hyperxmp}
\RequirePackage[unicode]{hyperref}
\RequirePackage{xstring}
\RequirePackage{setspace}

\newcommand{\phone}[1]{\def\@phone{#1}}

\def\@neighborhood{#1}
\def\@city{#2}
\def\@state{#3}
\def\@country{#4}
}

\def\@urlparams{\StrSubstitute{\@neighborhood+\@city+\@state+\@country}{ }{+}}
\def\@phoneparams{\StrSubstitute{\@phone}{ }{}}

\newcommand{\makecontact}{%
Phone: \href{tel://\@phone}{\@phone}

\vspace{\baselineskip}
Why I can't add the variable urlparams in the \texttt{href} below if I
can insert variables in the phone above (as you can see).

\vspace{\baselineskip}
The content of urlparams is given below:

\texttt{\@urlparams}.

If add the string'' manually to \texttt{href}  it works:

But adding the variable do not

}

\endinput

And this simple minimal working example mwe.tex

\documentclass{mycustomloc}

\address{Spring Falls}{Helena-West Helena}{AR}{United States of America}
\phone{+1 123 555-1234}

\begin{document}
\makecontact
\end{document}

I'm not able to compile it if I use \@urlparams inside the \href (last one, is commented), but "manually" writting the string contents to the first parameter of \href works.

Why this behavior is ocurring and how to fix, since I want to be able to use the \@urlparams inside the \href command.

I also could not find any reasoning, since I'm able to use the \@phone variable inside the first \href call.

mycustom.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mycustom}[2019/03/06 My custom class]
\RequirePackage{hyperxmp}
\RequirePackage[unicode]{hyperref}
\RequirePackage{xstring}
\RequirePackage{setspace}

\newcommand{\phone}[1]{\def\@phone{#1}}

\def\@neighborhood{#1}
\def\@city{#2}
\def\@state{#3}
\def\@country{#4}
}

\def\@urlparams{\StrSubstitute{\@neighborhood+\@city+\@state+\@country}{ }{+}[\first]\xdef\URLparams{\first}\first}
\def\@phoneparams{\StrSubstitute{\@phone}{ }{}}

\newcommand{\makecontact}{%
Phone: \href{tel://\@phone}{\@phone}

\vspace{\baselineskip}
Why I can't add the variable urlparams in the \texttt{href} below if I
can insert variables in the phone above (as you can see).

\vspace{\baselineskip}
The content of urlparams is given below:

\texttt{\@urlparams}.

If add the string'' manually to \texttt{href}  it works:

But adding the variable do not
}

\endinput

main.tex:

\documentclass{mycustom}

\address{Spring Falls}{Helena-West Helena}{AR}{United States of America}
\phone{+1 123 555-1234}

\begin{document}
\makecontact
\end{document}
• No. It says: ! Undefined control sequence.<argument> ...://www.google.com/maps?q=\URLparams . Anyhow, can you explain what you tried to do? – Lin Mar 9 at 4:46
• Please test it again... I didn't change something, but had rename the class from your previous question... Pay attention to the names of the class in order to avoid a possible make a mistake... It supposed to work (tested) and it is a matter of expansion since I using a variable with \xdef... May be you didn't copy the whole code before... I have already defined the variable – koleygr Mar 9 at 4:53
• Is there any good reason for the change in class name? – Lin Mar 9 at 5:01
• No, but Yes!... I was bored to rename the code in your previous question and just placed the code in the old files.... – koleygr Mar 9 at 5:12