1

I tried to customize moderncv to make my telephone number clickable. In other documents I successfully used the following:

\usepackage{hyperref}  
\href{tel:number_to_dial}{number_to_display}

Clicking on it, the configured telefone app such as skype/zoom opens.

Since moderncv already provides the command \emaillink I tried to copy the command and adapt it accordingly. Looking into the code of moderncvfooti.sty I guessed that the command \makecvfoot has to be adapted as well. Thus I created a main file cv.tex in which I defined a new command \tellink similar to \emaillink and used the command in my own footer-style file (in the same folder). The own footer-style file is mainly a copy from the original moderncvfooti.sty where I added a small part at \renewcommand*{\makecvfoot}{....

However the command causes compilation errors, which I don't understand. The error is "Undefined control sequence" but at a completely unrelated line. Thus I need some help figuring this out. I attached a minimal working example but commented out the problematic line:

cv.tex:

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{casual}
\moderncvcolor{blue}

\usepackage[utf8]{inputenc}
\usepackage[scale=0.75]{geometry}

%-------------------------------------------------------------------------------
% this is the new command similar to \emaillink
%-------------------------------------------------------------------------------
\newcommand*{\tellink}[2][]{%
  \ifthenelse{\equal{#1}{}}%
    {\href{tel:#2}{#2}}%
    {\href{tel:#2}{#1}}}


% personal data
\name{John}{Doe}
\title{Resumé title}
\address{street and number}{postcode city}{country}
\phone[mobile]{+1~(234)~567~890}
\phone[fixed]{+2~(345)~678~901}
\phone[fax]{+3~(456)~789~012}
\email{[email protected]}
\homepage{www.johndoe.com}
\social[linkedin]{john.doe}
\social[twitter]{jdoe}
\social[github]{jdoe}
\extrainfo{additional information}
%\photo[64pt][0.4pt]{picture}
\quote{Some quote}


\begin{document}

\makecvtitle

\section{Education}
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}

\section{Master thesis}
\cvitem{title}{\emph{Title}}
\cvitem{supervisors}{Supervisors}
\cvitem{description}{Short thesis abstract}
TEXT\\

\end{document}

moderncvfooti.sty

%% start of file `moderncvfooti.sty'.
%% Copyright 2006-2015 Xavier Danaux ([email protected]).
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License version 1.3c,
% available at http://www.latex-project.org/lppl/.


%-------------------------------------------------------------------------------
%                identification
%-------------------------------------------------------------------------------
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{moderncvfooti}[2015/07/28 v2.0.0 modern curriculum vitae and letter footer variant: 1]


%-------------------------------------------------------------------------------
%                required packages
%-------------------------------------------------------------------------------


%-------------------------------------------------------------------------------
%                overall foot definition
%-------------------------------------------------------------------------------
% fonts
\renewcommand*{\addressfont}{\normalsize\mdseries\slshape}

% symbols
%   footer symbol used to separate footer elements
\newcommand*{\footsymbol}{%
    {~~~{\rmfamily\textbullet}~~~}}% the \rmfamily is required to force Latin Modern fonts when using sans serif, as OMS/lmss/m/n is not defined and gets substituted by OMS/cmsy/m/n

% lengths
\@initializelength{\footwidth}%
\renewcommand*{\recomputefootlengths}{%
  \setlength{\footwidth}{0.8\textwidth}}

% commands
%   internal command to add an element to the footer
%   it collects the elements in a temporary box, and checks when to flush the box
\@initializebox{\footbox}%
\@initializebox{\foottempbox}%
\@initializelength{\footboxwidth}%
\@initializeif{\if@firstfootelement}\@firstfootelementtrue%
%   adds an element to the footer, separated by footsymbol
%   usage: \addtofoot[footsymbol]{element}
\newcommand*{\addtofoot}[2][\footsymbol]{%
  \if@firstfootelement%
    \savebox{\foottempbox}{\usebox{\footbox}#2}%
  \else%
    \savebox{\foottempbox}{\usebox{\footbox}#1#2}\fi%
  \settowidth{\footboxwidth}{\usebox{\foottempbox}}%
  \ifnum\footboxwidth<\footwidth%
    \savebox{\footbox}{\usebox{\foottempbox}}%
    \@firstfootelementfalse%
  \else%
    \flushfoot\\%
    \savebox{\footbox}{#2}%
    \savebox{\foottempbox}{#2}%
    \settowidth{\footboxwidth}{\usebox{\footbox}}%
    \@firstfootelementfalse\fi}
%   internal command to flush the foot
\newcommand*{\flushfoot}{%
  \strut\usebox{\footbox}%
  \savebox{\footbox}{}%
  \savebox{\foottempbox}{}%
  \setlength{\footboxwidth}{0pt}}


%-------------------------------------------------------------------------------
%                resume foot definition
%-------------------------------------------------------------------------------
% lenghts
\renewcommand*{\recomputecvfootlengths}{\recomputefootlengths}

% commands
\renewcommand*{\makecvfoot}{%
  \recomputecvfootlengths{}%
  \fancypagestyle{plain}{%
    \fancyfoot[c]{%
      \parbox[b]{\footwidth}{%
        \centering%
        \color{color2}\addressfont%
        \vspace{\baselineskip}% forces a white line to ensure space between main text and footer (as footer height can't be known in advance)
        % \ifthenelse{\isundefined{\@addressstreet}}{}{\addtofoot[]{\addresssymbol\@addressstreet}%
        %   \ifthenelse{\equal{\@addresscity}{}}{}{\addtofoot[~--~]{\@addresscity}}% if \addresstreet is defined, \addresscity and \addresscountry will always be defined but could be empty
        %   \ifthenelse{\equal{\@addresscountry}{}}{}{\addtofoot[~--~]{\@addresscountry}}%
        %   \flushfoot\@firstfootelementtrue\\}%
        % \collectionloop{phones}{% the key holds the phone type (=symbol command prefix), the item holds the number
        %   \addtofoot{\csname\collectionloopkey phonesymbol\endcsname\collectionloopitem}}%
        % \ifthenelse{\isundefined{\@email}}{}{\addtofoot{\emailsymbol\emaillink{\@email}}}%
        % \ifthenelse{\isundefined{\@homepage}}{}{\addtofoot{\homepagesymbol\httplink{\@homepage}}}%
        % \collectionloop{socials}{% the key holds the social type (=symbol command prefix), the item holds the link
        %   \addtofoot{\csname\collectionloopkey socialsymbol\endcsname\collectionloopitem}}%
        \ifthenelse{\isundefined{\@extrainfo}}{}{\addtofoot{\@extrainfo}}%
        \ifthenelse{\lengthtest{\footboxwidth=0pt}}{}{\flushfoot}% the lengthtest is required to avoid flushing an empty footer, which could cause a blank line due to the \\ after the address, if no other personal info is used
        \\TEST123\\
        \begin{tabular}{ll}
          \@firstname \@familyname~ & {\normalsize\mobilephonesymbol}~{\@mobile}\\
          % \@addressstreet~               &{\normalsize\mobilephonesymbol}~{\tellink{\@mobile}}\\ % <--------- THIS LINE DOES NOT
          \@addressstreet~               &{\normalsize\mobilephonesymbol}~{\href{tel:123}{\@mobile}}\\ % <--------- THIS WORKS
          % \@addressstreet~               &{\normalsize\mobilephonesymbol}~{\href{tel:\@mobile}{\@mobile}}\\ % <--------- THIS LINE DOES NOT
          \@addressstreet~               &{\emailsymbol~\emaillink{\@email}}\\
          \@addresscity~         & \@email
        \end{tabular}
        }}}%
  \pagestyle{plain}}


%-------------------------------------------------------------------------------
%                letter foot definition
%-------------------------------------------------------------------------------
% commands
\renewcommand*{\recomputeletterfootlengths}{\recomputefootlengths}
\renewcommand*{\makeletterfoot}{%
  \recomputeletterfootlengths{}%
  \fancypagestyle{plain}{%
    \fancyfoot[c]{%
      \parbox[b]{\footwidth}{%
        \centering%
        \addressfont\color{color2}%
        \vspace{\baselineskip}% forces a white line to ensure space between main text and footer (as footer height can't be known in advance)
        \vspace{-\baselineskip}% to cancel out the extra vertical space taken by the name (below) and ensure perfect alignment of letter and cv footers
        \strut{\bfseries\upshape\@firstname~\@lastname}\\% the \strut is required to ensure the line is exactly \baselineskip tall
        \ifthenelse{\isundefined{\@addressstreet}}{}{\addtofoot[]{\addresssymbol\@addressstreet}%
          \ifthenelse{\equal{\@addresscity}{}}{}{\addtofoot[~--~]{\@addresscity}}% if \addresstreet is defined, \addresscity and addresscountry will always be defined but could be empty
          \ifthenelse{\equal{\@addresscountry}{}}{}{\addtofoot[~--~]{\@addresscountry}}%
          \flushfoot\@firstfootelementtrue\\}%
        \collectionloop{phones}{% the key holds the phone type (=symbol command prefix), the item holds the number
          \addtofoot{\csname\collectionloopkey phonesymbol\endcsname\collectionloopitem}}%
        \ifthenelse{\isundefined{\@email}}{}{\addtofoot{\emailsymbol\emaillink{\@email}}}%
        \ifthenelse{\isundefined{\@homepage}}{}{\addtofoot{\homepagesymbol\httplink{\@homepage}}}%
        \collectionloop{socials}{% the key holds the social type (=symbol command prefix), the item holds the link
          \addtofoot{\csname\collectionloopkey socialsymbol\endcsname\collectionloopitem}}%
        \ifthenelse{\isundefined{\@extrainfo}}{}{\addtofoot{\@extrainfo}}%
        \ifthenelse{\lengthtest{\footboxwidth=0pt}}{}{\flushfoot}% the lengthtest is required to avoid flushing an empty footer, which could cause a blank line due to the \\ after the address, if no other personal info is used
        }}}%
  \pagestyle{plain}}


\endinput


%% end of file `moderncvfooti.sty'.

EDIT: I included some test where I manually insert the link with \href{tel:123}{\@mobile} which displays the correct number and links to 123. But inserting \href{tel:\@mobile}{\@mobile}does not work and fails with undefined control sequence. I think this is the crux.

2
  • Did you saw the related question tex.stackexchange.com/q/487905/16550 ? Follow there the first link in comments too!
    – Mensch
    May 7, 2020 at 11:23
  • I didn't saw the question, but after looking into it and following the comments I think those problem are more related to using href properly. This however this is not my problem (I guess) since manually including href in my footer works. I edited the question. I think it is related to how the macro tellink is expanded? However I don't know enough to be sure.
    – v.tralala
    May 7, 2020 at 11:47

1 Answer 1

2

Class moderncv uses moderncvcollection.sty to create a printable information of the different versions of telefon available. That means that your used command is defined in another way you expect:

% compatibility with versions <= 1.4.0
\newcommand*{\mobile}[1]{\collectionadd[mobile]{phones}{#1}}

or

\collectionfindbykey {phones}{mobile}

if you inspect the used macro with command \show\@mobile ...

But there is a simple work around: define your own command \@mymobil like

\makeatletter
\def\@mymobile{+1~(234)~567~890} % <====================================
\makeatother

and then you can simply use code like

\makeatletter
%\show\@mobile % <=======================================================
\cvitem{Tel.}{\mobilephonesymbol~{\@mymobile}}
\cvitem{tellink}{\mobilephonesymbol~{\tellink{\@mymobile}}}
\cvitem{test}{\mobilephonesymbol~{\href{tel:123}{\@mymobile}}}
\cvitem{test}{\mobilephonesymbol~{\href{tel:\@mymobile}{\@mymobile}}}
\makeatother

in your cv tex file. To change the footer in moderncvfooti.sty you have to delete the original call for \mobile etc. depending on which numbers should be shown with the link ...

A short MWE (only cv tex file, no manipulated sty file!) could be:

\documentclass[11pt,a4paper,sans]{moderncv}

\moderncvstyle{casual}
\moderncvcolor{blue}

\usepackage[utf8]{inputenc}
\usepackage[scale=0.75]{geometry}

%-------------------------------------------------------------------------------
% this is the new command similar to \emaillink
%-------------------------------------------------------------------------------
\newcommand*{\tellink}[2][]{%
  \ifthenelse{\equal{#1}{}}%
    {\href{tel:#2}{#2}}%
    {\href{tel:#2}{#1}}}

\makeatletter
\def\@mymobile{+1~(234)~567~890} % <====================================
\makeatother

%\patchcmd{\makecvfoot} % command to be patched
  %{} % search
  %{} % change to
  %{} % success
  %{} % error

% personal data
\name{John}{Doe}
\title{Resumé title}
\address{street and number}{postcode city}{country}
\phone[mobile]{+1~(234)~567~890}
\phone[fixed]{+2~(345)~678~901}
\phone[fax]{+3~(456)~789~012}
\email{[email protected]}
\homepage{www.johndoe.com}
\social[linkedin]{john.doe}
\social[twitter]{jdoe}
\social[github]{jdoe}
\extrainfo{additional information}
%\photo[64pt][0.4pt]{picture}
\quote{Some quote}


\begin{document}

\makecvtitle

\section{Education}
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}

\section{Master thesis}
\cvitem{title}{\emph{Title}}
\cvitem{supervisors}{Supervisors}
\cvitem{description}{Short thesis abstract}

\makeatletter
%\show\@mobile % <=======================================================
\cvitem{Tel.}{\mobilephonesymbol~{\@mymobile}}
\cvitem{tellink}{\mobilephonesymbol~{\tellink{\@mymobile}}}
\cvitem{test}{\mobilephonesymbol~{\href{tel:123}{\@mymobile}}}
\cvitem{test}{\mobilephonesymbol~{\href{tel:\@mymobile}{\@mymobile}}}
\makeatother

\end{document}

shows the following pdf with included links:

resulting pdf

Simular you need to define \@myphone etc. for original command \phone etc.

1
  • Thank you for not only giving the answer but also showing how you arrived there! I didnt knew the \show command and it seems to be a very useful one to remember for future use :) Thanks again!
    – v.tralala
    May 19, 2020 at 10:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .