[Tex/LaTex] Automatic bold for every first character of a line

boldformatting

It's possible to do this

Lorem ipsum dolor sit amet,

consectetur adipisci elit, sed eiusmod

tempor incidunt ut labore

et dolore magna aliqua. Ut enim

ad minim veniam, quis nostrud

exercitation ullamco laboris nisi ut aliquid

ex ea commodi consequat. Quis aute

iure reprehenderit in voluptate velit

esse cillum dolore eu fugiat nulla pariatur .

Excepteur sint obcaecat cupiditat non proident,

sunt in culpa qui officia deserunt

mollit anim id est laborum.

without writing the following code

\textbf{L}orem ipsum dolor sit amet, \\
\textbf{c}onsectetur adipisci elit, sed eiusmod \\
\textbf{t}empor incidunt ut labore \\
\textbf{e}t dolore magna aliqua. Ut enim \\
\textbf{a}d minim veniam, quis nostrud \\
\textbf{e}xercitation ullamco laboris nisi ut aliquid \\
\textbf{e}x ea commodi consequat. Quis aute \\
\textbf{i}ure reprehenderit in voluptate velit \\
\textbf{e}sse cillum dolore eu fugiat nulla pariatur. \\
\textbf{E}xcepteur sint obcaecat cupiditat non proident, \\
\textbf{s}unt in culpa qui officia deserunt \\
\textbf{m}ollit anim id est laborum.

but, for example, something like this?

\begin{bold_first}
Lorem ipsum dolor sit amet, \\
consectetur adipisci elit, sed eiusmod \\
tempor incidunt ut labore \\
et dolore magna aliqua. Ut enim \\
ad minim veniam, quis nostrud \\
exercitation ullamco laboris nisi ut aliquid \\
ex ea commodi consequat. Quis aute \\
iure reprehenderit in voluptate velit \\
esse cillum dolore eu fugiat nulla pariatur. \\
Excepteur sint obcaecat cupiditat non proident, \\
sunt in culpa qui officia deserunt \\
mollit anim id est laborum.
\end{bold_first}

Best Answer

Assuming you do want fixed line ends:

\documentclass{article}
\newcommand\dob[1]{\textbf{#1}}
\newenvironment{boldfirst}{\obeylines\everypar{\dob}}{}
\begin{document}
\begin{boldfirst}
Lorem ipsum dolor sit amet,
consectetur adipisci elit, sed eiusmod
tempor incidunt ut labore
et dolore magna aliqua. Ut enim
ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquid
ex ea commodi consequat. Quis aute
iure reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint obcaecat cupiditat non proident,
sunt in culpa qui officia deserunt
mollit anim id est laborum.
\end{boldfirst}
\end{document}

enter image description here

To make a nice professional job of it, you could also add some spacing before and afterwards, and control the indent of each line.

A little explanation

As explained in the TeXbook (p. 352) the \obeylines macro is defined in plain TeX to make the end-of-line character (0x13, or \^^M) an "active" character, and then to make it equivalent to \par. The effect of this is to make TeX treat each line as a separate paragraph.

You can then customise the exact effect in two ways. You can redefine \par to do something different, or you can use the \everypar mechanism, as I have done above. Normally the \everypar token list is empty, but if you define it to be non-empty then all the tokens in the list are copied into the beginning of every paragraph. See pp. 282-283 of the TeXbook.

If you want to redefine \par then bear in mind the following points:

  • You should redefine it before calling \obeylines
  • TeX saves the original meaning of \par as a command called \endgraf, which can be useful
  • You can combine both techniques

Restrictions

These facilities are part of Plain TeX, and therefore only available to LaTeX in formats that are built on top of Plain TeX (which is most of the normal ones). The TeXbook has a number of examples of how to use \obeylines effectively. As defined above the boldfirst environment will only work at the top level of a document - you could not use it as the argument to another command for example.