Macros generating hyperlinks with URLs passing arguments

  • Context: LaTeX 
  • Thread starter Thread starter Eclair_de_XII
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around generating hyperlinks in LaTeX using macros, specifically focusing on issues encountered when passing arguments to a custom command that utilizes the \href function from the hyperref package. The scope includes technical explanations and potential solutions related to LaTeX document preparation.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • Post 1 presents a LaTeX command \wiki that attempts to create a hyperlink with arguments, but encounters an error related to the use of \MakeLowercase within \href.
  • Post 2 suggests that the issue may be due to \MakeLowercase being used inside \href and proposes testing the hyperlink without the \wiki command.
  • Post 3 reiterates the belief that \MakeLowercase is causing the problem and notes that manually typing the hyperlink commands results in a functioning hyperlink.
  • Post 4 offers an alternative approach by using \protect with \MakeLowercase in the \wiki command, while also expressing uncertainty about the feasibility of the original intention due to the nature of TeX commands and macros.
  • Post 5 expresses gratitude for the assistance provided, indicating a willingness to explore the suggestions made.

Areas of Agreement / Disagreement

Participants express a shared belief that the use of \MakeLowercase is problematic, but there is no consensus on a definitive solution or whether the original goal is achievable.

Contextual Notes

The discussion highlights potential limitations in using commands within macros in LaTeX, as well as the need for careful handling of argument passing in the context of hyperlink generation.

Eclair_de_XII
Messages
1,082
Reaction score
91
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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 9 ·
Replies
9
Views
6K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 8 ·
Replies
8
Views
13K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 11 ·
Replies
11
Views
6K
  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 1 ·
Replies
1
Views
4K