So these were the steps:

1) I created an `\adsalmaurl` command where the part of the URL that contains `%` characters is after `\detokenizer`, while keeping the closing braces in the next line.

```latex
\newcommand{\adsalmaurl}{
https://ui.adsabs.harvard.edu/search/q=%5Cdetokenize%7B%2528%2528%2528abs%253AALMA%2529%2520AND%2520year%253A1996-2026%2529%2520AND%2520property%253Arefereed%2529%2520AND%2520collection%253Aastronomy
}}
```

2) Once the `\adsalmaurl` command is created, I can use it inside `\href`, but just in case it could have some interactions with `\footnote` I also created a new command:

```latex
\newcommand{\adsalmaquery}{\href{\adsalmaurl}{\small{\texttt{(((abs:ALMA) AND year:1996-2026) AND property:refereed) AND collection:astronomy}}}}
```

3) I then use the composed `\adsalmaquery` inside of the footnote:

```latex
\footnote{As per the following NASA Astronomical Data Service (ADS) query: \adsalmaquery}
```

This made \(\LaTeX\) happy, and so I was also happy… but wanted to share this mostly to future me, in case I forget why LaTeX complains about URL-encoded/quoted URLs again…

[1]: https://ui.adsabs.harvard.edu/search/q=%28%28%28abs%3AALMA%29%20AND%20year%3A1996-2026%29%20AND%20property%3Arefereed%29%20AND%20collection%3Aastronomy

🧵 2/2

#TIL #TodayILearned #LaTeX #HyperRef #HRef #XURL #detokenizer #LaTeXQuirks #TIL #TodayILearned #LaTeX #HyperRef #HRef #XURL #detokenizer #LaTeXQuirks

Astrophysics Data System

A powerful, streamlined new Astrophysics Data System

Today I Learned that using quoted URLs in \(\LaTeX\) is quite tricky, and that `\detokenizer` is your friend.

I was trying to have a `\footnote` that pointed to the ALMA papers which are refereed, and that are published in the astronomy collection of the NASA Astronomy Database System (ADS) [1], and I was getting errors while trying to use
HyperRef's `\url` and `\href` commands, in particular a Runaway error inside footnote and href.

In the end, there were several issues that made LaTeX hickup on it.

The first one, the URL was not fully quoted, and needed to change `(` and `)` to their quoted versions,`%28` and `%29`, respectively, because the parenthesis were also considered suspect.

The second one, and is the main source of issues, is that `%`, in LaTeX, is the character for line comments: anything in the line after `%` is treated as a comment, unless it is in a verbatim environment… or inside `\detokenizer`.

Third, even with `\detokenizer{https://url.tld/%20quoted%20url}`, you might get issues.

So, what solved the issue?

🧵 1/2

#TIL #TodayILearned #LaTeX #HyperRef #HRef #XURL #detokenizer #LaTeXQuirks