5

(This a follow up of this question about indentation of paragraphs with the standalone class.)

The following MCE gives the expected result (indented paragraphs):

\documentclass[varwidth]{standalone}

\newlength\keptparindent
\keptparindent=\parindent

\begin{document}
\parindent=\keptparindent

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris.  Nam arcu libero, nonummy eget, consectetuer id, vulputate a,
magna. Donec vehicula augue eu neque.

Pellentesque habitant morbi tristique senectus et ne
tus et malesuada fames ac turpis egestas.
\end{document}

But, if:

\begin{document}
\parindent=\keptparindent

is replaced by the (supposed) equivalent in-preamble instruction:

\AddToHook{begindocument/end}{%
  \parindent=\keptparindent
}
\begin{document}

the paragraphs are not indented anymore:

\documentclass[varwidth]{standalone}

\newlength\keptparindent
\keptparindent=\parindent


\AddToHook{begindocument/end}{%
  \parindent=\keptparindent
}
\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris.  Nam arcu libero, nonummy eget, consectetuer id, vulputate a,
magna. Donec vehicula augue eu neque.

Pellentesque habitant morbi tristique senectus et ne
tus et malesuada fames ac turpis egestas.
\end{document}

Why, and is it possible to have indented paragraphs with only a in-preamble instruction?

Edit

Here is my File List

standalone.cls    2022/10/10 v1.3b Class to compile TeX sub-files standalone
shellesc.sty    2023/07/08 v1.0d unified shell escape interface for LaTeX
ifluatex.sty    2019/10/25 v1.5 ifluatex legacy package. Use iftex instead.
   iftex.sty    2022/02/03 v1.0f TeX engine tests
 xkeyval.sty    2022/06/16 v2.9 package option processing (HA)
 xkeyval.tex    2014/12/03 v2.7a key=value parser (HA)
standalone.cfg    2022/10/10 v1.3b Default configuration file for 'standalone' 
class
 article.cls    2023/05/17 v1.4n Standard LaTeX document class
  size10.clo    2023/05/17 v1.4n Standard LaTeX file (size option)
varwidth.sty    2009/03/30 ver 0.92;  Variable-width minipages
l3backend-pdftex.def    2023-11-09 L3 backend support: PDF output (pdfTeX)
 ***********
5
  • 1
    \AfterEndEnvironment inserts the code behind \end{<environment>}. You want \AfterBeginEnvironment or \AtBeginDocument.
    – Skillmon
    Dec 6, 2023 at 8:41
  • Yes, sorry, I corrected my question. The same problem occurs with \AddToHook{begindocument/end} so the question remains :) Dec 6, 2023 at 8:45
  • @cabohah which versions are you using? I just updated TL23 and I don't get indentations using Denis' example that uses \AddToHook
    – daleif
    Dec 6, 2023 at 8:51
  • @cabohah I added my file list (see daleif comment). Dec 6, 2023 at 8:53
  • Ah, I see, there is still an adapted standalone.cfg in my search path. With the original one I also don't have an indent. Sorry!
    – cabohah
    Dec 6, 2023 at 8:59

1 Answer 1

6

Unfortunately standalone does not use hooks, but appends \sa@cls@afterbegindocument to \document. And this \sa@cls@afterbegindocument is used to do the \standalone and therefore activate varwidth. The resulting code in \document is:

\UseOneTimeHook {begindocument/end}
\ignorespaces
\sa@cls@afterbegindocument

So the begindocument/end hooks are executed before the code relevant for the missing indent.

As a workaround, you can use:

\listfiles
\documentclass[varwidth]{standalone}

\newlength\keptparindent
\keptparindent=\parindent

\makeatletter
\AddToHook{begindocument/end}{%
  \csname sa@cls@afterbegindocument\endcsname
  \let\sa@cls@afterbegindocument\relax
  \parindent=\keptparindent
}
\makeatother

\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris.  Nam arcu libero, nonummy eget, consectetuer id, vulputate a,
magna. Donec vehicula augue eu neque.

Pellentesque habitant morbi tristique senectus et ne
tus et malesuada fames ac turpis egestas.
\end{document}

to get

enter image description here

Note:

\listfiles
\documentclass[varwidth]{standalone}

\newlength\keptparindent
\keptparindent=\parindent

\AddToHook{begindocument/end}{%
  \standalone
  \NewCommandCopy\STANDALONE\standalone
  \def\standalone{\RenewCommandCopy\standalone\STANDALONE}%
  \parindent=\keptparindent
}

\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris.  Nam arcu libero, nonummy eget, consectetuer id, vulputate a,
magna. Donec vehicula augue eu neque.

Pellentesque habitant morbi tristique senectus et ne
tus et malesuada fames ac turpis egestas.
\end{document}

would also be possible.

2

You must log in to answer this question.

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