使用 tikz 制作多页代码

使用 tikz 制作多页代码

问题描述了如何在 minted 代码中使用 tikzmarks。但是,如果代码跨度超过一页,结果就不正确。

有没有办法来解决这个问题?

梅威瑟:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{minted}

\begin{document}
\begin{minted}[escapeinside=??]{py}
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long?\tikzmark{mark}? function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  \end{minted}

  \begin{tikzpicture}[remember picture]
    \draw[overlay, latex-, thick] (pic cs:mark) --++ (1,1);
  \end{tikzpicture}
\end{document}

新MWE

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{minted}

\newcommand{\mymarkright}[2]{\tikzmark{#1}%
  \begin{tikzpicture}[overlay, remember picture]
    \draw [overlay, latex-, thick] (pic cs:#1) --++ (0.5,-0.5) node[anchor=west, align=center, rectangle, fill=red!30, draw] {#2};
\end{tikzpicture}}

\begin{document}
\begin{minted}[escapeinside=??]{py}
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
  # this is a a long?\mymarkright{a}{Here goes\\some text}? function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  \end{minted}

\end{document}

在此处输入图片描述

答案1

您需要添加带有标记的叠加图片。为了解决下面的所有评论,我重写了答案,其中包含几个 pgf 键,允许您自定义箭头的外观。我希望给这些键起了不言自明的名字。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\newcounter{mymark}
\usepackage{minted}
\newcommand{\MarkMe}[2][]{\stepcounter{mymark}%
\tikzmark{mark-\number\value{mymark}}%
\begin{tikzpicture}[overlay,remember picture]
    \def\pv##1{\pgfkeysvalueof{/tikz/my mark/##1}}
    \draw[/tikz/my mark/arrow,line width=\pv{line width},red,shorten >=\pv{halo},
    shorten <=\pv{halo},
    preaction={draw,line width=\pv{line width}+2*\pv{halo},white,/tikz/my mark/arrow}] 
    ([yshift=2pt]pic cs:mark-\number\value{mymark}) 
    --++ (\pv{x},\pv{y}) node[above,/tikz/my mark/mark node]{#2};
  \end{tikzpicture}}
\tikzset{my mark/.cd,
mark node/.style={fill=red!30,draw},
line width/.initial=1pt,
halo/.initial=0.5pt,
x/.initial=1cm,
y/.initial=1cm,
arrow/.style={latex-}}
\begin{document}
\begin{minted}[escapeinside=??]{py}
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long?\MarkMe{bla}? function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  \end{minted}
\end{document}

在此处输入图片描述

至于您问题的下一个迭代:有趣!我不知道minted会这样做。无论如何,这里有一个解决方案:使用eso-picatbegshi最后绘制内容。当然,这可以与上面的答案结合起来,通过将环境包装到tikzpicture\AddToShipoutPictureFG*{...}并加载。eso-pic

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{minted}
\usepackage{eso-pic}

\newcommand{\mymarkright}[2]{\tikzmark{#1}%
\AddToShipoutPictureFG*{%
  \begin{tikzpicture}[overlay, remember picture]
    \draw [ latex-, thick] (pic cs:#1) --++ (0.5,-0.5) 
    node[anchor=west, align=center, rectangle, fill=red!30, draw] {#2};
\end{tikzpicture}}}

\begin{document}
\begin{minted}[escapeinside=??]{py}
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
  # this is a a long?\mymarkright{a}{Here goes\\some text}? function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  def function1(args):
    # this is a a long function
  \end{minted}

\end{document}

在此处输入图片描述

相关内容