2

I have macro that adds one entry in a table. The first entry is URL.

This works on most URL's except some with funny characters.

I want to use a macro, since inside the macro I'd like to customize it based on some condition.

Now I have the \url command inside the macro itself. Not on the caller side. Is there a way to pass the URL without getting the error or do I have to change all my code to add \url at the caller side?

here is MWE

\documentclass[12pt]{article}
\usepackage{hyperref}

\newcommand{\addEntry}[3]
{%
    \expandafter\url\expandafter{\detokenize{#1}}%
    &#2
    &#3
   \\\hline
}%

\begin{document}

\begin{tabular}[c]{|p{2in}|p{2in}|p{1in}|}\hline 
Link&description&date added\\\hline 
\addEntry{https://www.maplesoft.com/support/help/maple/view.aspx?path=odeadvisor%2FAbel}{Maple entry for Abel first kind}{August 2022}
\end{tabular}

\end{document}

The above gives an error due the url having ? and %? The error is

lualatex foo.tex

(/usr/local/texlive/2022/texmf-dist/tex/latex/l3backend/l3backend-luatex.def)
(./foo.aux) (/usr/local/texlive/2022/texmf-dist/tex/latex/base/ts1cmr.fd)
(./foo.out) (./foo.out))
Runaway argument?
{https://www.maplesoft.com/support/help/maple/view.aspx?path=odeadvis\ETC.
! File ended while scanning use of \addEntry.
<inserted text> 
\par 
<*> foo.tex
        
? 

I know I can just not use a macro and hardcode everything in the table itself, like this

\begin{tabular}[c]{|p{2in}|p{2in}|p{1in}|}\hline 
Link&description&date added\\\hline 
\url{https://www.maplesoft.com/support/help/maple/view.aspx?path=odeadvisor%2FAbel}&Maple entry for Abel first kind&August 2022
\end{tabular}

And the above works. But how to do it using a macro? I tried putting the \url on caller side, but it did not work. This is what I did

\documentclass[12pt]{article}
\usepackage{hyperref}

\newcommand{\addEntry}[3]
{%
    #1
    &#2
    &#3
   \\\hline
}%

\begin{document}

\begin{tabular}[c]{|p{2in}|p{2in}|p{1in}|}\hline 
Link&description&date added\\\hline 
\addEntry{\url{https://www.maplesoft.com/support/help/maple/view.aspx?path=odeadvisor%2FAbel}}{Maple entry for Abel first kind}{August 2022}
\end{tabular}

\end{document}

Still give same error.

How to correctly pass this URL to the macro?

ps. I do not want to edit the URL and escape any funny characters, that is why I am using \url and \href

TL 2022 on Linux.

1 Answer 1

3

You need to read URL argument as verbatim. This can be done with \NewDocumentCommand{}{}{} from xparse

enter image description here

\documentclass[12pt]{article}
\usepackage{geometry}
\usepackage[colorlinks]{hyperref}

\NewDocumentCommand{\addEntry}{vmm}{%
    \url{#1} & #2 & #3 \\ \hline}

\begin{document}

\begin{tabular}{|p{2in}|p{2in}|p{1in}|}
    \hline 
    Link & description & date added \\
    \hline 
    \addEntry{https://www.maplesoft.com/support/help/maple/view.aspx?path=odeadvisor%2FAbel}%
        {Maple entry for Abel first kind}%
        {August 2022}
\end{tabular}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .