21

I am using $\longrightarrow{}$ at many places in my document. I should say around two to three times per page. I was wondering if there is a way to assign a shortcut (i.e. lra) and wherever I use lra it will put $\longrightarrow{}$.

So far I am getting by with Ctrl+C & Ctrl+V.

doncherry
  • 54,637
Aku
  • 11,026

4 Answers4

23

Expanding on Frabjous's answer, I would do this:

\usepackage{xspace}

...

\newcommand{\lra}{\ensuremath{\longrightarrow{}}\xspace}

This gives you a \lra command that is sensitive to the trailing space without defining two macros for it.

night owl
  • 7,593
  • As such it works great. How to use this for shortcut $\xrightarrow[\text{Unicode text 1}]{\text{Unicode text 2}}$ – Aku Dec 28 '10 at 19:30
  • @Mark: What is the package xspace most commonly useful for? – night owl Jul 18 '11 at 17:49
  • 1
    @nightowl: The package xspace provides the command \xspace, which does or does not add a space depending on whether there's a punctuation sign right after it. Foo\xspace . will expand to Foo., Foo\xspace Bar will expand to Foo Bar. This comes in handy for new macros which will behave correctly no matter what follows. Here's an interesting question on xspace's behavior toward different punctuation signs: http://tex.stackexchange.com/questions/15252/why-does-xspace-behave-differently-for-parenthesis-vs-braces-brackets – doncherry Aug 20 '11 at 16:54
15

alt text

\documentclass{minimal}
\def\lra{\ensuremath\longrightarrow}
\def\lras{\ensuremath\longrightarrow\ }
\begin{document}
\noindent%
The \lra without a trailing space.

\noindent%
The \lras with a trailing space.
\end{document}
Display Name
  • 46,933
11

I'd do it like this:

\newcommand{\lra}{\ensuremath{\longrightarrow{}}}

Thanks to ensuremath, this will work both inside and outside of math mode -- with no need for $...$.

frabjous
  • 41,473
8

You can use let which allows you to copy the content of a command into a new command.

 \let\lra\longrightarrow

 $\lra$
yannisl
  • 117,160