如果在环境中,带有跨页面边界的 tikzmark 的 Tikz 图片将不会打印

如果在环境中,带有跨页面边界的 tikzmark 的 Tikz 图片将不会打印

合并用 s绘制括号的解决方案tikzmark使它们跨越页面边界,给我带来了一个有趣的问题:如果tikzmark位于环境中,它不会在第一页上打印垂直部分。
编辑:我正在使用来自最新更新到包含宏的 tikzmark 包\iftikzmarkoncurrentpage,我也在下面添加了它。

% !TEX TS-program = xelatexmk
\documentclass{article}
\usepackage[paperwidth=3in,paperheight=1in]{geometry}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark}
\newcounter{tikzmarklines}\setcounter{tikzmarklines}{0} % 

% The following code provides the iftikzmarkoncurrentpage macro
\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}%
  \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}%
  \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}%
  }

\begin{document} 
% This works fine:
Text \linestart text text
\newpage
Text text \linefinish text

% But not this
\begin{center} Text \linestart text text \end {center}
\newpage 
\begin{center} Text text \linefinish text \end {center}
\end{document}

第二页上只印有小钩子,而没有印到第三页的垂直线。

在此处输入图片描述

有任何想法吗?

答案1

您需要使 if 成为全局的:\global\firstmarktrue并且,正如您所指出的,\global\firstmarkfalse

% !TEX TS-program = xelatexmk
\documentclass{article}
\usepackage[paperwidth=3in,paperheight=1in]{geometry}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark}
\newcounter{tikzmarklines}\setcounter{tikzmarklines}{0} % 

% The following code provides the iftikzmarkoncurrentpage macro
\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\number\value{tikzmarklines}}%
  \global\firstmarktrue
  \iftikzmarkoncurrentpage{b\number\value{tikzmarklines}}%
  \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\number\value{tikzmarklines}}{pic cs:b\number\value{tikzmarklines}}];
  \end{tikzpicture}%
  \fi
}

\newcommand{\linefinish}{%
  \iffirstmark
  \tikzmark{b\number\value{tikzmarklines}}%
  \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\number\value{tikzmarklines}}{0,0}];
  \end{tikzpicture}%
  }

\begin{document} 
% But not this
\begin{center} Text \linestart text text \end{center}
\newpage 
\begin{center} Text text \linefinish text \end{center}


% This works fine:
Text \linestart text text
\newpage
Text text \linefinish text

\end{document}

在此处输入图片描述

相关内容