Text FormattingNeed help for my diary

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
ckleiner
Posts: 7
Joined: Mon Jan 31, 2022 8:38 pm

Need help for my diary

Post by ckleiner »

I write my diary in LaTeX and for each day, I have a command

\DAY{<title>}{<text for that day>}.

Now I want to create a private and a public version of the diary. In the private version, all text shall be contained.

The public version however, should only feature specific parts.
For that purpose, I’d like to “tag” certain text parts with a command \PUBLIC{<public text>}.
However, I would like to avoid “tagging” every text which is not public with \PRIVATE.{<private text>}. Instead, PRIVATE should be the default for all text not marked with \PUBLIC.

Code: Select all

\documentclass{article}

\newcommand{\DAY}[2]{
	{\bf #1}\\
	#2
}

\newcommand{\PUBLIC}[1]{#1}


\begin{document}

 \DAY{First entry in my diary}{
	This text should be present only in the private version.
	\PUBLIC{Only this text should appear in the public version.}
	This text should be present only in the private version.
}

\end{document}
The above code should output the following:

(1) For the private version:

++++++++++++++
First entry in my diary
This text should be present only in the private version.
Only this text should appear in the public version.
This text should be present only in the private version.
++++++++++++++

(2) For the public version:

++++++++++++++
First entry in my diary
Only this text should appear in the public version.
++++++++++++++

Any help appreciated.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Neridi
Posts: 2
Joined: Wed Sep 21, 2022 2:48 pm

Need help for my diary

Post by Neridi »

I’m not an expert on this, but I’m somewhat doubtful you’ll be able to get around using some sort of indication for which text is supposed to be private. What you’re trying to do, to my understanding, requires LaTeX to do something that would be strange for it to do, hide large areas of text by default.

If you are willing to go with something that involves tagging the private rather than the public parts, you could use conditional switches. In my experience, they are a fairly easy solution to implement and there are good explanations, for example https://ramblingacademic.com/2016/10/31 ... -versions/ or https://stackoverflow.com/questions/571 ... tex-source.

For your specific use case, you could define a switch called PRIVATE (or something even shorter) and use something like this:

Code: Select all

\documentclass{article}

\newif\ifPRIVATE

\PRIVATEfalse % turn on if you don’t want to print the private parts
%\PRIVATEtrue % turn on if you want to print the private parts

\begin{document}

\ifPRIVATE

This is text that should only be present in the private version.

\fi

This text should appear in the public version.

\end{document}
Post Reply