2

I have a file (test.tex) which content is:

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{subcaption}
\pagestyle{empty}
\begin{document}

\begin{figure}

\includegraphics[width=\linewidth]{example-image} \caption{This caption should disappeard...}

\end{figure}

\end{document}

and produces the layout:

enter image description here

Until Tex Live 2019 I used to run the command:

pdflatex "\AtBeginDocument{\def\caption#1{}} \nonstopmode \input{test.tex}"

to obtain a figure without the caption:

enter image description here

But with TeX Live 2020 it doesn't work anymore. The .pdf file produced still contains the caption. It happens when packages like subcaption are called.

Is there a way to obtain the same result with TeX Live 2020?

Gabriele
  • 1,815
  • Works for me with an updated TL 2020... Run the example with pdflatex "\listfiles\DebugHooksOn\AtBeginDocument{\def\caption#1{}} \nonstopmode \input{test.tex}" then upload the log to https://pastebin.com/ (or similar), please – Phelype Oleinik Feb 15 '21 at 22:20
  • @PhelypeOleinik, this is the TeX Live 2020 log: https://pastebin.com/8CABV4vv – Gabriele Feb 15 '21 at 22:33
  • This is the Tex Live 2019 one: https://pastebin.com/26inparP – Gabriele Feb 15 '21 at 22:34
  • @DavidCarlisle, is this a question addressed to me? – Gabriele Feb 15 '21 at 22:37
  • your texlive 2020 format is not up to date (it is showing February not October release) – David Carlisle Feb 15 '21 at 22:38
  • @DavidCarlisle, I simply ran what Phelype Oleinik asked in the first comment. – Gabriele Feb 15 '21 at 22:41
  • @GabrieleNicolardi ah Ok, Phelype was assuming you had an up to date texlive 2020 – David Carlisle Feb 15 '21 at 22:43
  • tlmgr update --self --all should update your texlive (possibly needing sudo depending how it was installed) – David Carlisle Feb 15 '21 at 22:45
  • @GabrieleNicolardi Yes, I asked for that command to have some debugging from lthooks because I assumed your TL was up-to-date (it's not). As David said, updating should solve the problem. The culprit is that your version of caption delays defining \caption to \AtBeginDocument, which happens after your redefinition. If you don't want to update you can (but I really don't recommend you to) build with pdflatex "\edef\documentclass{\unexpanded{\RequirePackage{etoolbox}\AfterEndPreamble{\def\caption#1{}}}\unexpanded\expandafter{\documentclass}} \nonstopmode \input{test.tex}" – Phelype Oleinik Feb 15 '21 at 23:10
  • By the way, I can reproduce the problem with an updated TeX Live 2019, so I guess yours isn't updated as well – Phelype Oleinik Feb 15 '21 at 23:10
  • @PhelypeOleinik the \AfterEndPreamble solution doesn't work. I'm trying to update my texlive... but neither the solution with sudo nor the one without sudo work: https://pastebin.com/nQmMD8Zm (I never updated my texlive versions) – Gabriele Feb 15 '21 at 23:12
  • @GabrieleNicolardi Sorry, I posted a comment which I then realised it didn't work. I deleted and posted a new one. Regarding updating: try sudo chown -R $(whoami):$(whoami) /usr/local/texlive, then tlmgr update --self --all again – Phelype Oleinik Feb 15 '21 at 23:17
  • @PhelypeOleinik, Both solutions work. If you like you can report it into an answer to my question so I can accept it. Thanks – Gabriele Feb 15 '21 at 23:52

1 Answers1

3

From your log (which was actually the terminal session, which contains far less information than the actual .log file):

This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2020-02-02> patch level 5

which tells you you have TeX Live 2020 from February, and also

subcaption.sty    2020/01/22 v1.3d Sub-captions (AR)
 caption.sty    2020/01/03 v3.4h Customizing captions (AR)
caption3.sty    2020/01/03 v1.8h caption3 kernel (AR)

which are also from the beginning of the year.

The problem is that that version of caption.sty defines \caption \AtBeginDocument, which then happens after your command-line redefinition. You can either update (recommended) or use a later hook to redefine \caption.


To update TeXLive you only need to run (maybe with sudo if you installed with root):

tlmgr update --all --self

(--all tells it to update all packages; you can replace it by a list of packages to update; use tlmgr update --list to see packages that have update candidates. --self tells tlmgr to update itself if needed). In your particular case, for some reason sudo tlmgr doesn't work, so you can try changing the ownership of the texlive folder with sudo chown -R $(whoami):$(whoami) /usr/local/texlive ($(whoami) expands to your user name).


To work around that you need to use a hook later than \AtBeginDocument (unless you had a newer LaTeX, then you could use lthooks and all would be much easier).

The best way would be to add a \csname mycommandline\endcsname after \begin{document}, then build with:

$ pdflatex "\def\mycommandline{\def\caption##1{}} \input{test.tex}"

However, assuming you don't want to change your document (I do not recommend doing this!) you can use \AfterEndPreamble, provided by etoolbox, but since you are loading from the command line you can't load a package, otherwise TeX sets \jobname (opens the .log) and your document will be saved into texput.pdf. So you need a hook to delay loading etoolbox to delay redefining \caption (see the complication?). You can hook into \documentclass (don't):

pdflatex "\edef\documentclass{\unexpanded{\RequirePackage{etoolbox}\AfterEndPreamble{\def\caption#1{}}}\unexpanded\expandafter{\documentclass}} \input{test.tex}"