有人能帮助我改进这个命令吗?
\def\mydots{\leavevmode\xleaders\hbox to 0.40em{\hfil.\hfil}\hfill\kern0pt}
我一直用它来填充右边和左边单词之间的空格。但是,当我开始在水平宽度较小的环境中使用它时(这需要换行),它就开始断线了。
以下内容使用以下方式创建:
\begin{itemize}
\item First Line \mydots \textit{10 km}
\item Second line \mydots \textit{20 meters}
\item Another entry \mydots \textit{10 dollars}
\item Some longer distance$^1$ \mydots \textit{20 goals}
\item Time for parentheses (+1L) \mydots \textit{20 liters}
\item Time for zero parenthesees \mydots \textit{20 liters}
\item Time for a really lengthy sentence \mydots \textit{40 euros}
\item Now-hyphened sentence \mydots \textit{10 doors}
\item Now-hyphened but really long sentence \mydots \textit{20 points}
\item another short \mydots \textit{5 verses}
\item Last one for now$^1$ \mydots \textit{30 days}\\ \rule{0 pt}{0in}$^1$\textit{Sample footnote causing no known issue}
\end{itemize}
正如您所看到的,我的标准用例是一些文本后跟\mydots
一些斜体文本(但并非总是如此,我希望在任何情况下都能做到这一点)。我的困难是,我希望在不修改其实现的情况下改进此命令,它是我的 .cls 的一部分,需要手动更改数百个文件。
本质上我想要发生的事情是,所有 \mydots 后面的文本都需要被强制放到一行中,并在需要时对 \mydots 之前的文本进行换行,使得至少部分前面的单词落在带有点的行上。
我认为这可以通过欺骗 latex 使其认为 \mydots 后面的所有文本都是一个单词来实现。但我不确定如何做到这一点。
答案1
一点胶水平衡....
\documentclass{article}
\def\mydots{\futurelet\mytmp\xmydots}
\def\xmydots{\ifx\mytmp\textit
\expandafter\xxmydots
\else
\expandafter\xxxmydots
\fi}
\def\xxmydots#1#2{\xxxmydots\mbox{#1{#2}}}
\def\xxxmydots{\leavevmode
\unskip\nobreak\space
\null\nobreak\xleaders\hbox to 0.40em{\hfil.\hfil}\hfill\kern0pt}
\textwidth7cm
\begin{document}
\begin{itemize}\rightskip0pt plus.7\hsize
\item First Line \mydots \textit{10 km}
\item Second line \mydots \textit{20 meters}
\item Another entry \mydots \textit{10 dollars}
\item Some longer distance$^1$ \mydots \textit{20 goals}
\item Time for parentheses (+1L) \mydots \textit{20 liters}
\item Time for zero parenthesees \mydots \textit{20 liters}
\item Time for a really lengthy sentence \mydots \textit{40 euros}
\item Now-hyphened sentence \mydots \textit{10 doors}
\item Now-hyphened but really long sentence \mydots \textit{20 points}
\item another short \mydots \textit{5 verses}
\item Last one for now$^1$ \mydots \textit{30 days}\\ \rule{0 pt}{0in}$^1$\textit{Sample footnote causing no known issue}
\end{itemize}
\end{document}