诗歌音节间的韵律

诗歌音节间的韵律

为了在音节之间添加模糊的、非字距调整的线,是否有办法让命令检测它是否与空格相邻,如果是,则 (a) 恢复空格,然后 (b) 将小节放在中间?(或者,用户可以在空格之间放置 \m,例如to be, \m or not \m to be,在这种情况下,代码应该检测到这一点并后退半个空格来放置小节。)

伪代码:

我是否与某个空间相邻?

  • Y:恢复空间(我已经通过进入它前面并作为命令而破坏了它),并将 bar 放在该空间的中间

  • N:在字母之间放置条形图,而不会影响字母间距

     \documentclass[varwidth]{standalone}
     \usepackage{xcolor}
    
     \newcommand\m{%
      {%
       \color{gray!50}%
       \rule[-\dp\strutbox]{0.3pt}%
       {\baselineskip}%
      }%
     }%
    
     \begin{document}
    
     \noindent To be,\m or not\m to be,\m that is\m the question:\\
     Whether\m 'tis nob\m ler in\m the mind\m to suffer\\
     The slings\m and ar\m rows of\m outrage\m ous fortune,\\
     Or to\m take arms\m against\m a sea\m of troubles
    
     \end{document}
    

答案1

在此处输入图片描述

 \documentclass[varwidth]{standalone}
 \usepackage{xcolor}
\makeatletter
% just do this locally if you need | for tables or tikz etc
\catcode`\|\active 
 \newcommand|{\futurelet\poetry@tmp\poetry@bar}

\newcommand\poetry@bar{%
    \ifhmode\unskip\fi
    \ifx\poetry@tmp\@sptoken
     % half word space see
     % https://tex.stackexchange.com/questions/88991/what-do-different-fontdimennum-mean/
     \hskip.5\fontdimen2\font\@plus.5\fontdimen3\font\@minus.5\fontdimen4\font
    \fi
   {\color{gray!50}%
   \rule[-\dp\strutbox]{0.3pt}%
   {\baselineskip}}%
       \ifx\poetry@tmp X\fi
    \ifx\poetry@tmp\@sptoken
     % half word space
     \hskip.5\fontdimen2\font\@plus.5\fontdimen3\font\@minus.5\fontdimen4\font
    \fi
   \ignorespaces
}  

\makeatother
 \begin{document}
\setlength\parskip{0pt}

 To be,| or not| to be,| that is| the question:\\
 Whether| 'tis nob|ler in| the mind| to suffer\\
 The slings| and ar|rows of| outrage|ous fortune,\\
 Or to| take arms| against| a sea| of troubles

 \end{document}

|比 更容易输入,\m并且可以避免丢失空格,因此您可以使用\futurelet

相关内容