[OS X TeX] help with \newcommand

Michael Sharpe msharpe at ucsd.edu
Sat Jun 5 10:58:07 EDT 2010


On Jun 5, 2010, at 7:10 AM, Ramón Figueroa-Centeno wrote:

> 
> Aloha,
> 
> I want to define a new command that will make my life a lot easier. Here is
> what I would like:
> 
> \newcommand{\foo}[1]{#1 $\#1$}
> 
> So that I could invoke it as "\foo{aleph}" I get the same as if I typed
> "aleph $\aleph$" (no backslash on the first character).
> 
> Also, much harder (I think):
> 
> a command that would do URL encoding right from within LaTeX to pass
> arguments to the hyperref package:
> 
> \newcommand{\foo2}[1]{\href{<#1 url encoded>}{#1}}
> 
> so that "\foo2{Hello you}" would yield the same as typing
> "\href{http://Hello%20you}{Hello you}"
> 
> Thanks,
> 


You can encode spaces using 
\makeatletter
\def\encspace#1{\encspace at i#1  \@empty}
\def\encspace at i#1 #2{%
#1%
\ifx#2\@empty\else\%20\expandafter\encspace at i\fi
#2}
\makeatother

so that \encspace{This used to have spaces} produces This%20used%20to%20have%20spaces.

Michael


More information about the MacOSX-TeX mailing list