# How to make a switch for print vs. display versions of a document with respect to links/URLs

I want the print version of a document have links or URLs written out but the online version have the abbreviated tag/name. So the switch, set at the beginning, will choose between two alternatives, e.g.

    \url{http://tex.stackexchange.com/questions/ask}

-

It should be as simple as: (the macro is taken almost verbatim from bidi package)

\documentclass{article}
\newif\ifprint
\usepackage{hyperref}
\makeatletter
\begingroup
\catcode\$=6 % \catcode\#=12 % \gdef\href@$1{\expandafter\href@split$1##\\}% \gdef\href@split$1#$2#$3\\$4{% \hyper@@link{$1}{$2}{\ifprint$1\else\$4\fi}%
\endgroup
}%
\endgroup
\makeatother
\newcommand*\PrintOn{\printtrue}
\begin{document}
\PrintOn
\end{document}

-

Besides the links, there might be other things you need to set for screen viewing or printing, so you will need some sort of a switch. This would normally go in the preamble of the document as shown below.

I will use the ifthen package for the boolean as people still find its syntax useful:

\usepackage{ifthen}
\newboolean{ForPrinting}


You then set the various parameters as:

\ifthenelse{\boolean{ForPrinting}}{}{}


What you normally need to take care of, is margins, link colors and the typing of urls. For the links you can define a command as:

\newcommand\link[2][1]{%
\ifthenelse{\boolean{ForPrinting}}{\url{#1}}
{\href{#1}{#2}}
}


The following MWE illustrates the technique and some typical values for settings:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{ifthen}
\newboolean{ForPrinting}

%\setboolean{ForPrinting}{true}

%% Initialize values to ForPrinting=false
\newcommand{\Margins}{hmarginratio=1:1}     % Symmetric margins
\newcommand{\PDFPageLayout}{SinglePage}
%% Re-set if ForPrinting=true
\ifthenelse{\boolean{ForPrinting}}{%
\renewcommand{\Margins}{hmarginratio=2:3} % Asymmetric margins
\renewcommand{\PDFPageLayout}{TwoPageRight}
\usepackage[body={5.25in,8.4in},\Margins]{geometry}

\usepackage[pdftex,
hyperfootnotes=false,
pdftitle={Project Name},
pdfkeywords={maths,equations},
pdfstartview=Fit,    % default value
pdfstartpage=1,      % default value
pdfpagemode=UseNone, % default value
bookmarks=true,      % default value
pdfpagelayout=\PDFPageLayout,
pdfdisplaydoctitle,
pdfpagelabels=true,
bookmarksopen=true,
bookmarksopenlevel=1,
\ifthenelse{\boolean{ForPrinting}}{\url{#1}}
{\href{#1}{#2}}
}
\begin{document}
\section{One}

@Maesumi The hyperref is added in the MWE above near the linkcolor.You need to setboolean{ForPrinting}{true}, uncomment the line. –  Yiannis Lazarides May 30 '12 at 21:27