[Tex/LaTex] Braces inside or outside

formattingtags

Some tags work inside their braces: {\scriptsize lorem}.

Others, outside: \flushright{lorem} (and they stay in force for a while).

Edit: Others outside, lasting only within the braces: {\textbf lorem}.

Others, either inside or outside: \em{lorem}, ditto \tt.

The difference may depend on declarative form vs. action form, although that triggers bad memories of high school Latin. Why are text format commands used inside braces?

How can one remember which tag has which scope?

Best Answer

% !TEX TS-program = pdflatex
% !TEX encoding = UTF-8 Unicode
% arara: pdflatex
\pdfminorversion=7
% ateb: https://tex.stackexchange.com/a/367883/
\documentclass{article}
\usepackage[a4paper,scale=.9]{geometry}
\usepackage{booktabs}
\usepackage{cfr-lm}
\begin{document}
\verb|\flushright| is really starting an environment and would be better marked as such in \LaTeX.

\verb|\begin{flushright}lorem\end{flushright}| \begin{flushright}lorem\end{flushright}

\verb|{\textbf lorem}| is not the same as \verb|\textbf{lorem}|.
The former will make only the \verb|l| bold, while the latter will make \verb|lorem| bold.
\verb|\bfseries| is a \emph{switch} and does not take an argument.
Everything following will be bold until the switch is changed or the local \TeX{} group ends.
Hence, limiting its scope requires a local group, \verb|{\bfseries lorem}|.

\begin{tabular}{ccc}
  \verb|\textbf{lorem}| & \verb|{\textbf lorem}| & \verb|{\bfseries lorem}| \\
  \textbf{lorem} & {\textbf lorem} & {\bfseries lorem} \\
\end{tabular}

\verb|\scriptsize| is another switch: everything following will be in this size, until another size is activated or the local \TeX{} group ends.
{\scriptsize Hence, brackets are needed to limit the scope, \verb|{\scriptsize lorem}|.
However, to be fully effective, the scope of size-changing macros must include a paragraph break at the end.}
In some contexts, this doesn't matter (and can even be exploited), but generally, ending a size mid-paragraph is not what you want.

\scriptsize \verb|\scriptsize| is another switch: everything following will be in this size, until another size is activated or the local \TeX{} group ends.
{\normalsize Hence, brackets are needed to limit the scope, \verb|{\scriptsize lorem}|.
However, to be fully effective, the scope of size-changing macros must include a paragraph break at the end.}
In some contexts, this doesn't matter (and can even be exploited), but generally, ending a size mid-paragraph is not what you want.

\normalsize
\verb|\tt| is obsolete and ought not be used in \LaTeXe{} at all.
Use \verb|\ttfamily| as a switch, \verb|{\ttfamily lorem}|, or \verb|\texttt| with an argument, \verb|\texttt{lorem}|.

If you stick to \LaTeX{} font selection commands, then all those which take arguments have names beginning with \verb|\text| (with the exception of \verb|\emph|, as explained below), while switches do not.
Switches instead have standard endings which indicate the kind of thing they switch: \verb|size| for size, \verb|family| for family, \verb|shape| for shape and \verb|series| for width and weight.

\newcommand*\cs[1]{\texttt{\textbackslash#1}}
\begin{center}
    \begin{tabular}{*{7}{l}}
      \toprule
      Switch & Switch & Text & Switch & Text & Switch & Text \\
      \midrule
      \cs{tiny} & \cs{upshape} & \cs{textup} & \cs{rmfamily} & \cs{textrm} & \cs{mdseries} & \cs{textmd} \\
      \cs{scriptsize} & \cs{itshape} & \cs{textit} & \cs{sffamily} & \cs{textsf} & \cs{bfseries} & \cs{textbf} \\
      \cs{footnotesize} & \cs{slshape} & \cs{textsl} & \cs{ttfamily} & \cs{texttt} \\
      \cs{small} & \cs{scshape} & \cs{textsc}  \\
      \cs{large} \\
      \cs{Large} \\
      \cs{LARGE} \\
      \cs{Huge} \\
      \cs{normalsize} & \cs{normalfont} & \cs{textnormal} & \cs{normalfont} & \cs{textnormal} & \cs{normalfont} & \cs{textnormal} \\
      \bottomrule
    \end{tabular}
\end{center}

This system is the New Font Selection Scheme, introduced with \LaTeXe more than twenty years ago (so no longer so `new').

\verb|\emph{lorem}| is not part of this scheme because, strictly speaking, it does not specify a particular font change but is, rather, \emph{semantic} mark-up.
\verb|\emph| and the \TeX{} switch \verb|\em| specify that text should be \emph{emphasised} using whatever format is currently active for marking such text.
By default, this means that text is italicised, if currently non-italic, or made upright, if currently italic.
However, it would be perfectly legitimate to design a class in which important text was made bold rather than rendered italic/non-italic.

With the default settings, the difference between the semantic \verb|\emph| and the non-semantic \verb|\textit| can be observed by seeing what happens when such changes are nested.

\begin{verbatim}
This is not especially important.
\emph{This is very important, especially \emph{this phrase}, which deserves particular attention.}

This is not especially important.
\textit{This is very important, especially \textit{this phrase}, which deserves particular attention.}

This is not especially important.
\emph{This is very important, especially \textit{this phrase}, which deserves particular attention.}

This is not especially important.
\textit{This is very important, especially \emph{this phrase}, which deserves particular attention.}
\end{verbatim}
This is not especially important.
\emph{This is very important, especially \emph{this phrase}, which deserves particular attention.}

This is not especially important.
\textit{This is very important, especially \textit{this phrase}, which deserves particular attention.}

This is not especially important.
\emph{This is very important, especially \textit{this phrase}, which deserves particular attention.}

This is not especially important.
\textit{This is very important, especially \emph{this phrase}, which deserves particular attention.}
\end{document}

font stuff and things

Related Question