tikz 内置有 beamer

tikz 内置有 beamer

我正在尝试tikz node在 a 内定义 a minted frame。我有以下 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}

据我了解,这应该可行,但我收到以下错误:

! 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} ;}

我不知道问题是什么。任何帮助我都会很感激。谢谢。

答案1

这是 Pygments 实现的一个已知问题escapeinside,请参阅minted手册。显然,LaTeX 控制序列类似于当前词法分析器的字符串或注释php

建议的解决方案是此 GitHub 评论。对于您的特定示例,我们可以使用活动的修改版本!添加:我还添加了一个$\bar x\sqrt x$来说明在执行以下操作时 LaTeX 控制序列被破坏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}

条形图与平方根

添加:正如你所见,\sqrt x是没问题的,但是\bar x变成了\bar{␣}x

但同样,如果如果您只想插入稍后使用的标记,那么这个答案@DavidCarlisle 就足够了。添加:由于没有产生错误,我只能假设它以\tikzmark某种方式正常工作\sqrt

相关内容