1

I have this MWE:

\documentclass[11pt]{article}
\usepackage{amsmath}

\RequirePackage[colorlinks=true
  ,urlcolor=blue
  ,anchorcolor=blue
  ,citecolor=blue
  ,filecolor=blue
  ,linkcolor=blue
  ,menucolor=blue
  ,linktocpage=true
  ,pdfproducer=medialab
  ,pdfa=true
]{hyperref}

\usepackage[poorman,capitalize,english]{cleveref}

\pagestyle{empty}
\begin{document}

\section{First section\label{sec:01}}
Text \cref{eq:01} in \cref{sec:01}:
\begin{equation}
\label{eq:01}
x+y=z
\end{equation}

\end{document}

When I run pdflatex MWE.tex I get the MWE.sed file, but if I run:

sed -f MWE.sed MWE.tex > unclevereffedMWE.tex

I get:

\documentclass[11pt]{article}
\usepackage{amsmath}

\RequirePackage[colorlinks=true
  ,urlcolor=blue
  ,anchorcolor=blue
  ,citecolor=blue
  ,filecolor=blue
  ,linkcolor=blue
  ,menucolor=blue
  ,linktocpage=true
  ,pdfproducer=medialab
  ,pdfa=true
]{hyperref}

\pagestyle{empty}
\begin{document}

\section{First section\label{sec:01}}
Text \cref{eq:01} in \cref{sec:01}:
\begin{equation}
\label{eq:01}
x+y=z
\end{equation}

\end{document}

If I remove the hyperref package it works. Now, I'm trying to "force" the generation of a working .sed file without removing the hyperref package. I tried:

\documentclass[11pt]{article}
\usepackage{amsmath}

\makeatletter
\@namedef{[email protected]}{} 
\makeatother

\RequirePackage[colorlinks=true
  ,urlcolor=blue
  ,anchorcolor=blue
  ,citecolor=blue
  ,filecolor=blue
  ,linkcolor=blue
  ,menucolor=blue
  ,linktocpage=true
  ,pdfproducer=medialab
  ,pdfa=true
]{hyperref}

\usepackage[poorman,capitalize,english]{cleveref}

\pagestyle{empty}
\begin{document}

\section{First section\label{sec:01}}
Text \cref{eq:01} in \cref{sec:01}:
\begin{equation}
\label{eq:01}
x+y=z
\end{equation}

\end{document}

but it doesn't work. I think I need to fool the option:

\@ifpackageloaded{hyperref}

in cleveref.sty. Is it possible? Am I doing it all wrong.

Note. Please keep in mind that my final goal is to "force" the generation of the .sed file "without" modifying the original MWE.tex file.

My goal is to pass external redefinitions/options to the pdflatex engine. Something like:

pdflatex "\AtBeginDocument{OPTIONS} \input{MWE.tex}"

I don't care of warnings or layout at this stage.

5
  • I have no idea why cleveref didn't write that so that it works with hyperref. You probably will have to disable loading it with \makeatletter \disable@package@load{hyperref}{}\makeatother, this naturally assumes that you don't use commands from hyperref somewhere in your document. Nov 28, 2023 at 14:33
  • From what I can tell, the poorman option does not work at all. Processing the original file through the sed script that is generated will do things like replace \crefmiddleconjunction with a comma, \cref@line@name with "Line"; and so on. The problem is, none of the expressions it replaces is a user-level command, so effectively the only thing it does is remove the \usepackage[options]{cleveref} line, and that breaks everything (hyperref or otherwise). If I replace \cref with \ref it works, but all of the things cleverref puts in there (e.g., "Figure" or "Equation") are absent.
    – karlh
    Nov 28, 2023 at 15:22
  • @UlrikeFischer I didn't know about \disable@package@load{hyperref}{}. Is it a new feature? It works. I will use it with \let\href\empty\let\url\empty\let\texorpdfstring\empty to generate the .sed file. Nov 28, 2023 at 15:30
  • I stand corrected: the first two lines of the sed script do in fact replace \cref{eq:01} and \cref{sec:01} (which cleveref uses internally to set off equations and sections/subsections/etc.). I think I figured out a workaround that I can post as an answer.
    – karlh
    Nov 28, 2023 at 15:31
  • @karlh I don't want to use the .sed file really. I need it to prepare an emacs-lisp query-replace function. For my purposes poorman works. Nov 28, 2023 at 15:33

