https://wiki.contextgarden.net/api.php?action=feedcontributions&user=Eggdropsoap&feedformat=atomWiki - User contributions [en]2024-03-29T10:06:06ZUser contributionsMediaWiki 1.34.1https://wiki.contextgarden.net/index.php?title=URL&diff=13614URL2012-02-22T18:06:03Z<p>Eggdropsoap: spelling</p>
<hr />
<div>== Overview ==<br />
URLs can be typeset in various ways. You may specify a URL for later reuse via [[cmd:useURL|\useURL]]:<br />
<texcode><br />
\useURL[aurl] [http://xkcd.com/149/] [] [I prefer hot dogs.] <br />
</texcode><br />
where #1 is the identifier, #2 is the URL you want to point to, and #4 the text to be displayed where the URL is used. #3 can be used for the 'file path' portion of the URL, if you want. This dates back to when hyperlink support in <br />
DVI viewers required that split.<br />
<br />
Alternatively, you can use only two arguments and the URL will be used as its own text. <br />
<texcode><br />
\useURL[anotherurl] [http://xkcd.com/224/]<br />
</texcode><br />
(That way any character may appear inside the URL string without breaking things under certain circumstances, which can happen when you specify the URL itself as the fourth argument.)<br />
<br />
Now that you have defined some URLs you are ready to dereference them by their identifier wherever you please. Don't forget to enable interaction for clickable WWW-look-and-feel.<br />
<texcode><br />
\setupinteraction[state=start]<br />
\starttext<br />
\from[aurl] % typesets the URL description in color<br />
\from[anotherurl] % typesets the URL in color<br />
\stoptext<br />
</texcode><br />
<br />
You can use<br />
<texcode><br />
\url[aurl]<br />
</texcode><br />
as well, which behaves like \from[#1].<br />
<br />
== E-Mail mailto ==<br />
<context source=yes><br />
\setupinteraction[state=start] <br />
\useurl [mymail] [mailto:nobody@example.zzz] [] [visible@mailaddress.zzz] <br />
<br />
\starttext <br />
Send your spam to \from[mymail]! <br />
\stoptext <br />
</context><br />
<br />
<br />
<br />
=== another solution ===<br />
<br />
<context source=yes><br />
\setupinteraction[state=start] <br />
<br />
\starttext <br />
Send your spam to \goto{visible@mailaddress.zzz}[url(mailto:nobody@example.zzz)] <br />
\stoptext <br />
</context><br />
<br />
== Hyphenation ==<br />
URLs tend to become large monsters under many circumstances but you may have a good reason not to conceal them from the reader. <br />
This is where hyphenation comes in handy.<br />
ConTeXt provides a dedicated mechanism for chopping them into pieces:<br />
<context source=yes><br />
\hyphenatedurl{http://bits.blogs.nytimes.com/2010/03/05/a-former-book-designer-says-good-riddance-to-print/?hpw}<br />
</context><br />
This has some characters predefined where Hans “likes” URLs to break (see the list at the beginning of [[source:lang-url.lua|lang-url.lua]], cf. [http://www.ntg.nl/pipermail/ntg-context/2008/032959.html a message on ntg-context]).<br />
If you prefer other characters you can add them via:<br />
<texcode><br />
\sethyphenatedurlnormal{:=?&}<br />
\sethyphenatedurlbefore{?&}<br />
\sethyphenatedurlafter {:=}<br />
</texcode><br />
<br />
URL hyphenation can, of course, be used wherever you need them.<br />
<texcode><br />
\useURL[yaurl] [http://xkcd.com/638/] [] [\hyphenatedurl{http://xkcd.com/638/}]<br />
\starttext<br />
\from[yaurl]<br />
\stoptext<br />
</texcode><br />
<br />
Note: the <code>#</code> sign should be escaped, that is, replaced by <code>\#</code>.<br />
<br />
== Other ways ==<br />
Another way of typesetting URLs is the [[cmd:goto|\goto{#1}[#2]]] command. This expects the description text as first argument and the actual URL as the second one; note that it has to be wrapped in url(#2) to create a clickable link:<br />
<texcode><br />
\goto{In Lua, array indices start from one.}[url(http://www.xkcd.com/163/)]<br />
</texcode><br />
<br />
== Setting color and style ==<br />
For \url:<br />
<texcode><br />
\setupurl<br />
[color=blue,<br />
style=\tf]<br />
</texcode><br />
For \goto and \from:<br />
<texcode><br />
\setupinteraction<br />
[state=start,<br />
color=blue,<br />
style=\tf]<br />
</texcode><br />
<br />
== Tips and Tricks ==<br />
If you need many hyperrefs in your document these definitions may be handy for you<br />
<context source=yes><br />
\def\href#1#2{\useURL[#2][{#2}][][{#1}]\goto{\url[#2]}[url(#1)]} <br />
\def\ahref#1{\color[linkcolor]{\ttx \href{#1}{<#1>}}} <br />
\def\fullahref#1{\color[linkcolor]{\ttx \href{#1}{http://#1}}} <br />
\def\mailto#1{\useURL[#1][mailto:#1][][#1]\from[{#1}]} <br />
\def\MailTo#1#2{\useURL[#1][mailto:#1][][#2]\from[{#1}]} <br />
<br />
Send mail to \MailTo{foo@bar.zzz}{Mr. Foo}<br />
</context></div>Eggdropsoap