2

I need to write several documents that are fairly close to each other, i.e.same structure of header/footer, call a common set of forms. I wrote a Main.tex document with a set of \if\x 1 { my document content}\fi to control the content of each document. My variable "x" is also used as information in the header.

Minimal example:

\documentclass[a4paper,10pt, ,landscape]{article}
\usepackage{fancyhdr}
\usepackage{lastpage}
%\newcommand\x{1}

\rhead{My document \x}
\lhead{Left header}
\chead{version:1.0}
\lfoot{\thepage\ ~of~\pageref{LastPage}}
\cfoot{}

\begin{document}
\if\x 1 {
  \include{FrontPage}
  \include{FormA}
  \include{FormB}
  \include{FormC}
}\fi

\if\x 2 {  
  \include{FrontPage}
  \include{FormA}
  \include{FormB}
  \include{FormB}
}\fi

\if\x 3 {   
  \include{FrontPage}
  \include{FromA}
  \include{FromC}
  \include{FormC}
}\fi 
\end{document}

On Linux (Ubuntu), I wrote a makefile:

SHELL   = /bin/sh

all:
    make tex
    make clean

tex:
    for number in 1 2 3; do \
        echo $$number ; \
        pdflatex -no-pdf --jobname=Mydocument-No-$$number "\newcommand\x{$$number} \input{main.tex}"  ; \
        pdflatex --jobname=Mydocument-No-$$number "\newcommand\x{$$number} \input{main.tex}"  ; \
    done;\

help:
    echo "USAGE: make [all/tex/clean]"

clean:
    rm -f *.aux *.dvi *.idx *.ilg *.ind *.log *.nav *.out *.snm *.xdv *.toc *~

Which call my main.tex file 3 times, sending the value of x to my latex document, and also renaming the output. At the end I get 3 pdf. I only have to write "make" in the Konsole of Kile to make it work.

Unfortunately, I now have to transfer this process under Windows - Any idea on how to write the equivalent of my makefile in Windows ? I have TeXnicCenter and Texmaker installed.

  • there are of course make implementations for windows, or you could write a loop in dos cmd syntax or use Lua (and the texlua that comes with tex) for a cross-platform alternative. – David Carlisle Nov 2 '17 at 17:42
  • 1
    Might be useful: stackoverflow.com/questions/17158419/… – Andrew Nov 2 '17 at 18:35
1

I solved this, by writing a makefile.bat for Windows as suggested by David Carlisle:

FOR %%i IN (1,2,3) DO (
echo %%i
pdflatex --jobname=Mydocument-No-%%i "\newcommand\x{%%i} \input{main.tex}"  
pdflatex --jobname=Mydocument-No-%%i "\newcommand\x{%%i} \input{main.tex}" 
)
DEL *.aux *.log *.backup

I run it by double clicking on the file.

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.