2 Answers 2

1

Let's take my MWE where I removed the poorman option from the cleveref package's options:

\documentclass[11pt]{article}
\usepackage{amsmath}

\RequirePackage[colorlinks=true
  ,urlcolor=blue
  ,anchorcolor=blue
  ,citecolor=blue
  ,filecolor=blue
  ,linkcolor=blue
  ,menucolor=blue
  ,linktocpage=true
  ,pdfproducer=medialab
  ,pdfa=true
]{hyperref}

\usepackage[capitalize,english]{cleveref}

\pagestyle{empty}
\begin{document}

\section{First section\label{sec:01}}
Text \cref{eq:01} in \cref{sec:01}:
\begin{equation}
\label{eq:01}
x+y=z
\end{equation}

\end{document}

I can generate the MWE.sed file with this command:

latexmk -pdf -usepretex='\PassOptionsToPackage{poorman}{cleveref}\makeatletter\disable@package@load{hyperref}{}\makeatother' -pdflatex='touch %D; pdflatex -draftmode  %O %P' MWE.tex

I use:

latexmk -pdf

to call pdflatex and compile the file the correct number of times.

-usepretex='\PassOptionsToPackage{poorman}{cleveref}

to pass the poorman option to the cleveref package.

\makeatletter\disable@package@load{hyperref}{}\makeatother'

to disable the hyperref package, as suggested by Ulrike Fischer.

-pdflatex='touch %D; pdflatex -draftmode  %O %P' MWE.tex

to avoid to generate the MWE.pdf file.

Now I can use:

sed -f MWE.sed MWE.tex > unclevereffedMWE.tex

In my real cases I will use this command:

latexmk -pdf -usepretex='\PassOptionsToPackage{poorman}{cleveref} \makeatletter\disable@package@load{hyperref}{}\makeatother \let\href\empty\let\url\empty\let\texorpdfstring\empty' -pdflatex='touch %D; pdflatex -draftmode  %O %P' -output-directory=/tmp -jobname=uncleveref MWE.tex

adding:

\let\href\empty\let\url\empty\let\texorpdfstring\empty

and the options:

-output-directory=/tmp -jobname=uncleveref

to generate the file /tmp/uncleveref.sed.

I will use the uncleveref.sed file to prepare an Emacs interactive function to perform the replacements.

0

The clash is because hyperref writes things to the .aux file that cleveref is not expecting. The following seems to work around the problem:

\documentclass[11pt]{article}
\usepackage{amsmath}

%\usepackage[colorlinks=true
%  ,urlcolor=blue
%  ,anchorcolor=blue
%  ,citecolor=blue
%  ,filecolor=blue
%  ,linkcolor=blue
%  ,menucolor=blue
%  ,linktocpage=true
%  ,pdfproducer=medialab
%  ,pdfa=true
%]{hyperref}

\usepackage[poorman,capitalize,english]{cleveref}

\pagestyle{empty}
\begin{document}

\section{First section\label{sec:01}}
Text \cref{eq:01} in \cref{sec:01}:
\begin{equation}
\label{eq:01}
x+y=z
\end{equation}

\end{document}

Now run sed:

sed -f MWE.sed MWE.tex > MWE_unclever.tex

Now edit the "unclever" file and uncomment the hyperref parts, and it should work fine.

1
  • I already knew that commenting hyperref was a solution. But I don't want to modify the MWE.tex file. This is precisely an MWE. In other cases the hyperref package may be called within other packages. This command does the magic: latexmk -pdf -usepretex='\makeatletter\disable@package@load{hyperref}{}\makeatother' -pdflatex='touch %D; pdflatex -draftmode %O %P' MWE.tex Nov 28, 2023 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .