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 would like to define a new command like the following. The latex when compiling should emit I_{wr} when given without arguments, or the optional arguments should come as a subscript.

\newcommand{\myCommand}[1][]{I_{wr#1}}

So If I give $\myCommand{2}$, then it would emit the text as I_{wr}2. The 2 does not come in the subscript form. Could anyone please tell me how to do this correctly?

Thank You

share|improve this question

1 Answer 1

up vote 8 down vote accepted

It's already correct except for the usage:

\newcommand{\myCommand}[1][]{I_{wr#1}}

The argument is an optional argument that uses square brackets:

$\myCommand[2]$

Full example:

\documentclass{article}

\newcommand{\myCommand}[1][]{I_{wr#1}}

\begin{document}
\[
  \myCommand[2] = 2 * \myCommand
\]
\end{document}

Result

share|improve this answer

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.