1

I am trying to make a beamer presentation with the following tcblisting declaration in the preamble.

\newtcblisting{ListingBoxWithEscape}[2][]{
minted language=#2,
minted style=friendly,
minted options={breaklines,autogobble,fontsize=\footnotesize,tabsize=2,escapeinside=!!},
title=#1
}

In my document I have:

\begin{ListingBoxWithEscape}{html}
    <body>
    <div class="container">
      <div class="jumbotron">
        <h1>Grid Cols and a Row</h1>!
        \tikz \node[coordinate] (a) {};
        !<p>Resize this responsive page to see the effect</p>
      </div>

      <div class="row">
        <div class="col-sm-4">
          <h3>Web Design</h3>
          <p>This is Web design. This is web design. This is web design..</p>
          <p>We are trying to learn Responsive web design using Bootstrap......</p>
        </div>
\end{ListingBoxWithEscape}

To which I get the following errors:

! Package tikz Error: A node must have a (possibly empty) label text.

See the tikz package documentation for explanation.
Type  H <return>  for immediate help.
  ...                                              

l.6 \PYG{esc}{    \tikz \node[coordinate] (a) {};}

I am unable to figure out what the problem may be. Anybody have any ideas?

Here is an MWE:

\documentclass{beamer}

\usepackage{tikz}
\usepackage{tcolorbox}

\tcbuselibrary{xparse,minted}

\newtcblisting{ListingBoxWithEscape}[2][]{
    minted language=#2,
    minted style=friendly,
    minted options={breaklines,autogobble,fontsize=\footnotesize,tabsize=2,escapeinside=!!},
    title=#1
}

\usetikzlibrary{calc,shapes.callouts,shapes.arrows,positioning}

\begin{document}
\begin{frame}[c,fragile]
    \frametitle{Test}
    \begin{ListingBoxWithEscape}{html}
        <body>
        <div class="container">
          <div class="jumbotron">
            <h1>Grid Cols and a Row</h1>!
            \tikz \node[coordinate] (a) {};
            !<p>Resize this responsive page to see the effect</p>
          </div>

          <div class="row">
            <div class="col-sm-4">
              <h3>Web Design</h3>
              <p>This is Web design. This is web design. This is web design..</p>
              <p>We are trying to learn Responsive web design using Bootstrap......</p>
            </div>
    \end{ListingBoxWithEscape}
\end{frame}
\end{document}
2

I find that if I hide the tikzpicture in a command, say \newcommand\tst{\tikz[remember picture]{\coordinate (a);}}, and then use this command, the error message is gone. The following has many inputs from @egreg, whom I thank for the comments below. As @egreg points out, the issue are the { and }, I was only guessing that something in (I thought there is something fundamentally wrong, but as @egreg pointed out you may want to add listing only.)

\documentclass{beamer}

\usepackage{tikz}
\usepackage{tcolorbox}

\tcbuselibrary{xparse,minted}

\newtcblisting{ListingBoxWithEscape}[2][]{listing only,
    minted language=#2,
    minted style=friendly,
    minted options={breaklines,autogobble,fontsize=\footnotesize,tabsize=2,
    escapeinside=!!},
    title=#1
}

\usetikzlibrary{calc,shapes.callouts,shapes.arrows,positioning}
\begin{document}
\begin{frame}[c,fragile]
\newcommand\tst{\tikz[remember picture]{\coordinate (a);}}
    \frametitle{Test}
    \begin{ListingBoxWithEscape}{html}
        <body>
        <div class="container">
          <div class="jumbotron">
            <h1>Grid Cols and a Row</h1>!\tst!
            <p>Resize this responsive page to see the effect</p>
          </div>

          <div class="row">
            <div class="col-sm-4">
              <h3>Web Design</h3>
              <p>This is Web design. This is web design. This is web design..</p>
              <p>We are trying to learn Responsive web design using Bootstrap......</p>
            </div>
    \end{ListingBoxWithEscape}
    \begin{tikzpicture}[remember picture,overlay]
    \draw[red,latex-] (a) to[out=0,in=-90] ++ (1,1) node[above] {test};
    \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

| improve this answer | |
  • I guess it's a problem of category codes; for some reason {} doesn't get recognized for the node label. Hiding the picture in a macro solves the issue because the replacement text is tokenized in advance. – egreg Jul 9 '19 at 9:23
  • @egreg Thanks! Yes, that makes sense. I am however concerned about the lower half of the tcolorbox, this seems to be rubbish, regardless of the escape stuff. – user121799 Jul 9 '19 at 9:25
  • I guess the OP forgot to add listing only – egreg Jul 9 '19 at 9:27
  • @egreg Makes sense, thanks! – user121799 Jul 9 '19 at 9:27
  • The temporary definition can better be done inside the frame, prior to the ListingBoxWithEscape environment. – egreg Jul 9 '19 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.