2

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 and user3 as 'True', then my output should contain

command (ex) : \def\arg1=true, arg2=false, arg1=true \input{myfile}

chapterName1

sectionName1

How can I do this?

6
  • For 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? Apr 8, 2013 at 13:03
  • Hi, For the false condition "the whole section should not be shown"
    – BusyBee
    Apr 8, 2013 at 13:40
  • I have edited my question. I guess it will be more clear. Thanks
    – BusyBee
    Apr 8, 2013 at 13:58
  • @umaraman It reminds me of one of my question tex.stackexchange.com/questions/79522/…
    – karathan
    Apr 8, 2013 at 14:31
  • Let'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?] Apr 8, 2013 at 15:02

1 Answer 1

2

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.

You must log in to answer this question.

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