0

I have defined a simple class

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mycustom}[2019/03/06 My custom class]
\LoadClass{article}
\RequirePackage{setspace}

\newcommand{\summary}{
    \begingroup
    \setlength{\parindent}{0cm}
    \onehalfspacing
}

\newcommand{\ensummary}{
    \endgroup
}

\endinput

Given that I created a simple LaTeX file, defined as:

\documentclass{mycustom}

\usepackage{lipsum}

\begin{document}

        \lipsum[1][1-3]

        \summary
        \lipsum[1][1-4]\par
        \ensummary

        \lipsum[1][1-3]

\end{document}

I noticed that I do not add the par inside the \summary the One and Half Spacing just don't work. I would like to know how this behavior occurs, and if there is a way to remove \par and keep the same behavior (one and half spacing inside the \summary). Any hints for improvement are very welcome.

This is the paragraph when I add \par

With par

This is the paragraph without \par

Without par

Pay attention to the inline spacing in paragraph at the middle.

Lin
  • 1,191
  • Can't get the behavior you are describing... With or without \par I get the same output. Also, why not an environment but commands? – koleygr Mar 09 '19 at 03:03
  • This question may provide some relevant information: Inconsistent line spacing – barbara beeton Mar 09 '19 at 03:09
  • Nice. Indeed it helped. Adding a newline tells to latex that paragraph ended. – Lin Mar 09 '19 at 03:15
  • 1
    Unfortunately, \newline may in some edge cases add an extra (blank) line. \par is less susceptible to that problem, but even that, if preceded by a space, may do the same if the last line is very tight; that can be avoided by inserting \unskip\par before \endgroup in ghe \ensummary definition. But @koleygr's question, "why not an environment?", is applicable here; that automatically takes care of all these concerns. – barbara beeton Mar 09 '19 at 03:28
  • I don't know what a environment is. If is better I would gladly learn about. – Lin Mar 09 '19 at 03:29
  • 1
    You can create an environment with the command \newenvironment{sumarry}{<place here the \summary content>}{<place here the \ensumarry content>} ... Forget \begingroup and \endgroup since an environment is "grouping" its content by default.... and use like \begin{summary} <content> \end{summary} – koleygr Mar 09 '19 at 03:39

1 Answers1

4

You should end the environment definition with \par so that it is in the scope of the linespace change. Conversely you should start the environment with \par otherwise the preceding text may be affected (try the example below without the first \par in the definition).

As noted in comments this should be an environment (latex normally prevents commands being defined with names starting with \end...) in which case the explicit \begingroup is not needed, also \newline never ends a paragraph, it just forces a linebreak.

\documentclass{article}

\usepackage{setspace,lipsum}

\newenvironment{summary}
{\par\setlength{\parindent}{0cm}\onehalfspacing}
{\par}

\begin{document}

        \lipsum[1][1-3]
        \begin{summary}
        \lipsum[1][1-4]
        \end{summary}

        \lipsum[1][1-3]

\end{document}
David Carlisle
  • 757,742