1

I tried to wrote the code of an environment for acrostics, using cenverse and boldfirst, but it doesn't work (probably because cenverse use // and boldfirst not).

\newcommand\dob[1]{\textbf{#1}}
\newenvironment{boldfirst}{\obeylines\everypar{\dob}}{}

\newenvironment{acrostic}[1]
{
    \begin{midpage}

        \def\cenverse#1\\{\settowidth{\versewidth}{#1}\begin{verse}[\versewidth]#1\\}

            \begin{boldfirst}
            }{
            \end{boldfirst}

        \end{verse}

    \end{midpage}

    \newpage
}

The final result must be one acrostic in the centre of every page, with the first letter of every line in bold. Each first letter must be aligned with the upper and the lower letters.

Example of the use:

\documentclass[a4paper,oneside]{book}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}

\usepackage{verse}
\usepackage{midpage}
\usepackage{microtype}

\newcommand\dob[1]{\textbf{#1}}
\newenvironment{boldfirst}{\obeylines\everypar{\dob}}{}


\newenvironment{acrostic}[1]
{
    \begin{midpage}

        \def\cenverse#1\\{\settowidth{\versewidth}{#1}\begin{verse}[\versewidth]#1\\}

            \begin{boldfirst}
            }{
            \end{boldfirst}

        \end{verse}

    \end{midpage}

    \newpage
}

\begin{document}

\begin{acrostic}
Elizabeth it is in vain you say
Love not—thou sayest it in so sweet a way:
In vain those words from thee or L.E.L.
Zantippe's talents had enforced so well:
Ah! if that language from thy heart arise,
Breath it less gently forth—and veil thine eyes.
Endymion, recollect, when Luna tried
To cure his love—was cured of all beside—
His follie—pride—and passion—for he died.
\end{acrostic}

\end{document}
3

1 Answer 1

5

An easy change in my code for your similar question allows to get the widest line for setting \versewidth (actually, there will be a tiny offset due to the bold first letter, but it's negligible).

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{environ,expl3,verse,midpage}

\ExplSyntaxOn
\NewEnviron{boldfirst}{%
  \user_boldfirst:V \BODY
}

\seq_new:N \l__user_lines_seq
\seq_new:N \l__user_aline_seq
\tl_new:N \l__user_firstword_tl
\cs_new_protected:Npn \user_boldfirst:n #1
 {
  \seq_set_split:Nnn \l__user_lines_seq { \\ } { #1 }
  \dim_zero:N \versewidth
  \seq_map_inline:Nn \l__user_lines_seq
   {
    \hbox_set:Nn \l_tmpa_box { ##1 }
    \dim_compare:nT { \box_wd:N \l_tmpa_box > \versewidth }
     { \dim_set:Nn \versewidth { \box_wd:N \l_tmpa_box } }
   }
  \begin{verse}[\versewidth]
  \seq_map_function:NN \l__user_lines_seq \__user_bolden_line:n
  \end{verse}
 }
\cs_generate_variant:Nn \user_boldfirst:n { V }

\cs_new_protected:Npn \__user_bolden_line:n #1
 {
  \seq_set_split:Nnn \l__user_aline_seq {~} { #1 }
  \seq_pop_left:NN \l__user_aline_seq \l__user_firstword_tl
  \__user_print_first:V \l__user_firstword_tl
  \seq_use:Nn \l__user_aline_seq { ~ } \\
 }
\cs_new_protected:Npn \__user_print_first:n #1
 {
  \int_compare:nTF { \tl_count:n { #1 } == 1 }
   {
    \textbf{#1} ~ %
   }
   {
    \__user_bfkern:nnw #1 \q_stop
   }
 }
\cs_generate_variant:Nn \__user_print_first:n { V }

\cs_new_protected:Npn \__user_bfkern:nnw #1 #2 #3 \q_stop
 {
  \hbox_set:Nn \l_tmpa_box { #1 #2 }
  \hbox_set:Nn \l_tmpb_box { #1 \kern0pt #2 }
  \textbf{#1}\kern\dim_eval:n { \box_wd:N \l_tmpa_box - \box_wd:N \l_tmpb_box } 
  #2 #3 ~ %
 }

\ExplSyntaxOff

\begin{document}

\begin{midpage}

\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. \\
{\^{E}}xcepteur sint obcaecat cupiditat non proident, \\
sunt in culpa qui officia deserunt \\
mollit anim id est laborum. \\
T{}o show kern \\
To show kern \\
A problem is not here
\end{boldfirst}

\end{midpage}
\end{document}

enter image description here

10
  • If I add this [ goo.gl/eGktXs ] after \ExplSyntaxOff and then I use \begin{acrostic} ...acrostic... \end{acrostic}, why it doesn't work?
    – ᴜsᴇʀ
    Jul 21, 2014 at 10:01
  • @user Because you're not defining an environment correctly.
    – egreg
    Jul 21, 2014 at 10:23
  • This [ goo.gl/hjJM0M ] is correct, I think, but it doesn't work anyway.
    – ᴜsᴇʀ
    Jul 21, 2014 at 11:20
  • @user That seems correct, but "it doesn't work" means too little.
    – egreg
    Jul 21, 2014 at 11:52
  • It returns error like this LaTeX Error: \begin{boldfirst} on input line 121 ended by \end{ac rostic}., LaTeX Error: \begin{midpage} on input line 143 ended by \end{docu ment}., etc. and the result is all the acrostics in a single page.
    – ᴜsᴇʀ
    Jul 21, 2014 at 12:08

You must log in to answer this question.

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