2

I want to check the url given to \href. For that I have rename \href to execute some code. I think something is wrong parsing the arguments, because the code enters a loop and TeX capacity is exceeded.

\documentclass{article}
\usepackage[left=1cm,includemp,right=1.0cm, marginparwidth=6cm]{geometry}

\usepackage{hyperref}

\RequirePackage{xparse}
\RequirePackage[unique=true]{bashful}
\RequirePackage{marginnote}

\let\hrefnormal\href
\DeclareDocumentCommand \href {o m m}{%
   \IfNoValueTF{#1}
   {\hrefnormal{#2}{#3}}
   {\hrefnormal[#1]{#2}{#3}}%
   \marginnote{URL: \splice{curl -IsS \detokenize{#2} 2>&1 | head -n 1 |  sed \detokenize{'s/HTTP\/1\.1 ... //'}}}
}




\begin{document}
\setlength{\parindent}{0pt}
\begin{center}
 {\huge\textbf{URL Validation}}
\end{center}

Hidden URLs:

\href{http://tex.stackexchange.com/test-404/}{This will give a 404 - Page Not Found}
\end{document}
TeXtnik
  • 5,853

1 Answers1

2

\usepackage{letltxmacro} is needed since \href is a command with optional arguments.

\documentclass{article}
\usepackage[left=1cm,includemp,right=1.0cm, marginparwidth=6cm]{geometry}



\usepackage{xparse}
\usepackage[unique=true]{bashful}
\usepackage{marginnote}
\usepackage{letltxmacro}
\usepackage{hyperref}

 \LetLtxMacro\hrefnormal\href
 \DeclareDocumentCommand\href{o m m}{%
    \IfNoValueTF{#1}
    {\hrefnormal{#2}{#3}}
    {\hrefnormal[#1]{#2}{#3}}%
    \marginnote{URL: \splice{curl -IsS \detokenize{#2} 2>&1 | head -n 1 |  sed \detokenize{'s/HTTP\/1\.1 ... //'}}}
  }




\begin{document}
\setlength{\parindent}{0pt}
\begin{center}
 {\huge\textbf{URL Validation}}
\end{center}

Hidden URLs:

\href{http://tex.stackexchange.com/test-404/}{This will give a 404 - Page Not Found}

\href{http://tex.stackexchange.com/questions/356377/rename-href-command-to-check-arguments-first}{Page Found}%
\end{document}

enter image description here