# Short question

After a \clip and a \pgfresetboundingbox, the bounding box is permanently (0,0)rectangle(0,0). How can I turn on the bounding-box calculation and obtain a fairly small bounding box?

# The story

The example below

\documentclass{article}
\usepackage{tikz}
\begin{document}

\tikz{
\clip circle(10);
\pgfresetboundingbox
\fill circle(10);
%   \useasboundingbox(-10,-10)(10,10); % makes no difference
}

\end{document}


results in

where the rectangle is the US-letter paper from article and the center of the circle is approximately the starting point of normal documents. This shows that \pgfresetboundingbox resets the bounding box, as expected. However, a normal path does not repair it. Neither does an explicit \useasboundingbox.

The question is:

After a \clip and a \pgfresetboundingbox,
How can I turn on the calculation of bounding box?

Recall that in everyday usage, the code with \pgfresetboundingbox will always give a smaller or equal bounding box than that without \pgfresetboundingbox. In the case above, it does give me a smaller bounding box. (just too small)

Therefore I expect that if somehow we can turn the calculation on, it should not give a bounding box that is larger than that without \pgfresetboundingbox.

In other words,

After a \clip and a \pgfresetboundingbox,
How can I turn on the calculation of bounding box
such that it is the smallest but contains everything visible?

\tikz{
\clip(5,0)--(-4,-4)--(0,5)--cycle;
\pgfresetboundingbox
\fill(-5,0)--(4,4)--(0,-5)--cycle;
}


should give me

where the hidden parts are

# Possible application

The following code generate bad right border. (beacuse of the control point)

\tikz{
\fill(0,-1)..controls(10,0)..(0,1);
}


It would be good if we can apply some clipping only on right border.

% Caution! imaginary code
\tikz[clip right at x=7]{
\fill(0,-1)..controls(10,0)..(0,1);
}


which is implemented by inserting

    \clip(-\maxdimen,-\maxdimen)rectangle(7,\maxdimen);
\pgfresetboundingbox


# Remark

If two clippings are issued consecutively, the bounding box should be even smaller.

• That doesn't look like the actual outcome of your code. – percusse Feb 2 '16 at 13:48
• What is the relation between the first and the second figure you posted? – Alenanno Feb 2 '16 at 14:03
• @Alenanno Second one is the desired usecase of the question. First one is the test MWE – percusse Feb 2 '16 at 14:15
• @percusse I finishing updating packages and the first figure is the exact output. I am now editing my question to make it more friendly. – Symbol 1 Feb 2 '16 at 14:33

I see you have added some details to your question, but I had already done the first part, so I'll post it. I can see that I might have to change something for you to "reuse" the clipping, at first the question seemed to imply it was a one-time thing.

Showing shapes

Hidden

## Code

\documentclass{standalone}
\usepackage{tikz}

\usetikzlibrary{shapes.geometric}

\begin{document}
\tikz{
\useasboundingbox(-10,-10)(10,10);
\node[
anchor=east, %fill=yellow,
minimum height=25cm, minimum width=5cm,
isosceles triangle, rotate=45,
] (trifill) at (current bounding box.north east) {};
\node[
anchor=east, %draw, dashed,
minimum height=25cm, minimum width=5cm,
isosceles triangle, rotate=225
] (tridashed) at (current bounding box.south west) {};

\begin{scope}
\clip (trifill.apex) foreach \i in {left corner, right corner} {--(trifill.\i)} --cycle;
\clip (tridashed.apex) foreach \i in {left corner, right corner} {--(tridashed.\i)} --cycle;
\fill[black] (current bounding box.south west) rectangle (current bounding box.north east);
\end{scope}
}
\end{document}

• That is a good idea to achieve \fill by a second \clip. But sadly this does not apply to \draw. Thanks anyway. – Symbol 1 Feb 2 '16 at 15:39
• @Symbol1 Mmh not sure what you're referring to. As in using \draw instead of \fill? – Alenanno Feb 2 '16 at 15:42
• Yes: what if I replace \fill(-5,0)--(4,4)--(0,-5)--cycle; by \draw(-5,0)--(4,4)--(0,-5)--cycle; – Symbol 1 Feb 2 '16 at 15:48