Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra blank page with standalone class #724

Closed
aminophen opened this issue Jul 29, 2019 · 14 comments
Closed

Extra blank page with standalone class #724

aminophen opened this issue Jul 29, 2019 · 14 comments

Comments

@aminophen
Copy link
Contributor

Sorry if reported elsewhere.

By running latex and dvipdfmx, the following MWE produces 2 pages in recent versions of pgf (v3.1.2 -- v3.1.4a current). The second page is blank.

% Package: pgfrcs 2019/02/02 v3.1.1 (3.1.1)
% Package: pgfrcs 2019/07/17 v3.1.4a (3.1.4a)
\documentclass[dvipdfmx]{standalone}
\usepackage{tikz}
\begin{document}
a
\end{document}

In TL2018 frozen (v3.1.1), it produced only 1 page.

@hmenke hmenke added the xetex label Jul 30, 2019
@hmenke
Copy link
Member

hmenke commented Aug 3, 2019

Bisected to fbfabbd

I would argue that the problem is in standalone rather than tikz because if I replace the documentclass with article it works fine. Here is a MWE without TikZ.

\documentclass{standalone}
\AtBeginDocument{\AtEndDocument{\clearpage}}
\begin{document}
a
\end{document}

@tattsan
Copy link

tattsan commented Aug 4, 2019

standalone.cls has an option 'tikz':

\documentclass[dvipdfmx,tikz]{standalone}
% \usepackage{tikz}
\begin{document}
a
\end{document}

and this produces no blank page.

@aminophen
Copy link
Contributor Author

aminophen commented Aug 4, 2019

\documentclass[dvipdfmx,tikz]{standalone}

Yes, that produces no blank page, but the page is not cropped to the size of 'a'; it results in A4 paper. This behavior is not expected at all...

@aminophen
Copy link
Contributor Author

I would argue that the problem is in standalone rather than tikz
because if I replace the documentclass with article it works fine.
\AtBeginDocument{\AtEndDocument{\clearpage}}

@hmenke I agree with you, thanks.

@tattsan
Copy link

tattsan commented Aug 4, 2019

but the page is not cropped to the size of 'a'

I see.

To use with dvipdfmx, I added the following line in the definition of \sa@placebox (defined in standalone.cls).

 \def\sa@placebox{%
    \newpage
    \global\pdfpagewidth=\wd\sa@box
    \global\pdfpageheight=\ht\sa@box
    \global\paperwidth=\wd\sa@box
    \global\paperheight=\ht\sa@box
    \global\hsize=\wd\sa@box
    \global\vsize=\ht\sa@box
    \global\@colht=\ht\sa@box
    \global\@colroom=\ht\sa@box
    \special{papersize=\the\pdfpagewidth,\the\pdfpageheight}%%%%%  This line.
    \noindent\usebox\sa@box
    \newpage
  }%

This also produce no blank page, and the page is cropped.

@hmenke
Copy link
Member

hmenke commented Aug 4, 2019

I'm closing this for now, because the issue seems to be in standalone.

@hmenke hmenke closed this as completed Aug 6, 2019
@hmenke hmenke added this to the 3.1.5 milestone Nov 3, 2019
@hmenke hmenke removed this from the 3.1.5 milestone Nov 29, 2019
@u-fischer
Copy link
Contributor

This topic just came up again: https://tex.stackexchange.com/questions/610206/standalone-creates-extra-empty-page-mwe

The empty page is triggered by the \clearpage inserted by pgf in pgfutil-latex.def

\AtBeginDocument{\AtEndDocument{\clearpage\the\pgfutil@everybye}}

As far as I can see only the driver files pgfsys-pdftex.def and pgfsys-luatex.def add something to the toks register \pgfutil@everybye. So there should be no need to issue the \clearpage in dvi mode at all. I also think (but I didn't test) that one can use in a current latex the shipout/lastpage hook for this instead of enddocument.

@hmenke
Copy link
Member

hmenke commented Aug 11, 2021

As already noted earlier in this thread, standalone is broken. See #724 (comment) for MWE.

@u-fischer
Copy link
Contributor

I know that the \clearpage has only an ill effect in standalone. I did read the thread.

But it is not clear if it is a bug. Creating single pages from content is not an easy task, and it is quite possible that standalone can't avoid the bad side effect from \clearpage in dvi mode without breaking something else.

It remains the fact that pgf issues an in dvi mode unneeded \clearpage. And imho it makes more sense here to ask pgf to not add it in the first place or to use another hook than asking standalone to remove it again with \RemoveFromHook.

@hmenke
Copy link
Member

hmenke commented Aug 11, 2021

But it is not clear if it is a bug.

How is that not a bug? Using \clearpage in standalone is completely broken.

Creating single pages from content is not an easy task

Maybe it is but it's beyond the scope of PGF and therefore not my problem.

@davidcarlisle
Copy link
Member

but the \clearpage is not issued by standalone but by PGF. pgfutil-latex.def having

\AtBeginDocument{\AtEndDocument{\clearpage\the\pgfutil@everybye}}

so if any document for any reason puts any kind of box into \AtEndDocument after this, it comes after the clearpage and an extra page will be generated.

@hmenke
Copy link
Member

hmenke commented Aug 11, 2021

As I said, not my problem. However, you're welcome to open a PR with a *forward- and backward-compatible solution and I'll merge it.

Locking the conversation because that's my final statement.

@pgf-tikz pgf-tikz locked as resolved and limited conversation to collaborators Aug 11, 2021
@muzimuzhi
Copy link
Member

This seems to work, at the cost of a new dependency atveryend for latex prior to 2020-10-01.

BTW, it seems standalone's repo has moved from bitbucket to sourceforge (https://sourceforge.net/projects/standalone/), but the bitbucket issues were lost.

diff --git a/tex/generic/pgf/utilities/pgfutil-latex.def b/tex/generic/pgf/utilities/pgfutil-latex.def
index 07a7fb1a..7574895a 100644
--- a/tex/generic/pgf/utilities/pgfutil-latex.def
+++ b/tex/generic/pgf/utilities/pgfutil-latex.def
@@ -90,11 +90,17 @@
 
 \def\pgfutil@check@rerun#1#2{\@newl@bel{pgf@lab}{#1}{#2}}
 
-\AtBeginDocument{\AtEndDocument{\clearpage\the\pgfutil@everybye}}
-
 % \@ifl@t@r is defined \@onlypremable so we have to save it here
 \let\pgfutil@ifl@t@r=\@ifl@t@r
 
+% ensure \pgfutil@everybye is used after the \clearpage inside \enddocument
+\pgfutil@ifl@t@r\fmtversion{2020/10/01}{
+  \AtBeginDocument{\AddToHook{enddocument/afterlastpage}{\the\pgfutil@everybye}}
+}{
+  \usepackage{atveryend}
+  \AtBeginDocument{\AfterLastShipout{\the\pgfutil@everybye}}
+}
+
 \def\pgfutil@insertatbegincurrentpagefrombox#1{%
   \edef\pgf@temp{\the\wd\pgfutil@abb}%
   \global\setbox\pgfutil@abb\hbox{%

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

6 participants