(I came to this from the duplicate question Emphasize first line of paragraph in LaTeX)
Yiannis solution is very nice. Here is another method, which leads to less visual differences between the first two lines in the way the inter-word spaces are treated. My code presumably leads to inferior results in general compared to Yiannis's (the emphasizing can extend to the beginning of the second line or end a bit too short in the first line), but I do propose it as it is simpler minded than Yiannis's sophisticated macros! Also it seems to work with the example including inline mathematics, and allows hyphenation at the end of the first line (but the emphasizing applies to entire words).
Inline math should be written (whenever there is a chance it will belong to the emphasized text) either without spaces (e.g. $a+b=c$) or be enclosed in doubled braces (e.g. {{$ a + b = c $}}). Then, breaking at the end of lines will work correctly.
The code defines two user commands \decorate and \Decorate (as well as other commands to decide the style of the emphasized text). \decorate is used as \decorate{TEXT} (where TEXT cannot contain a \par token), and \Decorate is to be put at the beginning of a paragraph (so can't be used in a \parbox for example, contrarily to the lowercase form).
Both admit an optional parameter (default value 0.95) which gives a rough idea of the number of lines to which the emphasizing will be applied.
And \Decorate has a starred version \Decorate* which tries to provoke expansion of the paragraph to which it is applied (see the end of the code for a comparative illustration). It is not possible though to use \lipsum[1] as an argument (even with option nopar to package lipsum), but lipsum@i is ok.
\documentclass[a4paper]{article}
\makeatletter
\def\addtobufferwithaspace#1#2{\expandafter\def\expandafter#1%
\expandafter{#1 #2}}
\def\deco@step#1{%
\setbox1=\hbox{\deco@buffer{} #1}%
\dimen0\hsize\advance\dimen0-\parindent\relax
#1
\ifdim\wd1>\deco@scale\dimen0
\expandafter\deco@trail
\else
\addtobufferwithaspace\deco@buffer{#1}%
\expandafter\deco@parsei
\fi
}
\def\deco@trail#1\@nil{\deemphasizingcommand #1}
\def\deco@parsei#1{\ifnot@nil{#1}{\deco@parse #1}}
\def\deco@parse #1 {\deco@step{#1}}
\newcommand*{\decorate}[2][.95]{%
\def\deco@scale{#1}%
\def\deco@buffer{\emphasizingcommand}%
\emphasizingcommand
\deco@parse #2 \@nil
\deemphasizingcommand
}
\def\@@Decorate[#1] #2\par{\decorate[#1]{#2}\par}
\def\@@eDecorate[#1] #2\par{%
\def\@decorate{\decorate[#1]}%
\edef\@Decorated{\noexpand\@decorate{#2}}%
\@Decorated\par}
\newcommand*\@Decorate[1][.95]{\@@Decorate[#1] }
\newcommand*\@eDecorate[1][.95]{\@@eDecorate[#1] }
\newcommand*\Decorate{\@ifstar{\@eDecorate}{\@Decorate}}
\makeatother
\newcommand{\emphasizingcommand}{\bfseries}
\newcommand{\deemphasizingcommand}{\normalfont\normalsize}
\usepackage[nopar]{lipsum}
\begin{document}
\Decorate
I am (of course) shocked! and appalled! I have a particular typesetting
task, described below. Trying to find out how to emphasize the line of text
automatically. The issue here is that I have no idea where the line would
break. Ideally it would be start paragraph with slanted shape and then
revert to upright shape upon first line break.
\Decorate[.5] I am (of course) shocked! and appalled! I have a particular
typesetting task, described below. Trying to find out how to emphasize the
line of text automatically.
\renewcommand{\emphasizingcommand}{\bfseries\slshape}
\noindent\parbox{5cm}{\decorate{
I am (of course) shocked! and appalled! I have a particular typesetting
task, described below. Trying to find out how to emphasize the line of text
automatically. The issue here is that I have no idea where the line would
break. }}
\parbox{3cm}{\decorate{
I am (of course) shocked! and appalled! I have a particular typesetting
task, described below. Trying to find out how to emphasize the line of text
automatically. The issue here is that I have no idea where the line would
break. }}
\parbox{2.5cm}{\raggedright\decorate{
I am (of course) shocked! and appalled! I have a particular typesetting
task, described below. Trying to find out how to emphasize the line of text
automatically. The issue here is that I have no idea where the line would
break. }}
\parbox{2.5cm}{\raggedleft\decorate{
I am (of course) shocked! and appalled! I have a particular typesetting
task, described below. Trying to find out how to emphasize the line of text
automatically. The issue here is that I have no idea where the line would
break. }}
\renewcommand{\emphasizingcommand}{\ttfamily\Large\frenchspacing}
\renewcommand{\deemphasizingcommand}{\normalfont\normalsize\nonfrenchspacing}
\begin{center}
\begin{minipage}{0.5\linewidth}
\centering
\Decorate[1.5]
I am (of course) shocked! and appalled! I have a
particular typesetting task, described below. Trying to find out how to
emphasize the line of text automatically. The issue here is that I have no
idea where the line would break. Ideally it would be start paragraph with
slanted shape and then revert to upright shape upon first line break.
\par
\end{minipage}
\end{center}
\renewcommand{\emphasizingcommand}{\scshape}
\Decorate There is no just \emph{ground}, therefore, \mbox{$ a + b = c $} for
the charge $x\in\{0,1,2\}$ brought against me by certain ignoramuses $ x
\in\{ 0,1,2 \}$.
\Decorate Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu
libero, nonummy eget, consectetuer id, vulputate a, magna.
\Decorate[4] Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu
libero, nonummy eget, consectetuer id, vulputate a, magna.
\renewcommand{\emphasizingcommand}{\bfseries}
%% \clearpage
\decorate{Let's try with a short sentence.}
\decorate[.2]{And another one.}
\decorate[.2]{And another one.}
\decorate[.2]{And another one.}
\makeatletter
\Decorate* \lipsum@v
\Decorate* \lipsum@vi
\Decorate*[1] \lipsum@vii
\makeatother
\def\tmpa{dolor sit amet, consectetuer
adipiscing elit. Ut purus elit, }
\Decorate[.1] \tmpa \tmpa
\Decorate*[.1] \tmpa \tmpa
\end{document}
magaz? – Antal Spector-Zabusky Oct 14 '10 at 23:43\FirstLine{Lorem ipsum dolor sit amet, … mollit anim id est laborum.}(except with the full text instead of the …, but I don't think that's quite necessary in this comment :-) ). It's odd behavior, that's for sure—I'm going to see if I can isolate it to a weird package interaction. – Antal Spector-Zabusky Oct 15 '10 at 00:01magazandpdfsyncdon't play nice together. Removingpdfsyncmade everything work. The hyphenation is slightly different than manual-small-capitalization, but it's only off by something like half a word. It looks like the only remaining problem is integrating it with dropcaps, which should be doable. – Antal Spector-Zabusky Oct 15 '10 at 00:09magazto play nicely withlettrine? I am trying to get initial capitals + first line small capitals, but it appears that\FirstLinegets tripped up by the initial capital, and winds up applying the special formatting to too much text. – Aaron Mar 06 '11 at 06:31