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 cannibalised some code from the thread Simple speech bubbles, arrows or balloon like shapes in beamer. It works really well, but crashes whenever non-alphanumeric characters are used in the node. Here's the code

\newcommand{\callouts}[3]{\tikz[remember picture,baseline]{\node[anchor=base,inner sep=0,outer sep=0]%
    (#3){\colorbox{#1!20}{#3}};\node[overlay,rectangle callout,%
    callout relative pointer={(0cm,0.5cm)},fill=#1!20] at ($(#3.south)+(-0cm,-0.7cm)$){#2};}%
    }%

And this is what it creates;

enter image description here

However, when I try to highlight and label a string with a non-alphanumeric character, e.g. comma or a mathematical symbol, the command crashes. I've tried using math mode and the \text{} command, but neither of these work. Any pointers appreciated.

share|improve this question
    
Instead of posting a fragment of code, it's much more helpful to post a complete minimal example that shows your problem. This will make is easier for people to help you. –  Alan Munn Oct 12 '12 at 13:05
    
Thanks Alan. Meant to to that. I'm still having difficulties with using certain maths symbols, e.g. the \neg operator. I've tried putting this in brackets, using \text, and using math mode. –  Nick Riches Oct 12 '12 at 14:07
    
@NickRiches please see my updated answer for a solution allowing the use of \neg; no need for extra braces now. –  Gonzalo Medina Oct 12 '12 at 15:19
    
Cheers that's brill –  Nick Riches Oct 12 '12 at 16:53

1 Answer 1

up vote 11 down vote accepted

The problem is that the string that is used for the label contents of the node is also used also to provide a name for the node and this can cause problems; the solution is to use another (simpler) string for naming the node; in the following example I use a counter to provide the name for the nodes:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.callouts,shapes.arrows}

\newcounter{mycallout}

\newcommand{\callouts}[3]{%
  \stepcounter{mycallout}
  \tikz[remember picture,baseline]{\node[anchor=base,inner sep=0,outer sep=0]%
    (\themycallout) {\colorbox{#1!20}{#3}};\node[overlay,rectangle callout,%
    callout relative pointer={(0cm,0.5cm)},fill=#1!20] at ($(\themycallout.south)+(-0cm,-0.7cm)$){#2};}%
    }%

\begin{document}

\callouts{blue}{text;$a\neg$}{text,$a\neg$}

\end{document}

enter image description here

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.