moderncv 添加电话号码链接

moderncv 添加电话号码链接

我尝试自定义 moderncv,使我的电话号码可点击。在其他文档中,我成功使用了以下内容:

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

单击它,将打开配置的电话应用程序(例如 skype/zoom)。

由于 moderncv 已经提供了该命令,因此\emaillink我尝试复制该命令并对其进行相应的调整。查看的代码后,moderncvfooti.sty我猜测该命令\makecvfoot也必须进行调整。因此,我创建了一个主文件cv.tex,在其中定义了一个\tellink类似于的新命令\emaillink,并在自己的页脚样式文件中(在同一文件夹中)使用该命令。自己的页脚样式文件主要是从原始文件复制而来,moderncvfooti.sty我在 处添加了一小部分\renewcommand*{\makecvfoot}{...

但是该命令会导致编译错误,我不明白。错误是“未定义控制序列”但在完全不相关的行上。因此我需要一些帮助来解决这个问题。我附上了一个最小的工作示例,但注释掉了有问题的行:

变种

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

moderncvfootisty.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'.

编辑:我进行了一些测试,手动插入链接,\href{tel:123}{\@mobile}显示正确的号码和链接123。但是插入\href{tel:\@mobile}{\@mobile}不起作用,并且因未定义的控制序列而失败。我认为这是关键所在。

答案1

moderncv用于moderncvcollection.sty创建可用不同版本的电话的可打印信息。这意味着您使用的命令以您期望的另一种方式定义:

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

或者

\collectionfindbykey {phones}{mobile}

如果您使用命令检查使用的宏\show\@mobile...

但有一个简单的解决方法:定义你自己的命令,\@mymobil例如

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

然后你可以简单地使用类似的代码

\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

在您的 cv tex 文件中。要更改页脚,moderncvfooti.sty您必须删除原始呼叫\mobile等。具体取决于应与链接一起显示哪些数字...

简短的 MWE(仅 cv tex 文件,没有操作sty文件!)可能是:

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

显示以下带有链接的 pdf:

生成的 pdf

类似地,您需要\@myphone为原始命令等定义等\phone

相关内容