3

I'm using moderncv to write my CV and I'd like to use a shorthand link in the header of my CV. The command \httplink has an optional argument to do this, but this argument is not passed to \homepage.

How can I redefine \homepage to pass the shorthand link as an optional argument to \httplink in the \maketitle command without messing everything up?

An example of what I was thinking of is

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

\moderncvstyle{classic}
\moderncvcolor{blue}

\renewcommand*{\homepage}[2]{\def\@homepage[#1]{#2}}

\firstname{John}
\lastname{Doe}

\homepage[shorthand]{long link that I'd like to mask}

\begin{document}

\maketitle

\end{document}

Except that I don't if that is the proper way to redefine homepage and this code doesn't redefine line 265 of moderncvclassic.sty where, as far as I can tell the argument of homepage is passed to httplink.

Werner
  • 603,163
Kpantzas
  • 803

1 Answers1

2

You'll have to patch \makecvhead after loading the classic style using something like etoolbox (already loaded by the class).

I've done so below, replacing the \httpslink{\@homepage} piece with a conditional based on whether you supplied a shorthand argument <desc> or not through the updated \homepage[<desc>]{<URL>}:

enter image description here

\documentclass{moderncv}

\moderncvstyle{classic} \moderncvcolor{blue}

\makeatletter \patchcmd{\makecvhead}% <cmd> {\httpslink{@homepage}}% <search> {{\ifx@homepage@shorthand\relax \httpslink{@homepage}% Used \homepage{<URL>} \else \httpslink[@homepage@shorthand]{@homepage}% Used \homepage[<desc>]{<URL>} \fi}}% <replace> {}{}% <success><failure>

\RenewDocumentCommand{\homepage}{o m}{% \let@homepage@shorthand\relax% \providecommand@homepage{#2}% \IfValueT{#1}{\def@homepage@shorthand{#1}}% } \makeatother

\firstname{John} \lastname{Doe}

\homepage[shorthand]{long_link_that_id_like_to_mask}

\begin{document}

\maketitle

\end{document}

Werner
  • 603,163
  • Thanks, it works fine, except for urls containing &. In that case I get an error (href@split has an extra }). I looked it up, and the solution seems to be enclose the \href{} commange in {}. How would you do it in your solution? – Kpantzas Nov 18 '14 at 18:56
  • @Kpantzas: See the updated solution. – Werner Nov 18 '14 at 19:17
  • Great! Applied the same patch to makelettertitle, it works like a charm! – Kpantzas Nov 18 '14 at 20:52
  • I'm almost a decade too late, by now this MWE does not work anymore. Can you update the solution to recent changes in the moderncv class (or whatever else is not working anymore)? – And Jun 12 '23 at 14:44
  • One more remark: This solution works fine for the CV, but when I generate the cover letter in the same document, the url is not masked there. Is there some way to fix this? – And Mar 28 '24 at 08:50
  • @And: Can you provide a minimal example that sets up your environment? That way I have something to work with. – Werner Mar 28 '24 at 16:24