Text FormattingAutomatic Linking

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
ForenDaddy
Posts: 8
Joined: Tue Oct 18, 2011 3:37 pm

Automatic Linking

Post by ForenDaddy »

hi there,

i am looking for a way to automatically set a link on a word or phrase.
example: "my awesome book"
everytime i use this text latex should create a link around this phrase that leads to a section where i present my book.
right now i use hyperref which works but is also a little bit tyring to type it all the time again and again. plus i want to add other words or phrases which makes it inconvenient to go on like this.

is there a way to get it done automatically without "tagging" every single time the phrase?
Last edited by ForenDaddy on Tue Nov 01, 2011 11:28 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Automatic Linking

Post by Stefan Kottwitz »

Hi,
ForenDaddy wrote:right now i use hyperref which works but is also a little bit tyring to type it all the time again and again.
create a macro for it in your preamble, let's say \mybook, which contains the phrase and the hyperlink. In the text use just \mybook. So you save typing, and you have the definition at one place. You could later easily change the definition, such as emphasized formatting or different linking, which has effect on all occurrences in the document.

Optionally, if you need such macro it several times and if it's more than just a hyperlink (maybe formatting), create a basic macro, such as \mylink{text}{link}, which contains hyperlinking and formatting commands, and \mybook and \myarticle etc. use that. So one macro is responsible for the functionality of all your internal links.

Stefan
LaTeX.org admin
ForenDaddy
Posts: 8
Joined: Tue Oct 18, 2011 3:37 pm

Re: Automatic Linking

Post by ForenDaddy »

well this is nice too but not quite what i want.
i don't want to rewrite every word.
i want to search latex for a specific phrase and set the formatting i want.
your way is the other way round. and right now it is quite the same as how i do it. a bit shorter and more powerful but still i have to replace everything.

i am still hoping for the hero on the white horse ;-) with the magic trick.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Re: Automatic Linking

Post by Stefan Kottwitz »

An easy way would be using the editor replace feature and replacing "my awesome book" by "\mybook" for the complete document. This can be done once, instead of letting LaTeX do it during each compilation, even if this could be done by advanced features.

Stefan
LaTeX.org admin
Post Reply