0

I was hoping to find a command in etoolbox that would help resolve this type of error. Is there one?

EDIT on 10/14. What I'm looking for is: when two packages' define the same command, resulting in an error, to be able to prevent the error. I was thinking a patch that wraps around the command, in either package, an ifdef and changes the implementation accordingly. Surely this can be done with etoolbox.

\documentclass{report}
\usepackage{lastpage}
\usepackage{lipsum}
\usepackage{xwatermark}
\usepackage{hyperref}

\usepackage{titleps}%--------------------------------------------------
\newpagestyle{special}
{
  \setfoot{}
  {\thepage/\pageref{LastPage}}
  {}
}
\pagestyle{special}

\begin{document}

\chapter{Intro}

\lipsum[1]

\end{document}

ERROR: LaTeX Error: Command \headrule already defined.

--- TeX said --- Or name \end... illegal, see p.192 of the manual.

See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ...

                                               l.308 \newcommand\headrule{\setheadrule{.4\p@}}

--- HELP --- No help available

xwatermark.sty:

\ifpgn@showheadrule
    \def\headrule{{%
      \color{\pgn@headrulecolor}%
      \hrule\@height\pgn@headruleheight\@depth\pgn@headruledepth
        \@width\headwidth\vspace{\pgn@headrulesep}%
      \hrule\@height\pgn@headruleheight\@depth\pgn@headruledepth
        \@width\headwidth\vspace{-\pgn@headrulesep}%
    }}%
  \else
    \let\headrule\relax
  \fi
Erwann
  • 2,100

2 Answers2

0

The issue with the already defined \headrule comes from the titleps package. In fact, you don't have to use it to put your watermark on the last page (a feature that you need if I understand well your code).

I had however another issue: I had to load the xcolor package, before xwatermark, otherwise I had a compilation error.

Here is the complete MWE, with a few options for the \newwatermark command for demonstration:

\documentclass{report}

\usepackage{lipsum}
\usepackage{xcolor}
\usepackage[printwatermark=true]{xwatermark}
\usepackage{hyperref}

% Watermarks
\newwatermark[lastpage,color=gray!25,xpos=0,ypos=0,angle=45]{My Watermark}

\begin{document}

    \chapter{Intro}

    \lipsum[1-6]

\end{document}
  • This answer considers that you want to use the xwatermark to write some text on your last page. If however you really need both xwatermark and titleps packages it is not what you are looking for. – Alexandre Quenon Oct 14 '19 at 07:03
0

I modified the code such that titleps and xwatermark are effectively, not just hypothetically, used together.

\documentclass{report}
\usepackage{lastpage}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage[printwatermark]{xwatermark}
\let\headrule=\undefined % solution<-----------
\let\footrule=\undefined % ------------------->

\usepackage{titleps}%--------------------------
\newpagestyle{special}
{
  \setfoot{}
  {\thepage/\pageref{LastPage}}
  {}
}
\pagestyle{special}

%   https://tex.stackexchange.com/questions/36880/insert-a-blank-page-after-current-page#36881
\def\blankpage{%
  \clearpage%
  \null%
  \clearpage}

\newwatermark[
pages={2},
fontfamily=bch,
color=gray!25,
angle=45,
scale=3,
xpos=0,
ypos=15
]{WATERMARK}

\begin{document}

\chapter{Intro}

\lipsum[1]

\blankpage

\end{document}

Show

Erwann
  • 2,100