Command/goto

From Wiki
Jump to navigation Jump to search


\goto

Summary

The command \goto is used for clickable links

Settings

\goto{...}[...]
{...}content
[...]reference

Description

This command creates a clickable link (or just normal text when interaction is not enabled).

It takes two arguments, the first in curly braces is the text, the second in square braces is the label to link to.

You should not normally have to use this command for reference links inside your document. Internal links are better made using \in, \at or \about, which are more conceptual (and lookup the section or page number as well).

But if you want to implement some custom command for building links, this command is useful. You might also want to use the \ref command for getting the raw page number, section number, section title, etc.

Or if you want to create a clickable link to something outside of the current document.


TODO: there are examples below of various possible arguments in #2, but not a proper list of options (See: To-Do List)


Examples

Example 1

\setupinteraction[state=start]
\reference[label:1]{Some text}

\page[yes] % Insert page break

Link to \goto{some text}[label:1].

(of course the wiki cannot really make a workable link)

Links to URLs

\goto{Wiki}[url(http://wiki.contextgarden.net)]
\goto{Email}[url(mailto:spam@example.com)]

Link to a page

\goto{Other page}[page(3)]

Open a file or program

\goto{Start}[program(test.tex)]

By enclosing \goto’s destination in program(#1) you have some means of launching files or programs.

Of course, this is a security issue.

However, PDF readers seem to handle this inconsistently.

The following test.tex will attempt to open itself. Notice that per default PDF readers stay in the current working directory.

\setupinteraction[state=start]
\starttext
\goto{A file}[program(test.tex)]\par                    % case 1: destination specified
\goto{A command}[program(/usr/bin/kwrite test.tex)]\par % case 2: program and destination specified
\stoptext

Behavioural study of PDF viewers

This comparison was made on Linux/x86 and OSX 10.9.5 (replacing /usr/bin/kwrite test.tex with /Applications/Preview.app test.pdf). YMMV.

reader version behaviour
acroread 9.2, Linux/x86 Case 1 succeeds. Runs the associated mime type application on the argument.

Case 2 results in a file error.

Acrobat Reader DC 2017.009, OSX Case 1 succeeds after asking back. Runs the default application for .tex files.

Case 2 fails with a file not found message.

Acrobat Pro 9.5.5, OSX Case 1 succeeds after asking back. Runs the default application for .tex files.

Case 2 fails with a file not found message.

okular 0.11.2, Linux/x86 Case 1 succeeds. Runs the associated mime type application on the argument.

Case 2 fails. Note that calling an executable (without the file argument) will be prevented by Okular for safety reasons.

xpdf 3.02, Linux/x86 Case 1 fails.

Case 2 succeeds: Xpdf allows execution of arbitrary commands in a shell with user privileges.

Google Docs as of 2010-10-24 Case 1 fails.

Case 2 fails.

mupdf 7.2, Linux/x86 Case 1 fails.

Case 2 fails.

Preview.app 7.0, OSX Case 1 fails (nothing happens).

Case 2 fails with a file not found message.

File Viewer.app 1.4, OSX Case 1 succeeds. Runs the default application for .tex files.

Case 2 fails with a file not found message.

PDF.js Opera 49, Firefox 61, OSX Links are not active, nothing happens.

Notes

See also

Help from ConTeXt-Mailinglist/Forum

All issues with: