Enable and disable contents of \chapter command
You can start from here. The methods below feature the environ
package to skip content, but you could also try to use the comment
package for this purpose.
\documentclass[openany]{scrbook}
\usepackage{environ}
\usepackage{pdftexcmds}
\newcommand{\username}{user1}
\makeatletter
\NewEnviron{condchapter}[2][user]{
\ifnum\pdf@strcmp{#1}{\username}=\z@
\chapter{#2}
\BODY
\else
\fi
}
\makeatother
\begin{document}
\begin{condchapter}[user1]{Title-1}
Some text.
\end{condchapter}
\begin{condchapter}[user2]{Title-2}
Some text.
\end{condchapter}
\renewcommand{\username}{user2}
\begin{condchapter}[user2]{Title-3}
Some text.
\end{condchapter}
\end{document}
Another possibility with the list of enabled users:
\documentclass[openany]{scrbook}
\usepackage{environ}
\usepackage{xstring}
\newcommand{\username}{user1}
\makeatletter
\NewEnviron{condchapter}[2][user]{
\IfSubStr{#1}{\username}{%
\chapter{#2}
\BODY
}{}
%\else
%\fi
}
\makeatother
\begin{document}
\begin{condchapter}[user1]{Title-1}
Some text.
\end{condchapter}
\begin{condchapter}[user2]{Title-2}
Some text.
\end{condchapter}
\renewcommand{\username}{user2}
\begin{condchapter}[user2, user3]{Title-3}
Some text.
\end{condchapter}
\end{document}
PS: to create all files at once you can start from the answers here
Another possibility is to use only the comment
package for this purpose without the modifications to the chapter
command.
Related videos on Youtube
BusyBee
Updated on August 01, 2022Comments
-
BusyBee over 1 year
I have large set of contents for the user. For a different user I would like to show different contents. For this I would like to produce different output by showing and not showing some of the contents (say chapters sections subsection) of the document.
My Idea is: While writing chapter/section I declare it to enable showing to a specific user by setting argument to true or false. For example,
if (user1 == true) then it should be there in
user1.pdf
More specifically, something like:
Macro is:
\chapter <chapterName1> [bool arg1][bool arg2][bool arg3]
\chapter <chapterName1> [user1==true][user2==false][user3==false] \chapter <chapterName2> [user1==true][user2==true][user3==false] \section <sectionName1> [user1==true][user2==true][user3==true]
If I pass
user1
anduser3
as 'True', then my output should containcommand (ex) :
\def\arg1=true, arg2=false, arg1=true \input{myfile}
chapterName1 sectionName1
How can I do this?
-
Steven B. Segletes over 10 yearsFor a false condition, are you expecting the whole section to be deleted, or merely the invocation of a section header not to occur? Also, I'm not sure I understand the logic involved in your arguments. That is, what argi conditions define an overall true condition?
-
BusyBee over 10 yearsHi, For the false condition "the whole section should not be shown"
-
BusyBee over 10 yearsI have edited my question. I guess it will be more clear. Thanks
-
karathan over 10 years@umaraman It reminds me of one of my question tex.stackexchange.com/questions/79522/…
-
Steven B. Segletes over 10 yearsLet's see if I understand correctly, the
[]
parameters following the chapter/section are the default allowabilities for that chap/sec. At the beginning of the file, or on the command line, you would like to specify the target users for this particular build. What I don't understand is, if user3 is true, he should not get chapterName1, and yet your example shows him getting it. Are you proposing a means to override the defaults? [Also, do you have a typo by mentioning arg1 twice, and arg3 not at all in your "command ex" line?] -
BusyBee over 10 yearsHi Steven Thanks for you reply, Yes you got my idea of allow abilities.I gave two parameters user1 and user3, chapterName1 is allowable to user1 as well thats why output has chapterName1)
-