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.

Some LaTeX formatting commands like \textcolor{red}{...}, \sout{...} or \textsf{...} work fine when the thing inside is a single paragraph but fail to compile if you put a paragraph break in the argument.

\textsf{This paragraph is in sans-serif.} % OK

\textsf{This one too.

So should this one be.} % Doesn't compile.

Question 1: why is this? I feel I haven't understood how LaTeX processes these commands internally. Is there a general way to build a command that works with paragraphs or to turn one that doesn't into one that does?

Question 2: what commands, if any, can I use to apply the following changes to a block containing several paragraphs within my text? For color I know I can use the color environment already.

  • sans-serif \textsf or monospace \texttt
  • strikeout and underline \sout and \ul (from ulem)
share|improve this question
1  
For sans-serif/monospace, enclose the paragraphs in a group and use \sffamily/\ttfamily. –  lockstep Feb 11 '13 at 12:17

1 Answer 1

up vote 7 down vote accepted

Certain commands do not permit new paragraphs: \textbf, \textsf, \texttt, etc. To achieve the effect you want, you'll need to use a different form: \bfseries, \sffamily, \ttfamily, \itshape. If you load the xcolor package, then you can issue \color{<name_of_color>}.

If you don't want to effect document wide changes, then you need to embed these commands within some kind of grouping. That can be as simple as {...} or an environment like \begin{minipage}{<width>}...\end{minipage}.

Here's a MWE:

\documentclass{article}
\usepackage{xcolor}
\usepackage{lipsum}
\begin{document}

{\bfseries \lipsum[1-2] }

{\sffamily \lipsum[1-2] }

{\itshape  \lipsum[1-2] }

{\color{blue} \lipsum[1-2] }

\begin{itemize}\bfseries\itshape\color{orange}
\item A
\item B
\item C
\end{itemize}

\lipsum[1]

\end{document}

If you don't want to hassle with embedding things inside another environment or parentheses, then you can use \normalfont to restore settings. This won't, however, work for restoring color; for that you'll have to issue \normalcolor or \color{black}.

\lipsum[1]

\color{green}\itshape
\lipsum[1]

\color{black}\normalfont
\lipsum[1]

In a similar fashion, you can change font sizes by issuing \large or \scriptsize etc., to undo the effect of these commands (if not embedded in some kind of a group) use \normalsize.

In summary

Each font changing command is paired with a command which can work across multiple paragraphs.

\textbf{...}    \bfseries
\textsf{...}    \sffamily
\textit{...}    \itshape
etc. 

These are all well documented; so it shouldn't be hard for you to find all such paired commands. However, a word of caution, do not use \bf, \it, and the such. These are TeX commands and most likely will not do what you want. The LaTeX commands \bfseries, \itshape, only change the aspect of the text you want (series type, shape, family). Among more subtle effects the LaTeX commands enact and depending on whether the fonts you use provide support, the effects of the LaTeX commands are additive.

If the commands in the second column are not embedded within some kind of a group and you want to restore default behavior, then you can issue

\normalfont

You can change the size of the font with the commands

\large
\small
\footnotesize

The default size can be restored using

\normalsize

Color attributes can be changed, provided you've loaded xcolor. As with \textxx{...} type commands, there is also a pair:

\textcolor{<color>}{<text>}     \color{<color>}

Colors can be restored by issuing

\normalcolor    
share|improve this answer
1  
Thanks, this answers all the "how" questions. I still wonder why there's two versions of each command, I presume it's something to do with how LaTeX works internally? –  Bristol Feb 12 '13 at 15:36

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.