6

Consider the code

\documentclass[12pt]{book}
\usepackage[T1]{fontenc}
%\usepackage[sfdefault]{cabin}

\newcommand{\longemdash}{{\fontfamily{cmss}\selectfont---}}
\newcommand{\emdash}{\nobreak---\nobreak\hskip0pt}

\newcommand{\fancyquote}[2]{%
  \par\noindent{#1}\\*\hspace*{\fill}\longemdash\fontfamily{cmss}\selectfont\textit{\textbf{#2}}%
}

\begin{document}
\thispagestyle{empty}

\fancyquote{{\scshape{Baseball}} is 90 percent mental. The other half is physical.}{Yogi Berra}

\vspace*{20pt}

\fancyquote{If people don't want to come to the ballpark, how are you going to stop them?}{Yogi Berra}

\vspace*{20pt}

\fancyquote{You can observe a lot by watching.}{Yogi Berra}
\end{document}

which produces

enter image description here

QUESTION: How may I automatically display the first word of every quote in small caps without having to resort to something {\scshape{Baseball} every time?

Thank you.

3 Answers 3

6

Isolate the first word with a delimited argument.

\documentclass[12pt]{book}
\usepackage[T1]{fontenc}
\usepackage[sfdefault]{cabin}

\usepackage{showframe}

\newcommand{\longemdash}{\makebox[1em][s]{---\hss---}}

\makeatletter
\newcommand{\fancyquote}[2]{%
  \fancyquote@#1\@nil{#2}%
}
\def\fancyquote@#1 #2\@nil#3{%
  \par\noindent\textsc{#1} #2\\*\hspace*{\fill}\longemdash{\itshape\bfseries#3}%
}
\makeatother

\begin{document}
\thispagestyle{empty}

\fancyquote{Baseball is 90 percent mental. The other half is physical.}{Yogi Berra}

\vspace*{20pt}

\fancyquote{If people don't want to come to the ballpark, how are you going to stop them?}{Yogi Berra}

\vspace*{20pt}

\fancyquote{You can observe a lot by watching.}{Yogi Berra}

\end{document}

enter image description here

4

Your first \fancyquote doesn't reset the font afterward, so your subsequent text is still in the cmss family. I think this was unintentional, so I changed that in my solution.

My solution works in plain TeX, it simply delimits the parameter in a TeX macro with a space.

baseball quotes

\font\twelverm=cmr10 at 12pt
\font\twelvesc=cmcsc10 at 12pt % Roman small caps
\font\twelveecso=ecso1200 % cmss bold italic
\font\twelveecss=ecss1200 % cmss default

\twelverm % Also set math fonts to 12pt here

\def\fancyquoteA#1 {{\twelvesc#1} }
\def\fancyquote#1#2{\par\noindent\fancyquoteA#1 \par\hfill{\twelveecss---\twelveecso#2}\par}

\fancyquote{Baseball is 90 percent mental. The other half is physical.}{Yogi Berra}

\vskip20pt
\fancyquote{If people don't want to come to the ballpark, how are you going to stop them?}{Yogi Berra}

\vskip20pt
\fancyquote{You can observe a lot by watching.}{Yogi Berra}

\bye

This can easily be converted to more LaTeX code, you can remove the \font definitions and replace them with LaTeX font macros instead.

1
  • I think the OP really does want the quotation text to be rendered in a sans serif font (e.g., Cabin), in addition to the first word of the quotation being rendered in small caps (and sans serif).
    – Mico
    Mar 26, 2023 at 13:22
3

Here's a LuaLaTeX-based solution. It makes use of Lua's built-in string function to identify the "word" -- taken to be a sequence of one or more alphabetical characters -- at the start of a string and to render this word in small caps. (Whitespace at the very start of the string is permitted, in the sense that it is removed from the string.) If the string of interest doesn't start with a word as defined above, the string is output without modification.

enter image description here

% !TEX TS-program = lualatex
\documentclass[12pt]{book}

%% Lua-side code
\usepackage{luacode} % for 'luacode' environment
\begin{luacode}
function first_word_sc ( s )
  s = s:gsub ( "^%s*(%a+)" , "\\textsc{%1}" )
  tex.sprint ( s )
end
\end{luacode}

%% LaTeX-side code: utility macro that invokes the Lua function
\newcommand\FirstWordSC[1]{%
  \directlua { first_word_sc ( "#1" ) }}


\usepackage{fontspec}
%\setmainfont{Latin Modern Roman}
%\setsansfont{Latin Modern Sans}
\newfontfamily{\Cabin}{Cabin Regular}

\newcommand{\longemdash}{\textsf{\textemdash}}

\newcommand{\fancyquote}[2]{%
  \par\noindent{\Cabin\FirstWordSC{#1}}\\*%
  \hspace*{\fill}\longemdash\textsf{\textit{\textbf{#2}}}%
}

\begin{document}

\fancyquote{Baseball is 90 percent mental. The other half is physical.}{Yogi Berra}

\vspace*{20pt}

\fancyquote{If people don't want to come to the ballpark, how are you going to stop them?}{Yogi Berra}

\vspace*{20pt}

\fancyquote{  You can observe a lot by watching.}{Yogi Berra}

\end{document}

You must log in to answer this question.

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