GeneralSOLVED Multiple versions of a document from one source file

LaTeX specific issues not fitting into one of the other forums of this category.
nieproszenieja
Posts: 9
Joined: Tue Jul 08, 2008 10:25 pm

SOLVED Multiple versions of a document from one source file

Post by nieproszenieja »

Hello,
let's assume, that I have a latex file:

Code: Select all

\documentclass{article}
\begin{document}
\begin{itemize}
\item First item
\item Second item
\end{itemize}
\end{document}
I need to produce from this file three different versions of document, e.g. first version only with first item, second with second item, and third with both of them.
I know, that i can use ifthen package or sed tool to achieve this, but when you have many documents, which differs only in a few places (e.g. uC specification) and the rest is the same, producing them e.g. with Makefile is complicated.
Is there any simpler way, maybe latex built-in functionality, to do this?

Thank you.
nieproszenieja
Last edited by nieproszenieja on Thu Jul 31, 2008 9:55 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.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

SOLVED Multiple versions of a document from one source file

Post by localghost »

Perhaps another topic will help you in finding a solution to this issue [1]. There have been given some interesting approaches.

[1] managed compilation


Best regards and welcome to the board
Thorsten¹
nieproszenieja
Posts: 9
Joined: Tue Jul 08, 2008 10:25 pm

SOLVED Multiple versions of a document from one source file

Post by nieproszenieja »

localghost wrote:Perhaps another topic will help you in finding a solution to this issue [1]. There have been given some interesting approaches.
[1] managed compilation
Thank you for response.

Still I can't write Makefile without sed, which can produce from one source file a few versions of document, although comment package (from 4th post [1]) seems to simplify the task.

So is there any way to include/exclude some parts of source file at build time, without using external tools (like sed) and (maybe) with comment/ifthen package?

Thanks.
nieproszenieja
User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

SOLVED Multiple versions of a document from one source file

Post by T3. »

nieproszenieja wrote:Still I can't write Makefile without sed, which can produce from one source file a few versions of document, although comment package (from 4th post [1]) seems to simplify the task.

So is there any way to include/exclude some parts of source file at build time, without using external tools (like sed) and (maybe) with comment/ifthen package?
I'm not sure what are you trying to achieve exactly. Do you mean activation/deactivation of document fragments without making changes to your source file? If that's the case then you could move the setup of the comment package from the source to the command line like this:

Code: Select all

latex \RequirePackage{comment}\includecomment{commentA}\excludecomment{commentB}\input{yoursource}
Is that what you have in mind?

Cheers,

Tomek
nieproszenieja
Posts: 9
Joined: Tue Jul 08, 2008 10:25 pm

SOLVED Multiple versions of a document from one source file

Post by nieproszenieja »

T3. wrote: I'm not sure what are you trying to achieve exactly. Do you mean activation/deactivation of document fragments without making changes to your source file? If that's the case then you could move the setup of the comment package from the source to the command line like this:

Code: Select all

latex \RequirePackage{comment}\includecomment{commentA}\excludecomment{commentB}\input{yoursource}
Is that what you have in mind?
Yes, this is exactly what I mean - I want to create different versions of document without editing source file, activating/deactivating some parts of source from Makefile or command line.

The command works great. It is possible now, to check in source file wherther commentA and/or commentB and/or comment package were already defined from command line (if not, the default values will be used)?
User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

SOLVED Multiple versions of a document from one source file

Post by T3. »

nieproszenieja wrote:The command works great. It is possible now, to check in source file wherther commentA and/or commentB and/or comment package were already defined from command line (if not, the default values will be used)?
You could have a switch in your source:

Code: Select all

\ifx\commentsetup\undefined
% setup cammands for the comment package
\fi
Then, define '\commentsetup' on the command line to skip the default setup in the source:

Code: Select all

latex \RequirePackage{comment}\includecomment{commentA}\excludecomment{commentB}\let\commentsetup=\relax\input{yoursource}
Alternatively, you could have '\input{commentsetup}' in your preamble and 'commentsetup.tex' file would contain the configuration for the comment package. This file could be easily created from the make file. Then you can compile as usual. Choose whichever solution you prefer.

Cheers,

Tomek
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

SOLVED Multiple versions of a document from one source file

Post by meho_r »

Or maybe try optional package. It is very simple and still very suitable for the job:) Read .sty file for instructions.
nieproszenieja
Posts: 9
Joined: Tue Jul 08, 2008 10:25 pm

SOLVED Multiple versions of a document from one source file

Post by nieproszenieja »

From optional.sty:
"Enable multiple versions of a document to be printed from one source file, especially if most of the text is shared between versions."

Package optional is very similar to comment, but it is more flexible and there is an easier way to declare which parts of source should be activated or deactivated.
It works perfectly. So it's time for a small summary from your posts:

File: optional_example.tex

Code: Select all

\documentclass{article}
\ifx\UseOption\undefined
\def\UseOption{optb}
\fi
\usepackage{optional}
\begin{document}
\begin{itemize}
\opt{opta}{\item First item}
\opt{optb}{\item Second item}
\end{itemize}
\end{document} 
Try to compile this with this commands and compare the results:

Code: Select all

pdflatex -jobname optional_example "\def\UseOption{opta}\input{optional_example}"
pdflatex optional_example.tex
pdflatex -jobname optional_example "\def\UseOption{opta,optb}\input{optional_example}"
For me it's great. Maybe there is a better way, to find out from source file, whether there is a command-line argument for latex/pdflatex or not, but i don't know about it. For me it looks OK.

Thank you all for your help.
Best regards,
nieproszenieja
Last edited by nieproszenieja on Wed Aug 20, 2008 4:43 pm, edited 1 time in total.
User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

SOLVED Multiple versions of a document from one source file

Post by T3. »

The idea to use '\jobname' for variant switching is nice, especially that you also get a differently named document for each variant. Below is a solution that will allow you to keep the setup code for all the variants in your main file.

Code: Select all

\def\DefaultSetup{YourMainFileName}
\ifx\jobname\DefaultSetup
% default settings for optional or comment package
\fi
\def\SetupA{SetupA}
\ifx\jobname\SetupA
% settings for variant A
\fi
[...]
And in your make file it's sufficient to have:

Code: Select all

pdflatex YourMainFileName
pdflatex -jobname=SetupA YourMainFileName
...
Cheers,

Tomek
nieproszenieja
Posts: 9
Joined: Tue Jul 08, 2008 10:25 pm

SOLVED Multiple versions of a document from one source file

Post by nieproszenieja »

T3. wrote:The idea to use '\jobname' for variant switching is nice, especially that you also get a differently named document for each variant. Below is a solution that will allow you to keep the setup code for all the variants in your main file.

Code: Select all

\def\DefaultSetup{YourMainFileName}
\ifx\jobname\DefaultSetup
% default settings for optional or comment package
\fi
\def\SetupA{SetupA}
\ifx\jobname\SetupA
% settings for variant A
\fi
[...]
And in your make file it's sufficient to have:

Code: Select all

pdflatex YourMainFileName
pdflatex -jobname=SetupA YourMainFileName
...
I don't know why, but it doesn't work for me (in \jobname and \Defaultsetup is the same string, I checked this)
Althrough, in both examples you keep all variants in main file (setup "opta", "optb" etc.).
The difference is, that this method is less flexible (you can't change output file name) and you need to write additional code (ifx statement) for each setup (i.e. for each \def\UseOption{...}), but usage is much simpler,

Code: Select all

pdflatex -jobname=SetupA filename VS pdflatex -jobname filename "\def\UseOption{opta,optb}\input{filename}"
So for those, which doesn't want to complicate source code is the first method, and for those who like simple command, the second.
Post Reply