如何查明手动插入处是否发生中断\discretionary
?
我无法通过在参数中分配来做到这一点\discretionary
——在做出中断决定之前分配已经完成:
\documentclass[a4paper]{article}
\newcommand\addto[2]{%
\xdef#1{\unexpanded\expandafter{#1#2}}%
}%
\parindent=0pt
\begin{document}
\def\test{}
\discretionary{\addto\test1wa-}{ter}{\addto\test2water}
\test
\def\test{}
\null\space\hskip\dimexpr\textwidth-5mm\relax
\discretionary{\addto\test1wa-}{ter}{\addto\test2water}
\test
\end{document}
答案1
\discretionary
的参数全部执行,以便 TeX 可以使用换行和不换行的框。需要这些框的测量值来决定段落换行时哪种排列看起来最好。
如果你尝试通过的参数做一些有趣的事情\discretionary
,那么你可能很容易得到一个关于! Improper discretionary list.
如果你不介意测试机制进行多次编译,你可以使用参考值带模块保存位置用于保存坐标并比较操作前后的情况\discretionary
。
\documentclass[a4paper]{article}
\usepackage[savepos]{zref}
\parindent=0pt
\begin{document}
\leavevmode\zsavepos{beforeA}%
\discretionary{wa-}{ter}{water}%
\zsavepos{afterA}%
\ifnum\zposy{beforeA}=\zposy{afterA}No \else A \fi break occurred.
\leavevmode\space\hskip\dimexpr\textwidth-5mm\relax
\zsavepos{beforeB}%
\discretionary{wa-}{ter}{water}%
\zsavepos{afterB}%
\ifnum\zposy{beforeB}=\zposy{afterB}No \else A \fi break occurred.
\end{document}
如果你不想每个标签有两个,\discretionary
你可以使用TikZ/pgf用于保存坐标并在执行之前和之后进行比较\discretionary
。这也需要多次 LaTeX 运行才能匹配。(内部 TikZ/pgf 还\pgfsyspdfmark
通过 .aux 文件为每个事物创建某种标签(这些事物),例如\coordinate
,环境的不同实例tikz
应记住这些标签。)
\documentclass[a4paper]{article}
\RequirePackage{tikz}%
\usetikzlibrary{math}%
\newlength\scratchy
\parindent=0pt
\begin{document}
\leavevmode\begin{tikzpicture}[overlay, remember picture]%
\coordinate (before) at (0,0) ;
\end{tikzpicture}%
\discretionary{wa-}{ter}{water}%
\begin{tikzpicture}[overlay, remember picture]%
\coordinate (after) at (0,0) ;
\tikzmath{coordinate \vectoritchy;
\vectoritchy = (before)-(after);
\scratchy = (\vectoritchyy);
}%
\global\scratchy\scratchy
\end{tikzpicture}%
\ifdim\scratchy=0pt No \else A \fi break occurred.
\leavevmode\null\space\hskip\dimexpr\textwidth-5mm\relax
\begin{tikzpicture}[overlay, remember picture]%
\coordinate (before) at (0,0) ;
\end{tikzpicture}%
\discretionary{wa-}{ter}{water}%
\begin{tikzpicture}[overlay, remember picture]%
\coordinate (after) at (0,0) ;
\tikzmath{coordinate \vectoritchy;
\vectoritchy = (before)-(after);
\scratchy = (\vectoritchyy);
}%
\global\scratchy\scratchy
\end{tikzpicture}%
\ifdim\scratchy=0pt No \else A \fi break occurred.
\end{document}
!!! 这些方法破坏了连字和字距调整等等 !!!