我想用\\
(或)包中的\newline
宏隐藏一些包含换行符的文本,但失败了——隐藏的部分根本没有换行符,请参阅附图。但在隐藏文本中可以很好地工作。\blackout
censor
\par
\blackout
我的问题是:如何使用(或)制作\blackout
支持文本。\\
\newline
另一个问题:\blackout{\lipsum[1]}
造成故障。为什么?
梅威瑟:
\documentclass{article}
\usepackage{censor,lipsum,geometry}
\geometry{showframe}
\begin{document}\parindent=0pt\noindent\noindent
|some\\ text|\\
|\blackout{some\\ text}|%typeset has not line feed.
%\blackout{\lipsum[1]} %Wrong use, why?
\end{document}
答案1
正如我在另一个帖子中向 OP 解释的那样,我正在努力censor
改进以解决换行问题。事实上,它解决了宏的一般问题。虽然为时过早,但我还是将其作为\makeatother
代码包含在内。
它使用tokcycle
伪环境来处理输入。在提供的机制下,宏只是通过,不受审查。但是,如果宏完全可扩展,则可以使用,\expanded{<\macro>}
并且将对扩展的内容应用审查。
对于 OP 的 lipsum 问题,\lipsum
是不可扩展的,因此,它不能被审查为\blackoutenv
或的参数\xblackoutenv
。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{censor,lipsum,lmodern}
\usepackage{tokcycle}[2021/03/10]
\makeatletter
\newif\ifexpandarg
\def\@dump#1{\addcytoks[1]{\expandafter\censor\expandafter{#1}}\def#1{}}
\def\spacelap{.6ex}
\def\censpace{\rlap{\censorrule{\spacelap}} \llap{\censorrule{\spacelap}}}
\def\@append#1#2{\tc@defx#1{#1#2}}
\xtokcycleenvironment\xblackoutenv
{\@append\censored@word{##1}}
{\tctestifcon\ifexpandarg{\expandafter\processtoks\expandafter{\expanded{##1}}}%
{\processtoks{##1}}\@dump\censored@word\expandargfalse}
{\@dump\censored@word\tctestifx{~##1}{\@append\censored@word{##1}}%
{\tctestifx{\expanded##1}{\expandargtrue}{\addcytoks{##1}}}}
{\@dump\censored@word\addcytoks{\censpace}}
{\def\censored@word{}}
{\@dump\censored@word}
\xtokcycleenvironment\blackoutenv
{\@append\censored@word{##1}}
{\tctestifcon\ifexpandarg{\expandafter\processtoks\expandafter{\expanded{##1}}}%
{\processtoks{##1}}\@dump\censored@word\expandargfalse}
{\@dump\censored@word\tctestifx{~##1}{\@append\censored@word{##1}}%
{\tctestifx{\expanded##1}{\expandargtrue}{\addcytoks{##1}}}}
{\@dump\censored@word\addcytoks{##1}}
{\def\censored@word{}}
{\@dump\censored@word}
\makeatother
\begin{document}
\parindent=0pt\noindent\noindent
|some\\ text |\\
|\blackoutenv
some\\text
\endblackoutenv|
\blackoutenv
today is \today
today is \expanded{\today}
\endblackoutenv
\xblackoutenv
today is \today
today is \expanded{\today}
\endxblackoutenv
but lipsum is not expandable
\end{document}