I use this code (fixed by marmot :) ...), which worked perfectly until a point where my document got too many pages.
At a given point I get a "Dimension too large" error.
It uses code that tests if a given tikzmark is on a page, so my hunch is that the problem lies there somewhere, that too many pages cause trouble... Alas, I have no clue whatsoever how to troubleshoot.
Given the nature of the problem, the following is an "as-minimal-as-it-gets-not-working-example" :)
(If you delete two rows of the \repeatenoughtimes macro you will get it to work ... just to show that the problem has definitely to do with repeating it too often.)
% !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}
\lipsum[1-2]instead of\lipsum[1-5], the error goes away. – Apr 15 '19 at 16:03\repeatenoughtimes, you get the error back :( ... hence my hunch it's the page count ??? ... but honestly I have no idea... – jan Apr 15 '19 at 16:35