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.

In a description like

\begin{description}
\item[\texttt{DoSomething(items[])}:]
...
\end{description}

, how do I escape the "]" character?

share|improve this question
1  
I was obviously having some kind of meltdown here, I was reading this question even as I was suggesting \[\]. I blame the lack of coffee. –  You Jul 19 '11 at 10:43
    
In this particular case you don't need any special precaution, of course, since the ] is already protected by braces. In general \item[...{...[]...}...] –  egreg Jul 19 '11 at 10:51
add comment

1 Answer

up vote 10 down vote accepted

Group only the brackets or the whole expression with additional curly braces.

\documentclass{article}

\begin{document}
  \begin{description}
    \item[\texttt{DoSomething(items{[]})}:]
    \item[{\texttt{DoSomethingElse(items[])}:}]
  \end{description}
\end{document}
share|improve this answer
    
this works, thanks. –  ptikobj Jul 19 '11 at 10:41
1  
This is the correct answer which I would have posted as well. I therefore undeleted it. –  Martin Scharrer Jul 19 '11 at 10:44
3  
The reason a ] breaks and adding { } works is that optional arguments are not handled like normal ones (which can be cascaded) but are read as part of a macros parameter text from the [ to the very next ]. Placing the ] inside { } effectively hides it from TeX token scanner which is forced to obey the group. Note that macros defined with xparse handle cascaded [ ] correctly (through some extra effort done by that package). –  Martin Scharrer Jul 19 '11 at 10:49
    
@Martin: Thanks. I wasn't sure since \item[\texttt{DoSomething(items[])}:] works as is and doesn't need grouping. Additional braces are only necessary when writing \item[{DoSomething(items[]):}]. –  Thorsten Donig Jul 19 '11 at 15:51
    
@Thorsten: Any braces around ] will do. It doesn't matter if they are part of a macro argument or not. –  Martin Scharrer Jul 19 '11 at 15:52
show 1 more 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.