Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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

2 Answers 2

up vote 8 down vote accepted

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

share|improve this answer

This should work.

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

%% Without link
% \newcommand{\myhref}[2]{#2}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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