In a description like
\begin{description}
\item[\texttt{DoSomething(items[])}:]
...
\end{description}
, how do I escape the "]" character?
In a description like
\begin{description}
\item[\texttt{DoSomething(items[])}:]
...
\end{description}
, how do I escape the "]" character?
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}
] 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
\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
] will do. It doesn't matter if they are part of a macro argument or not.
– Martin Scharrer
Jul 19 '11 at 15:52
\[\]. I blame the lack of coffee. – You Jul 19 '11 at 10:43]is already protected by braces. In general\item[...{...[]...}...]– egreg Jul 19 '11 at 10:51