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.

In Markdown, you can do

[google.][1]
...
[1]:http://www.google.com

In LaTeX, I've tried

\href{\ref{1}}{google?}
...
\label{1}{http://www.google.com}

But that doesn't work, and I'm tired of having long URLs in my document. How do you label and reference a URL?

share|improve this question
    
FWIW, this is the default style in ConTeXt: see documentation for \useURL –  Aditya Jun 12 '13 at 13:43
    
Is there any package I can import to get this functionality in regular LaTeX? –  Scott Jun 12 '13 at 13:49
add comment

2 Answers

Here a small suggestion:

\documentclass[a4paper]{article}

\usepackage{hyperref}

\makeatletter
\newcommand*\makrdownlink[2]{%
 \immediate\write\@auxout{%
   \string\expandafter\string\gdef\string\csname\space markdownlink#1\string\endcsname{#2}%
 }%  
}

\newcommand*\makrdownref[2]{%
 \@ifundefined{markdownlink#1}
  {\typeout{Undefined ref~markdownlink#1}\textbf{#2}}%
  {\href{\@nameuse{markdownlink#1}}{#2}}%  
}
\makeatother
\begin{document}


\makrdownref{2}{google}

\makrdownlink{2}{www.google.com}
\end{document}

The procedure can be simplified if you define your links in the preamble. Then you don't need to write something to the aux file.

share|improve this answer
add comment
up vote 2 down vote accepted

A simple solution. In my document preamble, I wrote:

\newcommand{\sage}{http://www.sagemath.org}

Then, when I wanted to reference it, I used

\href{\sage}{This text will be linked to sagemath.org}
share|improve this answer
add comment

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.