Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LaTeX: \reviewbreakall のようなナニカ
\documentclass{article}
\makeatletter %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code BEGIN
\newif\ifreview@ba@break
\def\review@ba@end{\review@ba@end@}
\DeclareRobustCommand{\reviewbreakall}[1]{%
\begingroup
\review@ba@breakfalse
\review@break@all@a#1\review@ba@end
\endgroup
}
\def\review@break@all@a{%
\futurelet\review@ba@tok\review@break@all@b
}
\def\review@break@all@b{%
\ifx\review@ba@tok\review@ba@end
\let\next\@gobble
\else\ifx\review@ba@tok\@sptoken
\let\next\review@break@all@c
\else\ifx\review@ba@tok~%
\let\next\review@break@all@d
\else\ifx\review@ba@tok\bgroup
\let\next\review@break@all@e
\else
\let\next\review@break@all@f
\fi\fi\fi\fi
\next
}
\expandafter\def\expandafter\review@break@all@c\space{%
\space
\review@ba@breakfalse
\review@break@all@a
}
\def\review@break@all@d#1{%
\review@break@all@f{\mbox{\space}}%
}
\def\review@break@all@e#1{%
\review@break@all@f{{#1}}%
}
\def\review@break@all@f#1{%
\ifreview@ba@break
\hskip0pt plus 0.02em\relax
\fi
#1%
\review@ba@breaktrue
\review@break@all@a
}
\makeatother %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code END
\begin{document}
\parbox{100pt}{\ttfamily\reviewbreakall{%
Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.
}%
}
\end{document}
@zr-tex8r

This comment has been minimized.

Copy link
Owner Author

commented Mar 15, 2019

  • 各文字の間に \hskip0pt plus 0.02em\relaxを挿入して出力する
  • ただし空白トークンを読んだ場合は\spaceを実行
    • だから空白は行分割可能になり、行分割すると空白は消える
  • グループ{...}はそのまま一かたまりで出力する
  • ~を読んだ場合も空白を出力し、この空白は行分割可能で、かつ行末行頭にあっても消えない

仕様変更の要望があればZRさんに言いましょう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.