Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Assume I want to have a section within an article with different indentation/parskipping. Is there a way to undo that command at the end of the section so the next section behaves again as if I never used a setlength on parindent?

I mean I could just use the \setlength{\parindent}{}-command again with the default parameters but what if I don't know the standard parameters of latex?

\documentclass{article}
\usepackage{ngerman, blindtext}
\begin{document}
\section{Section with different settings}

\setlength{\parindent}{0cm}\setlength{\parskip}{4ex plus 0.3ex minus 0.1ex}

\blindtext\par\blindtext
%Here I would want to undo the setlength command from above and go back to default
\section{Section back to default settings}

\blindtext\par\blindtext
\end{document}
share|improve this question

2 Answers 2

up vote 18 down vote accepted

Enclose the section in question within a group.

\documentclass{article}
\usepackage{ngerman, blindtext}
\begin{document}

\begingroup
\section{Section with different settings}

\setlength{\parindent}{0cm}\setlength{\parskip}{4ex plus 0.3ex minus 0.1ex}

\blindtext\par\blindtext
\endgroup

%Here I would want to undo the setlength command from above and go back to default
\section{Section back to default settings}

\blindtext\par\blindtext
\end{document}
share|improve this answer
    
Wow, thanks for that quick answer! Simple solution :) Will accept it as answer in 5minutes. –  Philipp Feb 19 '12 at 14:15
    
Thanks very much, I needed this too! upvote. –  s0rce Feb 19 '12 at 17:44

A different way than using groups can come handy in certain situations:

\newcommand{\keepvalues}{%
  \edef\restorevalues{%
    \parindent=\the\parindent
    \parskip=\the\parskip
  }%
}

Then you can say

\keepvalues

\section{Section with different settings}

\setlength{\parindent}{0cm}
\setlength{\parskip}{4ex plus 0.3ex minus 0.1ex}

<text>

\restorevalues

\section{Section back to default settings}

A more generic approach can be giving \keepvalues a list of length parameters to keep:

\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\keepvalues}{ O{\parindent,\parskip} }
  {
   \tl_clear:N \l_tmpa_tl
   \clist_map_inline:nn { #1 }
     { \tl_put_right:Nx \l_tmpa_tl { ##1 = \skip_use:N ##1 } }
   \cs_set:Npx \restorevalues { \tl_use:N \l_tmpa_tl }
  }
\ExplSyntaxOff

\begin{document}

\keepvalues[\parindent,\parskip,\leftmargini]

\section{Section with different settings}

\setlength{\parindent}{0cm}
\setlength{\parskip}{4ex plus 0.3ex minus 0.1ex}
\addtolength{\leftmargini}{2em}

<text>

\restorevalues

\section{Section back to default settings}

The call \keepvalues is equivalent to \keepvalues[\parindent,\parskip]. In the argument can go a list of parameters which can be set with \setlength.

No nested calls, of course.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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