
タイトルにあるように、 内で何かがクリップされた場合に LaTeX 警告を発行できるかどうかを知りたいですtikzpicture
。 もしできるなら、どうすればこれを実現できるでしょうか?
私の使用例では、図面を作成するための小さなマクロ セットに取り組んでおり、特定の定義済み描画領域の外側に何かを描画した場合に警告が表示されるようにしたいと考えています。領域外のものが描画されないように、図面でクリッピングを使用しています。これにより、ページ レイアウトが乱れるのを防ぎますが、ユーザーには、実際にページに配置されていないものがあること (出力を手動で検査する以外) はわかりません。私の特定の使用例では、ユーザーに事前に通知できれば便利です。
理想的には、この警告は、環境またはクリップ自体clip warn
にスタイル ( など) を配置することによって有効になります。scope
\path
出発点およびテスト目的のための MWE を次に示します。
\documentclass{article}
\usepackage{tikz}
\tikzset{x=1em,y=1em}
\tikzset{
clip warn/.style = {
% insert magic code here
},
}
\begin{document}
This diagram should not produce a warning:
\tikz{\path[clip] (0,0) rectangle (1,1); \draw (0.25,0.25) -- (0.75,0.75)}
This diagram should produce a warning:
\tikz{\path[clip] (0,0) rectangle (1,1); \draw (-0.25,0.25) -- (0.25,0.75)}
\end{document}
答え1
リビジョンこれは、境界ボックスとの交差を計算し、交差がある場合は警告を発するスニペットです。(明らかに、境界ボックスの外側に完全にパスがある場合は、警告は発せられません。) このバージョンでは、\IssueWarnings
画像の最後に配置する必要がありますが、失敗する理由がわかりませんexecute at end picture={\IssueWarning}
。これに関する情報があれば、ぜひお知らせください。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\tikzset{x=1em,y=1em}
\newcounter{Paths}
\makeatletter% from https://tex.stackexchange.com/a/5354/121799
\tikzset{nomorepostaction/.code=\let\tikz@postactions\pgfutil@empty
\stepcounter{Paths}}
\newcommand\CheckIfPathExists[1]{
\pgfutil@ifundefined{tikz@intersect@path@name@#1}{\global\def\myPathExists{0}}{\global\def\myPathExists{1}}
}
\makeatother
\newcommand{\IssueWarnings}{\CheckIfPathExists{clip}
\ifnum\myPathExists=1
\xdef\CurrentPaths{\thePaths}
\foreach \i in {2,...,\CurrentPaths}
{\fill [name intersections={of=clip and path\i, name=i, total=\t}]
%[red, opacity=0.5, every node/.style={above left, black, opacity=1}]
\pgfextra{\xdef\Warn{\t}};
}
\ifnum\Warn>0\typeout{Warning: some paths got clipped}\fi
\else
\typeout{clip path not found}
\fi
}
\tikzset{
clip warn/.style = {clip,name path=clip},
every picture/.style={%
execute at begin picture={\setcounter{Paths}{0}},
execute at end picture={%
% \IssueWarnings %<- doesn't work and I dunno why
},
},
every path/.style={postaction={nomorepostaction,draw,
name path=path\thePaths}}}
\begin{document}
This diagram should not produce a warning:
\tikz{\path[clip warn] (0,0) rectangle (1,1);
\draw (0.25,0.25) -- (0.25,0.75);
\IssueWarnings
}
This diagram should produce a warning:%\typeout{checking second picture}
\tikz{\path[clip warn] (0,0) rectangle (1,1);
\draw (-0.25,0.25) -- (0.25,0.75);
\IssueWarnings
}
\end{document}