颜色直到换行符(不使用 luatex)

颜色直到换行符(不使用 luatex)

我需要创建一个基于\color这样的结果的 命令在此处输入图片描述

\documentclass{article}
\usepackage{xcolor}

% \def\costumcol#1{.....}

\begin{document}

sample text sample text sample text sample text sample text 
sample text sample text sample text \costumcol{red} sample text 
sample text sample text sample text sample text sample text 

\hsize=.8\textwidth

sample text sample text sample text sample text sample text 
sample text sample text sample text \costumcol{red} sample text 
sample text sample text sample text sample text sample text 

\end{document}

答案1

这实际上并不是颜色包的设计目的,并且也不是完全健全,但是......

在此处输入图片描述

\documentclass{article}
\usepackage{xcolor}
\makeatletter
\def\costumcol#1{{\let\aftergroup\@gobble\color{#1}}\vadjust{\reset@color}}
\makeatother
\begin{document}

sample text sample text sample text sample text sample text 
sample text sample text sample text \costumcol{red} sample text 
sample text sample text sample text sample text sample text 

\hsize=.8\textwidth

sample text sample text sample text sample text sample text 
sample text sample text sample text \costumcol{red} sample text 
sample text sample text sample text sample text sample text 

\end{document}

相关内容