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

Possible regression in the fall 2020 LaTeX release - interaction between xwatermark.sty and atbegshi #411

Closed
gamboz opened this issue Oct 14, 2020 · 9 comments

Comments

@gamboz
Copy link

gamboz commented Oct 14, 2020

Brief outline of the bug

Compiling the MWE below gives error with texlive 2020 installed today, but not with texlive 2020 installed around September 29th.

Since the xwatermark.sty file is the same, I think the issue may be related to the hooks in atbegshi / atbegshi-ltx.

For completeness, I do receive a warning about

/usr/local/texlive/2020/texmf-dist/tex/latex/base/atbegshi-ltx.sty

LaTeX Warning: You have requested package `atbegshi',
               but the package provides `atbegshi-ltx'.

(and the same for atveryend).

Minimal example showing the bug

\RequirePackage{latexbug}
\documentclass{article}

\usepackage{xwatermark}

\begin{document}
test
\end{document}

Log and PDF file

Obtained with pdflatex mwe (and type "r" when prompted)

mwe.log
mwe.pdf

@PhelypeOleinik
Copy link
Member

Running your test says:

(latexbug)                This test file uses third-party file(s)
(latexbug)                
(latexbug)                ==============
(latexbug)                xwatermark.sty
(latexbug)                test.xwm
(latexbug)                hyperref.sty  ->  LaTeX Team 
(latexbug)                    https://github.com/latex3/hyperref/issues
(latexbug)                ==============

and indeed catoptions (loaded by xwatermark) does some heavy patches to LaTeX macros, and this broke with the latest LaTeX release. The author of catoptions was notified, but there was no update so far.

You can try to patch over catoptions, but beware that it's a patch on top of another patch, so it's bound to break eventually.

\documentclass{article}

% catoptions patch (no guarantee that will work):
% must be applied before loading catoptions
\def\FIXcatoptions\endgroup#1\begingroup{#1}
\AddToHook{package/after/catoptions}
  {\gleftaddtocs\document{\FIXcatoptions}}

\usepackage{xwatermark}

\begin{document}
test
\end{document}

@FrankMittelbach
Copy link
Member

FrankMittelbach commented Oct 15, 2020

> 
> LaTeX Warning: You have requested package `atbegshi',
>                but the package provides `atbegshi-ltx'.
> ```
> 
> 
> (and the same for atveryend).

that happens because xwatermark changes a lot if internal LaTeX macros through overwriting them or replacing them in a way that was never meant to be supported. It therefore now clobbers parts that handle this kind of warning. If you load these packages before xwatermark then the warnings go away (because at that point they are correctly handled). Of course, that doesn't solve the problem that xwartermark is overwriting internals in an now incompatible way.As @PhelypeOleinik said the author has been informed that his packages will break months back.

@gamboz
Copy link
Author

gamboz commented Oct 15, 2020

Thank you all.
I've also asked the author of xwatermark if he can do something.

AFAICT the issue is not in LaTeX itself, so I'm closing it.

However, do you think it would be possible to "identify" packages not compatible with the current LaTeX macros so that they do not end up in standard distributions (telixve, miktex, etc.)?
I don't know if this is the right place to ask :)

@gamboz gamboz closed this as completed Oct 15, 2020
@PhelypeOleinik
Copy link
Member

Sometimes we can identify, and notify the maintainer (it happens quite often). But there are cases when the maintainer is not responsive for whatever reason, or that we didn't identify the incompatibility (it's TeX, after all, the possibilities for incompatibility are endless :-)

That said, no, we can't do much about those packages as long as they have a maintainer (if they don't, then we can ask CTAN to take over and fix them, which happens often too), let alone take it out of distributions (that would be rather bad, actually). The good option really is for the maintainer to fix the package.

@mrpiggi
Copy link

mrpiggi commented Oct 15, 2020

@gamboz For a feasible workaround and/or an up-to-date solution you might want to get rid of package xwaterwark at all and use scrlayer instead.

https://tex.stackexchange.com/questions/400966/watermark-on-selected-pages-or-xwatermark-and-scrlayer-scrpage

@FrankMittelbach
Copy link
Member

@gamboz For a feasible workaround and/or an up-to-date solution you might want to get rid of package xwaterwark at all and use scrlayer instead.

most likely no package is needed given that LaTeX now has the hooks shipout/background and shipout/foreground which are precisely for adding something onto each or just the next page (using \AddToHookNext). The hooks expect picture commands, ie they span a picture env with the topleft corner of the page being 0,0.

@gamboz
Copy link
Author

gamboz commented Oct 22, 2020

@FrankMittelbach thank you for pointing out the new hooks. It solved my problem in less than 10 lines :)

\documentclass{article}
\usepackage{xcolor}
\usepackage{graphicx}

\newcommand{\watermark}{%
  \fontfamily{ucr}\fontseries{m}\fontsize{40}{1}\selectfont%
  \color{gray}%
  \put(560,-120){%
    \rotatebox{-90}{Some watermark 123}
  }
}

\AddToHook{shipout/background}{\watermark}

\begin{document}
hi
\newpage

pg.2
\end{document}

@FrankMittelbach
Copy link
Member

welcome, and one more advice ... since the fall release 2020 picture coordinates can be dimensions (in which case no \unitlength is used so something like .5\paperheight can be usefully employed

@ysalmon
Copy link

ysalmon commented Nov 3, 2020

You can try to patch over catoptions, but beware that it's a patch on top of another patch, so it's bound to break eventually.

\documentclass{article}

% catoptions patch (no guarantee that will work):
% must be applied before loading catoptions
\def\FIXcatoptions\endgroup#1\begingroup{#1}
\AddToHook{package/after/catoptions}
  {\gleftaddtocs\document{\FIXcatoptions}}

\usepackage{xwatermark}

\begin{document}
test
\end{document}

This fix works great with the recent version of LaTeX but causes problems when compiling with an older version (which alas happens when compiling at work where LaTeX is not updated as frequently). I suggest to protect it with a version check like that TeX.SX answer.

\makeatletter   % if not in a package
\newcommand*\@iflatexlater{\@ifl@t@r\fmtversion}
\@iflatexlater{2020/10/01}{%
\def\FIXcatoptions\endgroup#1\begingroup{#1}
\AddToHook{package/after/catoptions}
  {\gleftaddtocs\document{\FIXcatoptions}}%
}{}
\makeatother   % if not in a package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants