Macros generating hyperlinks with URLs passing arguments

  • LaTeX
  • Thread starter Eclair_de_XII
  • Start date
I will try to find another solution or work around the issue. Thank you for your expertise and for summarizing the issue so succinctly.In summary, it seems that the problem with the hyperlink stems from using the command \MakeLowercase inside the \href command. While manually typing out the hyperlink commands seems to work, it may not be possible to use the \wiki command in this case. Further investigation or a different solution may be needed.
  • #1
Eclair_de_XII
1,083
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:
\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}

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
  • #2
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?
 
  • #3
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
 
  • #4
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
  • #5
I see. Thank you for your assistance, in any case.
 

Related to Macros generating hyperlinks with URLs passing arguments

1. What is the purpose of using macros to generate hyperlinks with URLs?

The purpose of using macros to generate hyperlinks with URLs is to dynamically create clickable links that direct users to specific web pages or resources. This allows for a more efficient and automated way of generating hyperlinks, as opposed to manually typing out each URL.

2. How do macros generate hyperlinks with URLs?

Macros generate hyperlinks with URLs by using a combination of variables, functions, and conditional statements to construct the URL based on specific criteria. This allows for a customizable and dynamic approach to creating hyperlinks.

3. Can macros pass arguments through the URL?

Yes, macros can pass arguments through the URL by using query strings. Query strings are a set of parameters added to the end of a URL, separated by an ampersand (&), which can be used to pass data or arguments to the web page being linked to.

4. What are the benefits of using macros to generate hyperlinks with URLs?

The benefits of using macros to generate hyperlinks with URLs include increased efficiency, automation, and customization. Additionally, macros can also help reduce errors and save time by generating multiple hyperlinks at once.

5. Are there any limitations to using macros for generating hyperlinks with URLs?

One limitation of using macros for generating hyperlinks with URLs is that they may not be supported by all web browsers. Additionally, macros may require some coding knowledge and may not be as user-friendly for those without programming experience.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
906
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
Replies
12
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • Programming and Computer Science
Replies
7
Views
1K
Replies
2
Views
2K
Replies
8
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
18
Views
2K
  • Special and General Relativity
Replies
8
Views
2K
Back
Top