1

Given this small document class file mycustomloc.cls:

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

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

\newcommand{\address}[4]{
    \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:

    Loc.: \href{https://www.google.com/maps?q=Spring+Falls+Helena-West+Helena+AR+United+States+of+America}{\@city, \@state \,-- \@country}

    But adding the variable do not

    Loc.: \href{https://www.google.com/maps?q=\@urlparams}{\@city, \@state \,-- \@country}
}

\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.

2

mycustom.cls:

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

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

\newcommand{\address}[4]{
    \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:

    Loc.: \href{https://www.google.com/maps?q=Spring+Falls+Helena-West+Helena+AR+United+States+of+America}{\@city, \@state \,-- \@country}

    But adding the variable do not
    Loc.: \href{https://www.google.com/maps?q=\URLparams}{\@city, \@state \,-- \@country}
}

\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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.