当文档页面过多时,使用 tikzmark 时会出现 tikz 图形“尺寸太大”错误

当文档页面过多时,使用 tikzmark 时会出现 tikz 图形“尺寸太大”错误

我用代码(由 marmot 修复 :) ...),它工作得很好,直到我的文档页面太多。
在给定点,我收到“尺寸太大”错误。它使用代码测试给定的 tikzmark 是否在页面上,所以我的直觉是问题出在某个地方,页面太多会造成麻烦... 唉,我完全不知道如何排除故障。

考虑到问题的性质,以下是一个“尽可能最小的不起作用的例子”:)(如果你删除宏的两行,\repeatenoughtimes你就会让它起作用……只是为了表明问题肯定与重复太频繁有关。)

% !TEX TS-program = xelatexmk
\documentclass{article}
%\usepackage[a6paper]{geometry}
\usepackage[paperwidth=4in,paperheight=3in]{geometry}
%\url{https://tex.stackexchange.com/q/483547/86}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark}
\newcounter{tikzmarklines}\setcounter{tikzmarklines}{0} % 

%% Code added recently to the package which provides the \iftikzmarkoncurrentpage code: 
\makeatletter

\newif\iftikzmark@
\renewcommand\iftikzmark[3]{%
    \@ifundefined{save@pt@\tikzmark@pp@name{#1}}{%
      #3%
    }{%
      #2%
    }%
}%

\newcommand\iftikzmarkexists[1]{%
  \@ifundefined{save@pt@\tikzmark@pp@name{#1}}{%
    \tikzmark@false%
  }{%
    \tikzmark@true%
  }%
  \iftikzmark@
}%

\newcommand\iftikzmarkonpage[2]{%
  \@ifundefined{save@pt@\tikzmark@pp@name{#1}}{%
    \tikzmark@false
  }{%
    \@ifundefined{save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname}{%
      \tikzmark@false
    }{%
      \ifnum\csname save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname\endcsname=#2\relax%
      \tikzmark@true
      \else
      \tikzmark@false
      \fi
    }%
  }%
  \iftikzmark@
}

\newcommand\iftikzmarkoncurrentpage[1]{%
  \@ifundefined{save@pt@\tikzmark@pp@name{#1}}{%
    \tikzmark@false
  }{%
    \@ifundefined{save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname}{%
      \tikzmark@false
    }{%
      \ifnum\csname save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname\endcsname=\the\value{page}\relax%
      \tikzmark@true
      \else
      \tikzmark@false
      \fi
    }%
  }%
  \iftikzmark@
}
\makeatother

\tikzset{
  next page=below,
  brace/.style n args={2}{insert path={%
  ([xshift=0.15em,yshift=0.1pt+.5ex]#1) -- 
  ([xshift=-0.3pt,yshift=0.1pt+.5ex]#1) -- 
  ([xshift=-0.3pt,yshift=-0.1pt+.5ex]#2) -- 
  ([xshift=0.15em,yshift=-0.1pt+.5ex]#2) -- 
  ([xshift=0.15em,yshift=0.1pt+.5ex]#2) --
  ([xshift=0.3pt,yshift=0.1pt+.5ex]#2) --
  ([xshift=0.3pt,yshift=-0.1pt+.5ex]#1) --
  ([xshift=0.15em,yshift=-0.1pt+.5ex]#1) --
  cycle}}}

\newif\iffirstmark

\newcommand{\linestart}{%
  \stepcounter{tikzmarklines}%
  \tikzmark{a\thetikzmarklines}%
  \global\firstmarktrue
  \iftikzmarkoncurrentpage{b\thetikzmarklines}%
  \else
  \begin{tikzpicture}[remember picture,overlay,next page=below]%
  \clip (current page text area.south west) rectangle (current page text area.north east);
  \fill[overlay,brace={pic cs:a\thetikzmarklines}{pic cs:b\thetikzmarklines}];
  \end{tikzpicture}%
  \fi
}

\newcommand{\linefinish}{%
  \iffirstmark
  \tikzmark{b\thetikzmarklines}%
  \global\firstmarkfalse
  \fi
  \begin{tikzpicture}[remember picture,overlay]%
  \clip (current page text area.south west) rectangle (current page text area.north east);
  \fill[overlay,brace={pic cs:a\thetikzmarklines}{0,0}];
  \end{tikzpicture}%
  }

\usepackage{lipsum}

\newcommand{\repeatenoughtimes}{
Text \linestart text text\par
Text text \linefinish text\par
Text \linestart text text\par
Text text \linefinish text\par
\lipsum[1-5]
}

\begin{document} 

\repeatenoughtimes\repeatenoughtimes\repeatenoughtimes\repeatenoughtimes
\repeatenoughtimes\repeatenoughtimes\repeatenoughtimes\repeatenoughtimes
\repeatenoughtimes\repeatenoughtimes\repeatenoughtimes\repeatenoughtimes
\repeatenoughtimes\repeatenoughtimes\repeatenoughtimes\repeatenoughtimes
\repeatenoughtimes\repeatenoughtimes\repeatenoughtimes\repeatenoughtimes

\end{document}

答案1

这是我建议的修复方法。要尝试一下,请\makeatletter ... \makeatother在加载 tikzmark 库后将其放在序言中。

我完全有可能不明白\numexpr维度是如何运作的,但主意是声音。

\tikzdeclarecoordinatesystem{pic}{%
  \pgfutil@in@,{#1}%
  \ifpgfutil@in@%
    \tmk@labeldef#1\@nil
  \else
    \tmk@labeldef#1,(0pt,0pt)\@nil
  \fi
  \@ifundefined{save@pt@\tmk@label}{%
    \tikz@scan@one@point\pgfutil@firstofone\tmk@def
  }{%
    \pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}%
    \save@orig@pic%
    \pgfsys@getposition{\pgfpictureid}\save@this@pic%
    \pgf@process{\pgfpointorigin\save@this@pic}%
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    \pgf@process{\pgfpointorigin\save@orig@pic}%
    \advance\pgf@x by -\pgf@xa
    \advance\pgf@y by -\pgf@ya
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    \pgf@process%
    {\pgfpointorigin\csname save@pt@\tmk@label @offset\endcsname}%
    \advance\pgf@xa by \pgf@x
    \advance\pgf@ya by \pgf@y
      \@ifundefined{save@pg@\csname save@pt@\tmk@label\endcsname}{}{%
        \@ifundefined{save@pg@\pgfpictureid}{}{%
          \pgfkeysvalueof{/tikz/next page vector}%
        \edef\tmk@pg{\the\numexpr \csname save@pg@\csname save@pt@\tmk@label\endcsname\endcsname - \csname save@pg@\pgfpictureid\endcsname\relax}%
        \advance \pgf@xa by %
        \tmk@pg\pgf@x\relax
        \advance \pgf@ya by %
        \tmk@pg\pgf@y\relax
        }%
      }%
      \pgf@x=\pgf@xa
      \pgf@y=\pgf@ya
    \pgftransforminvert
    \pgf@pos@transform{\pgf@x}{\pgf@y}%
    }%
  }

答案2

(评论太长了)。这是 tikzmark 的一个错误,与下一页选项有关。它将 \pgf@y 乘以页码,页码足够大时就会爆炸。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{
  next page=below,
 }
\begin{document}
\setcounter{page}{30}
\tikzmark{blub}\tikz[remember picture]\draw(pic cs:blub);
\end{document}

相关内容