1

I'm currently having issues using xwatermark and the clip and trim={} options of \includegraphics for graphics that are completely unrelated to the watermark produced by xwatermark. Here's a MWE that illustrates the problem:

\documentclass[letterpaper,10pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{newtxtext}
\usepackage{newtxmath}
\usepackage[usenames,dvipsnames,svgnames,table,hyperref]{xcolor}
\usepackage{graphicx}
\usepackage[extendedchars,encoding,filenameencoding=utf-8]{grffile}
\usepackage{float}
\usepackage[letterpaper,left=0.5in,right=0.5in,top=0.75in,bottom=0.75in]{geometry}
\usepackage{fancyhdr}
\usepackage{varioref}
\usepackage[unicode,bookmarks,raiselinks,pageanchor,hyperindex,colorlinks]{hyperref}
\usepackage{cleveref}
\usepackage[all]{hypcap}

% The problem package
\usepackage[printwatermark]{xwatermark}

\begin{document}

    CTAN lion draw­ing by Duane Bibby.

    % This works with \usepackage[printwatermark]{xwatermark}
    \begin{figure}[H]
        \centering
        \includegraphics[width=10cm,height=10cm,keepaspectratio]{ctan-lion.png}
    \end{figure}

    % This doesn't work with \usepackage[printwatermark]{xwatermark}
    \begin{figure}[H]
        \centering
        \includegraphics[width=10cm,height=10cm,keepaspectratio,clip,trim={2cm 2cm 2cm 2cm}]{ctan-lion.png}
    \end{figure}

\end{document}

When commenting out \usepackage[printwatermark]{xwatermark} the following correct PDF is produced:Correct PDF

If the document is compiled with \usepackage[printwatermark]{xwatermark} active the following LaTeX errors are reported:

! Paragraph ended before \Gread@parse@vp was complete.<to be read again>\par
! LaTeX Error: \begin{figure} on input line 32 ended by \end{document}.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \end{document}
! You can't use `\end' in internal vertical mode.\enddocument ...cumenthook \deadcycles \z@ \@@end \end{document}
! LaTeX Error: \begin{figure} on input line 32 ended by \end{document}.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \end{document}
! Emergency stop.<> xwatermark-issue.tex (job aborted, no legal \end found)Here is how much of TeX's memory you used:18296 strings out of 492639284815 string characters out of 6133102404018 words of memory out of 1200000021996 multiletter control sequences out of 15000+6000007211 words of font info for 16 fonts, out of 8000000 for 90001141 hyphenation exceptions out of 819153i,6n,58p,860b,638s stack positions out of 5000i,500n,10000p,200000b,80000s! ==> Fatal error occurred, no output PDF file produced!

I've tracked the problem down to the clip and trim={} options of the second \includegraphics in the MWE. If BOTH options are omitted the the document compiles fine when using \usepackage[printwatermark]{xwatermark}. Does anyone have any insight as to why xwatermark is interfering with the options of \includegraphics or how to fix it?

Thank you in advance.

  • I wouldn't use xwatermark. It is a quite intrusive package with known interference to other packages. Your example is a proof: it redefines an internal graphics command and so breaks the normal key handling. – Ulrike Fischer Nov 19 '18 at 22:55
1

Change the order of the \includegraphics options: clip after trim (with no braces).

\includegraphics[width=10cm,height=10cm,keepaspectratio,trim=2cm 2cm 2cm 2cm,clip]{example-image-a}
  • I've confirmed that your suggestion solved my problem. Thank you for the help! – jgriggs Nov 19 '18 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.