Generalcompiling another document from the current one

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
moshiko
Posts: 30
Joined: Fri May 08, 2009 9:03 am

compiling another document from the current one

Post by moshiko »

Hi,

I have two source files main.tex and A.tex.
Each file is standalone, so pdflatex main.tex gives main.pdf and similarly A.tex -> A.pdf.

My goal is to put what is in A.pdf in certain position in main.pdf.

Using the answer I got for my previous question:
http://www.latex-community.org/forum/vi ... =45&t=9655

I manage to use the textpos package like this:

Code: Select all

\begin{textblock}{2}(2.1,4.6)
\includegraphics[scale=1.4]{A.pdf}
\end{textblock}]
Note that I need to manuall crop A.pdf before doing the above, since otherwise it will also include all the margins which I don't need. (I use pdfcrop.pl for that).

My question:
-------------
Can I avoid creating A.pdf, cropping it and somehow convince latex to take A.tex and do the same ?
After all A.pdf was generated by Latex to begin with, so there should be someway to do something like this:

Code: Select all

\begin{textblock}{2}(2.1,4.6)
\specialcommand[scale=1.4]{A.tex}
\end{textblock}
where \specialcommand is something like \input, with the big difference that A.tex has its own documentclass, preamble, packages etc.

I would appreciate any idea.

thanks.
Last edited by moshiko on Wed Aug 11, 2010 11:53 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.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

compiling another document from the current one

Post by frabjous »

My first recommendation would be to use the trim, bb or viewport options to \includegraphics so that it doesn’t include the entire PDF; that way it doesn’t need to be cropped beforehand. See the graphicx package documentation for details.

That might not work, though if A.pdf would be different sizes on different compilations...

You could look at the subdocs package, but I doubt it’s what you want.

Simplest way is to write a shell script or batch file that calls the tools you need in order, and compile using that instead, e.g. (for Mac or linux):

Code: Select all

#!/bin/bash
pdflatex --interaction=nonstopmode A.tex
pdfcrop.pl A.pdf
pdflatex --interaction=nonstopmode main.tex
I suppose you could also use \write18 or similar commands to make LaTeX call external commands (assuming you've got -shell-escape or -enable-write18 enabled when you compile), but this doesn't seem any easier than just writing a script.
moshiko
Posts: 30
Joined: Fri May 08, 2009 9:03 am

Re: compiling another document from the current one

Post by moshiko »

Hi,

thanks for the reply.
Indeed, A.pdf does not have a fixed size.. In every run it can have a different size. I need something that will work for every size of A.pdf.

the subdocs is nice, but it only shares the .aux, doesn't really gives what I need.

Right now I am using an automatic shell script. The problem is that there are many files like A.pdf that I include in main.pdf. So, I need to pdflatex A1.tex, and pdfcrop, then for A2.tex and so on.
It would be more efficient to somehow include all the .tex files into one source code and then pdflatex at once.

any idea ?

thanks.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

compiling another document from the current one

Post by frabjous »

Normally you could just pust the code that generates the figures in place of the \includegraphics calls, but from your description of what your document is like, it isn’t clear whether or not you have to use external PDFs or not. A minimal example of the sort of thing involved would make it much easier to tell.

If you’re running a UNIX-like environment and your scripts are in bash, you can of course automate compiling them in your script too, e.g., with a script that compiled and cropped all .tex files in the folder other than main.tex then compiled main.tex:

Code: Select all

#!/bin/bash
for file in $(ls *.tex | grep -v 'main.tex') ; do
	pdflatex --interaction=nonstopmode "${file}.tex"
	pdfcrop.pl "${file}.pdf"
end
pdflatex --interaction=nonstopmode --synctex=1 main.tex
But you really haven't given us enough information to know what the best thing to do would be.
moshiko
Posts: 30
Joined: Fri May 08, 2009 9:03 am

compiling another document from the current one

Post by moshiko »

Hi,

Indeed A.tex has its own preamble, with packages and definitions that are in general different from those used in main.tex.

Here is an example:

Main.tex
----------

Code: Select all

\documentclass{article}
\usepackage{graphicx}
\usepackage[absolute]{textpos}
\usepackage{amsmath}
\pagestyle{empty}

\setlength{\TPHorizModule}{10mm}
\setlength{\TPVertModule}{\TPHorizModule}
\textblockorigin{0mm}{0mm} % start everything near the top-left corner
\setlength{\parindent}{0pt}

\begin{document}

\begin{textblock}{2}(3.1,6.6)
\includegraphics[scale=1]{A_crop.pdf}
\end{textblock}

This is something written in main.tex

\end{document}
A.tex
----------

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathpazo}
\usepackage{graphicx}
\usepackage{cite}
\usepackage{bbm}

\begin{document}

This is something written in A.tex

\end{document}


A_crop.pdf is generated from A.pdf using
perl pdfcrop.pl A.pdf A_crop.pdf

Notice the different font styles. I have hundreds of inclusions in main.tex.
Right now, I use an automatic script, which pdflatex every A.tex, crop it and finally pdflatex main.tex. Besides the time it takes, it requires me to make sure perl is installed. In addition, I get hundreds of temporary files from the compilation of all the A.tex files. I believe there should be some tricky way to include the source A.tex in latex *as is*, and direct him to compile it standalone, crop and insert as pdf. this way it is a compilation of a single file rather than hundreds compilation and pdfcrops.

I would appreciate any idea.

thanks.

p.s. attached is also main.pdf for convenience.
Attachments
main.pdf
(21.14 KiB) Downloaded 292 times
Post Reply