首字母缩略词环境

首字母缩略词环境

我尝试编写一个环境代码首字母缩略词, 使用森弗斯大胆第一,但它不起作用(可能是因为森弗斯使用//大胆第一不是)。

\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
}

最终结果必须是每页中央的一首首字母诗,每行首字母均以粗体显示。每个首字母必须与大写字母和小写字母对齐。

使用示例:

\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}

答案1

针对您的类似问题,对我的代码进行简单更改即可获得最宽的设置线\versewidth(实际上,由于首字母粗体,会有微小的偏移,但可以忽略不计)。

\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}

在此处输入图片描述

相关内容