LaTeX Macros generating hyperlinks with URLs passing arguments

  • Thread starter Thread starter Eclair_de_XII
  • Start date Start date
AI Thread Summary
The discussion centers on generating hyperlinks in LaTeX using a custom command that incorporates URL arguments. An error arises due to the use of \MakeLowercase within the \href command, which leads to a mismatch in definitions. A workaround is suggested by adding \protect before \MakeLowercase, allowing the command to function correctly. Users confirm that manually typing the hyperlink commands results in a working link, indicating that the issue is specific to the macro implementation. The conversation highlights the complexities of using macros in TeX compared to standard commands.
Eclair_de_XII
Messages
1,082
Reaction score
91
TL;DR Summary
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 Eclair_de_XII
I see. Thank you for your assistance, in any case.
 

Similar threads

Replies
1
Views
7K
Replies
3
Views
2K
Replies
8
Views
12K
Replies
4
Views
3K
Replies
5
Views
1K
Replies
1
Views
8K
Back
Top