1

I have a file foo.tex

\documentclass{article}

\usepackage{pdfpages}
\newcommand{\hello}{Hello world!}

\begin{document}
\includepdf[pages=-]{bar}

This is foo.pdf.
\end{document}

The first page of this document is imported using the pdfpages package and the pdf is generated by another file bar.tex

\documentclass{amsart}

\title{Bar.pdf}

\begin{document}
\maketitle

This is bar.pdf.

% I want the macro \hello to be passed to this document.
\end{document}

The annoying this about this workflow is that altering bar.pdf requires that I re-compile bar.tex. I'd prefer it if bar.tex were automatically compiled every time I complile foo.tex. Is this possible? If so, is it possible for this to be done in such a way that passes macros defined by foo.tex to bar.tex?

I'm aware of a package called combine, but reading through the documentation hasn't convinced me that combine would solve my problem.

Update. The \write18 command appears to accomplish the task of compiling bar.tex when foo.tex is compiled.

\documentclass{article}

\immediate\write18{latex bar.tex}

\usepackage{pdfpages}
\newcommand{\hello}{Hello world!}


\begin{document}
\includepdf[pages=-]{bar}

This is foo.pdf.
\end{document}

However, I'm still not sure how to pass the \hello macro to bar.tex.

  • Have a look at the latexmk package. I've not ever played with it but I am fairly sure that it can do what you want. – Andrew Nov 17 '17 at 23:21
2

You can use shell-escape to run the second document, this assumes bash syntax in the shell you may need minor changes for other commandlines

bar.tex using \hello

\documentclass{amsart}

\title{Bar.pdf}

\begin{document}
\maketitle

This is bar.pdf.

% I want the macro \hello to be passed to this document.
\hello

\end{document}

main.tex

\documentclass{article}

\usepackage{pdfpages}
\newcommand{\hello}{Hello world!}

\immediate\write18{pdflatex \string\\def\string\\hello{\hello}\string\\input{bar}}

\begin{document}
\includepdf[pages=-]{bar}

This is foo.pdf.
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.