Text FormattingManaging censorship by class of document?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
ygini
Posts: 2
Joined: Mon Aug 08, 2016 6:45 pm

Managing censorship by class of document?

Post by ygini »

Hello

I'm using LaTeX to write confidential documents, for those document I use the traffic light protocol (https://www.us-cert.gov/tlp) manage by 4 different custom classes used to add color and sharing instruction in header and footnote.

Those documents are used for many purpose and I would like to be able to censor some informations of the document based on the current traffic light.

I've found multiple solutions on different forum but nothing who fit my needs for now.

My main problem is, the content to protect can be in a middle of a paragraph or in a table cell, It can be regular text, \verb|| text, or even \url{} text.

My main idea was to use my custom classes to create and renew custom commands (like \GreenSecret, \AmberSecret, \RedSecret) to specify when a block of text must be redacted or not.

What do you think? What would be the best solution and implementation?

I'm new to this level of LaTeX customization so I don't really know what to look as a good source of inspiration. I've only written custom classes for custom look, nothing more.
Last edited by cgnieder on Wed Sep 21, 2016 8:08 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

SteWo
Posts: 1
Joined: Tue Sep 20, 2016 3:07 pm

Managing censorship by class of document?

Post by SteWo »

Hi ygini!

I never had to deal with such a requirement but I would take a look at the ifthenelse-package: Define via \setboolean four 'levels' as boolean variables and use them nested. E.g. like so:

Code: Select all

\setboolean level0 true
\setboolean level1 true
\setboolean level2 false
\setboolean level3 false

...

\ifthenelse level0
{some general text and within:
	\ifthenelse level1
	{some lightly confidential text and within
		\ifthenelse level2
		{some really confidential text and within
			\ifthenelse level3
			{area-51 information}
		}
	}
}
Got the idea? This example's output should only show the text up to what may be shown for levels 0 and 1 but not levels 2 and 3. As this is not actual code you might want to study the relevant documentation.

Hope I could help.

Best
Last edited by cgnieder on Wed Sep 21, 2016 8:09 pm, edited 1 time in total.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Managing censorship by class of document?

Post by cgnieder »

Here is some idea. I hope the code is self-explanatory. Feel free to ask if it isn't:

Code: Select all

\documentclass{article}

\usepackage{etoolbox}

% a counter for the current level of secrecy:
\newcounter{secretlevel}

% a macro for internal book-keeping:
\newcommand*\secretlevels{}

% error message for wrong level names (thinking of typos):
\newcommand*\unknownsecretlevel[1]{%
  \ClassError{myclass}{unknown secret level}{The secret level `#1' is unknown}%
}

% a check if a level is defined:
\newcommand\ifsecretlevelexist[3]{\ifinlist{#1}{\secretlevels}{#2}{#3}}

% a check for the current level:
\newcommand\ifsecretlevel[3]{%
  \ifnumless{\csuse{level-#1}}{\value{secretlevel}+1}
    {#2}
    {#3}%
}

% setting a certain level:
\newcommand*\setsecretlevel[1]{%
  \ifsecretlevelexist{#1}
    {\setcounter{secretlevel}{\csuse{level-#1}}}
    {\unknownsecretlevel{#1}}%
}

% define levels:
\newcommand*\newsecretlevel[2]{%
  \listadd\secretlevels{#1}%
  \csdef{level-#1}{#2}%
}

% print depending on the current level and the specification:
\newcommand*\secret[2]{%
  \ifsecretlevelexist{#1}
    {\ifsecretlevel{#1}{#2}{}}
    {\unknownsecretlevel{#1}}%
}

% define some levels:
\newsecretlevel{Green}{0}
\newsecretlevel{Amber}{1}
\newsecretlevel{Red}{2}

% set default level:
\setsecretlevel{Green}

\begin{document}

\section{Level Green: we only see green}
\secret{Green}{I am green} \par
\secret{Amber}{I am amber} \par
\secret{Red}{I am red}

\section{Level Amber: we see green and amber}
\setsecretlevel{Amber}
\secret{Green}{I am green} \par
\secret{Amber}{I am amber} \par
\secret{Red}{I am red}

\section{Level Red: we see green, amber and red}
\setsecretlevel{Red}
\secret{Green}{I am green} \par
\secret{Amber}{I am amber} \par
\secret{Red}{I am red}

% gives an error:
% \secret{Purple}{I am purple}

\end{document}
Regards
site moderator & package author
Post Reply