1

I’m trying to define a new environment whose objective is to display an image and a bubble giving some text on the drawing.

One of the thing it could produce would be:

enter image description here

To do this, I’ve find some LaTeX command here and there for the bubble (but I have to confess that I do not understand it...) I modify it to an environment, then I create my own environment.

Here is the (bad) LaTeX code:

\usepackage{graphicx}
\RequirePackage[tikz]{bclogo}
\usetikzlibrary{arrows,shapes,calc}

%to create an ellipse whose contain the text given in parameter
\newcommand{\bulle}[1]
{   \tikz   [remember picture,baseline]
                {   \node[anchor=base,inner sep=0,outer sep=0] (#1) {{}};
                    \node[overlay, ellipse callout, fill=gray!50] 
                                at ($(#1.north)+(-.5cm,0.8cm)$) {#1};
                }
}

%transform \bulle into an environment
\newenvironment{bullenv}[0]
{   \bulle\bgroup
}
{   \egroup
}

%display an image and a bubble whose position is to be adjusted
\newenvironment{advice}[3]
{   \includegraphics[scale=0.25]{#1}
    \hspace{#2}
    \vspace{#3}
    \begin{bullenv}
}
{   \end{bullenv}
}

I’ve tried to use it like that:

\begin{advice}{Images/dessin.pdf}{9cm}{3cm}
    This is my advice
\end{advice}

Unfortunately, it doesn’t work and I do not know how to fix it...

Here is the compilation report:

! Missing \endcsname inserted.
<to be read again>
\bgroup
l.35 \begin{advice}{Images/dessin.pdf}{9cm}{3cm}
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
! Extra \endcsname.
<argument> ...pgf@sh@sa@\tikz@fig@name \endcsname
{\pgf@sh@reanchor {\tikz@s...
l.35 \begin{advice}{Images/dessin.pdf}{9cm}{3cm}
I'm ignoring this, since I wasn't doing a \csname.
! Missing \endcsname inserted.
<to be read again>
\bgroup
l.35 \begin{advice}{Images/dessin.pdf}{9cm}{3cm}
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
! Missing \endcsname inserted.
<to be read again>
\bgroup
l.35 \begin{advice}{Images/dessin.pdf}{9cm}{3cm}
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
...
l.35 \begin{advice}{Images/dessin.pdf}{9cm}{3cm}
I'm ignoring this, since I wasn't doing a \csname.
! Package tikz Error: Giving up on this path. Did you forget a semicolon?.
See the tikz package documentation for explanation.
Type H <return> for immediate help.
...
l.36 T
his is my advice
This error message was generated by an \errmessage
command, so I can't give any explicit help.
Pretend that you're Hercule Poirot: Examine all clues,
and deduce the truth by order and method.
Missing character: There is no h in font null font!
Missing character: There is no i in font null font!
Missing character: There is no s in font null font!
Missing character: There is no i in font null font!
Missing character: There is no s in font null font!
Missing character: There is no m in font null font!
Missing character: There is no y in font null font!
Missing character: There is no a in font null font!
Missing character: There is no d in font null font!
Missing character: There is no v in font null font!
Missing character: There is no i in font null font!
Missing character: There is no c in font null font!
Missing character: There is no e in font null font!
Overfull \hbox (29.01105pt too wide) in paragraph at lines 35--38
[][] []
[]
Underfull \hbox (badness 10000) in paragraph at lines 35--38
[]
[1
{/usr/local/texlive/2017/texmf-var/fonts/map/pdftex/updmap/pdftex.map} <./Images/dessin.pdf>] (./essai_3.aux)
LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.)

The funny thing is what LaTeX tells:

Pretend that you're Hercule Poirot: Examine all clues, and deduce the truth by order and method.

If someone have an idea, it would be very appreciate.

2
  • 1
    Please provide an MNWE so we can reproduce the error. We can't compile a code fragment and we don't have your files. Use e.g. example-image so everyone has the image you use. \bulle takes an argument. You're passing it \bgroup, but that isn't going to work. You can't name a node \bgroup.
    – cfr
    Commented Jun 7, 2018 at 17:29
  • 2
    You need the env package for this so that you can capture the contents of the environment to put in the bubble. But wouldn't a command be simpler here? How much stuff are you going to put in the bubble? Not too much, I'd assume. So why not just define \advice with 4 arguments?
    – cfr
    Commented Jun 7, 2018 at 17:35

1 Answer 1

3

It seems to me that you are making things far too complicated. You don't need an environment. You don't need \bulle and you don't need bullenv. All you need is a single command taking 4, rather than 3, arguments. (If you want to get fancy, you could make a key-value interface, but sticking to 4 arguments keeps the code dead simple.) This also means you don't need remember picture or calc or two runs or anything like that.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.callouts}
\newcommand\advice[4]
{%
  \tikz{%
    \node [inner sep=0, outer sep=0] {\includegraphics[scale=.25]{#1}};
    \node [ellipse callout, overlay, fill=gray!50] at (#2,#3) {#4}; 
  }%
}
\begin{document}
\advice{tiger}{-25mm}{-2.5mm}{This is my advice}
\end{document}

If you don't need line breaks, use \newcommand*\advice instead. If you do need line breaks, add align=center to the options for the call-out node.

tiger says ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .