I've some minipagein my document and the parindent reset automatically in this environment.

After some research, I've found a solution in this topic that I want to improve.

My goal :

  • Redefine minipage to set parindent automatically as proposed by touhami.

My questions :

  • How change the minipage environment (with \makeatletter) to redefine preamble of minipage as :
  • Is it bad use to force indent in minipage environment and in which case is it wrong ? The topic here had already asked this question but there are no answer.

  • More globally, how/where can I know the details of an environment defined in LaTeX in order to change it ? I've already modify some environment defined in package where i could read the code in the documentation but for minipage environment, I'm not able to find where this environment is defined.

Thank you for you help and sorry if there is some english mistakes.



%%Command to set indentation in minipage


\section{My section}
\subsection{Example of indented text and non-indented in minipage}


        This is a long text to fill the line untill a linebreak appears.

        And there is no indent for each paragraph.

        And this minipage has indentation for each paragraph.

You can find the source code of LaTeX in source2e. In TeX Live, the command texdoc source2e opens the corresponding PDF document; then you can use the search function of your PDF viewer or the index to find what you are looking for (e.g., commented source code for minipage).

Another way is to look at the file latex.ltx that should be part of your TeX distribution, but it has no comments. latex.ltx is the compilation of many files, with comments removed. The source file for minipage is called ltboxes.dtx, you may have it if you have source code for your TeX distribution.

If you look in one of these files, you'll see that \parindent and \parskip are both set to zero inside a minipage (\@parboxrestore is called from \@iiiminipage, which is itself called directly and indirectly from \minipage). Therefore, if you see indentation for text inside a minipage, it is either out of the minipage (which is a box) or has been switched on explicitly inside (these two possibilities are visually different, of course).

I believe the following expanded version of your example should help you understand this and do more or less what you want. Note the use of \xdef instead of \edef inside the definition of \saveparinfo. This way, you can do things like

  \saveparinfo{four em}%
  Foo bar.\par}

\useparinfo{four em}%

which would otherwise cause an error, because with \edef, the macros used to store the saved parameters would only be defined inside the group. \xdef makes these macros \global, just like macros defined with \newcommand. Now, the full example I promised. :-)



% Command to save \parindent and \parskip under a specific key. The argument
% is the key and can even contain non-letters (e.g., hyphens or spaces).
  \expandafter\xdef\csname my@#1@parindent\endcsname{\the\parindent}%
  \expandafter\xdef\csname my@#1@parskip\endcsname{\the\parskip}%

% Restore parameters that were saved under the specified key.
  \parindent=\csname my@#1@parindent\endcsname \relax
  \parskip=\csname my@#1@parskip\endcsname \relax


% Like minipage, but suppresses indentation if used in vertical mode (i.e.,
% before a paragraph has been started).
  % If we are about to start a paragraph, the indentation box will be *out*
  % of the minipage -> empty it first.
  \minipage    % like \begin{minipage} but gives nicer error handling here
  \endminipage % ditto for \end{minipage}


\section{My section}
\subsection{Example of indented text and non-indented in minipage}


\parindent=0pt\relax % Suppress paragraph indentation and save parameters
No indentation. We saved the \verb|\parindent| and \verb|\parskip| parameters
under key \texttt{zero}.

  This is a long text to fill the line until a linebreak appears. Bla bla
  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla.

  And there is no indentation for any paragraph.

Now, paragraphs are indented. We saved the \verb|\parindent| and
\verb|\parskip| parameters under key \texttt{oneem}. Bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla bla.

Another paragraph with the same parameters. Bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla bla bla.

  Here, paragraphs are not indented. \lipsum[1]

  Other paragraph inside the minipage. No indentation.

\begin{minipage}{\linewidth-\parindent} % real minipage environment
  Here, the whole minipage is preceded by an indentation box, but there is
  no indentation for paragraphs \emph{inside} the minipage.


  This minipage starts at the left margin and has no indentation for its
  paragraphs (this was restored using key \texttt{zero}).


  This minipage starts at the left margin and has one em indentation for
  each paragraph (this was restored using key \texttt{oneem}).


Page 1

Page 1

Page 2

Page 2

Page 3

Page 3

  • I fixed the comment before the definition of \saveparinfos . You can even use non-letters in key names; for instance, key one-em or even one em (with a space inside) would have been fine! – frougon Apr 4 '19 at 5:45
  • I also switched to using \xdef instead of \edef when defining the macros where parameters are saved (e.g., \my@zero@parindent, \my@zero@parskip). This will be useful if you call \useparinfo in a scope (group) that is not “visible” from where \saveparinfos was called (e.g., if \useparinfo is called at outer scope with a given key, while \saveparinfos was called earlier with the same key but inside a group). – frougon Apr 4 '19 at 8:03
  • I renamed \saveparinfos to \saveparinfo for consistency with \useparinfo... – frougon Apr 4 '19 at 8:22
  • After a while, i'm back, sorry for the delayed answer while you completely answered my ask. Do you know if there is a reason why the minipage has been configured to set to zero \parindent and \parskip ? – Piroooh Jun 1 '19 at 14:27
  • What a pleasant surprise. :-) I suppose that for the typical layout work minipage was developed for, \parindent is more often a nuisance than something desirable. TeX's \vbox is similar to minipage in some respects but does honour \parindent. Try this: \parindent=1em \setbox0=\vbox{\hbox{Really, I like}\par \hbox{them!}}---\vbox{\hsize=15em I like \box0 \ paragraph indentation boxes a lot.}. – frougon Jun 2 '19 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.