# Programming with LaTeX xkeyval

I have assigned to do the following task. Since I am not good at Latex I am wondered its possibilities.

I would like to assign parameter while developing document. EX:

file1.tex

\chapter chapter_name1 [arg1=true]or [arg1]


file2.tex

\chapter chapter_name2 [arg1][arg2]
\include<file3> (here it should go to file3.tex and again checks there relevant argument in order to include correct chapter/section)


file3.tex

\section chapter_name1 [arg2][arg3]
\subsection sunsection_name [arg4]


myfile.tex

it has some loops and parser to split input parameters in order to include relevant files.

At time of compiling at terminal I should decide(by passing arguments) which chapter will be inserted into myfile.pdf file. EX:

pdflatex "\def \parameter {arg2 arg3} input{myfile.tex}"

Then myfile.pdf should have

chapter_name2
section_name1


I have heard about xargs and xkeyval packages but I hardly understand it. Still I am not sure how it will help me. Is my task possible? If so, please suggest me what I should do?

To avoid confusions i have modified the question.

I have large set of contends for the user. For 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 is show able to which kind of user by setting argument to true or false.

if user1==true then it should be there in user1.pdf

for example

Macro is (ex): \Modifiedchapter [bool arg1][bool arg2][bool arg3]

\Modifiedchapter <chapterName1> [user1==true][user2==false][user3==false]

\Modifiedchapter <chapterName2> [user1==true][user2==true][user3==false]

\Modifiedsection <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?

• If the \include feature is used, then package askinclude asks on the terminal during compilation which include files are to be used. – Heiko Oberdiek Apr 7 '13 at 21:23

It is a good idea not to change the syntax of standard commands such as \chapter and \section. Although LaTeX allows you to refine any part of the system, taking advantage of that flexibility will make your document fragments hard to process in any other context.

You are already using \include which is designed to support partial compilation which appears to be your real use case.

When using \include you should not use the file extension, you should just use

\include{file3}


Otherwise LaTeX will not find the relevant aux files.

adding \includeonly{file3} (which can be done via a command line similar to your example, or just added to your main file) will cause file3 to be included and any other files referenced via \include to be skipped.

• Hi Thanks for the reply. My question is different. I mean when ever /include command comes the program should checks it content and decide which part should go to myfile.pdf. – BusyBee Apr 8 '13 at 11:29
• @umaraman I realise that is what you meant but what I mean is that it is unnecessarily complicated to use \include which is just there to support compilation of document fragments and then try to redefine it to use a different syntax for almost identical behaviour. If you want exactly the behaviour you describe, don't use the standard commands \chapter, \section \include use your own commands that you can define any way you need. Also although you have tagged this as xkeyval that refers to a syntax of the form key=value with an = but your suggested syntax does not use that form. – David Carlisle Apr 8 '13 at 11:37
• If I understood you right, you can define a set of ifs in the preamble and build the compilation options based on them. – cacamailg Apr 8 '13 at 12:54
• @cacamailg no I mean why not use the file based system that is built into latex where you customise what is in/out based on which file it is in rather than by a section label. (It is much easier, and already implemented in the latex format) to do the former. – David Carlisle Apr 8 '13 at 13:22
• You can use both approaches... Something like: \ifTestA \include{TestA} \else \include{TestB}. – cacamailg Apr 8 '13 at 13:34