2

When the following is compiled with pdflatex, there is more space between the part in bold in the first sentence than in the second sentence. Why is it so, and is there a way to have the first sentence with the correct spacing?

This problem was encountered while writing a program that generates latex code and I'd prefer to use the \begin{} ... \end{} structure for text formatting if possible.

\documentclass[12pt]{article}
\begin{document}

A sentence with
\begin{bfseries}
some words
\end{bfseries}
in  bold.

A sentence with  {\bfseries some words} in bold.

\end{document}
2

2 Answers 2

5

Description

  • insert %, so no space is inserted at the end of the line (in code)
  • or simply use \textbf{...}

Result

enter image description here

Code

\documentclass[12pt]{article}
\begin{document}

A sentence with
\begin{bfseries}%
some words
\end{bfseries}%
in  bold.

A sentence with  {\bfseries some words} in bold.

A sentence with \textbf{some words} in  bold.

\end{document}
9

In my opinion, the idea that \begin{env} is a wrapper for \env is a design mistake of LaTeX. Alas, it's not really possible to change this after 40 years.

There are no environments called bfseries, itshape, large or similar. One can use \begin{bfseries}...\end{bfseries}, but should know what actually happens.

In your input there is a space

  • before \begin{bfseries}
  • after \begin{bfseries}
  • after words
  • after \end{bfseries}

All of them come from the endlines. To the contrary, no spaces are added with

A sentence with {\bfseries some words} in bold.

but, of course, it's better to do

A sentence with \textbf{some words} in bold.

We can see why by typesetting all three versions in the same sequence.

\documentclass{article}

\begin{document}

A sentence with
\begin{bfseries}
some words
\end{bfseries}
in  bold.

A sentence with {\bfseries some words} in bold.

A sentence with \textbf{some words} in bold.

{\bfseries if} text

\textbf{if} text

\end{document}

Since the difference with {\bfseries ...} and \textbf{...} is not so evident from the example, I add two more tests. In the last one, you see that there's more space between “if” and ”text”, due to the italic correction that's added at font change.

enter image description here

The pseudoenvironment bfseries is safe if used between paragraphs. Otherwise you need to mask some of the endlines, limiting clarity of input.

On the other hand, a simple test shows that \begin{large}...\end{large} or similar is bad even between paragraphs. I use scriptsize in order to better show the problem.

\documentclass{article}
\usepackage[nopar]{lipsum}

\begin{document}

\lipsum[1][1-4]

\begin{scriptsize}
\lipsum[1][1-4]
\end{scriptsize}

\lipsum[1][1-4]

{\scriptsize\lipsum[1][1-4]\par}

\end{document}

enter image description here

As you see, the second paragraph is typeset with the baseline distance pertaining to \normalsize, not to \scriptsize. The last paragraph is typeset correctly. Of course you might do

\begin{scriptsize}
\lipsum[1][1-4]\par
\end{scriptsize}

but, again, this requires thinking each time to what's needed.

Define your own environments correcting such bad behaviors, if you really want and avoid using declarations as environments.

2
  • I'm not sure I understand the issue because if you omit the \par in {\scriptsize\lipsum[1][1-4]\par}, the paragraph is also typeset with the wrong baseline distance, so the {\scriptsize ...} version is not better than the begin ... end. Commented Feb 25, 2023 at 22:50
  • 1
    @Gribouillis That's why I recommend defining your own environments and not rely on “naked” commands.
    – egreg
    Commented Feb 25, 2023 at 23:03

You must log in to answer this question.

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