3

I have some documents where certain text may need to be hidden (whiteout). The text is often in large blocks that span multiple lines. The removed text needs to take up the same space as it would if the text was present. Setting the text to white is not acceptable.

I have investigated the censor package, but the xblackout command does not work across environments, but it is common for this text to include \gls commands.

I have tried the solution below posted here: Censor text spanning multiple lines

However, when a glossary item is encountered, the following error is reported:

! Package glossaries Error: Glossary entry `{AC}' has not been defined.

It seems as if \gls needs to be first expanded, but my understanding is \gls is not fully expandable. Any ideas for censoring \gls items would be greatly appreciated.

A M(non)WE is provided below.

\documentclass{article}
\usepackage{soul}
\usepackage{glossaries}

\makeglossaries
\newacronym{AC}{AC}{Alternating Current}

\makeatletter

\DeclareRobustCommand*\secret{%
    \SOUL@setup%
    \def\SOUL@everytoken{{\phantom{\the\SOUL@token}}}%
    \def\SOUL@everyhyphen{%
        \discretionary{%
            \SOUL@setkern\SOUL@hyphkern%
            \phantom{\SOUL@sethyphenchar}%
        }{}{}%
    }%
    \def\SOUL@everyexhyphen##1{%
        \SOUL@setkern\SOUL@hyphkern%
        \hbox{\phantom{##1}}%
        \discretionary{}{}{%
            \SOUL@setkern\SOUL@charkern%
        }%
    }%
    \SOUL@%
}
\makeatother

\begin{document}

This is some text. Some of this text is to be hidden, but the whitespace should be retained. Some of the text to be hidden may include glossary items, such as \gls{AC}. Foo.

\glsresetall

This is some text. \secret{Some of this text is to be hidden, but the whitespace should be retained. Some of the text to be hidden may include glossary items, such as \gls{AC}}. Foo.

\printglossary

\end{document}

2 Answers 2

1

Proof of concept. Insensitive to definitions.

\documentclass{article}
\usepackage{soul}
\usepackage{glossaries}

\makeglossaries
\newacronym{AC}{AC}{Alternating Current}

\makeatletter
\let\glsorig\gls
\DeclareRobustCommand*\secret{%
  \begingroup
    \def\gls##1{\phantom{##1}}%
    \SOUL@setup%
    \def\SOUL@everytoken{{\phantom{\the\SOUL@token}}}%
    \def\SOUL@everyhyphen{%
        \discretionary{%
            \SOUL@setkern\SOUL@hyphkern%
            \phantom{\SOUL@sethyphenchar}%
        }{}{}%
    }%
    \def\SOUL@everyexhyphen##1{%
        \SOUL@setkern\SOUL@hyphkern%
        \hbox{\phantom{##1}}%
        \discretionary{}{}{%
            \SOUL@setkern\SOUL@charkern%
        }%
    }%
    \SOUL@%
  \endgroup
}
\newcommand*\restoregls{\let\gls\glsorig}
\makeatother

\begin{document}
This is some text. Some of this text is to be hidden, but the whitespace should be retained. Some of the text to be hidden may include glossary items, such as \gls{AC}. Foo.

\glsresetall

This is some text. \secret{Some of this text is to be hidden, but the whitespace should be retained. Some of the text to be hidden may include glossary items, such as \gls{AC}}. Foo.

\restoregls

\gls{AC}

\printglossary

\end{document}

missing acronyms

3
  • thanks for the solution. However, it does not accomplish what I am looking for. The text after "This is some text." should not show in the 2nd block. Also, the \gls part should take the full entry width (if it was the first use). I came up with a solution that seems to work.
    – Kent A.
    Jun 6, 2017 at 3:12
  • @KentA. Hence the 'Proof of concept. Insensitive to definitions.'
    – cfr
    Jun 6, 2017 at 3:15
  • @KentA. You should post your solution as an answer. You should probably accept it if you're happy with it, too. Otherwise, post it but don't accept and see if somebody else comes up with something better.
    – cfr
    Jun 6, 2017 at 3:16
1

After trying several things, I found that the key is to register the commands with soul. Here, I register \gls, \ref, \cite, and \pageref with the \soulregister command. Looks like the space before "Foo" is larger on the second paragraph, but hopefully that should be a simple fix.

Here is a working example:

\documentclass{article}
\usepackage{soul}
\usepackage{glossaries}

\makeglossaries

\soulregister\cite7
\soulregister\ref7
\soulregister\pageref7
\soulregister\gls7

\newacronym{AC}{AC}{Alternating Current}

\makeatletter
\DeclareRobustCommand*{\secret}{%
    \SOUL@setup%
    \def\SOUL@everytoken{{\phantom{\the\SOUL@token}}}%
    \def\SOUL@everyhyphen{%
        \discretionary{%
            \SOUL@setkern\SOUL@hyphkern%
            \phantom{\SOUL@sethyphenchar}%
        }{}{}%
    }%
    \def\SOUL@everyexhyphen##1{%
        \SOUL@setkern\SOUL@hyphkern%
        \hbox{\phantom{##1}}%
        \discretionary{}{}{%
            \SOUL@setkern\SOUL@charkern%
        }%
    }%
    \SOUL@%
}
\makeatother

\begin{document}
This is some text. Some of this text is to be hidden, but the whitespace should be retained. Some of the text to be hidden may include glossary items, such as \gls {AC}. Foo.

\glsresetall

This is some text. \secret{Some of this text is to be hidden, but the whitespace should be retained. Some of the text to be hidden may include glossary items, such as \gls{AC}}. Foo.

\gls{AC}

\printglossary

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .