Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to write a macro similar to the \href command from the hyperref package, but which takes a single argument. The URL is generated by making the argument lowercase.

Here is a minimal example:

\documentclass{article}
\usepackage{hyperref}
\newcommand\mylink[1]{\href{www.\lowercase{#1}.com}{#1}}

\begin{document}
\mylink{MyURL}
\end{document}

However, the \lowercase command is not expanded, and the link points to www.\lowercase{MyURL}.com. Is there a way to solve this problem?

share|improve this question
add comment

1 Answer

up vote 10 down vote accepted
\newcommand\mylink[1]{\lowercase{\href{www.#1.com}}{#1}}

will work.

As requested in comments a more complicated example:

\documentclass{article}
\usepackage{hyperref}

\newcommand\mylink[1]{\lowercase{\href{www.#1.com}}{#1}}
\newcommand\mymail[2]{%
\lowercase{\def\tmpa{#1}}%
\uppercase{\def\tmpb{#2}}%
\href{mailto:\tmpa.\tmpb}{#1.#2}}

\begin{document}
\mylink{MyURL}

\mymail{David}{Example.ORG}

\end{document}
share|improve this answer
    
Thanks, that's great. Do you know any reason why this stops working if I put in my class file rather than the preamble? Or do I need to check for conflicting settings? –  Prince Goulash Jan 28 '13 at 11:07
    
should make no difference unless something else redefines it add \show\mylink after \begin{document} and tex will stop and show you the definition, if it isn't your definition something else is defining it. –  David Carlisle Jan 28 '13 at 11:31
    
Apologies - it was a typo that was confusing me. Thanks again for the solution. –  Prince Goulash Jan 28 '13 at 12:15
    
Surprising that it works. But out of curiosity: How to expand stuff in \href? I might want to do something like: \href{mailto:\lowercase{#1}.\uppercase{#2}}{#1.#2} –  Frederick Nord Feb 11 '13 at 17:07
    
Things expand automatically in \href: the problem is that \lowercase is not an expandable command, I'll add code to the answer for this –  David Carlisle Feb 11 '13 at 17:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.