\@gobble
. It's description says Removes (gobbles) its argument. (long) but I still don't know what it does.I'm asking because I'm recently going through this list of macros and I have trouble understanding this one.
\@gobble
. It's description says Removes (gobbles) its argument. (long) but I still don't know what it does.NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
\@gobble
takes an argument and does nothing. \@gobbletwo
takes two arguments and does nothing. Sounds meaningless, but for example it's a way to disable a command that takes arguments. You can override or disable simple commands like \let\thepage\relax
. (\relax
also does "nothing") Now, you don't have page numbers displayed anymore. But if you do the same with macros with arguments, the arguments would still be there and appear in your text. Then you can use \gobble
, \@gobble
or \@gobbletwo
.Code: Select all
\documentclass{article}
\pagenumbering{gobble}
\begin{document}
First page
\newpage
Second page
\newpage
Third page
\end{document}
Code: Select all
\documentclass{book}
\makeatletter
\let\chapter\@gobbletwo
\makeatother
\begin{document}
text
\listoffigures
more Text
\end{document}
IMHO not the best example, at least not without any clarification. UsuallyStefan Kottwitz wrote: Here, we disable the \chapter macro because we don't want to have a separate chapter for the list of figures:Code: Select all
\documentclass{book} \makeatletter \let\chapter\@gobbletwo \makeatother \begin{document} text \listoffigures more Text \end{document}
\chapter
is a command with an optional and a mandatory argument, but this does not fit \@gobbletwo
, because it eats two mandatory arguments. So why does it work in the example? It works, because \listoffigures
does use \chapter*{\listfigurename}
. So in the example, the asterisk *
is the first argument and {\listfigurename}
is the second. However, the shown code would fail using also a normal chapter:
Code: Select all
\documentclass{book}
\makeatletter
\let\chapter\@gobbletwo
\makeatother
\begin{document}
\listoffigures
\chapter{Test}
With text.
\end{document}
W
of the word With
after \chapter{Test}
because now, \chapter
is a command with two mandatory arguments (and both are not used). An example like
Code: Select all
\documentclass{book}
\makeatletter
\let\chapter\@gobbletwo
\makeatother
\begin{document}
\listoffigures
\chapter[Toas]{Test}
With text.
\end{document}
Code: Select all
\documentclass{book}
\begin{document}
text
\begingroup
\makeatletter
\let\chapter\@gobbletwo
\listoffigures
\endgroup
more Text
\end{document}
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p