General ⇒ Padding Zeros in an \href
-
- Posts: 2
- Joined: Tue Sep 30, 2025 9:18 pm
Padding Zeros in an \href
Note that in my code examples, I have substituted the string "xxxxx" for "https". I have done this because the site formatter takes things that look like an html link and abbreviates them, thus, making some of my latex code disappear.
In the header I have:
\newcounter{ChChCounter}
\newcounter{ChExCounter}
\newcommand{\AudioLinkStr}{%
xxxxx://fredgeorge.com/the\_book/ex\_\padzeroes[2]{\decimal{ChChCounter}}-\padzeroes[2]{\decimal{ChExCounter}}.mp3
}
and so, in my document, the command \AudioLinkStr will create strings that look like:
xxxxx://fredgeorge.com/the_book/ex_06-01.mp3
which is what I want.
BUT, when I include \AudioLinkStr in a \href{}{} construct as follows:
\href{AudioLinkStr}{\textbf{Audio Example Whatever}}
a clickable link is created in my document, BUT the link does _NOT_ go to the audio example on the web in a browser. Instead the link tries to open the document "AudioLinkStr.pdf" with a PDF viewer!
When I change the argument in \href from AudioLinkStr to \AudioLinkStr, building the document returns the error:
! TeX capacity exceeded, sorry [input stack size=10000].
\@protected@testopt ...estopt \else \@x@protect #1
\fi
l.128 \href{\AudioLinkStr} {\textbf{Audio Example Whatever...
! ==> Fatal error occurred, no output PDF file produced!
How can I fix the above? What am I doing wrong?
Thank you for your help.
P.S. I wonder if the problem is related to the fact that I have underscores in my web link. Notice that in the above I have to format the link with back slashes before the underscores:
xxxxx://fredgeorge.com/the\_book/ex\_ ...
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- Stefan Kottwitz
- Site Admin
- Posts: 10362
- Joined: Mon Mar 10, 2008 9:44 pm
Re: Padding Zeros in an \href
welcome to the forum!
That may be solved with \expandafter, like this:
Code: Select all
\expandafter\href\expandafter{AudioLinkStr}{\textbf{Audio Example Whatever}}
Code: Select all
\newcommand{\AudioLinkStr}{%
https://fredgeorge.com/the\_book/ex\_\padzeroes[2]{\decimal{ChChCounter}}-\padzeroes[2]{\decimal{ChExCounter}}.mp3
}
-
- Posts: 2
- Joined: Tue Sep 30, 2025 9:18 pm
Re: Padding Zeros in an \href
Included here is a complete latex example which illustrates my problem. \AudioLinkStr _is_ returning a correctly formatted string, but I cannot get \AudioLinkStr to work in \href
Thank you all for taking a look.
Code: Select all
\documentclass[11pt]{book}
\usepackage[colorlinks = true, linkcolor = blue, urlcolor = blue, citecolor = blue, anchorcolor = blue]{hyperref}
\usepackage{fmtcount}
\newcounter{ChChCounter}
\newcounter{ChExCounter}
\newcommand{\AudioLinkStr}{%
https://soundcloud.com/user-145142078/ex\_\padzeroes[2]{\decimal{ChChCounter}}-\padzeroes[2]{\decimal{ChExCounter}}
}
\begin{document}
\setcounter{ChChCounter}{6}
\setcounter{ChExCounter}{1}
% THIS INDICATES THAT MY STRING IS FORMATTED CORRECTLY
% https://soundcloud.com/user-145142078/ex_06-01
\AudioLinkStr
\vspace{0.1in}
% THIS SHOWS THAT THE HARD CODED STRING WILL WORK IN THE \href{} CONSTRUCT
\href{https://soundcloud.com/user-145142078/ex_06-01}{\textbf{Audio Example \theChChCounter-\theChExCounter}}
\vspace{0.1in}
% BUT THIS LINK DOES NOT WORK
\href{AudioLinkStr}{\textbf{Audio Example \theChChCounter-\theChExCounter}}
\vspace{0.1in}
% AND I DID NOT GET \expandafter TO WORK AS WELL
\expandafter\href\expandafter{AudioLinkStr}{\textbf{Audio Example \theChChCounter-\theChExCounter}}
\vspace{0.1in}
\end{document}