3

I'm writing a CV for my wife using moderncv. We're not sure whether her supervisor wants links in the document, so every time a link might be required, I write the text twice:

PhD student at the Weizmann Institute of Science
% PhD student at the \textcolor{cyan}{\href{http://www.weizmann.ac.il/}{Weizmann Institute of Science}}}

If the tutor decides that we should use links, I will comment out the unlinke text:

% PhD student at the Weizmann Institute of Science
PhD student at the \textcolor{cyan}{\href{http://www.weizmann.ac.il/}{Weizmann Institute of Science}}}

I don't like duplicating code, so I was looking for a way to define a Tex macro for my link style. Perhaps something like:

PhD student at the {\myhref{http://www.weizmann.ac.il/}{Weizmann Institute of Science}}

Where \myhref is defined once at the top, where I can toggle the links on and off, and set the link colors if they exist.

Is there a way to define a global, custom macro in tex?

  • IMHO, just put the links, but color them black; they will still work, but won't impact the printed document. In any case, you will need to pick darker colors than the horrible default ones… – Damien Pollet Feb 25 '13 at 14:43
8

This is all I can say without an MWE. Maybe it works for you.

\documentclass{article}
\usepackage{hyperref, etoolbox}

\newtoggle{supervisor}
%\toggletrue{supervisor}

\newcommand{\myhref}[2]{%
  \iftoggle{supervisor}%
    {\href{#1}{#2}}%
    {#2}%
}

\begin{document}
PhD student at the \myhref{http://www.weizmann.ac.il/}{Weizmann Institute of Science}
\end{document}

As for the link color, I suggest you use the options provided by hyperref (colorlinks, urlcolor etc.)

5

This should work.

%% With link
\newcommand{\myhref}[2]{%
  \textcolor{cyan}{\href{#1}{#2}}}

%% Without link
% \newcommand{\myhref}[2]{#2}

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.