# User command shortcut for limits

I'm a grey headed guy taking a calculus class. I'm trying to figure out how to make a user command with two arguments to generate limit statement with right arrow. I keep having to type \lim_{x \rightarrow \infty} blah blah.

So, I would like shortcut with first param as in x above and second param where the limit is going to.

• Instead of a command, you could use an editor (or a third party program) which lets you insert snippets. – Manuel Feb 8 '14 at 18:42


\newcommand{\mylim}{code goes here}


where \mylim is the name of the macro we want to define. In the second set of curly parentheses, we add the code we want to use as a shortcut. We use a hash # and a number to denote the first input, second input, and so on. So we'd write:

\newcommand{\mylim}{\lim_{#1 \to #2}}


Then we need to tell LaTeX that this command takes two mandatory arguments, so we add [2] between the name of the macro, and the definition:

\newcommand{\mylim}[2]{\lim_{#1 \to #2}}


More information about defining new macros can be found on this Wikibooks page.

And here's a minimal example:

\documentclass{article}

\usepackage{amsmath}

\newcommand{\mylim}[2]{\lim_{#1 \to #2}}

\begin{document}

\begin{equation*}
\mylim{x}{\infty} blah\;blah
\end{equation*}

\end{document}


which produces

• Please provide an explanation of your answer, along with code. – Chris Chudzicki Feb 8 '14 at 18:30