1

I have trying to use new command to represent math, and this is what I type in:

\\
\newcommand\fpi2[2][\pi][2]{frac{#1}{#2}}\\
\newcommand\mylim[2][x]{lim_{#1\to #2}}

I'm trying to create a new command which represent $frac{\pi}{2}$ Is it possible for me to use \mylim{${\fpi2}^-$}?

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
  • Unless you use a \csname ... \endcsname workaround method, you can't have a non-letter (such as the numeral 2) be part of a command name. Use a command name such as \fpi or \fpitwo instead. – Mico Sep 11 '13 at 16:58
  • You have posted several questions in the last few days repeating the same error every time: you need a backslash \frac and \lim not frac and lim (in addition to the point of this question that you can not have a command \fpi2.) – David Carlisle Sep 11 '13 at 18:30

1 Answers1

2

The name of a command should contain only letters (not absolutely true, but at the moment let's accept it). Apparently your command doesn't require arguments, since you are interested in a constants string:

\documentclass{article}

\newcommand\fpi{\frac{\pi}{2}}
\newcommand\mylim[2][x]{\lim_{#1\to #2}}

\begin{document}

$\fpi\quad\mylim{\fpi^-}$

\[
\fpi\quad\mylim{\fpi^-}
\]

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • 1
    @HuangElizabeth You're welcome! Don't forget that (after a sensible wait) you can accept answers by clicking the checkmark to their left :-) – Gonzalo Medina Sep 11 '13 at 17:03