I have done all sorts of searches on the internet and did not find an answer to this. What I want to do is while compiling a latex file, redirect part of the dvi (or pdf) output to one file and another part of the output to another file. Specific example would be to redirect the main text to something like projectdescription.dvi and bibliography to something like refs.dvi. I know that I can do this with the dvips of dviodfm filter by giving page ranges after the file is compiled. But is there anyway to give directives within the latex source file so that this redirection happens automatically. This makes is easier when text is added or deleted and the page ranges change.
I want something like
\begin{document}
% redirect output to proj.dvi -- whatever this command is
main text
% redirect output from this point on to refs.dvi
references
\end{document}
and this should generate two dvi files with the appropriate content. Sort of like what \input does to the input text, only in reverse for the output.
Any help would be appreciated.
Thanks.
Mihran
General ⇒ How to redirect latex output to multiple files?
NEW: TikZ book now 40% off at Amazon.com for a short time.

- Stefan Kottwitz
- Site Admin
- Posts: 10348
- Joined: Mon Mar 10, 2008 9:44 pm
Re: How to redirect latex output to multiple files?
Hi tuceryan,
welcome to this board!
I like to say welcome to you. But I'm afraid it may not be possible what you want to do, at least I don't know a way. Either I would split with pdfpages later, or spilt into several tex files before.
Stefan
welcome to this board!
I like to say welcome to you. But I'm afraid it may not be possible what you want to do, at least I don't know a way. Either I would split with pdfpages later, or spilt into several tex files before.
Stefan
Re: How to redirect latex output to multiple files?
Hmm, that's a tough one. I'm not knowledgeable enough to make any strong statements about what's possible in TeX and what not but I've certainly never heard of outputting .dvi to several files during one job. So I would say that this scenario is a no go.
However, if all you want is to extract some specific page ranges in an automated way, here's what I would do.
During latex run write to an external file (or job log file) messages about the page ranges that you want to extract. After latex finishes read that info and run dvips as usual. For example placing in your document:
\immediate\write18{echo You are on \thepage\space page> msg.txt}
just after \begin{document} will create msg.txt file containing: "You are on 1 page". You will need to enable write18 for this to work (--enable-write18 switch in MiKTeX). In this way you can even create batch scripts that will do the appropriate postprocessing and just call them after latex finishes.
Cheers,
Tomek
However, if all you want is to extract some specific page ranges in an automated way, here's what I would do.
During latex run write to an external file (or job log file) messages about the page ranges that you want to extract. After latex finishes read that info and run dvips as usual. For example placing in your document:
\immediate\write18{echo You are on \thepage\space page> msg.txt}
just after \begin{document} will create msg.txt file containing: "You are on 1 page". You will need to enable write18 for this to work (--enable-write18 switch in MiKTeX). In this way you can even create batch scripts that will do the appropriate postprocessing and just call them after latex finishes.
Cheers,
Tomek
Re: How to redirect latex output to multiple files?
Thanks for the pointers. Since I did not find anything in the TeX book and on google, you are probably right that I can't do it. So, I'll do it as a filter after the fact. However, I like your idea of generating a script to be run after the latex job. I'll see if I can utilize it somehow.
Thanks again.
Mihran
Thanks again.
Mihran
How to redirect latex output to multiple files?
Your problem can be solved with the \include directives. For this to work, you need take the two parts of your document that you want to go into separate output files and put them in separate LaTeX child documents. Then, you make a master document that \include's these two parts.
Now, you can control which of these parts appear in the output with the \includeonly directive. The part you omit will be invisible, although its page numbers and cross references will be preserved. You can run latex twice, with different parts included, to produce different outputs. Alternatively, you can make two master documents with different names that include the different parts. I found this feature in the following URL, which has a longer description and examples:
http://www.ics.mq.edu.au/~rdale/resourc ... truct.html
-Cengiz
Now, you can control which of these parts appear in the output with the \includeonly directive. The part you omit will be invisible, although its page numbers and cross references will be preserved. You can run latex twice, with different parts included, to produce different outputs. Alternatively, you can make two master documents with different names that include the different parts. I found this feature in the following URL, which has a longer description and examples:
http://www.ics.mq.edu.au/~rdale/resourc ... truct.html
-Cengiz
Re: How to redirect latex output to multiple files?
Using \includeonly will only let the excluded files unprocessed. It will not exclude them from the output.
How to redirect latex output to multiple files?
It does exclude them from the output for me.miltos wrote:Using \includeonly will only let the excluded files unprocessed. It will not exclude them from the output.