2

I'm trying to define a tikz node inside a minted frame. I have the following MWE:

\documentclass[tikz, xcolor={svgnames}, aspectratio=43]{beamer}

\usepackage{minted}
\usepackage{tikz}

\usetikzlibrary{shapes}

\begin{document}
    \begin{minted}[
        autogobble,
        escapeinside=||,
        fontsize=\scriptsize,
        breaklines
    ]{php}
        <?php
            $dbhost = 'localhost';
            $dbuser = 'root';
            $dbpass = 'password';
            $dbname = 'STUDENTSREG';
            $conn = new mysqli ($dbhost, $dbuser, $dbpass, $dbname);
            if($conn->connect_error ) {
                die('Could not connect: ' . $conn->connect_error);
            }
            //prepare and bind 
            $stmt = $conn->prepare("INSERT INTO STUDENT (SID, SNAME, EMAIL) VLAUES (?, ?, ?) "); 
            $stmt->bind_param("sss",$id, $name, $email); |\tikz \node (sink) {dasfkj} ;|
            //set parameters and execute
            $id = 1004; $name = "JKL"; $email="[email protected]";
            $stmt->execute(); 

            $id = 1005; $name = "MNO"; $email="[email protected]";
            $stmt->execute(); 
            echo "Entered records successfully\n";
            $stmt->close();
            $conn->close();
        ?>
    \end{minted}
\end{document}

From what I understand this should work but I get the following error:

! 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.13 ... }\PYG{esc}{\tikz \node (sink) {dasfkj} ;}

I have no idea what the issue is. Any help would be appreciated. Thanks.

6
  • What is the purpose of |\tikz \node (sink) {dasfkj} ;|? Removing it solves your problem. There is no node labelled sink defined so it causes the error. Jul 16, 2018 at 17:29
  • The purpose is to define a node so I can use it in a path later. I know removing it removes the error but that’s not my problem. I need to define a node here.
    – K G
    Jul 16, 2018 at 17:32
  • 1
    I don’t understand what you mean by “there is no node defined.” Doesn’t this statement define a node called ‘sink’ here?
    – K G
    Jul 16, 2018 at 17:35
  • Please have a look at this answer. Jul 16, 2018 at 17:55
  • Thanks. I’ve seen this answer. That’s what inspired this code. But as you can see it’s not working for me. I’m not doing anything different from the suggested answer that I can identify. Could you point out what I’m doing wrong?
    – K G
    Jul 16, 2018 at 18:19

1 Answer 1

2

This is a known problem of how Pygments implements escapeinside, see p. 24 of the minted manual. Apparently the LaTeX control sequence resembles a string or comment for the current php lexer.

A workaround is suggested in this GitHub comment. For your particular example, we can use a modified version of the active !. Added: I also included a $\bar x\sqrt x$ to illustrate that LaTeX control sequence is broken when doing escapeinside:

\documentclass[tikz, xcolor={svgnames}, aspectratio=43]{beamer}

\usepackage{minted}
\usepackage{tikz}

\usetikzlibrary{shapes}

\begin{document}
    \begingroup
    \catcode`\!=\active
    \def!#1#2!{\tikz{\node (#1) {#2};}}
    $\bar x\sqrt x$
    \begin{minted}[
        autogobble,
        escapeinside=||,
        fontsize=\scriptsize,
        breaklines
    ]{php}
        |$\bar x\sqrt x$|<?php
            $dbhost = 'localhost';
            $dbuser = 'root';
            $dbpass = 'password';
            $dbname = 'STUDENTSREG';
            $conn = new mysqli ($dbhost, $dbuser, $dbpass, $dbname);
            if($conn->connect_error ) {
                die('Could not connect: ' . $conn->connect_error);
            }
            //prepare and bind 
            $stmt = $conn->prepare("INSERT INTO STUDENT (SID, SNAME, EMAIL) VLAUES (?, ?, ?) "); 
            $stmt->bind_param("sss",$id, $name, $email); |!{sink}{dasfkj}!|
            //set parameters and execute
            $id = 1004; $name = "JKL"; $email="[email protected]";
            $stmt->execute(); 

            $id = 1005; $name = "MNO"; $email="[email protected]";
            $stmt->execute(); 
            echo "Entered records successfully\n";
            $stmt->close();
            $conn->close();
        ?>
    \end{minted}
    \endgroup
\end{document}

bar vs sqrt

Added: As you can see, \sqrt x is fine, but \bar x becomes \bar{␣}x.

But again, if If you want to simply insert a marker to be used later, then this answer by @DavidCarlisle suffices. Added: Since no error is generated, I can only assume that \tikzmark somehow works as \sqrt does.

2
  • Thanks. But wouldn’t inserting the marker run into the same limitations?
    – K G
    Jul 16, 2018 at 19:05
  • @KG I cannot guarantee. Please check my updated answer. Jul 16, 2018 at 19:55

You must log in to answer this question.

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