Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there a way to execute a .bat file directly from a latex document when I compile that document?

I would something like this:

\documentclass{article}

\begin{document}
\chapter{test}
bla bla bla
ecc...
\executebat{C:\...\...\...}
\end{document}
share|improve this question
    
Are you thinking to launching MakeIndex from inside your LaTeX run? –  egreg Dec 3 '12 at 17:10
3  
You want \write18. For that to work, you will need to compile with --shell-escape. –  G. Poore Dec 3 '12 at 18:49
    
@egreg Thanks, but I know your package "imakeidx" : ) –  FormlessCloud Dec 4 '12 at 17:13
add comment

1 Answer

up vote 5 down vote accepted

You have to run LaTeX (latex, pdflatex, xelatex or lualatex) with the -shell-escape option: then this code defines what you need.

\usepackage{pdftexcmds}
\makeatletter
\newcommand{\executebat}[1]{%
  \ifnum\pdf@shellescape=\@ne
    \immediate\write18{#1}%
  \else
    \GenericError{}{Shell escape not enabled}{}
      {You have to run (pdf)LaTeX with the option `-shell-escape'}%
  \fi
}
\makeatother

However, if your purpose is to run MakeIndex, then the imakeidx package does it without user intervention (not with the article class unless some precautions are taken).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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