Macros generating hyperlinks with URLs passing arguments

  • Context: LaTeX 
  • Thread starter Thread starter Eclair_de_XII
  • Start date Start date
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 2K views
Eclair_de_XII
Messages
1,085
Reaction score
92
TL;DR
I am trying to create a macro that will pass a given string as an argument, to insert into the hyperlink that the macro will output. The problem is, that sometimes the given string will sometimes not be in lowercase, and the hyperlink will link to something else, because the site is case-sensitive.

My attempt resulted in the error found in the body of this message.
Running this

[CODE highlight="6,10"]\documentclass{article}

\usepackage{hyperref}
\usepackage{textcase}

\newcommand{\wiki}[2]{\href{https://en.wikipedia.org/wiki/#1_\MakeLowercase{#2}}{Curriculum vitae}}

\begin{document}

\wiki{Curriculum}{Vitae} % Wikipedia redirects this URL to the one below
\href{\https://en.wikipedia.org/wiki/Curriculum_vitae} % This one takes the user directly to the intended page

\end{document}[/CODE]

gives

Code:
! Use of \Hy@href doesn't match its definition.
\MakeLowercase  #1->{\def \reserved@a ##
                                        1##2{\let ##2##1\reserved@a }\expand...
 
Physics news on Phys.org
I got a feeling that the problem stems from the presence of \MakeLowercase inside \href.

What happens if you write it out directly without using the \wiki command?
 
DrClaude said:
I got a feeling that the problem stems from the presence of \MakeLowercase inside \href.

I do believe that is the problem, here. When typing out the hyperlink commands manually, I get a pdf document with a working hyperlink and all. Capture1.PNGCapture.PNG
 
You can try
Code:
\newcommand{\wiki}[2]{\href{https://en.wikipedia.org/wiki/#1_\protect\MakeLowercase{#2}}{Curriculum vitae}}
but it might just be that what you are trying is not possible (commands in TeX are not exactly the same as macros).
 
  • Like
Likes   Reactions: Eclair_de_XII
I see. Thank you for your assistance, in any case.