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
{%
\parindent=4em\relax
\saveparinfo{four em}%
Foo bar.\par}
\useparinfo{four em}%
Etc.
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. :-)
\documentclass[11pt,a4paper]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{lipsum}
\usepackage{calc}
\makeatletter
% 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).
\newcommand*{\saveparinfo}[1]{%
\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.
\newcommand*{\useparinfo}[1]{%
\parindent=\csname my@#1@parindent\endcsname \relax
\parskip=\csname my@#1@parskip\endcsname \relax
}
\makeatother
% Like minipage, but suppresses indentation if used in vertical mode (i.e.,
% before a paragraph has been started).
\newenvironment{myMinipage}{%
% If we are about to start a paragraph, the indentation box will be *out*
% of the minipage -> empty it first.
\noindent
\minipage % like \begin{minipage} but gives nicer error handling here
}{%
\endminipage % ditto for \end{minipage}
}
\newcommand*{\nextSample}{\bigskip\filbreak}
\begin{document}
\section{My section}
\subsection{Example of indented text and non-indented in minipage}
\lipsum[1-2]
\bigskip
\parindent=0pt\relax % Suppress paragraph indentation and save parameters
\saveparinfo{zero}%
No indentation. We saved the \verb|\parindent| and \verb|\parskip| parameters
under key \texttt{zero}.
\nextSample
\begin{myMinipage}{\linewidth}
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.
\end{myMinipage}
\nextSample
\parindent=1em\relax
\saveparinfo{oneem}%
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.
\nextSample
\begin{myMinipage}{\linewidth}
Here, paragraphs are not indented. \lipsum[1]
Other paragraph inside the minipage. No indentation.
\end{myMinipage}
\nextSample
\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.
\lipsum[1]
\end{minipage}
\nextSample
\begin{myMinipage}{\linewidth}\useparinfo{zero}%
This minipage starts at the left margin and has no indentation for its
paragraphs (this was restored using key \texttt{zero}).
\lipsum[1]
\end{myMinipage}
\nextSample
\begin{myMinipage}{\linewidth}\useparinfo{oneem}%
This minipage starts at the left margin and has one em indentation for
each paragraph (this was restored using key \texttt{oneem}).
\lipsum[1]
\end{myMinipage}
\end{document}
Page 1
Page 2
Page 3