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 came across a problem when typing my report. I do not know how to fix this. The problem is as follows:

I have two custom commands defined like this:

\newcommand{\slr}[1][n]{\ensuremath{{\bf SL}(#1,\mathbb{R})}}

\newcommand{\lie}[1][G]{\ensuremath{{\bf L}(#1)}}

So that the first command gives an output like ${\bf SL}(n,\mathbb{R})$ and the second command gives the output like ${\bf L}(G)$. Here $n$ and $G$ are respectively the default arguments.

Now when I use these two commands together, I hope to get

$${\bf L}({\bf SL}(2,\mathbb{R}))$$

However, for some reason what I am getting is

$$ {\bf L}({\bf SL}(2),\mathbb{R})$$

Any ideas of what is going on here?

share|improve this question
    
In LaTeX, don't use \bf; use \bfseries or \textbf{...} or \mathbf{...}. –  Jubobs Mar 25 at 8:33
add comment

2 Answers 2

up vote 4 down vote accepted

The problem in \lie[\slr[2]] is that the optional argument to \lie is taken to be \slr[2. You can solve the issue with xparse:

\documentclass{article}
\usepackage{amsmath,amssymb,xparse}

\DeclareMathOperator{\slrop}{\mathbf{SL}}
\DeclareMathOperator{\lieop}{\mathbf{L}}

\NewDocumentCommand{\slr}{O{n}}{\slrop(#1,\mathbb{R})}
\NewDocumentCommand{\lie}{O{G}}{\lieop(#1)}

\begin{document}
Here it is: $\lie[\slr]$

With optional argument: $\lie[\slr[2]]$
\end{document}

enter image description here

I removed \ensuremath as I believe that you gain nothing from using \lie in text rather than $\lie$; to the contrary, I firmly believe that the latter form is much better, because math is always treated as math.

share|improve this answer
add comment

I cannot see it:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\newcommand\slr[1][n]{\ensuremath{\mathbf{SL}(#1,\mathbb{R})}}
\newcommand\lie[1][G]{\ensuremath{\mathbf{L}}(#1)}

\begin{document}

\[ {\bf L}({\bf SL}(2,\mathbb{R})) \]

\[ \lie[{\slr[2]}] \]

\[ \slr[\lie] \]

\end{document}

enter image description here

You have to put the optional argument into braces: [{\slr[2]}]

share|improve this answer
    
I am still getting the same problem. I am using the book class, if that helps. –  Vishal Mar 25 at 8:40
    
Also, as suggested above, I am now using \textbf instead of \bf. –  Vishal Mar 25 at 8:40
    
see myedited answer. –  Herbert Mar 25 at 8:46
    
It works by putting {} around the second argument. –  Vishal Mar 25 at 8:51
1  
[\slr[2]] takes the first ] as closing brace for the first [ and not for the second one, because [ looks only for a following ] –  Herbert Mar 25 at 8:54
show 2 more comments

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.