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 want to use some text as the optional parameter to some command. The text includes square braces ([ and ]), but since the optional parameter goes within square brackets, unexpected things happen.

More info: I want an itemized list whose bullets are citations like [GMR85]. I used this command:

\begin{itemize}
  \item[[GMR85]] ...
\end{itemize}

but it takes the first ] as the end of optional parameter.

Any way to escape ] ?

Edit: I specially want this to work in beamer. My current result is like:

Note how ] is not included the label.

EDIT 2

This bug has been solved in the latest versions of beamer.

share|improve this question
3  
Use {description} rather than {itemize} with lexicon-like lists. –  Charles Stewart Dec 7 '10 at 13:23
    
Also, why don't you use the bibliography environment? –  Caramdir Dec 7 '10 at 17:51
    
@Caramdir: I always use the bibliography environment, but let's just say that there are technical reasons I don't want to do that now. (It's a long story!). As a short answer, you can just assume that I want an enumerate listing whose labels include brackets. (while they aren't citations.) –  Sadeq Dousti Dec 7 '10 at 18:26
    
@Charles: Sorry, but even {description} environment does not work in the beamer. (Screenshot: s1.bild.me/bilder/311010/1151044untitled.PNG) –  Sadeq Dousti Dec 7 '10 at 18:37
    
I found a way to solve your beamer problem, please see my solution below... –  Matten Dec 7 '10 at 18:59
add comment

2 Answers

up vote 23 down vote accepted

group the citation...

\documentclass{article}
\begin{document}

\begin{itemize}
  \item[{[GMR85]}] ...
\end{itemize}
\end{document}

The Beamer package makes things a little bit more difficult.

\documentclass{beamer}
\begin{document}

\def\braces#1{[#1]}

\begin{frame}{frame title}
\begin{itemize}
  \item[\braces{GMR95}] ...
\end{itemize}
\end{frame}

\end{document}

This works fine for me.

share|improve this answer
    
Thanks Matten, but it does not work either (I tried) –  Sadeq Dousti Dec 7 '10 at 13:01
2  
It does not work? I'll put a complete example in my answer, I have compiled it and it works fine for me... –  Matten Dec 7 '10 at 13:04
1  
itemize will cause the bullet cross beyond the left margin. See my answer (not really answer actually, just a comparison) :-) –  xport Dec 7 '10 at 17:43
    
@Matten: Sorry, I should have described more. I'm using it in a beamer slide, and it does not work in that case (but works fine when you use the article documentclass). Can you test it in the beamer too? (screenshot of my result: s1.bild.me/bilder/311010/1151044untitled.PNG). –  Sadeq Dousti Dec 7 '10 at 18:35
    
hey Sadeq.. I supplied another approach for your beamer problem. Please see my second code example! –  Matten Dec 7 '10 at 18:55
show 3 more comments

Based on Charles Stewart's comment and Matten's answers, I make the following comparion. I suggest to follow the Stewart's suggestion. If we insist on using itemize environment instead of description, the bullet item will expands to the left crossing the left margin.

alt text

\documentclass[dvipsnames]{article}
\usepackage{xcolor}
\usepackage[showframe=true,margin=30mm]{geometry}
\usepackage{showexpl}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\SX@codeInput}{xleftmargin=0pt,xrightmargin=0pt}{}
  {\typeout{***Successfully patched \protect\SX@codeInput***}}
  {\typeout{***ERROR! Failed to patch \protect\SX@codeInput***}}
\makeatother
\lstset{%
  literate={ï}{}0
         {»}{}0
         {¿}{}0,
    breaklines=true,
    breakindent=0pt,    
    basicstyle=\ttfamily\scriptsize,
    keywordstyle=\color{blue}\sffamily\bfseries,
    commentstyle=\color{Green}\itshape,                                 
    stringstyle=\rmfamily,                          
    showstringspaces=false,
    backgroundcolor=\color{Yellow!30},
    frame=single,
    framerule=0.4pt,
    rulecolor=\color{red},
    framesep=3pt,
    xleftmargin=3.4pt,
    xrightmargin=3.4pt,
    tabsize=2,%
    explpreset={pos=b}%
}
\begin{document}

\begin{LTXexample}
\begin{description}
  \item{[GMR85]} I am happy.
  \item{[GMR86]} Are you happy?
\end{description}
\end{LTXexample}


\begin{LTXexample}
\begin{itemize}
  \item[{[GMR85]}] I am happy.
  \item[{[GMR86]}] Are you happy?
\end{itemize}
\end{LTXexample}

\end{document}
share|improve this answer
    
paralist also fixes the margin behavior. –  Caramdir Dec 7 '10 at 17:53
add 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.