\documentclass[12pt,a4paper]{article}
\def\rehbox{{\unskip\unpenalty\setbox0\lastbox\ifhbox0 \rehbox
\hbox{\unhbox0} \else \leavevmode \fi}}
\newcommand\printhyphens[1]{%
\setbox0\vbox{{%
\pretolerance-1\hsize=0pt\hfuzz=\maxdimen
\noindent\hspace*{0pt}#1\par\rehbox}\par}%
\unvbox 0
}
\begin{document}
\printhyphens{If you cannot reconsider this proposal, you are
incompatible, my dearest friend.}
\end{document}
是否可以构造一个\printhyphs
执行以下操作的宏:
\documentclass[12pt,a4paper]{article}
<hyphenfile = my-path/sillyhyphens.txt>
\begin{document}
\printhyphs{If you cannot}
\printhyphs{reconsider this proposal, you are}
\printhyphs{incompatible, my dearest friend.}
\end{document}
运行 (pdf|xe)latex 将创建一个文件:my-path/sillyhyphens.txt
,包含:
If you can- not
re- con- sid- er this pro- pos- al, you are
in- com- pat- i- ble, my dear- est friend.
符号后面是否-
有空格并不重要。
答案1
基于包的解决方案被实现为驱动程序soul
,用于收集宏中的音节和连字点,并将其写入到末尾的输出文件中:\printhyphs
soul
\printhyphs@line
\printhyphs
\SOUL@postamble
\documentclass{article}
\usepackage{soul}
\makeatletter
\newwrite\printhyphs@out
\immediate\openout\printhyphs@out=sillyhyphens.txt\relax
\DeclareRobustCommand*{\printhyphs}{%
\SOUL@setup
\def\SOUL@preamble{%
\global\let\printhyphs@line\@empty
}%
\def\SOUL@everyspace##1{%
\g@addto@macro\printhyphs@line{ }%
}%
\def\SOUL@everysyllable{%
\expandafter\g@addto@macro\expandafter\printhyphs@line
\expandafter{\the\SOUL@syllable}%
}%
\def\SOUL@everyhyphen{%
\g@addto@macro\printhyphs@line{- }%
}%
\def\SOUL@everyexhyphen##1{%
\g@addto@macro\printhyphs@line{##1}%
}%
\def\SOUL@postamble{%
\immediate\write\printhyphs@out{\printhyphs@line}%
}%
\SOUL@
}
\begin{document}
\printhyphs{If you cannot}%
\printhyphs{reconsider this proposal, you are}%
\printhyphs{incompatible, my dearest friend.}%
\end{document}
文件sillyhyphens.txt
中写入以下几行:
If you can- not
re- con- sider this pro- posal, you are
in- com- pat- i- ble, my dear- est friend.
答案2
tugboat 上会不时发布“连字符异常日志”(更新)。最近一次是在第33卷,第1期. 完整列表以拖船文章文件的形式tb0hyf.tex
发布到 ctan,连同其.pdf
输出一起作为hyphenex
包裹。
使用“showhyphens”例程来生成此列表;代码位于文章.tex
文件中,应该能够适应您所想的目的。