0

In an existing thread, it is shown how to suffix a hyperref URL with the generic "external URL" symbol. In another thread, the top answer shows how to use FontAwesome for inserting the favicons/logos of various companies into LaTeX documents.

I want to combine these two as follows: I want to get the same result of that first thread, except for domains whose favicons are registered in the preamble, where the generic symbol is substituted by that favicon for all calls to \href that use that domain.

MWE

\documentclass{article}
\usepackage{hyperref}
\usepackage{fontawesome}

% ... the logic that defines \faExternalLink as the default suffix for \href ... % ... some logic that defines \registerDomain[2] ...

\registerDomain{github.com}{\faGithub} \registerDomain{twitter.com}{\faTwitterSquare}

\begin{document} \href{https://twitter.com/elonmusk}{Link to Twitter/X's CEO}

\href{https://docs.github.com/en/get-started}{Link to GitHub's documentation}

\href{https://en.wikipedia.org/wiki/Donald_Knuth}{Link to a miscellaneous webpage} \end{document}

Note that the last two URLs use a subdomain. The middle one still needs to use the superdomain's icon.

Implementation ideas

If the domains and icons were hardcoded inside a command definition, it would probably be sufficient to use a conditional that checks if a substring is present in a URL string, although that could theoretically lead to spurious matches (in something like github.com.mywebsite.org) which might require a proper URL parser.

Here, we'll need some kind of global dictionary from domain to icon name.

Mew
  • 843

0 Answers0