WeBWorK Main Forum

hardcopy error webworkSetCopyrightFooter

hardcopy error webworkSetCopyrightFooter

by Andras Balogh -
Number of replies: 11

I am trying v. 2.18 as a new installation.

Trying to generate hardcopy of sets results in error message:

Failed to convert TeX to PDF with command 

...

First error in TeX log is:

! LaTeX Error: Can be used only in preamble.

l.277 \webworkSetCopyrightFooter


A hardcopy file does get generated, and it looks fine to me.


In reply to Andras Balogh

Re: hardcopy error webworkSetCopyrightFooter

by Alex Jordan -

Is the latex version is recent? And did you run the webwork2 check_latex script to see if it says anything helpful?



In reply to Alex Jordan

Re: hardcopy error webworkSetCopyrightFooter

by Andras Balogh -

It is a new installation of Ubuntu 20.04.6 LTS with everything new as per distro packages. It provides texlive 2019.

check_latex shows Compilation Success!

I even installed texlive-full.

Downloading the tex file I see that the problem is the fancyhdr package:
! Undefined control sequence.
\webworkSetCopyrightFooter ...ancyhdr}{\fancyfoot 

There seems to be an issue with fancyhdr and texlive 2019 (https://tex.stackexchange.com/questions/654047/fancyhdr-not-working-in-tex-live)

There are no errors when I process the same file on my mac using TeX Live 2023.

In reply to Andras Balogh

Re: hardcopy error webworkSetCopyrightFooter

by Alex Jordan -

If it's not a problem for other reasons, I recommend installing TeXLive 2023. You could install it somewhere other than where the Ubuntu package version lands, and make changes in localOverrides.conf so that WeBWorK uses the 2023 version. You need to set the path for the latex executables, and also for things like dvisvgm that comes with TeXLive.

IIRC, I ran into other issues with TeXLive 2019 (with regular use, not necessarily with WeBWorK).

In reply to Andras Balogh

Re: hardcopy error webworkSetCopyrightFooter

by Glenn Rice -

Your error does not seem to be the same as the error in the stack exchange post that you linked.  Also, that stack exchange error does not seem to be an issue that has been confirmed for texlive 2019.  From the comments on that post, it looks like it is actually something wrong with that user's setup.

I don't think that your issue is with fancyhdr at all from the error that you are seeing.  You are getting "Undefined control sequence", and I suspect it is from the "\webworkSetCopyrightFooter" command it shows.  That is defined in the webwork2/assets/tex/webwork2.sty file.

Could you post a TeX file you get from the zip file generated when the "TeX Source" option is selected?

In reply to Glenn Rice

Re: hardcopy error webworkSetCopyrightFooter

by Andras Balogh -

The webwork hardcopy generator shows the error only at \webworkSetCopyrightFooter, but when I download the TeX source and make webwork2.sty available than the  \fancyfoot in the definition of \webworkSetCopyrightFooter seems to show up as undefined when using the distribution provided texlive 2019.

Installing manually texlive 2023 and changing to it in site.conf did resolve the problem, but installation took much longer than using the package manager. 

Attached is the source file.


In reply to Glenn Rice

Re: hardcopy error webworkSetCopyrightFooter

by Malcolm Harper -

I had a similar error in similar circumstances, using Ubuntu 20.04.6 LTS, after upgrading to 2.18, check_modules.pl and check_latex were both fine, but there were errors of the form

! LaTeX Error: Can be used only in preamble.

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

l.524 \webworkSetCopyrightFooter

Your command was ignored.
...

I am posting what I found as the cause of the error.

I eventually tracked down the source of the error, and Glenn is correct. In the (new to WW 2.18) webwork2.sty LaTeX package, the command \webworkSetCopyrightFooter is defined. This command is invoked at the end of the hardcopy.tex document. The definition of \webworkSetCopyrightFooter uses the LaTeX commands \@ifpackageloaded{...}{...} and @ifclassloaded{...}{...} to set the copyright footer according to the class and package commands available in hardcopy.tex.

Some versions of LaTeX throw an error when \@ifpackageloaded or @ifclassloaded is used in the body of a LaTeX document. Indeed, the documentation will tell you that \@ifpackageloaded should only be used in class or style files, or in the document preamble (using \makeatletter and \makeatother), but never after the \begin{document} statement in a LaTeX document. This is the source of the error. When \webworkSetCopyrightFooter is invoked and uses \@ifpackageloaded in the body of the LaTeX document.

This LaTeX behaviour changed in 2021. With the release of LaTeX 2021-11-15, the @\if(something)loaded commands work in a latex document without issue (see LaTeX2e News Issue 34, Tests for package and class loading on page 4 and, in particular, footnote 2).

This explains why Andras' solution works. To avoid this error, update LaTeX to a version 2021-11-15 or later.

It is also possible to patch the definition of \webworkSetCopyrightFooter to work in older versions of LaTeX.

The following definition of \webworkSetCopyrightFooter works in older and newer versions of LaTeX:

%%%%%%%%%%
% A definition of \webworkSetCopyrightFooter
% that works in old and new latexs
% 2024-08-22
%%%%%%%%%%

% Define the footer components

\newcommand{\webworkSetCopyrightFooterLeft}{%
\raisebox{-0.325cm}{\includegraphics[width=3cm]{webwork_logo.png}}%
}
\newcommand{\webworkSetCopyrightFooterCenter}{%
\small\sffamily Generated by WeBWorK, \copyright~The~WeBWorK~Project.%
}
\newcommand{\webworkSetCopyrightFooterRight}{%
%\url{openwebwork.org}%
\href{https:\\openwebwork.org}{openwebwork.org}
}


% Define the macro that declares the copyright
% A format using fancyhdr
% A format for the exam class
% Empty otherwise

\AtBeginDocument{%
\newcommand{\webworkSetCopyrightFooter}{\relax}
\makeatletter%
\@ifpackageloaded{fancyhdr}{%
\@ifpackageloaded{tcolorbox}{%
\renewcommand{\webworkSetCopyrightFooter}{%
\fancyfoot[L]{\webworkSetCopyrightFooterLeft}%
\fancyfoot[C]{\webworkSetCopyrightFooterCenter}%
\fancyfoot[R]{\webworkSetCopyrightFooterRight}%
\pagestyle{fancy}%
}%
}%
{%
\renewcommand{\webworkSetCopyrightFooter}{%
\fancyfoot[L]{\webworkSetCopyrightFooterLeft}%
\fancyfoot[C]{\webworkSetCopyrightFooterCenter}%
\fancyfoot[R]{\webworkSetCopyrightFooterRight}%
\pagestyle{fancy}%
\clearpage%
}%
}%
{}%
}%

\@ifclassloaded{exam}%
{%
\renewcommand{\webworkSetCopyrightFooter}{%
\footer%
{\webworkSetCopyrightFooterLeft}%
{\webworkSetCopyrightFooterCenter}%
{\webworkSetCopyrightFooterRight}%
\clearpage
}%
}%
{}%
\makeatother%
}
In reply to Malcolm Harper

Re: hardcopy error webworkSetCopyrightFooter

by Alex Jordan -
Thanks for this! I will look closely at it when I have some time, and perhaps the change to the macro definition is appropriate for a hotfix to version 2.19.
In reply to Malcolm Harper

Re: hardcopy error webworkSetCopyrightFooter

by Alex Jordan -

I tried this and it works, as far as with the version of texlive that I have. I'm not able to test on a version of LaTeX prior to that critical version you indicated.

I could open a pull request with your work, but are you interested in doing that yourself and be a contributor to webwork2? Are you familiar with what is needed to open a pull request on GitHub?  The file to edit is:

https://github.com/openwebwork/webwork2/blob/main/assets/tex/webwork2.sty

starting at line 88. If you would prefer, I'm happy to do this. If it's OK with you I would attribute the commit to you.

In reply to Alex Jordan

Re: hardcopy error webworkSetCopyrightFooter

by Malcolm Harper -
Hi Alex, It would be fun to be a contributor to webwork! I'm pretty familiar with GitHub, I will open a pull request then.
In reply to Alex Jordan

Re: hardcopy error webworkSetCopyrightFooter

by Malcolm Harper -
Hi Alex, I am ready to submit the pull request. Which branch (main, develop, ...) should I submit it to? Thanks.
In reply to Malcolm Harper

Re: hardcopy error webworkSetCopyrightFooter

by Glenn Rice -

Since this will probably be a hotfix, you can use the "main" branch.  Any hotfix pull request also needs a paired pull request to develop, but I (or one of the other developers) can take care of opening a paired pull request to the develop branch.