Macros that contain catcode 1 and 2
Some TeX primitives (e.g., \vbox
, \hbox
) can be used with implicit braces: \bgroup
and \egroup
:
\documentclass[12pt]{book}
\usepackage{pgffor}
\newcommand{\blockStart}{%
\vspace{15pt}%
\vbox\bgroup
}
\newcommand{\blockStop}{%
\egroup
}
\begin{document}
\foreach \n in {0,...,34}{
\par text line
}
\blockStart
Keep these lines together\\
Keep these lines together\\
Keep these lines together
\blockStop
\foreach \n in {0,...,33}{
\par text line
}
\end{document}
This is also, how environment lrbox
works (\hbox
+ \bgroup
and \egroup
). However, \bgroup
and \egroup
cannot replace curly braces (category code tokens 1 and 2) for macro arguments.
This works:
\documentclass[12pt,letterpaper]{book}
\usepackage{pgffor}
\newcommand{\blockStart}{\begin{samepage}}
\newcommand{\blockStop}{\end{samepage}}
\begin{document}
\foreach \n in {0,...,35}{
\par text line
}
\blockStart
Keep these lines together\\
Keep these lines together\\
Keep these lines together
\blockStop
\foreach \n in {0,...,33}{
\par text line
}
\end{document}