开箱即用的方法:使用\hphantom

开箱即用的方法:使用\hphantom

这是代表我在戏剧诗中实现反线性的尝试的 MWE。(我觉得 eledmac 中的实现超出了我的需要。)理想情况下,我希望宏通过“查看”上一行对话来设置间距,但我认为我可能需要学习更多 TeX 才能做到这一点。您认为有没有简单的方法可以做到这一点?

\documentclass{article}
\usepackage{calc}
\makeatletter
\def\@hspace#1{\begingroup\setlength\dimen@{#1}\hskip\dimen@\endgroup}
\makeatother
\newcommand{\cn}[1]{\textsc{#1}}
\newcommand{\labe}[1]{\hspace{\widthof{#1}-\widthof{\cn{Xxx.}}}}

\begin{document}
\setlength{\parindent}{0in}

\cn{Sat}. But who would not lie down here in the meadow\\
\& long daydream on the blossom-stained glade’s\\
Wide \& warm \& welcoming breast?

\cn{Fur}. \labe{Wide \& warm \& welcoming breast?} Please let’s go\\
Into the Deep White Wood as the light fades\\
For this bright pocked \& dappled field abrades\\
The eye!  \& no one wants more songs about...

\end{document}

样品抗病毒

更新:运行良好的解决方案似乎使用页面上的位置而不是要遵循的文本的宽度。例如,egreg 的解决方案可以处理每行多个反唇印:

样品多重抗病毒

答案1

您可以使用。如果出现zref-savepos新的宏,则需要运行两次 LaTeX 。\antilabe

这个宏\antilabe会保存行中最后一个单词的 x 位置,并且在下一个非空行(应该以 开头\cn)中也会保存初始的 x 位置,这样我们就可以发出想要的\hspace(在这种情况下,字符的名称是在零宽度框中排版的)。

\documentclass{article}
\usepackage{zref-savepos,zref-user}

\newif\ifantilabe
\newcounter{antilabe}
\newcommand{\cn}[1]{%
  \par
  \ifantilabe
    \makebox[0pt][l]{\textsc{#1}.}%
    \zsaveposx{antilabe-\theantilabe-b}%
    \hspace{\numexpr\zposx{antilabe-\theantilabe-a}-\zposx{antilabe-\theantilabe-b}\relax sp}%
    \space
  \else
    \textsc{#1.}%
  \fi
  \antilabefalse
}

\newcommand{\antilabe}{%
  \unskip
  \stepcounter{antilabe}%
  \antilabetrue
  \zsaveposx{antilabe-\theantilabe-a}%
}

\newenvironment{dialogue}
 {\par\setlength{\parindent}{0pt}}
 {\par}

\begin{document}

\begin{dialogue}
\cn{Sat} But who would not lie down here in the meadow\\
\& long daydream on the blossom-stained glade’s\\
Wide \& warm \& welcoming breast?\antilabe

\cn{Fur} Please let’s go\\
Into the Deep White Wood as the light fades\\
For this bright pocked \& dappled field abrades\\
The eye!  \& no one wants more songs about...

\cn{Sat} But who would not lie down here in the meadow\\
\& long daydream on the blossom-stained glade’s\\
Wide \& warm \& welcoming breast?\antilabe
\end{dialogue}

\end{document}

在此处输入图片描述

答案2

开箱即用的方法:使用\hphantom

您正在重新实现\hphantom。 (和verse)。 以下产生相同的结果,除了在 verse 环境之前有一些缩进。 您可以通过将其添加到您的序言中来删除它:\AtBeginEnvironment{verse}{\setlength{\leftmargini}{0pt}}

\documentclass{article}
\newcommand{\cn}[1]{\textsc{#1.}}

\begin{document}
\begin{verse}
    \cn{Sat} But who would not lie down here in the meadow\\
    \& long daydream on the blossom-stained glade’s\\
    Wide \& warm \& welcoming breast?

    \cn{Fur} \hphantom{Wide \& warm \& welcoming breast?} Please let’s go\\
    Into the Deep White Wood as the light fades\\
    For this bright pocked \& dappled field abrades\\
    The eye! \& no one wants more songs about\dots{}
\end{verse}

\end{document}

更多自动化解决方案

\hphantom您可以创建一个命令,在第一次使用时存储该文本,然后调用它,而不必重复您想要在参数中偏移的文本。

\documentclass{article}
\NewDocumentCommand{\cn}{ m }{\textsc{#1.}}

\makeatletter
% Define blank dummy text in private command
\NewDocumentCommand{\@thisantilabe}{}{}

% Create a command to store dummy text, and print the text
\NewDocumentCommand{\antilabethis}{ m }{%
    \RenewDocumentCommand{\@thisantilabe}{}{#1}%
    #1%
}

% Insert horizontal space, using either stored dummy text, or the optional
% argument if provided
\NewDocumentCommand{\antilabe}{ o }{%
    \IfValueTF{#1}
        {\hphantom{#1}}
        {\hphantom{\@thisantilabe}}%
}
\makeatother

\begin{document}
\begin{verse}
    \cn{Sat} But who would not lie down here in the meadow \\
    \& long daydream on the blossom-stained glade’s \\
    \antilabethis{Wide \& warm \& welcoming breast?} % mark the text 

    \cn{Fur} \antilabe{} Please let’s go \\
    Into the Deep White Wood as the light fades \\
    For this bright pocked \& dappled field abrades \\
    The eye! \& no one wants more songs about\dots{}

    \antilabethis{\cn{Knuth} expanding macros---} \\
    \antilabe{} but still no one wants \\
    to set the type by hand \\

    \cn{Lamport}
    \antilabe[to set the type by hand] so we keep using \\
    software built in nineteen eighty-two.
\end{verse}

\end{document}

在此处输入图片描述

答案3

只是为了好玩。别忘了运行两次。

\documentclass{article}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\newcounter{markindex}
\newcommand{\eol}{\stepcounter{markindex}\tikzmark{eol\themarkindex}\par}

\newcommand{\cn}[1]{\tikz[remember picture, baseline=(origin)]{\coordinate (origin) at (0,0);
  \node[inner sep=0pt, anchor=base west]{\textsc #1.};
  \coordinate (eol) at (pic cs:eol\themarkindex);
  \path(origin -| eol);}}

\begin{document}
\setlength{\parindent}{0in}\rlap{\tikzmark{eol0}}%

\cn{Sat} But who would not lie down here in the meadow
\& long daydream on the blossom-stained glade’s
Wide \& warm \& welcoming breast?\eol

\cn{Fur} Wide \& warm \& welcoming breast? Please let’s go
Into the Deep White Wood as the light fades
For this bright pocked \& dappled field abrades
The eye!  \& no one wants more songs about...\eol

\end{document}

答案4

以下是使用纯 LaTeX 环境的解决方案tabbing:记住当前位置 ( \=),开始新行,排版标签,然后跳转到记住的位置 ( \>)。

\documentclass{article}
\newcommand\cn[1]{\textsc{#1}.}
\begin{document}
\begin{tabbing}
\cn{Sat}  But who would not lie down here in the meadow\\
\& long daydream on the blossom-stained glade’s\\
Wide \& warm \& welcoming breast? \=\\
\cn{Fur}\>Please let’s go\\
Into the Deep White Wood as the light fades\\
For this bright pocked \& dappled field abrades\\
The eye!  \& no one wants more songs about...
\end{tabbing}
\end{document}

在此处输入图片描述

相关内容