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}

\rhead{My document \x}
\lhead{Left header}
\lfoot{\thepage\ ~of~\pageref{LastPage}}

\if\x 1 {

\if\x 2 {  

\if\x 3 {   

On Linux (Ubuntu), I wrote a makefile:

SHELL   = /bin/sh

    make tex
    make clean

    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}"  ; \

    echo "USAGE: make [all/tex/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

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.