2

I'm used to compile my .tex files with this command:

pdflatex '\AtBeginDocument{\newlength\DX \DX=3cm \paperwidth=\dimexpr\paperwidth-\DX\relax \hoffset=\dimexpr\hoffset-.5\DX\relax \newlength\DY \DY=3cm \paperheight=\dimexpr\paperheight-\DY\relax \voffset=\dimexpr\voffset-.1\DY-.5\footskip\relax \RequirePackage{xcolor}} \nonstopmode\input{test.tex}'

I'll write it here in a more readeable way:

pdflatex '\AtBeginDocument{\newlength\DX
          \DX=3cm \paperwidth=\dimexpr\paperwidth-\DX\relax
          \hoffset=\dimexpr\hoffset-.5\DX\relax
          \newlength\DY \DY=3cm
          \paperheight=\dimexpr\paperheight-\DY\relax
          \voffset=\dimexpr\voffset-.1\DY-.5\footskip\relax \RequirePackage{xcolor}}
          \nonstopmode\input{test.tex}'

See Trim margins of the entire document (by command line)

But after the last update to the October release of TeX Live 2020 it doesn't work anymore.

This is a MWE. My file contains:

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

\begin{document}

\blindtext \blindtext \blindtext\footnote{\blindtext}

\end{document}

enter image description here

I want an output as if it were:

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{blindtext}
\usepackage{jheppub}
\usepackage[pass]{geometry}
\newlength\DX \DX=3cm
\paperwidth=\dimexpr\paperwidth-\DX\relax
\hoffset=\dimexpr\hoffset-.5\DX\relax
\newlength\DY \DY=3cm
\paperheight=\dimexpr\paperheight-\DY\relax
\voffset=\dimexpr\voffset-.1\DY-.5\footskip\relax

\begin{document}

\blindtext \blindtext \blindtext\footnote{\blindtext}

\end{document}

enter image description here

but I don't want to change my .tex file. I need to do it by command line.

Now, after TeX Live 2020 update, I get:

enter image description here

where the trimmed margins are wrong. I think that the probles is caused by something in the jheppub.sty file.

You can find the jheppub.sty file here: https://jhep.sissa.it/jhep/help/JHEP/TeXclass/DOCS/jheppub.sty

Gabriele
  • 1,815
  • I get the same output with TeX Live 2015, 2018, 2019, and 2020. None look like your desired output... – Phelype Oleinik Feb 16 '21 at 21:07
  • Ok, ok. I have also \RequirePackage{xcolor} after \relax because of other things I do. I updated my question. – Gabriele Feb 16 '21 at 21:11
  • Hm... Strange. With xcolor there I also get the same output with those four versions (which is what I expected), but the output now looks like the output you want (including with TeX Live 2020). What I find odd is the presence of xcolor changing the margins... – Phelype Oleinik Feb 16 '21 at 21:16
  • Indeed I need a working solution without xcolor. – Gabriele Feb 16 '21 at 21:18
  • So your problem is not at all related to updating, but to the inclusion or not of xcolor – Phelype Oleinik Feb 16 '21 at 21:20
  • Sorry, I finally found what cause the error. Is something in the package jheppub that I usually use in my editing work. But the different behaviour was introduced by the update. I need to heavily update my question. – Gabriele Feb 16 '21 at 21:27
  • @PhelypeOleinik I update my question with a real MWE. – Gabriele Feb 16 '21 at 21:38

1 Answers1

5

With the new LaTeX \AtBeginDocument commands from the user ("top-level") are executed last, after all other \AtBeginDocument.

This means that if you change the page layout there, you are reponsable to set all relevant values. No code in graphicx or color or geometry will do it for you.

In your case you are missing to set the pdf page values:

\pdfpageheight=\paperheight \pdfpagewidth=\paperwidth

An alternative is to use an earlier hook:

  \AddToHook{begindocument/before}{<your code>}
Ulrike Fischer
  • 327,261
  • Thanks. Is there a solution that works with both the new LaTeX and the previous releases? I need to do it by command line, without changing my .tex file. I tried to set the \pdfpage stuff into \AtBeginDocument but it doesn't work. – Gabriele Feb 16 '21 at 22:31
  • adding \pdfpageheight=\paperheight \pdfpagewidth=\paperwidth to your command should work with both (assuming that you use pdflatex). – Ulrike Fischer Feb 16 '21 at 22:34
  • You're right! It works! Many thanks! – Gabriele Feb 16 '21 at 22:48