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 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.

share|improve this question
2  
As an alternative to the TeX solutions below, you can define a shortcut/macro in your editor. –  Caramdir Dec 27 '10 at 0:40
add comment

4 Answers

up vote 6 down vote accepted

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}
share|improve this answer
7  
Given the "I am very new to TeX" statement in the question, I'd rephrase this with \newcommand rather than \def. –  Andrew Stacey Dec 27 '10 at 19:48
add comment

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.

share|improve this answer
    
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
    
@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: tex.stackexchange.com/questions/15252/… –  doncherry Aug 20 '11 at 16:54
add comment

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 $...$.

share|improve this answer
add comment

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

 \let\lra\longrightarrow

 $\lra$
share|improve this answer
    
What is the benefit of using \let in this case versus \def? –  Carl Morris Sep 25 '12 at 16:35
    
@CarlMorris It is slightly more efficient as it assigns a pointer to the existing definition. –  Yiannis Lazarides Sep 25 '12 at 18:48
    
@YiannisLazarides, this doesn't work with environments, right?, e.g. \let\v\verbatim –  PatrickT Feb 28 at 7:26
1  
@PatrickT Yes it will not work with environements or with LaTeX commands that take arguments etc.. –  Yiannis Lazarides Feb 28 at 13:47
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.