1

I have, for example, a section of a book with the label 'Bases'.

I want to create a hyperlink every time I type 'Bases' in my text without putting a command like ~\ref{}.

3

Why don't simply use a new command?

\documentclass{article}
\usepackage{hyperref}
\usepackage{xspace}
\newcommand{\Bases}{Section~\ref{Bases}\xspace}

\begin{document}
    \section{Just for example}\label{Bases}
    This is the reference \Bases to the section.
    This is another reference \Bases.
\end{document}

The hyperlinks aren't shown in the image but there are in the .pdf:

enter image description here

If you use fancyref package it is better to put sec: before the reference name "Bases", see LaTeX/Labels and Cross-referencing for more info.

1

This might be a simple way of doing it. Just add a command for each word. The \ behind the command in the text is just to make the following space character render as a space.

\documentclass{article}
\usepackage{hyperref}
\newcommand{\base}{\href{http://www.allyourbasearebelongtous.com}{base}}

\begin{document}
All your \base\ are belong to us!
\end{document} 

Example output:

All your base

  • The OP talked about reference to a section of a book... – CarLaTeX Feb 2 '17 at 7:43
  • Of a external book? If not then just change my url code to internal ref? – Jimmy Westberg Feb 2 '17 at 7:46
  • No, the reference to the a section within the same document, see my answer for an example... – CarLaTeX Feb 2 '17 at 7:53
  • "If not then just change my url code to internal ref?" was my second question. And you showed this example in your answer. – Jimmy Westberg Feb 2 '17 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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